chap-analytics 0.2.1__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/CHANGELOG.md +14 -1
  2. {chap_analytics-0.2.1/chap_analytics.egg-info → chap_analytics-0.2.2}/PKG-INFO +1 -1
  3. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/__init__.py +1 -1
  4. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/load.py +22 -1
  5. {chap_analytics-0.2.1 → chap_analytics-0.2.2/chap_analytics.egg-info}/PKG-INFO +1 -1
  6. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics.egg-info/SOURCES.txt +1 -0
  7. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/pyproject.toml +1 -1
  8. chap_analytics-0.2.2/tests/test_typescript_store.py +60 -0
  9. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/LICENSE +0 -0
  10. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/MANIFEST.in +0 -0
  11. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/README.md +0 -0
  12. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_patch.py +0 -0
  13. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_report/report.css +0 -0
  14. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_report/report.html +0 -0
  15. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_report/report.js +0 -0
  16. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_report/stats.js +0 -0
  17. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_vendor/LICENSE.vega +0 -0
  18. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_vendor/LICENSE.vega-embed +0 -0
  19. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_vendor/LICENSE.vega-lite +0 -0
  20. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_vendor/README.md +0 -0
  21. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_vendor/render.js +0 -0
  22. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_vendor/vega-embed.min.js +0 -0
  23. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_vendor/vega-lite.min.js +0 -0
  24. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/_vendor/vega.min.js +0 -0
  25. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/briefs.py +0 -0
  26. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/charts.py +0 -0
  27. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/export.py +0 -0
  28. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/frames.py +0 -0
  29. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/graph.py +0 -0
  30. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/models.py +0 -0
  31. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/py.typed +0 -0
  32. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/report.py +0 -0
  33. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/sample.py +0 -0
  34. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/schema.py +0 -0
  35. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/stats.py +0 -0
  36. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics/watch.py +0 -0
  37. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics.egg-info/dependency_links.txt +0 -0
  38. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics.egg-info/requires.txt +0 -0
  39. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/chap_analytics.egg-info/top_level.txt +0 -0
  40. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/examples/build_notebook.py +0 -0
  41. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/examples/chap_analytics_walkthrough.ipynb +0 -0
  42. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/examples/support_desk.py +0 -0
  43. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/setup.cfg +0 -0
  44. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/conftest.py +0 -0
  45. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/js_stats_runner.js +0 -0
  46. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_charts_and_briefs.py +0 -0
  47. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_differential.py +0 -0
  48. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_example.py +0 -0
  49. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_from_url_scheme.py +0 -0
  50. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_graph.py +0 -0
  51. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_handoff_and_routing.py +0 -0
  52. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_identity.py +0 -0
  53. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_notebook.py +0 -0
  54. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_projection.py +0 -0
  55. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_redaction_and_malformed.py +0 -0
  56. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_refusals.py +0 -0
  57. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_report.py +0 -0
  58. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_review_passes.py +0 -0
  59. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_sample_and_export.py +0 -0
  60. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_stats.py +0 -0
  61. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_successors.py +0 -0
  62. {chap_analytics-0.2.1 → chap_analytics-0.2.2}/tests/test_watch_export_models.py +0 -0
@@ -4,7 +4,20 @@
4
4
  so a protocol release moves the coordinator packages together and leaves this
5
5
  one where it is until the tables or the analyses change.
6
6
 
7
- ## Unreleased
7
+ ## 0.2.2
8
+
9
+ Reads the store of the TypeScript coordinator, which the Node templates of
10
+ `create-chap-app` run. Install it with `chap-coordinator` 0.3.0 or later where
11
+ the `coordinator` extra drives a live coordinator.
12
+
13
+ ### Fixed
14
+
15
+ - **A TypeScript coordinator's store.** `from_sqlite` and `from_json` read a
16
+ workspace snapshot the TypeScript coordinator wrote, which holds its tasks,
17
+ members, overrides and the other collections as lists where the Python
18
+ coordinator holds them as objects keyed by id. Reading one stopped with an
19
+ `AttributeError`; the collections are now keyed on load, and both
20
+ coordinators' stores project to the same tables.
8
21
 
9
22
  ## 0.2.1
10
23
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chap-analytics
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report
5
5
  Author-email: Brightbeam AI <oss@brightbeam.com>
6
6
  License-Expression: Apache-2.0
