Skip to content

Commit

Permalink
Moved favourite attribute of a run into the metadata for the run
Browse files Browse the repository at this point in the history
  • Loading branch information
gitjannes committed Dec 19, 2024
1 parent 0b69258 commit a4333e5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
3 changes: 0 additions & 3 deletions protzilla/disk_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def write(file_path: Path, dataframe: pd.DataFrame):
class KEYS:
# We add this here to avoid typos and signal to the developer that accessing the keys should be done through this class only
CURRENT_STEP_INDEX = "current_step_index"
FAVOURITE = "favourite"
STEPS = "steps"
STEP_OUTPUTS = "output"
STEP_FORM_INPUTS = "form_inputs"
Expand Down Expand Up @@ -124,7 +123,6 @@ def read_run(self, file: Path | None = None) -> StepManager:
run.get(KEYS.CURRENT_STEP_INDEX, 0), len(step_manager.all_steps) - 1
),
)
step_manager.favourite = run.get(KEYS.FAVOURITE, False)
return step_manager

def write_run(self, step_manager: StepManager) -> None:
Expand All @@ -136,7 +134,6 @@ def write_run(self, step_manager: StepManager) -> None:
self.clean_dataframes_dir(step_manager)
run = {}
run[KEYS.CURRENT_STEP_INDEX] = step_manager.current_step_index
run[KEYS.FAVOURITE] = step_manager.favourite
run[KEYS.DF_MODE] = step_manager.df_mode
run[KEYS.STEPS] = []
for step in step_manager.all_steps:
Expand Down
8 changes: 4 additions & 4 deletions protzilla/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def get_available_runinfo() -> tuple[list[dict[str, str | list[str]]], list[dict
for step in steps:
step_names.append(step.display_name)

tags = set()
metadata_yaml_path = os.path.join(directory_path, "metadata.yaml")
if os.path.isfile(metadata_yaml_path):
yaml_operator = YamlOperator()
metadata = yaml_operator.read(metadata_yaml_path)
tags = metadata.get("tags")
tags = metadata.get("tags", set())
favourite = metadata.get("favourite", False)

for tag in tags:
all_tags.add(tag)
Expand All @@ -62,11 +62,11 @@ def get_available_runinfo() -> tuple[list[dict[str, str | list[str]]], list[dict
"modification_date": datetime.datetime.fromtimestamp(modification_time).strftime("%d %m %Y"),
"memory_mode": step_manager.df_mode,
"run_steps" : step_names,
"favourite_status" : step_manager.favourite,
"favourite_status" : favourite,
"run_tags": tags
}

if step_manager.favourite:
if favourite:
runs_favourited.append(run)
else:
runs.append(run)
Expand Down
1 change: 0 additions & 1 deletion protzilla/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ def __init__(
self.df_mode = df_mode
self.disk_operator = disk_operator
self.current_step_index = 0
self.favourite = False #might cause problems because of backwards-compatibility
self.importing = []
self.data_preprocessing = []
self.data_analysis = []
Expand Down
20 changes: 12 additions & 8 deletions ui/runs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,19 @@ def favourite(request: HttpRequest):
else:
favourite_status = True

disk_operator = DiskOperator(run_name, "dummy_workflow_name")
directory_path = os.path.join(paths.RUNS_PATH, run_name)
yaml_path = os.path.join(directory_path, "run.yaml")
step_manager = disk_operator.read_run(yaml_path)
step_manager.favourite = not favourite_status
disk_operator.write_run(step_manager)
metadata_yaml_path = os.path.join(directory_path, "metadata.yaml")

yaml_operator = YamlOperator()
metadata = {}
if not os.path.exists(metadata_yaml_path):
with open(metadata_yaml_path, 'w') as file:
pass
else:
metadata = yaml_operator.read(metadata_yaml_path)

metadata["favourite"]= not metadata.get("favourite", False)
yaml_operator.write(Path(metadata_yaml_path), metadata)

return HttpResponseRedirect(reverse("runs:index"))

Expand Down Expand Up @@ -259,11 +266,8 @@ def add_tag(request: HttpRequest):
metadata = yaml_operator.read(metadata_yaml_path)
tags_from_metadata = metadata.get("tags")
tags.update(tags_from_metadata)
print(tags)
tags.add(run_tag)
print(tags)
metadata["tags"]= tags
print(metadata)
yaml_operator.write(Path(metadata_yaml_path), metadata)

return HttpResponseRedirect(reverse("runs:index"))
Expand Down

0 comments on commit a4333e5

Please sign in to comment.