find_mscodeids
The find_mscodeids command-line tool is the first executable stage of the
pipeline. It retrieves distinct CodeIDs from InfluxDB for a given time range,
builds per-leg semantic segments, and stores the resulting activity_leg and
activity_all records in PostgreSQL.
Purpose
This command is responsible for the bottom-up semantic construction described in the project:
retrieve the CodeIDs present in a time window
fetch reference wearable data for each CodeID
segment the activity separately for the left and right foot
store the per-leg segments as
activity_legcompute left/right overlaps and store them as
activity_all
This stage prepares the candidate bilateral windows that are later consumed by
find_gait.
Arguments
The tool accepts the following arguments:
-c, --config: path toconfig.yaml(required)-f, --from: start datetime of the query window-u, --until: end datetime of the query window-l, --lang: interface language (esoren)-v, --verbose: verbosity level--head-rows: number of preview rows when verbose output is enabled--save: whether to persist results in PostgreSQL (1) or run in dry mode (0)
If --from is omitted, the tool defaults to the previous day at
00:00:00. If --until is omitted, it defaults to the current time.
High-level execution flow
The command performs the following steps:
initialize translations
load configuration and create the shared
DataManagerretrieve distinct CodeIDs from InfluxDB
store each CodeID in PostgreSQL if needed
fetch the wearable reference stream for that CodeID
build left/right leg segments from raw data
prepare and optionally store
activity_legbuild bilateral overlaps and optionally store
activity_all
Dry-run mode
When --save 0 is used:
the command still performs the complete computation
results are printed for inspection
no rows are written to PostgreSQL
placeholder IDs are used internally when needed for downstream merging
Example usage
python -m ms_monitoring.find_mscodeids \
-c config.yaml \
-f "2025-05-11 00:00:00" \
-u "2025-05-12 00:00:00" \
--save 1 \
-v 2
Typical outputs
The command may generate:
new rows in
codeidsper-foot rows in
activity_legbilateral rows in
activity_all
Rows with no valid segments for one foot are handled gracefully. In that case, the missing foot is reported and only the valid semantic outputs are produced.
Implementation notes
timestamps are normalized through
ensure_utc(...)segment construction is gap-based
zero-duration segments are filtered out
bilateral activity is built through temporal overlap between left and right leg segments
storage goes through
DataManager.store_data(...)with validation and idempotent behaviour for the semantic tables