Skip to content

Commit

Permalink
Allow completed logs to be loaded for Analysis
Browse files Browse the repository at this point in the history
Whereas previously the files were not written back to disk first, here
we do. This is because I don't think I will continue working in Dash
(#97), so I feel like this temporary solution is good enough.
  • Loading branch information
PGijsbers committed Jun 23, 2020
1 parent 8f201e2 commit aa7a77f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
Binary file removed gama/dashboard/gama_model.pkl
Binary file not shown.
39 changes: 19 additions & 20 deletions gama/dashboard/pages/analysispage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# import base64
import base64
import itertools
import os
import shutil
import uuid
from typing import Dict, List, Optional

import dash_core_components as dcc
Expand Down Expand Up @@ -174,26 +178,21 @@ def build_page(self, app, controller):
def load_logs(self, list_of_contents, list_of_names):
# global aggregate_dataframe
if list_of_contents is not None:
tmp_dir = f"tmp_{str(uuid.uuid4())}"
os.makedirs(tmp_dir)
for content, filename in zip(list_of_contents, list_of_names):
# content_type, content_string = content.split(",")
# decoded = base64.b64decode(content_string).decode("utf-8")
# log_lines = decoded.splitlines()
dirname = r"C:\Users\Work\GamaLog"
report = GamaReport(dirname)
self.reports[filename] = report

# eval_copy = report.evaluations.copy()
# eval_copy["search_method"] = report.search_method
# if aggregate_dataframe is None:
# eval_copy["log_no"] = 0
# eval_copy["filename"] = filename
# aggregate_dataframe = eval_copy
# else:
# eval_copy["log_no"] = len(
# aggregate_dataframe["log_no"].unique())
# eval_copy["filename"] = filename
# aggregate_dataframe = pd.concat(
# [aggregate_dataframe, eval_copy])
content_type, content_string = content.split(",")
decoded = base64.b64decode(content_string).decode("utf-8")
with open(os.path.join(tmp_dir, filename), "w") as fh:
fh.write(decoded)

report = GamaReport(tmp_dir)
report_name = report.search_method
for i in itertools.count():
if f"{report_name}_{i}" not in self.reports:
break
self.reports[f"{report_name}_{i}"] = report
shutil.rmtree(tmp_dir)
return [{"label": logname, "value": logname} for logname in self.reports]
return []

Expand Down
9 changes: 6 additions & 3 deletions gama/logging/GamaReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ def __init__(self, log_directory: str):
self.metrics += ["length"]

self.incomplete = len(self.phases) < 3
self.update() # updates self.evaluations and self.method_data
# [ ] Dashboard -- how point to directory??
self.update(force=True) # updates self.evaluations and self.method_data
# [ ] Dashboard -- how point to directory?? => #97

self.search_method = self.hyperparameters["search_method"]
self.method_data = self.evaluations

def update(self) -> bool:
def update(self, force: bool = False) -> bool:
if not force and not self.incomplete:
return False

with open(os.path.join(self._log_directory, "evaluations.log"), "r") as fh:
header = fh.readline()[:-1]
self._last_tell = max(self._last_tell, fh.tell())
Expand Down

0 comments on commit aa7a77f

Please sign in to comment.