Skip to content

refactor: Consolidate calculated data documents into shared mapping#1223

Open
nathan-stender wants to merge 4 commits into
mainfrom
refactor/consolidate-calculated-data-documents
Open

refactor: Consolidate calculated data documents into shared mapping#1223
nathan-stender wants to merge 4 commits into
mainfrom
refactor/consolidate-calculated-data-documents

Conversation

@nathan-stender

Copy link
Copy Markdown
Collaborator

Summary

  • Introduces a shared map_calculated_data_documents() function in parsers/utils/calculated_data_documents/mapping.py that replaces 12 independent _get_calculated_data_aggregate_document() implementations across schema mappers
  • Removes 7 local CalculatedDataItem/DataSource type definitions from schema mappers, standardizing on CalculatedDocument from definition.py as the universal intermediate type
  • Eliminates unnecessary type conversions in parsers (e.g., qiacuity_dpcr was converting CalculatedDocumentCalculatedDataItem and back)
  • Net reduction of ~225 lines of duplicated code

Details

New file: src/allotropy/parsers/utils/calculated_data_documents/mapping.py

  • map_calculated_data_documents() — generic mapping for all schema versions
  • map_calculated_data_documents_for_dpcr() — thin wrapper for dPCR's calculated_datum field

Schema mappers updated (12):

  • plate_reader (rec/2024/06, rec/2025/03, benchling/2023/09)
  • pcr (rec/2024/09 qpcr, BENCHLING/2023/09 dpcr)
  • electrophoresis, solution_analyzer (x2), cell_counting
  • multi_analyte_profiling, spectrophotometry, binding_affinity_analyzer

Parsers updated (7):

  • agilent_tapestation_analysis, appbio_quantstudio, appbio_quantstudio_designandanalysis
  • beckman_pharmspec, chemometec_nucleoview, qiacuity_dpcr, appbio_absolute_q

Test plan

  • All 735 parser tests pass — no test JSON output files changed
  • All 315 discover_vendor tests pass
  • Lint (ruff + black + mypy) passes cleanly

🤖 Generated with Claude Code

Replace 12 independent _get_calculated_data_aggregate_document() implementations
and 7 local CalculatedDataItem/DataSource type definitions with a single shared
mapping function and the universal CalculatedDocument intermediate type.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nathan-stender
nathan-stender requested review from a team and slopez-b as code owners June 8, 2026 22:40
@nathan-stender
nathan-stender requested a review from tamargrey June 8, 2026 22:40
nathan-stender and others added 3 commits June 11, 2026 11:45
…node lists

Introduce a flat, config-based API (CalcDoc, Measurement, build_calc_docs) for
defining calculated data dependency graphs. This replaces 50+ nested helper
functions across parsers with readable node list constants, making it clear how
to add/edit calc docs without understanding the internal resolution engine.

- New: calcdocs/builder.py (Measurement, CalcDoc, build_calc_docs)
- New: calcdocs/views.py (shared FieldView, UuidView, SampleView, TargetView, etc.)
- Migrated: appbio_quantstudio, designandanalysis, unchained_labs, msd_workbench,
  cytiva_biacore, bmg_labtech parsers
- Removed: 7 redundant parser-specific view/config files
- Moved CalculatedDataConfigWithOptional to core config.py
- Net reduction: ~400 lines

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- CalcDoc.sources now takes list[Measurement | CalcDoc] instead of list[str]
- Removes output_name field — node identity is the Python object, not the name
- Removes _find_node linear scan — direct references eliminate name lookup
- Adds _validate_graph() for eager error checking at build time
- Adds describe_graph() utility for debugging node lists
- Removes internal config exports from __init__.py (public API only)
- Updates example to use new FieldView + build_calc_docs pattern
- Each experiment type's nodes defined in a function for clear object scoping

Benefits: typos in source names are now impossible (caught by Python itself),
duplicate name disambiguation is explicit (separate objects), and IDE support
(jump-to-definition, autocomplete) works on source references.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant