Skip to content

Commit

Permalink
Add timestamps to result reports
Browse files Browse the repository at this point in the history
and stop maintenance of yaml reports since we are not planning on using
them currently.
  • Loading branch information
saraedum committed Jun 21, 2024
1 parent 94549a0 commit 3287361
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 34 deletions.
13 changes: 8 additions & 5 deletions flatsurvey/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
Usage: worker local-cache [OPTIONS]
A cache of previous results stored in local JSON files.
Options:
-j, --json PATH JSON files to read cached data from or a directory to read recursively
--help Show this message and exit.
-j, --json PATH JSON files to read cached data from or a directory to read
recursively
-p, --pickles DIR directory of pickle files to resolve references in JSON
files
--help Show this message and exit.
"""
# *********************************************************************
Expand Down Expand Up @@ -165,7 +168,7 @@ def command(self):
['local-cache']
"""
return ["local-cache"] + [f"--json={json.name}" for json in self._jsons] + [f"--pickles={pickles.name}"]
return ["local-cache"] + [f"--json={json.name}" for json in self._jsons] + ([f"--pickles={self._pickles.name}"] if self._pickles is not None else [])

@classmethod
def bindings(cls, jsons, pickles):
Expand All @@ -174,7 +177,7 @@ def bindings(cls, jsons, pickles):
EXAMPLES::
>>> Cache.bindings([])
>>> Cache.bindings([], None)
[cache binding to Cache]
"""
Expand Down Expand Up @@ -207,7 +210,7 @@ def deform(self, deformation):
{'bindings': [cache binding to Cache]}
"""
return {"bindings": Cache.bindings(jsons=self._jsons)}
return {"bindings": Cache.bindings(jsons=self._jsons, pickles=self._pickles)}

def sources(self, *sources):
r"""
Expand Down
8 changes: 4 additions & 4 deletions flatsurvey/jobs/completely_cylinder_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ async def consume_cache(self):
The cached verdict can be reported back in JSON format::
>>> log.flush()
{"surface": {...}, "completely-cylinder-periodic": [{"cached": true, "value": false}]}
>>> log.flush() # doctest: +ELLIPSIS
{"surface": {...}, "completely-cylinder-periodic": [{"timestamp": ..., "cached": true, "value": false}]}
"""
results = self._cache.get(
Expand Down Expand Up @@ -270,8 +270,8 @@ async def report(self, result=None, **kwargs):
>>> import asyncio
>>> asyncio.run(ccp.report(result=False))
>>> report.flush()
{"surface": {...}, "completely-cylinder-periodic": [{"cylinder_periodic_directions": 0, "undetermined_directions": 0, "value": false}]}
>>> report.flush() # doctest: +ELLIPSIS
{"surface": {...}, "completely-cylinder-periodic": [{"timestamp": ..., "cylinder_periodic_directions": 0, "undetermined_directions": 0, "value": false}]}
"""
if self._resolved != Goal.COMPLETED:
Expand Down
6 changes: 3 additions & 3 deletions flatsurvey/jobs/cylinder_periodic_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ async def consume_cache(self):
>>> import asyncio
>>> asyncio.run(goal.consume_cache())
>>> report.flush()
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "cylinder-periodic-direction": [{"cached": true, "value": true}]}
>>> report.flush() # doctest: +ELLIPSIS
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "cylinder-periodic-direction": [{"timestamp": ..., "cached": true, "value": true}]}
"""
results = self._cache.get(
Expand Down Expand Up @@ -245,7 +245,7 @@ async def _consume(self, decomposition, cost):
>>> asyncio.run(cpd.report())
>>> report.flush()
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "cylinder-periodic-direction": [{"directions": 1, "value": true}]}
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "cylinder-periodic-direction": [{"timestamp": ..., "directions": 1, "value": true}]}
"""
Expand Down
4 changes: 2 additions & 2 deletions flatsurvey/jobs/flow_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ async def _consume(self, orientation, cost):
>>> asyncio.run(decompositions.produce())
True
>>> report.flush()
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "flow-decompositions": [{"orientation": {"type": "Vector<eantic::renf_elem_class>", "pickle": "..."}, "cylinders": 1, "minimal": 0, "undetermined": 0, "value": null}]}
>>> report.flush() # doctest: +ELLIPSIS
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "flow-decompositions": [{"timestamp": ..., "orientation": {"type": "Vector<eantic::renf_elem_class>", "pickle": "..."}, "cylinders": 1, "minimal": 0, "undetermined": 0, "value": null}]}
"""
start = time.perf_counter()
Expand Down
8 changes: 4 additions & 4 deletions flatsurvey/jobs/orbit_closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ async def consume_cache(self):
>>> import asyncio
>>> asyncio.run(goal.consume_cache())
>>> report.flush()
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "orbit-closure": [{"dense": true, "cached": true, "value": null}]}
>>> report.flush() # doctest: +ELLIPSIS
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "orbit-closure": [{"timestamp": ..., "dense": true, "cached": true, "value": null}]}
"""
with self._cache.defaults({"dense": None}):
Expand Down Expand Up @@ -301,8 +301,8 @@ async def _consume(self, decomposition, cost):
True
>>> asyncio.run(oc.report())
>>> report.flush()
{"surface": {"angles": [1, 3, 5], "type": "Ngon", "pickle": "..."}, "orbit-closure": [{"dimension": 6, "directions": 1, "directions_with_cylinders": 1, "dense": true, "value": {"type": "GL2ROrbitClosure", "pickle": "..."}}]}
>>> report.flush() # doctest: +ELLIPSIS
{"surface": {"angles": [1, 3, 5], "type": "Ngon", "pickle": "..."}, "orbit-closure": [{"timestamp": ..., "dimension": 6, "directions": 1, "directions_with_cylinders": 1, "dense": true, "value": {"type": "GL2ROrbitClosure", "pickle": "..."}}]}
"""
self._directions += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ async def consume_cache(self):
>>> import asyncio
>>> asyncio.run(goal.consume_cache())
>>> report.flush()
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "undetermined-iet --cache-only": [{"iets": ["IET(\u2026)", "IET(\u2026)"], "cached": true, "value": null}]}
>>> report.flush() # doctest: +ELLIPSIS
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "undetermined-iet --cache-only": [{"timestamp": ..., "iets": ["IET(\u2026)", "IET(\u2026)"], "cached": true, "value": null}]}
"""
if not self._cache_only:
Expand Down
3 changes: 1 addition & 2 deletions flatsurvey/reporting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from flatsurvey.reporting.json import Json
from flatsurvey.reporting.log import Log
from flatsurvey.reporting.report import Report
from flatsurvey.reporting.yaml import Yaml
from flatsurvey.reporting.progress import Progress

commands = [Log.click, Yaml.click, Json.click, Report.click, Progress.click]
commands = [Log.click, Json.click, Report.click, Progress.click]
14 changes: 9 additions & 5 deletions flatsurvey/reporting/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ async def result(self, source, result, **kwargs):
>>> asyncio.run(json.result(source=None, result=True))
"""
from datetime import datetime, timezone

