{"id":"sales-hour-across-days","publisher":"WESWOO","engine":"Python 3","title":{"zh":"下载可复算输入与代码","en":"Download runnable inputs and code"},"routine":"trading_hour","python_source":"def trading_hour(data):\n    from datetime import datetime,date\n    from zoneinfo import ZoneInfo\n    from decimal import Decimal\n    tz=ZoneInfo(data['zone'])\n    days={date.fromisoformat(day):0 for day in data['open_days']}\n    for stamp,amount in data['sales']:\n        t=datetime.fromisoformat(stamp)\n        if t.utcoffset() is None:\n            raise ValueError('timestamp needs UTC offset')\n        local=t.astimezone(tz)\n        if local.date() in days and local.hour==13:\n            days[local.date()]+=amount\n    return [list(days.values()),sum(days.values()),str(Decimal(sum(days.values()))/len(days)) if days else None]\n","checks":[{"condition":"Before and after fall clock change, one open day has zero sales","input":{"zone":"America/New_York","open_days":["2026-10-30","2026-11-02","2026-11-03"],"sales":[["2026-10-30T17:15:00+00:00",40],["2026-11-02T18:20:00+00:00",80],["2026-11-02T17:20:00+00:00",30]]},"expected":[[40,80,0],120,"40"],"observed":[[40,80,0],120,"40"]},{"condition":"Third day confirmed closed","input":{"zone":"America/New_York","open_days":["2026-10-30","2026-11-02"],"sales":[["2026-10-30T17:15:00+00:00",40],["2026-11-02T18:20:00+00:00",80],["2026-11-02T17:20:00+00:00",30]]},"expected":[[40,80],120,"60"],"observed":[[40,80],120,"60"]},{"condition":"Exactly 14:00 local excluded","input":{"zone":"America/New_York","open_days":["2026-10-30","2026-11-02","2026-11-03"],"sales":[["2026-10-30T17:15:00+00:00",40],["2026-11-02T18:20:00+00:00",80],["2026-11-02T17:20:00+00:00",30],["2026-11-02T19:00:00+00:00",50]]},"expected":[[40,80,0],120,"40"],"observed":[[40,80,0],120,"40"]},{"condition":"Corrected sale falls just inside the hour","input":{"zone":"America/New_York","open_days":["2026-10-30","2026-11-02","2026-11-03"],"sales":[["2026-10-30T17:15:00+00:00",40],["2026-11-02T18:20:00+00:00",80],["2026-11-02T17:20:00+00:00",30],["2026-11-02T18:59:00+00:00",60]]},"expected":[[40,140,0],180,"60"],"observed":[[40,140,0],180,"60"]}],"instructions":"Save python_source in a Python 3 module. Call the named routine with each check.input and compare with check.expected. Calendar case needs an IANA time-zone database."}