diff --git a/flatsurvey/cache/cache.py b/flatsurvey/cache/cache.py index eea3618..c26c2fd 100644 --- a/flatsurvey/cache/cache.py +++ b/flatsurvey/cache/cache.py @@ -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. """ # ********************************************************************* @@ -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): @@ -174,7 +177,7 @@ def bindings(cls, jsons, pickles): EXAMPLES:: - >>> Cache.bindings([]) + >>> Cache.bindings([], None) [cache binding to Cache] """ @@ -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""" diff --git a/flatsurvey/jobs/completely_cylinder_periodic.py b/flatsurvey/jobs/completely_cylinder_periodic.py index 4a317b3..a626bfe 100644 --- a/flatsurvey/jobs/completely_cylinder_periodic.py +++ b/flatsurvey/jobs/completely_cylinder_periodic.py @@ -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( @@ -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: diff --git a/flatsurvey/jobs/cylinder_periodic_direction.py b/flatsurvey/jobs/cylinder_periodic_direction.py index 8796900..489d039 100644 --- a/flatsurvey/jobs/cylinder_periodic_direction.py +++ b/flatsurvey/jobs/cylinder_periodic_direction.py @@ -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( @@ -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}]} """ diff --git a/flatsurvey/jobs/flow_decomposition.py b/flatsurvey/jobs/flow_decomposition.py index e90c143..4ae5d55 100644 --- a/flatsurvey/jobs/flow_decomposition.py +++ b/flatsurvey/jobs/flow_decomposition.py @@ -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", "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", "pickle": "..."}, "cylinders": 1, "minimal": 0, "undetermined": 0, "value": null}]} """ start = time.perf_counter() diff --git a/flatsurvey/jobs/orbit_closure.py b/flatsurvey/jobs/orbit_closure.py index b18296e..f51b4da 100644 --- a/flatsurvey/jobs/orbit_closure.py +++ b/flatsurvey/jobs/orbit_closure.py @@ -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}): @@ -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 diff --git a/flatsurvey/jobs/undetermined_interval_exchange_transformation.py b/flatsurvey/jobs/undetermined_interval_exchange_transformation.py index 3955a3a..64f09d0 100644 --- a/flatsurvey/jobs/undetermined_interval_exchange_transformation.py +++ b/flatsurvey/jobs/undetermined_interval_exchange_transformation.py @@ -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: diff --git a/flatsurvey/reporting/__init__.py b/flatsurvey/reporting/__init__.py index b2c0e6f..1dab193 100644 --- a/flatsurvey/reporting/__init__.py +++ b/flatsurvey/reporting/__init__.py @@ -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] diff --git a/flatsurvey/reporting/json.py b/flatsurvey/reporting/json.py index 57b2de6..6d7e9a6 100644 --- a/flatsurvey/reporting/json.py +++ b/flatsurvey/reporting/json.py @@ -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""" @@ -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 @@ -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 diff --git a/flatsurvey/reporting/reporter.py b/flatsurvey/reporting/reporter.py index cb92dba..ac99bc9 100644 --- a/flatsurvey/reporting/reporter.py +++ b/flatsurvey/reporting/reporter.py @@ -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:: @@ -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:: diff --git a/flatsurvey/survey.py b/flatsurvey/survey.py index d619079..dcc76ac 100644 --- a/flatsurvey/survey.py +++ b/flatsurvey/survey.py @@ -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. Surfaces: ngons The translation surfaces that come from unfolding n-gons. diff --git a/flatsurvey/worker/worker.py b/flatsurvey/worker/worker.py index b94c21d..511ceae 100644 --- a/flatsurvey/worker/worker.py +++ b/flatsurvey/worker/worker.py @@ -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. diff --git a/flatsurvey/reporting/yaml.py b/unsupported/reporting/yaml.py similarity index 97% rename from flatsurvey/reporting/yaml.py rename to unsupported/reporting/yaml.py index dc6a64e..1cffb10 100644 --- a/flatsurvey/reporting/yaml.py +++ b/unsupported/reporting/yaml.py @@ -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"""