result = self._simplify(result, **{"timestamp": str(datetime.now(timezone.utc)), **kwargs})

self._data.setdefault(str(source), [])
self._data[str(source)].append(self._simplify(result, **kwargs))
self._data[str(source)].append(result)

def _serialize_to_pickle(self, obj):
r"""
Expand Down Expand Up @@ -181,8 +185,8 @@ def _simplify_unknown(self, value):
>>> import asyncio
>>> asyncio.run(json.result("verdict", result=asyncio))
>>> json.flush()
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "verdict": [{"type": "module", "pickle": "..."}]}
>>> json.flush() # doctest: +ELLIPSIS
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "verdict": [{"timestamp": ..., "value": {"type": "module", "pickle": "..."}}]}
"""
return value
Expand All @@ -203,8 +207,8 @@ def flush(self):
Note that each result is reported individually, so the "verdict" is a list here::
>>> json.flush()
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "verdict": [true]}
>>> json.flush() # doctest: +ELLIPSIS
{"surface": {"angles": [1, 1, 1], "type": "Ngon", "pickle": "..."}, "verdict": [{"timestamp": ..., "value": true}]}
"""
import json
Expand Down
8 changes: 4 additions & 4 deletions flatsurvey/reporting/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def _simplify_primitive(self, value):
EXAMPLES::
>>> from flatsurvey.reporting import Yaml
>>> from flatsurvey.reporting import Json
>>> from flatsurvey.surfaces import Ngon
>>> surface = Ngon((1, 1, 1))
>>> log = Yaml(surface)
>>> log = Json(surface)
Rewrites SageMath integers as Python integers::
Expand Down Expand Up @@ -172,10 +172,10 @@ def _simplify(self, *args, **kwargs):
EXAMPLES::
>>> from flatsurvey.reporting import Yaml
>>> from flatsurvey.reporting import Json
>>> from flatsurvey.surfaces import Ngon
>>> surface = Ngon((1, 1, 1))
>>> log = Yaml(surface)
>>> log = Json(surface)
Combines arguments and keyword arguments::
Expand Down
1 change: 0 additions & 1 deletion flatsurvey/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
log Writes progress and results as an unstructured log file.
progress Reports progress on the command line.
report Generic reporting of results.
yaml Writes results to a YAML file.
<BLANKLINE>
Surfaces:
ngons The translation surfaces that come from unfolding n-gons.
Expand Down
1 change: 0 additions & 1 deletion flatsurvey/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
log Writes progress and results as an unstructured log file.
progress Reports progress on the command line.
report Generic reporting of results.
yaml Writes results to a YAML file.
Surfaces:
ngon Unfolding of an n-gon with prescribed angles.
pickle A base64 encoded pickle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ async def result(self, source, result, **kwargs):
- orientation: ...
"""
from datetime import datetime, timezone

result = self._simplify(result, **{"timestamp": str(datetime.now(timezone.utc)), **kwargs})

self._data.setdefault(str(source), [])
self._data[str(source)].append(self._simplify(result, **kwargs))
self._data[str(source)].append(result)

def _simplify_unknown(self, value):
r"""
Expand Down

0 comments on commit 3287361

Please sign in to comment.