args: {'query': 'SELECT * FROM daily LIMIT 10;'}


args: {'query': "SELECT 'resting_hr' as metric, AVG(resting_hr) as avg, STDDEV(resting_hr) as std FROM daily\nUNION ALL\nSELECT 'hrv', AVG(hrv), STDDEV(hrv) FROM daily\nUNION ALL\nSELECT 'sleep_hours', AVG(sleep_hours), STDDEV(sleep_hours) FROM daily\nUNION ALL\nSELECT 'glucose_mean', AVG(glucose_mean), STDDEV(glucose_mean) FROM daily\nUNION ALL\nSELECT 'steps', AVG(steps), STDDEV(steps) FROM daily;"}


args: {'query': 'SELECT \n    AVG(resting_hr) as avg_hr, MIN(resting_hr) as min_hr, MAX(resting_hr) as max_hr,\n    AVG(hrv) as avg_hrv, MIN(hrv) as min_hrv, MAX(hrv) as max_hrv,\n    AVG(sleep_hours) as avg_sleep, MIN(sleep_hours) as min_sleep, MAX(sleep_hours) as max_sleep,\n    AVG(glucose_mean) as avg_gluc, MIN(glucose_mean) as min_gluc, MAX(glucose_mean) as max_gluc,\n    AVG(steps) as avg_steps, MIN(steps) as min_steps, MAX(steps) as max_steps\nFROM daily;'}


args: {'query': 'SELECT \n    AVG(resting_hr * resting_hr) - AVG(resting_hr) * AVG(resting_hr) as var_hr,\n    AVG(hrv * hrv) - AVG(hrv) * AVG(hrv) as var_hrv,\n    AVG(sleep_hours * sleep_hours) - AVG(sleep_hours) * AVG(sleep_hours) as var_sleep,\n    AVG(glucose_mean * glucose_mean) - AVG(glucose_mean) * AVG(glucose_mean) as var_gluc,\n    AVG(steps * steps) - AVG(steps) * AVG(steps) as var_steps\nFROM daily;'}


args: {'query': 'SELECT * FROM daily ORDER BY date ASC;'}


args: {'query': "SELECT \n    AVG(CASE WHEN date < '2026-03-10' THEN resting_hr END) as avg_before,\n    AVG(CASE WHEN date BETWEEN '2026-03-10' AND '2026-03-21' THEN resting_hr END) as avg_during\nFROM daily;"}


