harbor run -t openthoughts/tasktrove-exp-rpt-scaffold-v2-scaffold-4161harbor download openthoughts/tasktrove-exp-rpt-scaffold-v2-scaffold-4161Task: Implement the missing functionality in the scaffolded module under /app/
What you need to implement
- Fill in all NotImplementedError stubs:
- parse_args(argv=None) -> str
- load_messages_from_path(path: str) -> List[SmsMessage]
- compute_summary(messages: List[SmsMessage]) -> Dict[str, Any]
- format_summary(summary: Dict[str, Any]) -> str
- main() -> int
What each part should do (based on docstrings, types, and tests)
- SmsMessage class (already scaffolded)
- Represents a single SMS message with fields: type, id, uri, direction, from_, to, body, cost
- Note: The JSON dataset uses the field "from"; map it to the attribute from_ to avoid Python keyword conflicts
- parse_args(argv=None) -> str
- Accept an optional list of command-line arguments (argv)
- If an argument is provided, treat the first positional item as the data file path and return it
- If no argument is provided, return the default data path (DEFAULT_DATA_PATH)
- When argv is None, behave as if using the actual command-line invocation (i.e., read from sys.argv)
- load_messages_from_path(path: str) -> List[SmsMessage]
- Read and parse a JSON file at the given path
- Expected JSON: a list of objects with fields: type, id, uri, direction, from, to, body, cost
- For each object, construct an SmsMessage:
- from_ comes from the "from" field
- Other fields map directly (type, id, uri, direction, to, body, cost)
- Return the list of SmsMessage instances
- Assume the JSON is well-formed for the purposes of tests
- compute_summary(messages: List[SmsMessage]) -> Dict[str, Any]
- Produce a summary dictionary containing:
- total_messages: int (len(messages))
- total_cost: float (sum of message.cost)
- direction_counts: dict with counts by direction (e.g., {"IN": n_in, "OUT": n_out})
- unique_senders: list[str] containing sender numbers (from_) in the order of their first appearance
- earliest_timestamp: str or None
- latest_timestamp: str or None
- Timestamps are extracted from each message.uri using TIMESTAMP_REGEX:
- If a uri contains a timestamp (sms://<ts>), capture <ts> (formatted as YYYY-MM-DDTHH:MM:SSZ)
- Determine the earliest and latest timestamps across all messages that have a timestamp
- Represent timestamps as strings in the same format (or None if not found)
- If no timestamps are found in any message, earliest_timestamp and latest_timestamp should be None
- format_summary(summary: Dict[str, Any]) -> str
- Convert the summary dictionary into a human-readable, deterministic string
- The string should contain all detail fields in a fixed, predictable order
- Suggested (but not mandatory to copy exactly) content to include:
- Total messages
- Total cost (formatted with reasonable precision)
- Direction counts (IN and OUT)
- Unique senders (in first-appearance order; join with a comma and space)
- Earliest created timestamp (or indicate None)
- Latest created timestamp (or indicate None)
- Return a single string with line breaks separating each piece of information
- main() -> int
- Orchestrate the flow:
- Determine the data path by calling parse_args(None) or with provided argv if invoked differently
- Load messages using load_messages_from_path(path)
- Compute the summary with compute_summary(messages)
- Format the summary with format_summary(summary)
- Print the resulting string to stdout
- Return 0 on success
- Keep behavior straightforward for tests (avoid noisy exceptions); tests typically exercise happy-path usage
Notes on behavior and edge cases
- TIMESTAMP_REGEX: Use this to scan each message.uri for a timestamp. If found, parse as UTC time (YYYY-MM-DDTHH:MM:SSZ). Handle None if not present.
- Unique senders: Preserve the order of first appearance of from_ values as they appear in the list of messages.
- Robustness: The tests will invoke these functions in isolation as well as via main(); ensure type hints and return types align with the scaffolding.
- Output formatting: The tests expect a stable, human-readable output from format_summary. Keep a consistent line order and formatting to ensure reproducibility.
Files to modify
- The scaffolded module located under /app/ (the file containing SmsMessage, parse_args, load_messages_from_path, compute_summary, format_summary, and main). Implement all NotImplementedError stubs in that file.
Testing information
- Tests are run with pytest. Implementations should be correct and well-typed to satisfy unit tests that import the functions and validate behavior, as well as tests that capture stdout from main/formatting.
Usage example (conceptual)
- If run with a path: python -m your_module data/smsmessages.json
- If run with no path: python -m your_module
- The program prints the formatted summary and exits with code 0
Important
- Do not reveal or hard-code the exact test expectations in the code or description here beyond the behavioral guidelines above. The formatting should be deterministic and aligned with the described behavior to satisfy the tests.