-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
258 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .memory_storage import MemoryStorageCodelet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import json | ||
from typing import Any | ||
|
||
from cst_python.core.entities import Memory | ||
|
||
class MemoryEncoder(json.JSONEncoder): | ||
def default(self, memory:Memory): | ||
return MemoryEncoder.to_dict(memory) | ||
|
||
@staticmethod | ||
def to_dict(memory:Memory, jsonify_info:bool=False): | ||
data = { | ||
"timestamp": memory.get_timestamp(), | ||
"evaluation": memory.get_evaluation(), | ||
"I": memory.get_info(), | ||
"name": memory.get_name(), | ||
"id": memory.get_id() | ||
} | ||
|
||
if jsonify_info: | ||
data["I"] = json.dumps(data["I"]) | ||
|
||
return data | ||
|
||
def load_memory(memory:Memory, memory_dict:dict[str,Any], load_json:bool=True): | ||
memory.set_evaluation(float(memory_dict["evaluation"])) | ||
memory.set_id(int(memory_dict["id"])) | ||
|
||
info_json = memory_dict["I"] | ||
info = json.loads(info_json) | ||
|
||
memory.set_info(info) |
Oops, something went wrong.