args: {'metric': 'resting_hr', 'start_date': '2026-03-10', 'magnitude': 24.0}


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # Date patterns: ISO (YYYY-MM-DD) or US Slash (MM/DD/YY)\n    iso_pattern = r\'(\\d{4}-\\d{2}-\\d{2})\'\n    us_slash_pattern = r\'(\\d{2}/\\d{2}/(\\d{2}))\'\n    \n    date_str = None\n    match_iso = re.search(iso_pattern, line)\n    if match_iso:\n        date_str = match_iso.group(1)\n    else:\n        match_us = re.search(us_slash_pattern, line)\n        if match_us:\n            parts = match_us.group(0).split(\'/\')\n            month, day, year = parts[0], parts[1], parts[2]\n            date_str = f"{year}-{month}-{day}"\n            # Handle 2-digit years (assume 20YY)\n            if len(year) == 2:\n                date_str = f"20{year}-{month}-{day}"\n        else:\n            return None\n\n    # Metric mapping\n    metric_map = {\n        \'steps\': \'steps\',\n        \'step count\': \'steps\',\n        \'resting hr\': \'resting_hr\',\n        \'rhr\': \'resting_hr\',\n        \'resting heart rate\': \'resting_hr\',\n        \'hrv\': \'hrv\',\n        \'heart rate variability\': \'hrv\',\n        \'sleep\': \'sleep_hours\',\n        \'slept\': \'sleep_hours\',\n        \'sleep hours\': \'sleep_hours\',\n        \'glucose\': \'glucose_mean\',\n        \'avg glucose\': \'glucose_mean\'\n    }\n\n    # Find the metric (longest match first)\n    found_metric = None\n    sorted_aliases = sorted(metric_map.keys(), key=len, reverse=True)\n    for alias in sorted_aliases:\n        if re.search(rf\'\\b{re.escape(alias)}\\b\', line, re.IGNORECASE):\n            found_metric = metric_map[alias]\n            break\n    \n    if not found_metric:\n        return None\n\n    # Extract value: find number after removing date and metric? \n    # Or just search for digits/decimals in the string excluding date parts.\n    # Let\'s strip known non-numeric characters from segments to be safe.\n    \n    # Cleaner approach: extract all numbers (including decimals) that are not part of the date\n


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Find Date\n    iso_pattern = r\'\\d{4}-\\d{2}-\\d{2}\'\n    us_slash_pattern = r\'(\\d{2})/(\\d{2})/(\\d{2,4})\'\n    \n    date_str = None\n    match_obj = None\n\n    # Try ISO first\n    iso_match = re.search(iso_pattern, line)\n    if iso_match:\n        date_str = iso_match.group(0)\n        match_obj = iso_match\n    else:\n        us_match = re.search(us_slash_pattern, line)\n        if us_match:\n            m, d, y = us_match.groups()\n            if len(y) == 2:\n                y = "20" + y\n            date_str = f"{y}-{m}-{d}"\n            match_obj = us_match\n\n    if not date_str:\n        return None\n\n    # 2. Find Metric\n    metric_map = {\n        \'steps\': \'steps\',\n        \'step count\': \'steps\',\n        \'resting hr\': \'resting_hr\',\n        \'rhr\': \'resting_hr\',\n        \'resting heart rate\': \'resting_hr\',\n        \'hrv\': \'hrv\',\n        \'heart rate variability\': \'hrv\',\n        \'sleep\': \'sleep_hours\',\n        \'slept\': \'sleep_hours\',\n        \'sleep hours\': \'sleep_hours\',\n        \'glucose\': \'glucose_mean\',\n        \'avg glucose\': \'glucose_mean\'\n    }\n\n    found_metric = None\n    # Sort aliases by length descending to ensure longest match (e.g., \'resting heart rate\' before \'rhr\')\n    sorted_aliases = sorted(metric_map.keys(), key=len, reverse=True)\n    for alias in sorted_aliases:\n        if re.search(rf\'\\b{re.escape(alias)}\\b\', line, re.IGNORECASE):\n            found_metric = metric_map[alias]\n            break\n    \n    if not found_metric:\n        return None\n\n    # 3. Find Value\n    # Remove the date part from the string to avoid picking up numbers in the date\n    remaining_text = line.replace(match_obj.group(0), "")\n    \n    # Regex for a number that might have commas or decimals\n    # We want the last number sequence found in the remaining text (typical for these logs)\n    num_pattern = r


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date\n    iso_match = re.search(r\'\\d{4}-\\d{2}-\\d{2}\', line)\n    us_match = re.search(r\'(\\d{2})/(\\d{2})/(\\d{2,4})\', line)\n    \n    if iso_match:\n        date_str = iso_match.group(0)\n        date_range = (iso_match.start(), iso_match.end())\n    elif us_match:\n        m, d, y = us_match.groups()\n        y = f"20{y}" if len(y) == 2 else y\n        date_str = f"{y}-{m}-{d}"\n        date_range = (us_match.start(), us_match.end())\n    else:\n        return None\n\n    # 2. Extract Metric\n    metric_map = {\n        \'steps\': \'steps\', \'step count\': \'steps\',\n        \'resting hr\': \'resting_hr\', \'rhr\': \'resting_hr\', \'resting heart rate\': \'resting_hr\',\n        \'hrv\': \'hrv\', \'heart rate variability\': \'hrv\',\n        \'sleep\': \'sleep_hours\', \'slept\': \'sleep_hours\', \'sleep hours\': \'sleep_hours\',\n        \'glucose\': \'glucose_mean\', \'avg glucose\': \'glucose_mean\'\n    }\n    found_metric = None\n    sorted_aliases = sorted(metric_map.keys(), key=len, reverse=True)\n    for alias in sorted_aliases:\n        if re.search(rf\'\\b{re.escape(alias)}\\b\', line, re.IGNORECASE):\n            found_metric = metric_map[alias]\n            break\n    if not found_metric:\n        return None\n\n    # 3. Extract Value (the number that isn\'t the date)\n    # We find all numbers in the string and pick one that doesn\'t overlap with the date range\n    num_pattern = r\'\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?|\\d+\\.\\d+|\\d+\'\n    for match in re.finditer(num_pattern, line):\n        start, end = match.span()\n        # Check if this number is part of the date string\n        if start < date_range[1] and end > date_range[0]:\n            continue\n        try:\n            val_str = match.group(0).replace(\',\', \'\')\n            return {\n                "date": date_str,\n                "metric": found_metric,\n                "value": float(val_


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    us_match = re.search(r\'(\\d{2})/(\\d{2})/(\\d{2,4})\', line)\n    \n    date_str = None\n    if iso_match:\n        date_str = iso_match.group(1)\n    elif us_match:\n        m, d, y = us_match.groups()\n        if len(y) == 2:\n            y = "20" + y\n        date_str = f"{y}-{m}-{d}"\n    else:\n        return None\n\n    # 2. Extract Metric\n    metric_map = {\n        \'steps\': \'steps\', \'step count\': \'steps\',\n        \'resting hr\': \'resting_hr\', \'rhr\': \'resting_hr\', \'resting heart rate\': \'resting_hr\',\n        \'hrv\': \'hrv\', \'heart rate variability\': \'hrv\',\n        \'sleep\': \'sleep_hours\', \'slept\': \'sleep_hours\', \'sleep hours\': \'sleep_hours\',\n        \'glucose\': \'glucose_mean\', \'avg glucose\': \'glucose_mean\'\n    }\n    found_metric = None\n    sorted_aliases = sorted(metric_map.keys(), key=len, reverse=True)\n    for alias in sorted_aliases:\n        if re.search(rf\'\\b{re.escape(alias)}\\b\', line, re.IGNORECASE):\n            found_metric = metric_map[alias]\n            break\n    if not found_metric:\n        return None\n\n    # 3. Extract Value\n    # Find the last number in the string that isn\'t part of the date\n    # First, identify the parts of the line that are NOT the date\n    date_pattern = r\'\\d{4}-\\d{2}-\\d{2}|\\d{2}/\\d{2}/\\d{2,4}\'\n    parts = re.split(date_pattern, line)\n    \n    # The value should be in one of the parts (usually the last part or second to last)\n    for part in reversed(parts):\n        num_'}


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Find Date\n    iso_match = re.search(r\'\\d{4}-\\d{2}-\\d{2}\', line)\n    us_match = re.search(r\'(\\d{2})/(\\d{2})/(\\d{2,4})\', line)\n    \n    if iso_match:\n        date_str = iso_match.group(0)\n        d_start, d_end = iso_match.span()\n    elif us_match:\n        m, d, y = us_match.groups()\n        y = f"20{y}" if len(y) == 2 else y\n        date_str = f"{y}-{m}-{d}"\n        d_start, d_end = us_match.span()\n    else:\n        return None\n\n    # 2. Find Metric\n    metric_map = {\n        \'steps\': \'steps\', \'step count\': \'steps\',\n        \'resting hr\': \'resting_hr\', \'rhr\': \'resting_hr\', \'resting heart rate\': \'resting_hr\',\n        \'hrv\': \'hrv\', \'heart rate variability\': \'hrv\',\n        \'sleep\': \'sleep_hours\', \'slept\': \'sleep_hours\', \'sleep hours\': \'sleep_hours\',\n        \'glucose\': \'glucose_mean\', \'avg glucose\': \'glucose_mean\'\n    }\n    found_metric = None\n    sorted_aliases = sorted(metric_map.keys(), key=len, reverse=True)\n    for alias in sorted_aliases:\n        if re.search(rf\'\\b{re.escape(alias)}\\b\', line, re.IGNORECASE):\n            found_metric = metric_map[alias]\n            break\n    if not found_metric:\n        return None\n\n    # 3. Find Value\n    text_without_date = line[:d_start] + line[d_end:]\n    num_pattern = r\'\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?|\\d+\\.\\d+|\\d+\'\n    numbers = re.findall(num_pattern, text_without_date)\n    if not numbers:\n        return None\n\n    try:\n        val_str = numbers[-1].replace(\',\', \'\')\n        value = float(val_str)\n        return {"date": date_str, "metric": found_metric, "value": value}\n    except (ValueError, IndexError):\n        return None\n'}


args: {'source': 'import re\nfrom datetime import datetime\n\ndef parse_line(line: str) -> dict | None:\n    # Regex patterns\n    iso_pattern = r\'(\\d{4})-(\\d{2})-(\\d{2})\'\n    us_slash_pattern = r\'(\\d{1,2})/(\\d{1,2})/(\\d{2,4})\'\n\n    date_val = None\n    norm_date = None\n    \n    # Try ISO first\n    iso_match = re.search(iso_pattern, line)\n    if iso_match:\n        date_val = iso_match.group()\n        norm_date = date_val\n    else:\n        # Try US Slash\n        us_match = re.search(us_slash_pattern, line)\n        if us_match:\n            m, d, y = us_match.groups()\n            if len(y) == 2:\n                year = int(y) + 2000 if int(y) <= 69 else int(y) + 1900\n                norm_date = f"{year}-{m.zfill(2)}-{d.zfill(2)}"\n            else:\n                norm_date = f"{y}-{m.zfill(2)}-{d.zfill(2)}"\n            date_val = us_match.group()\n\n    if not date_val or not norm_date:\n        return None\n\n    # Find the end position of the date match to only look at text after it\n    # We use finditer to ensure we get the right occurrence if there are multiple, \n    # but typically a line has one primary date.\n    match = re.search(re.escape(date_val), line)\n    if not match: # Fallback for complex regex matches\n        return None\n        \n    end_index = match.end()\n    remaining_text = line[end_index:]\n\n    # Find all numbers (integers or floats) in the remaining text\n    numbers = re.findall(r\'-?\\d+\\.?\\d*\', remaining_text)\n    total_value = sum(float(n) for n in numbers)\n\n    return {\n        \'date\': norm_date,\n        \'value\': total_value\n    }\n'}


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # Regex patterns for dates\n    iso_pattern = r\'\\d{4}-\\d{2}-\\d{2}\'\n    us_slash_pattern = r\'(\\d{1,2})/(\\d{1,2})/(\\d{2,4})\'\n\n    date_val = None\n    norm_date = None\n    \n    # Try ISO first\n    iso_match = re.search(iso_pattern, line)\n    if iso_match:\n        date_val = iso_match.group()\n        norm_date = date_val\n    else:\n        # Try US Slash\n        us_match = re.search(us_slash_pattern, line)\n        if us_match:\n            m, d, y = us_match.groups()\n            if len(y) == 2:\n                year = int(y) + 2000 if int(y) <= 69 else int(y) + 1900\n                norm_date = f"{year}-{m.zfill(2)}-{d.zfill(2)}"\n            else:\n                norm_date = f"{y}-{m.zfill(2)}-{d.zfill(2)}"\n            date_val = us_match.group()\n\n    if not date_val or not norm_date:\n        return None\n\n    # Find the end position of the date match to only look at text after it\n    match = re.search(re.escape(date_val), line)\n    if not match:\n        return None\n    end_index = match.end()\n    remaining_text = line[end_index:]\n\n    # Find all numbers (integers or floats) in the remaining text\n    numbers = re.findall(r\'-?\\d+\\.?\\d*\', remaining_text)\n    if not numbers:\n        return None # Or return 0.0? The tests suggest we need a metric too.\n    \n    total_value = sum(float(n) for n in numbers if n != \'\')\n\n    # Metric mapping\n    metric = None\n    lower_line = line.lower()\n    if \'rhr\' in lower_line or \'resting heart rate\' in lower_line:\n        metric = \'resting_hr\'\n    elif \'steps\' in lower_line:\n        metric = \'steps\'\n    elif \'heart rate variability\' in lower_line:\n        metric = \'hrv\'\n    elif \'avg glucose\' in lower_line or \'glucose\' in lower_line:\n        # The test case 4 and 9 specifically use "avg glucose" -> "glucose_mean"\n        if \'avg glucose\' in lower_line or \'glucose\' in lower_line:\n


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Try to find the date (ISO or US slash)\n    # ISO pattern: YYYY-MM-DD\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    # US pattern: MM/DD/YY or MM/DD/YYYY\n    us_match = re.search(r\'(\\d{2}/\\d{2}/\\d{2,4})\', line)\n    \n    date_str = None\n    match_end = 0\n    \n    if iso_match:\n        date_str = iso_match.group(1)\n        match_end = iso_match.end()\n    elif us_match:\n        date_str = us_match.group(1)\n        # Handle US date format conversion if needed? \n        # The spec usually wants the matched string or a standard one.\n        # Let\'s check the spec for requirements on date format in the output.\n        # Since I can\'t see it, I\'ll assume the matched string is fine first.\n        match_end = us_match.end()\n    \n    if not date_str:\n        return None\n\n    # 2. Get the part after the date (ignoring brackets if present)\n    # The line might look like "[2026-03-08] steps 18682" or "2026-03-08 steps 18682"\n    # We\'ll search for the metric and value in the rest of the string.\n    remaining = line[match_end:].strip()\n    if remaining.startswith(\']\'):\n        remaining = remaining[1:].strip()\n    elif remaining.startswith(\' \'):\n        remaining = remaining.strip()\n\n    # The pattern for "metric value" is usually a word followed by a number.\n    # Example: "steps 18682" or "miles 50.0"\n    # We use \\w+ for the metric and [\\d.]+ for the value.\n    data_match = re.search(r\'([a-zA-Z]+)\\s+(\\d+(?:\\.\\d+)?)\', remaining)\n    if not data_match:\n        return None\n    \n    metric = data_match.group(1)\n    value = float(data_match.group(2))\n\n    # Special handling for US dates to normalize them if necessary? \n    # Let\'s look at the error again. The errors were about values, not dates.\n    # But let\'s be safe and check if we should convert MM/DD/YY to YYYY-MM-DD.\n    if \'/\' in date_str:\n        parts = date_str


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    us_match = re.search(r\'(\\d{2}/\\d{2}/(\\d{2,4}))\', line)\n    \n    date_str = None\n    if iso_match:\n        date_str = iso_match.group(1)\n    elif us_match:\n        m, d, y = us_match.groups()\n        if len(y) == 2:\n            y = "20" + y\n        date_str = f"{y}-{m}-{d}"\n    \n    if not date_str:\n        return None\n\n    # 2. Define Metric Mapping\n    # Ordered from longest to shortest to avoid partial matches (e.g., \'sleep hours\' before \'sleep\')\n    METRIC_MAPPING = [\n        (\'step count\', \'steps\'),\n        (\'resting heart rate\', \'resting_hr\'),\n        (\'heart rate variability\', \'hrv\'),\n        (\'sleep hours\', \'sleep_hours\'),\n        (\'avg glucose\', \'glucose_mean\'),\n        (\'resting hr\', \'resting_hr\'),\n        (\'rhr\', \'resting_hr\'),\n        (\'steps\', \'steps\'),\n        (\'hrv\', \'hrv\'),\n        (\'slept\', \'sleep_hours\'),\n        (\'sleep\', \'sleep_hours\'),\n        (\'glucose\', \'glucose_mean\'),\n    ]\n\n    # 3. Search for Metric and Value\n    # We need to find the metric keyword in the line, then look for a number nearby.\n    # The spec says: "Values may contain thousands commas, a unit suffix, or an \'(approx)\' tag"\n    \n    found_metric = None\n    found_value = None\n\n    # Try each mapping\n    for alias, canonical in METRIC_MAPPING:\n        # Use word boundaries for the metric to avoid matching \'rhr\' inside something else (if possible)\n        # But some metrics are multi-word. Let\'s use a case-insensitive search for the alias.\n        pattern = r\'\\b\' + re.escape(alias) + r\'\\b\'\n        match = re.search(pattern, line, re.IGNORECASE)\n        if match:\n            # Found an alias! Now find the number after it.\n            # Look at the string following the metric name\n            after_text = line[match


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    us_match = re.search(r\'(\\d{2}/\\d{2}/(\\d{2,4}))\', line)\n    \n    if iso_match:\n        date_str = iso_match.group(1)\n    elif us_match:\n        m, d, y = us_match.groups()\n        y = "20" + y if len(y) == 2 else y\n        date_str = f"{y}-{m}-{d}"\n    else:\n        return None\n\n    # 2. Define Metric Mapping (Longest aliases first to ensure correct matching)\n    mapping = [\n        (\'step count\', \'steps\'),\n        (\'resting heart rate\', \'resting_hr\'),\n        (\'heart rate variability\', \'hrv\'),\n        (\'sleep hours\', \'sleep_hours\'),\n        (\'avg glucose\', \'glucose_mean\'),\n        (\'resting hr\', \'resting_hr\'),\n        (\'rhr\', \'resting_hr\'),\n        (\'steps\', \'steps\'),\n        (\'slept\', \'sleep_hours\'),\n        (\'sleep\', \'sleep_hours\'),\n        (\'glucose\', \'glucose_mean\'),\n        (\'hrv\', \'hrv\')\n    ]\n\n    # 3. Search for Metric and Value\n    for alias, canonical in mapping:\n        pattern = r\'\\b\' + re.escape(alias) + r\'\\b\'\n        match = re.search(pattern, line, re.IGNORECASE)\n        if match:\n            # Find the first number occurring after this metric name\n            after_text = line[match.end():]\n            num_match = re.search(r\'(\\d[\\d,.]*)\', after_text)\n            if num_match:\n                val_str = num_match.group(1).replace(\',\', \'\')\n                try:\n                    return {\n                        "date": date_str,\n                        "metric": canonical,\n                        "value": float(val_str)\n                    }\n                except ValueError:\n                    continue\n    return None\n'}


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    us_match = re.search(r\'(\\d{2}/\\d{2}/(\\d{2,4}))\', line)\n    if iso_match:\n        date_str = iso_match.group(1)\n    elif us_match:\n        m, d, y = us_match.groups()\n        y = "20" + y if len(y) == 2 else y\n        date_str = f"{y}-{m}-{d}"\n    else:\n        return None\n\n    mapping = [\n        (\'step count\', \'steps\'),\n        (\'resting heart rate\', \'resting_hr\'),\n        (\'heart rate variability\', \'hrv\'),\n        (\'sleep hours\', \'sleep_hours\'),\n        (\'avg glucose\', \'glucose_mean\'),\n        (\'resting hr\', \'resting_hr\'),\n        (\'rhr\', \'resting_hr\'),\n        (\'steps\', \'steps\'),\n        (\'slept\', \'sleep_hours\'),\n        (\'sleep\', \'sleep_hours\'),\n        (\'glucose\', \'glucose_mean\'),\n        (\'hrv\', \'hrv\')\n    ]\n\n    for alias, canonical in mapping:\n        pattern = r\'\\b\' + re.escape(alias) + r\'\\b\'\n        match = re.search(pattern, line, re.IGNORECASE)\n        if match:\n            after_text = line[match.end():]\n            num_match = re.search(r\'(\\d[\\d,.]*)\', after_text)\n            if num_match:\n                val_str = num_match.group(1).replace(\',\', \'\')\n                try:\n                    return {\n                        "date": date_str,\n                        "metric": canonical,\n                        "value": float(val_str)\n                    }\n                except ValueError:\n                    continue\n    return None\n\ntests = [\n    \'2026-03-07 - rhr: 79\',\n    \'[2026-03-08] steps 18682\',\n    \'[2026-03-09] heart rate variability 83 ms\',\n    \'---\',\n    \'avg glucose on 2026-03-11 = 117\',\n    \'resting heart rate on 03/12/26 = 49 (approx)\',\n    \'2026-03-13 - steps: 19050\',\n    \'sync error @ device\',\n    \'sleep hours on 03/15/26 = 5.8\',\n    \'2026-03-16 - avg glucose: 124 (appr


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    us_match = re.search(r\'(\\d{2}/\\d{2}/(\\d{2,4}))\', line)\n    if iso_match:\n        date_str = iso_match.group(1)\n    elif us_match:\n        m, d, y = us_match.groups()\n        y = "20" + y if len(y) == 2 else y\n        date_str = f"{y}-{m}-{d}"\n    else:\n        return None\n\n    mapping = [\n        (\'step count\', \'steps\'),\n        (\'resting heart rate\', \'resting_hr\'),\n        (\'heart rate variability\', \'hrv\'),\n        (\'sleep hours\', \'sleep_hours\'),\n        (\'avg glucose\', \'glucose_mean\'),\n        (\'resting hr\', \'resting_hr\'),\n        (\'rhr\', \'resting_hr\'),\n        (\'steps\', \'steps\'),\n        (\'slept\', \'sleep_hours\'),\n        (\'sleep\', \'sleep_hours\'),\n        (\'glucose\', \'glucose_mean\'),\n        (\'hrv\', \'hrv\')\n    ]\n\n    for alias, canonical in mapping:\n        pattern = r\'\\b\' + re.escape(alias) + r\'\\b\'\n        match = re.search(pattern, line, re.IGNORECASE)\n        if match:\n            after_text = line[match.end():]\n            num_match = re.search(r\'(\\d[\\d,.]*)\', after_text)\n            if num_match:\n                val_str = num_match.group(1).replace(\',\', \'\')\n                try:\n                    return {\n                        "date": date_str,\n                        "metric": canonical,\n                        "value": float(val_str)\n                    }\n                except ValueError:\n                    continue\n    return None\n\nprint(parse_line(\'[2026-03-09] heart rate variability 83 ms\'))\n'}


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date (ISO or US Slash)\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    us_match = re.search(r\'(\\d{2}/\\d{2}/(\\d{2,4}))\', line)\n    \n    if iso_match:\n        date_str = iso_match.group(1)\n    elif us_match:\n        m, d, y = us_match.groups()\n        y = "20" + y if len(y) == 2 else y\n        date_str = f"{y}-{m}-{d}"\n    else:\n        return None\n\n    # 2. Mapping of aliases to canonical names\n    # We\'ll use a list of tuples, ordered by alias length descending\n    mapping = [\n        (\'step count\', \'steps\'),\n        (\'resting heart rate\', \'resting_hr\'),\n        (\'heart rate variability\', \'hrv\'),\n        (\'sleep hours\', \'sleep_hours\'),\n        (\'avg glucose\', \'glucose_mean\'),\n        (\'resting hr\', \'resting_hr\'),\n        (\'rhr\', \'resting_hr\'),\n        (\'steps\', \'steps\'),\n        (\'slept\', \'sleep_hours\'),\n        (\'sleep\', \'sleep_hours\'),\n        (\'glucose\', \'glucose_mean\'),\n        (\'hrv\', \'hrv\')\n    ]\n\n    # 3. Find the metric and value\n    for alias, canonical in mapping:\n        # Use a regex that matches the alias as a whole word (case-insensitive)\n        pattern = r\'\\b\' + re.escape(alias) + r\'\\b\'\n        match = re.search(pattern, line, re.IGNORECASE)\n        if match:\n            # The value must follow the metric name eventually in the string\n            after_text = line[match.end():]\n            # Look for a number that may have commas or decimals\n            num_match = re.search(r\'(\\d[\\d,'}


args: {'source': 'import re\nfrom datetime import datetime\n\ndef parse_line(line: str) -> dict | None:\n    """Parses a line to extract date, metric name, and numerical value."""\n    date_obj = None\n    rem = line\n    \n    # 1. Extract Date (ISO or US Slash)\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    if iso_match:\n        try:\n            date_obj = datetime.strptime(iso_match.group(1), \'%Y-%m-%d\')\n            rem = line[:iso_match.start()] + line[iso_match.end():]\n        except ValueError:\n            pass\n\n    if date_obj is None:\n        us_match = re.search(r\'(\\d{1,2}/\\d{1,2}/(\\d{2,4}))\', line)\n        if us_match:\n            try:\n                ds = us_match.group(1)\n                year_part = us_match.group(2)\n                fmt = \'%m/%d/%y\' if len(year_part) <= 2 else \'%m/%d/%Y\'\n                date_obj = datetime.strptime(ds, fmt)\n                rem = line[:us_match.start()] + line[us_match.end():]\n            except (ValueError, IndexError):\n                pass\n\n    if not date_obj:\n        return None\n\n    # 2. Extract Value (the last number in the remaining text)\n    num_pattern = r\'(-?\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?|\\d+(?:\\.\\d+)?)\'\n    matches = list(re.finditer(num_pattern, rem))\n    if not matches:\n        return None\n    \n    match = matches[-1]\n    val_str = match.group(0).replace(\',\', \'\')\n    try:\n        value = float(val_str)\n    except ValueError:\n        return None\n\n    # 3. Extract Metric (text between date and value, cleaned)\n    metric_part = rem[:match.start()].strip()\n    # Remove common separators/artifacts like brackets, colons, dashes\n    metric_part = re.sub(r\'[\\[\\]\\:\\-]\', \'\', metric_part).strip()\n\n    if not metric_part:\n        return None\n\n    return {\n        \'date\': date_obj,\n        \'metric\': metric_part,\n        \'value\': value\n    }\n'}


args: {'source': 'import re\nfrom datetime import datetime\n\ndef parse_line(line: str) -> dict | None:\n    """Parses a line to extract date (as YYYY-MM-DD), metric name, and numerical value."""\n    date_str = None\n    rem = line\n    \n    # 1. Extract Date (ISO or US Slash)\n    iso_match = re.search(r\'(\\d{4}-\\d{2}-\\d{2})\', line)\n    if iso_match:\n        try:\n            date_str = iso_match.group(1)\n            rem = line[:iso_match.start()] + line[iso_match.end():]\n        except ValueError:\n            pass\n\n    if date_str is None:\n        us_match = re.search(r\'(\\d{1,2}/\\d{1,2}/(\\d{2,4}))\', line)\n        if us_match:\n            try:\n                ds = us_match.group(1)\n                year_part = us_match.group(2)\n                fmt = \'%m/%d/%y\' if len(year_part) <= 2 else \'%m/%d/%Y\'\n                dt = datetime.strptime(ds, fmt)\n                date_str = dt.strftime(\'%Y-%m-%d\')\n                rem = line[:us_match.start()] + line[us_match.end():]\n            except (ValueError, IndexError):\n                pass\n\n    if date_str is None:\n        return None\n\n    # 2. Extract Value (the last number in the remaining text)\n    num_pattern = r\'(-?\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?|\\d+(?:\\.\\d+)?)\'\n    matches = list(re.finditer(num_pattern, rem))\n    if not matches:\n        return None\n    \n    match = matches[-1]\n    val_str = match.group(0).replace(\',\', \'\')\n    try:\n        value = float(val_str)\n    except ValueError:\n        return None\n\n    # 3. Extract Metric (text between date and value, cleaned)\n    metric_part = rem[:match.start()].strip()\n    # Remove common separators/artifacts like brackets, colons, dashes, equals\n    metric_part = re.sub(r\'[\\[\\]\\:\\-\\=]\', \'\', metric_part).strip()\n\n    if not metric_part:\n        return None\n\n    return {\n        \'date\': date_str,\n        \'metric\': metric_part,\n        \'value\': value\n    }\n'}


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date\n    date_str = None\n    # ISO format YYYY-MM-DD\n    iso_match = re.search(r\'(\\d{4})-(\\d{2})-(\\d{2})\', line)\n    if iso_match:\n        date_str = f"{iso_match.group(1)}-{iso_match.group(2).zfill(2)}-{iso_match.group(3).zfill(2)}"\n    else:\n        # US format MM/DD/YY or MM/DD/YYYY\n        us_match = re.search(r\'(\\d{1,2})/(\\d{1,2})/(\\d{2,4})\', line)\n        if us_match:\n            m = int('}


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date (ISO or US slash)\n    date_str = None\n    iso_match = re.search(r\'(\\d{4})-(\\d{2})-(\\d{2})\', line)\n    if iso_match:\n        date_str = f"{iso_match.group(1)}-{iso_match.group(2).zfill(2)}-{iso_match.group(3).zfill(2)}"\n    else:\n        us_match = re.search(r\'(\\d{1,2})/(\\d{1,2})/(\\d{2,4})\', line)\n        if us_match:\n            m, d, y = us_match.groups()\n            y = int(y)\n            if y < 100:\n                y += 2000 # Assumption for this task context\n            date_str = f"{y}-{int(m):02d}-{int(d):02d}"\n\n    if not date_str:\n        return None\n\n    # 2. Find Metric and Value\n    # Mapping of aliases to canonical names\n    metric_map = {\n        "steps": "steps",\n        "distance": "distance",\n        "calories": "calories",\n        "heart rate": "heart_rate",\n        "hr": "heart_rate"\n    }\n\n    # Look for metric patterns: name followed by value (number)\n    # Examples: \'steps 123\', \'distance: 45.6 km\', \'calories=500\'\n    # We also need to handle commas in numbers like \'1,000\'\n    \n    # Improved regex for finding metric and number\n    # Matches "metric_name [separator] [number]"\n    pattern = r\'(steps|distance|calories|heart rate|hr)[:\\s=]+([\\d,.]+)\'\n    match = re.search(pattern, line, re.IGNORECASE)\n    \n    if not match:\n        return None\n\n    metric_raw = match.group(1).lower()\n    value_str = match.group(2).replace(\',\', \'\')\n\n    # Map to canonical name\n    canonical_metric = metric_map.get(metric_raw, metric_raw)\n    if canonical_metric == "heart rate":\n        canonical_metric = "heart_rate"\n\n    try:\n        value = float(value_str)\n    except ValueError:\n        return None\n\n    # Remove units if present (e.g., \'km\' in \'45.6 km\') - though regex above doesn\'t catch them, let\'s be safe\n    # Actually the current regex is sufficient for the examples provided in previous


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date (ISO or US slash)\n    date_str = None\n    iso_match = re.search(r\'(\\d{4})-(\\d{2})-(\\d{2})\', line)\n    us_match = re.search(r\'(\\d{1,2})/(\\d{1,2})/(\\d{2,4})\', line)\n\n    if iso_match:\n        date_str = f"{iso_match.group(1)}-{iso_match.group(2).zfill(2)}-{iso_match.group(3).zfill(2)}"\n    elif us_match:\n        m, d, y = us_match.groups()\n        y = int(y)\n        if y < 100:\n            y += 2000\n        date_str = f"{y}-{int(m):02d}-{int(d):02d}"\n\n    if not date_str:\n        return None\n\n    # 2. Extract Value (the first number found that isn\'t part of the date)\n    # We find all numbers and pick the one that isn\'t inside the date string or at the start/end in a way that matches date\n    # Easier: Find all numbers, but we know the date is already parsed. \n    # Let\'s remove the date from the line first to avoid confusion.\n    line_no_date = re.sub(r\'\\d{4}-\\d{2}-\\d{2}|\\d{1,2}/\\d{1,2}/\\d{2,4}\', \'\', line)\n    \n    # Find the number (allowing commas and decimals)\n    value_match = re.search(r\'(\\d[\\d,.]*)\', line_no_date)\n    if not value_match:\n        return None\n    \n    value_str = value_match.group(1).replace(\',\', \'\')\n    try:\n        value = float(value_str)\n    except ValueError:\n        return None\n\n    # 3. Extract Metric Name\n    # The metric is the text that remains after removing date, value, and units/noise.\n    # Remove date part from original line to get "context"\n    context = re.sub(r\'\\d{4}-\\d{2}-\\d{2}|\\d{1,2}/\\d{1,2}/\\d{2,4}\', \'\', line)\n    # Remove the value and any following text that looks like units (e.g., "bpm", "ms", "(approx)")\n    # We find where the number was in \'context\'\n    remaining = re.sub(r\'\\d[\\d,.]*\\s*[a-zA-Z]*(\\s*\\(.*\\))?\', \'\', context).strip()\n    # Also remove separators and filler words\n    for word in [\'on\', \'at\', \'is\', \'was\', \'=\', \':\',


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date (ISO or US Slash)\n    iso = re.search(r\'\\d{4}-\\d{2}-\\d{2}\', line)\n    us = re.search(r\'(\\d{1,2})/(\\d{1,2})/(\\d{2,4})\', line)\n    if iso:\n        date_str = iso.group()\n    elif us:\n        m, d, y = us.groups()\n        y = f"20{y}" if len(y) == 2 else y\n        date_str = f"{y}-{m.zfill(2)}-{d.zfill(2)}"\n    else:\n        return None\n\n    # 2. Metric Mapping\n    mapping = {\n        \'steps\': \'steps\',\n        \'heart rate\': \'heart_rate\', \'hr\': \'heart_rate\',\n        \'resting hr\': \'resting_hr\',\n        \'heart rate variability\': \'heart_rate_variability\', \'hrv\': \'heart_rate_variability\',\n        \'glucose\': \'glucose\'\n    }\n\n    # 3. Extract Metric and Value\n    content = line.replace(iso.group() if iso else us.group(), "").strip()\n    for pattern, canonical in mapping.items():\n        match = re.search(rf\'\\b{pattern}\\b\\s*:?\\s*([\\d,.]+)\', content, re.I)\n        if match:\n            try:\n                val_str = match.group(1).replace(\',\', \'\')\n                return {"date": date_str, "metric": canonical, "value": float(val_str)}\n            except (ValueError, IndexError):\n                continue\n    return None\n'}


args: {'source': 'import re\nfrom datetime import datetime\n\ndef'}


args: {'source': 'import re\n\ndef parse_line(line: str) -> dict | None:\n    # 1. Extract Date\n    iso_match = re.search(r\'(\\d{4})-(\\d{2})-(\\d{2})\', line)\n    us_match = re.search(r\'(\\d{1,2})/(\\d{1,2})/(\\d{2})\', line)\n    \n    if iso_match:\n        date_str = iso_match.group(0)\n        rem = line.replace(date_str, "")\n    elif us_match:\n        m, d, y = us_match.groups()\n        date_str = f"{y} {m}-{d}" # placeholder for sorting but need YYYY-MM-DD\n        # Correct US date to YYYY-MM-DD\n        year = int(y) + 2000\n        month = m.zfill(2)\n        day = d.zfill(2)\n        date_str = f"{year}-{month}-{day}"\n        rem = line.replace(us_match.group(0), "")\n    else:\n        return None\n\n    # 2. Define Metrics Mapping (case-insensitive matching)\n    metric_patterns = [\n        (r\'steps|step count\', \'steps\'),\n        (r\'resting hr|rhr|resting heart rate\', \'resting_hr\'),\n        (r\'hrv|heart rate variability\', \'hrv\'),\n        (r\'sleep|slept|sleep hours\', \'sleep_hours\'),\n        (r\'glucose|avg glucose\', \'glucose_mean\')\n    ]\n\n    found_metric = None\n    for pattern, canonical in metric_patterns:\n        if re.search(pattern, rem, re.IGNORECASE):\n            found_metric = canonical\n            break\n    \n    if not found_metric:\n        return None\n\n    # 3. Extract Value\n    # The number is likely the part that isn\'t the date or metric name.\n    # It might follow a colon, equals sign, or just space.\n    # We need to find the last number in the string after stripping metadata.\n    \n    # Remove everything up to the metric/value area? \n    # Actually, let\'s search for all numbers in \'rem\'.\n    # A number can have commas and dots: e.g., "18,682" or "5.8".\n    \n    # Let\'s try a more surgical approach:\n    # Find the part of the string that contains numbers after removing date/metric? \n    # No, let\'s just find all potential number strings in \'rem\'.\n    \n    # A better way to handle "va


args: {'line': '[04/27/26] resting hr 71 --- note: felt great today --- [2026-04-29] heart rate variability 59 sleep hours on 2026-04-30 = 6.5 2026-05-01 - avg glucose: 102 sync error @ device [05/03/26] step count 18897 [2026-05-04] hrv 67'}


args: {'line': '[2026-04-29] heart rate variability 59'}