@@ -41,7 +41,7 @@ The layers, bottom up:
41
41
  """
42
42
  from __future__ import annotations
43
43
 
44
- __version__ = "0.2.1"
44
+ __version__ = "0.2.2"
45
45
 
46
46
  from . import briefs, charts, export, graph, models, sample, stats, watch # noqa: E402
47
47
  from .frames import Frames, frames # noqa: E402
@@ -217,12 +217,33 @@ def _redact_state(state: dict | None, redact: Redactor | None) -> dict | None:
217
217
  return state
218
218
 
219
219
 
220
+ # The collections a workspace snapshot holds, and the field each is keyed by.
221
+ # The Python coordinator writes them as objects keyed by that field; the
222
+ # TypeScript coordinator writes them as lists. The projection reads objects.
223
+ _KEYED_COLLECTIONS = {
224
+ "tasks": "id", "overrides": "id", "whispers": "id", "deliberations": "id",
225
+ "handoffs": "id", "snapshots": "id", "route_decisions": "id", "members": "uri",
226
+ }
227
+
228
+
229
+ def _keyed_state(state: dict | None) -> dict | None:
230
+ """A snapshot with every collection keyed by id, whichever coordinator wrote it."""
231
+ if not isinstance(state, dict):
232
+ return state
233
+ out = dict(state)
234
+ for name, key in _KEYED_COLLECTIONS.items():
235
+ value = out.get(name)
236
+ if isinstance(value, list):
237
+ out[name] = {item[key]: item for item in value if isinstance(item, dict) and isinstance(item.get(key), str)}
238
+ return out
239
+
240
+
220
241
  def _chain(workspace: str, events: Iterable[dict], state: dict | None,
221
242
  source: str, redact: Redactor | None) -> Chain:
222
243
  evs = _apply_redaction(list(events), redact)
223
244
  evs.sort(key=lambda e: e.get("seq", 0) if isinstance(e, dict) else 0)
224
245
  return Chain(workspace=workspace, events=evs,
225
- state=_redact_state(state, redact), source=source)
246
+ state=_redact_state(_keyed_state(state), redact), source=source)
226
247
 
227
248
 
228
249
  def from_json(path: str, *, workspace: str | None = None, redact: Redactor | None = None) -> Chain:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chap-analytics
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report
5
5
  Author-email: Brightbeam AI <oss@brightbeam.com>
6
6
  License-Expression: Apache-2.0
@@ -56,4 +56,5 @@ tests/test_review_passes.py
56
56
  tests/test_sample_and_export.py
57
57
  tests/test_stats.py
58
58
  tests/test_successors.py
59
+ tests/test_typescript_store.py
59
60
  tests/test_watch_export_models.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "chap-analytics"
7
- version = "0.2.1"
7
+ version = "0.2.2"
8
8
  description = "The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -0,0 +1,60 @@
1
+ """A store the TypeScript coordinator wrote reads like one the Python coordinator wrote.
2
+
3
+ The TypeScript snapshot holds its collections as lists; the Python one holds
4
+ them as objects keyed by id. The same workspace, written both ways, has to
5
+ project to the same tables.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import sqlite3
11
+
12
+ import pandas as pd
13
+
14
+ from chap_analytics import frames, from_json, from_sqlite
15
+ from chap_analytics.sample import support_desk
16
+
17
+ KEYS = {"tasks": "id", "overrides": "id", "whispers": "id", "deliberations": "id",
18
+ "handoffs": "id", "snapshots": "id", "route_decisions": "id", "members": "uri"}
19
+
20
+
21
+ def as_typescript(state: dict) -> dict:
22
+ """The snapshot as the TypeScript coordinator writes it: collections as lists."""
23
+ out = dict(state)
24
+ for name in KEYS:
25
+ if isinstance(out.get(name), dict):
26
+ out[name] = list(out[name].values())
27
+ return out
28
+
29
+
30
+ def write_store(path, snapshot: dict) -> None:
31
+ con = sqlite3.connect(path)
32
+ con.execute("CREATE TABLE chap_workspaces (id TEXT PRIMARY KEY, version INTEGER NOT NULL, "
33
+ "data TEXT NOT NULL, updated_at TEXT NOT NULL)")
34
+ con.execute("INSERT INTO chap_workspaces VALUES (?, 1, ?, '2026-01-01T00:00:00Z')",
35
+ (snapshot["id"], json.dumps(snapshot)))
36
+ con.commit()
37
+ con.close()
38
+
39
+
40
+ def test_a_typescript_snapshot_projects_to_the_same_tables(tmp_path):
41
+ chain = support_desk()
42
+ snapshot = {**chain.state, "id": chain.workspace, "audit": chain.events}
43
+ python_store, ts_store = tmp_path / "py.db", tmp_path / "ts.db"
44
+ write_store(python_store, snapshot)
45
+ write_store(ts_store, as_typescript(snapshot))
46
+ assert isinstance(json.loads(sqlite3.connect(ts_store).execute("SELECT data FROM chap_workspaces").fetchone()[0])["tasks"], list)
47
+ a = frames(from_sqlite(str(python_store)))
48
+ b = frames(from_sqlite(str(ts_store)))
49
+ for name in ("tasks", "decisions", "overrides", "events"):
50
+ pd.testing.assert_frame_equal(getattr(a, name), getattr(b, name), check_like=True)
51
+ assert len(b.tasks) == len(a.tasks) > 0
52
+
53
+
54
+ def test_from_json_reads_a_typescript_snapshot(tmp_path):
55
+ chain = support_desk()
56
+ path = tmp_path / "ts.json"
57
+ path.write_text(json.dumps(as_typescript({**chain.state, "id": chain.workspace, "audit": chain.events})))
58
+ b = frames(from_json(str(path)))
59
+ a = frames(chain)
60
+ pd.testing.assert_frame_equal(a.tasks, b.tasks, check_like=True)
File without changes
File without changes
File without changes