# Design notes: why the Bridge Triage Desk UI is built this way This document records the reasons for the layout, the grouping and buying-path rules the page displays, and where every field comes from. It is written in plain English for teammates and for hackathon judges. The facts are taken from `engine/CONTEXT.md`, `engine/reference.py`, `engine/decision_log.py`, the UI code on this branch (`ui-v3`), `ui/data/SOURCES.md`, the contractor research notes, and the event dataset in the Grokathon bridges folder. Nothing here invents a price, a rating, an email address, or a count that is not in those sources. The user is a MassDOT bridge engineer. The page is the review desk: the bots propose a group, a cost, a buying path and a draft; the engineer signs off. The engine itself is plain Python with no LLM calls, so the same inputs always produce the same group and flags. ## 1. The problem and what the judges are scoring MassDOT's problem statement for this track is that inspection reports pile up faster than engineers can act on them. The team is building a desk that reads those reports, sorts each of the 200 bridges into a group with evidence, estimates cost when a pay item matches, picks the legal buying path, proposes a start date, and drafts paperwork that a human has to approve before anything goes out. Two findings in the data shaped the page: 1. **The database can lag the field.** Real 2025 town reports show some bridges in worse condition than the NBI record. The example used in the engine context is A-13-024 in Ashfield: NBI still has deck / super / sub as 6 / 6 / 6 (fair), but the 8 July 2025 report has superstructure 4 (poor). The page therefore puts NBI and the newest report side by side, marks differences in red, and treats `records_disagree` as its own flag even when another group wins. 2. **Urgent structural work often has nowhere to go in the work-order system.** The engine context notes that about 40 of 88 urgent findings need contractor work (in-house crews are not allowed to do it), while the work-order list only has 13 maintenance job types and those bridges are not in the project list. The page therefore surfaces `contract_needed` and, when contractor work is required, leads with a contractor email or bid notice rather than burying it under findings. The three judging themes this layout is meant to serve: - **Works on real data.** Identities, NBI ratings, coordinates, towns, the six Ashfield 2025 ratings, unit-cost bid prices, and the eight contractor names are real. Simulated findings and work orders are labeled. A yellow **SAMPLE DATA** banner appears whenever the page is not reading `engine/output/bridges.json`. - **Auditability.** Every group has a written reason, every reason is tagged with the rule that fired, evidence cites a source file and a page, and every sign-off is appended to one shared log. - **Human sign-off.** Approve, Edit and Reject (shown in plain language on the buttons) are the only way a recommendation moves forward. The page never sends email. ## 2. Layout and why each piece is where it is The page is one screen in three columns, plus a chat bubble in the corner. It is not a step-by-step wizard. The team considered clicking Next through “background, then findings, then the plan,” and rejected it: an engineer who already knows the bridge should not have to walk through screens they do not need. Deeper material is one click away, in collapsed sections on the same screen. ### Left: the list and filters The list is the work queue. Each row shows the bridge ID, town, the first reason, a `≠` mark when the report and the NBI disagree, and a badge for the latest decision. Group chips (Act now, Needs a contractor, Records disagree, Plan, No action, No report on file) show counts and filter the list. Search matches ID, town, BIN or structure number. By default the chips for **No action** and **No report on file** are off, so the first view is bridges that need a decision. The engineer can turn those groups back on. The list is sorted by group (act first, then contract, verify, plan, none, noreport) and then by bridge ID, so the most urgent work is at the top. PDF intake at the bottom of this column is a stub. The Inspector bot will attach here later; it is not wired on this branch. ### Center: the map Pins are colored by group so a district's pattern is visible at a glance (for example a cluster of “Act now” or “Records disagree”). Clicking a pin selects that bridge. The map starts zoomed out over Massachusetts. **Selecting a bridge flies the map in to zoom 15** (about street level) over 0.8 seconds, opens the pin's popup and enlarges that pin with a halo. Clearing the selection (the × on the summary card, or Esc) or changing the group filter zooms back out to fit the pins still in the list. `map/bridge-map.html` (Person B2) is not in the repo yet, so this branch uses its own Leaflet file, `ui/static/map.js`. The page only talks to the map through a small set of calls (`init`, `setBridges`, `setVisible`, `select`, `fitVisible`, `view`). When B2's file lands, those same calls — including the zoom-15 / zoom-out behavior — should be kept. ### Right: the detail panel, email first A long scroll of ratings, evidence, findings, plan and then the email was hard to use. The team agreed the engineer mostly needs a short summary and the draft they are being asked to approve; the rest should be there, but closed until someone wants it. The order on this branch is: 1. **Summary card.** Bridge ID, BIN, town, structure number, the group badge (with the rule number, for example “Rule 3: verify”), a one-line why, estimated cost, buying path, earliest start, a “records disagree” chip when it applies, a “contractor work” chip when it applies, **Copy link**, and **Open in Excel sheet**. 2. **Contractor email draft**, only when `contract_needed` is true or any finding is marked `contract: true`. A bridge such as A-13-024 (verify, no contractor findings) has no draft and goes from the summary to the decision. 3. **Contractor replies**, under the same condition. If `engine/output/replies/.json` exists, quotes are listed and the lowest remaining amount is highlighted “lowest quote.” Otherwise the panel says “No replies yet.” The engineer still has to confirm the firm is responsible and eligible before award. This is a placeholder list, not a live inbox. 4. **Decision**, under the question “Do you agree with this recommendation?”, then the decision history. 5. **Collapsed details**, with counts on the summary line: Reasons and rules, Evidence, NBI vs report ratings, Findings, and Plan details (suggested action, cost, buying path, start, crew). Why those pieces are shown at all: - **Reasons and rule tags.** The grouping is a fixed algorithm, not a model guess. Tagging each reason with “Rule 1: act” (and so on) makes the rule that fired visible and links it back to `CONTEXT.md` section 4. Cost and schedule notes point at section 5. Extra notes (NBI status E or K, urgency/severity mismatch) point at section 8. - **NBI vs report, differences in red.** This is the “database lags the field” check. The report source line says whether the ratings came from a real town report (marked “to verify”) or a simulated report. - **Evidence with a file name and page.** Judges asked for auditability. The Inspector's job is to extract findings with citations; the page shows those citations rather than paraphrasing them away. - **Findings with severity, urgency and a contractor badge.** The contractor badge is the `needs_contractor` keyword rule, so the engineer can see which items in-house crews cannot do. - **Cost as “no price yet” when there is no match.** The engine is forbidden from inventing a price. A missing pay item is a blank plus a reason, not a made-up number. - **Excel link.** Teammates noted that most engineers already work in Excel. B2's `engine/output/review.xlsx` is the familiar sheet (one row per bridge that is not `none` or `noreport`). The link serves that file when it exists and names the Bridge ID and row. Until B2 builds the file, the server generates a fallback workbook with the same columns (Decision is a blank Approve/Edit/Reject dropdown so `import_review_xlsx` stays compatible) and marks it SAMPLE when the page is on sample data. The real file, once present, is served instead and is never overwritten. - **Cancel and Undo.** "Change something first" and the dismiss-reason step include a grey-outline Cancel button that writes nothing and restores the original values. After a decision is logged, "Undo this decision" appends a `Withdrawn` row (note cites the original `when`) and `latest_decisions()` treats the bridge as undecided. The Excel dropdown does not include Withdrawn. - **Citations.** Evidence source names that end in `.pdf` link to `/files/source/`. Simulated current-cycle PDFs are bundled under `data/parsed/reports/`. Real Ashfield town reports are not bundled (they are large); the route serves a parsed extract, and only the Burton Hill Road / A-13-025 public URL recorded in the event SOURCES.csv is offered. Rule tags link to CONTEXT.md. Header links open the Excel sheet, the decision log, CONTEXT.md, DESIGN_NOTES.md, and SOURCES.md. - **Deep link `#bridge=`.** The hash stays in sync with the selection, so a colleague can open the same bridge. `?select=` still works as a fallback. Copy link puts the URL on the clipboard. ### The SAMPLE DATA banner Until B1 and B2 write `engine/output/bridges.json`, the server falls back to `ui/sample/bridges.sample.json` and shows a yellow banner: ratings and locations are real, findings are simulated, costs are placeholders. The sample is never written into `engine/output/`. When the real file appears, the banner goes away and the server re-reads the file if it changes. ### The Grok Bot bubble The bubble in the bottom right is for asking about **this screen**, not for a generic chatbot. The page posts the current context with the question: the selected bridge, active filters, visible IDs and counts, the map view, the latest decision, any email draft on screen, and whether the data is sample or engine output. That is so an engineer can ask “why is this in verify?” and the bot already has the ratings and reasons in front of it. On this branch the bubble is **mock only**. It returns a canned sentence built from that context. The real webhook (`mode: "webhook"` in `ui/config.json`) is not connected and answers 501. The key, when it is added, stays in the git-ignored config and is sent only from the server, never from the browser. Decisions do not depend on the bot. ## 3. The decision-making algorithm The rules live in `engine/reference.py` and are described in `CONTEXT.md` sections 4 and 5. They are drafts until Person C (the civil engineer) confirms them. The UI does not re-implement the rules; it displays the fields B1 and B2 write into `bridges.json`. The sample file on this branch is built with the same helper functions so the page can be demonstrated before the real file exists. ### Group assignment (first match wins) `records_disagree` and `contract_needed` are always computed and stored as their own fields, even when a higher group wins. For example a bridge can be in `act` and still show `records_disagree` and `contract_needed`. `contract_needed` is true when any finding with urgency Immediate or ASAP is work that `needs_contractor` would flag. The contractor-needed keyword rule (`needs_contractor(elem, desc)`), also a draft, is: - Beams/girders or Diaphragms, unless the description is about paint (structural steel repair). - Bearings described as frozen or tipped (bearing replacement). - Element Scour, or a description that mentions undermining (scour countermeasures). - Abutments, Piers or Wingwalls whose description mentions rebar, crack, spall, section, settle, tilt or lean (substructure concrete). ```mermaid flowchart TD start[Bridge: NBI record, plus newest report and findings if any] start --> q0{No findings and no report ratings?} q0 -->|yes| noreport[noreport: no report on file] q0 -->|no| q1{Any rating, report or NBI, of 3 or lower, or any Immediate finding?} q1 -->|yes| act[act: Act now] q1 -->|no| q2{Any Immediate or ASAP finding that needs a contractor?} q2 -->|yes| contract[contract: Needs a contractor] q2 -->|no| q3{Newest report deck, super or sub differs from NBI?} q3 -->|yes| verify[verify: Records disagree] q3 -->|no| q4{Any Immediate, ASAP or Prioritize finding crews can do?} q4 -->|yes| plan[plan: Plan] q4 -->|no| none[none: No action, Schedule-level findings only] ``` Four test bridges in the sample (expected groups are drafts until Person C confirms): | ID | What is true | Expected | |---|---|---| | A-13-024 | NBI 6/6/6, 2025 report super 4 | `verify`, `records_disagree: true` | | C-20-004 | Report super 2, three Immediate critical findings; NBI status E | `act`; reasons mention the temporary structure | | N-14-007 | Report super 2, Immediate findings; NBI status K | `act`; reasons mention the bridge is closed | | B-16-586 | Graffiti coded Immediate with severity Minor | `act`, plus a reason flagging an urgency/severity mismatch | ### Cost Person B2 maps each actionable finding to a bid pay item from `DERIVED_unit_costs.csv` (real prices from three 2026 MassDOT bridge contracts) and multiplies by quantity. The draft unit prices in `CONTEXT.md` section 5, still waiting on Person C, are: - Structural steel repairs: $50/LB (item 107.97) - Rapid-hardening concrete repair: $5,000/CY (item 909.5) - Asphalt patching: $339/TON (item 451) - Anchor bolt corrective action at bearings: $2,500 EA (item 913.21) There is no clear match yet for bearing replacement, scour protection or joints. In those cases `est_cost` is left null and a reason says so. A price is never invented. **The sample file on this branch does not use those bid prices.** It uses placeholder rates only so every buying tier appears in the demo, and it writes “SAMPLE cost from placeholder rates, not a bid price” into the reasons. When B2's real `bridges.json` lands, those placeholders go away. ### Buying path (M.G.L. c.30 §39M) `buying_path(est_cost)` in `reference.py`: | Estimated cost | `buying_path` | What it means | |---|---|---| | Under $10,000 | `under_10k_sound_business_practices` | Sound business practices (periodic quotes, keep a record) | | $10,000 to $50,000 inclusive | `10k_50k_three_written_quotes` | Written scope; seek at least three written quotes; two-week notice on the website, COMMBUYS, the Central Register and an office posting; award to the lowest-priced responsible firm; 50% payment bond if the cost is over $25,000 | | Over $50,000 | `over_50k_advertised_sealed_bid` | Sealed public bids, advertised two weeks (Central Register, a local newspaper, COMMBUYS) plus a one-week posting; advertising also under c.149 §44J; MassDOT prequalification (c.81 §8B and 700 CMR 14.00); 5% bid deposit; 100% performance and payment bonds within three days of award; award to the lowest responsible and eligible bidder as defined in §39M(c) | | `est_cost` is null | `unknown` | No path is chosen until there is a price or a quote | | “Act now” emergency | (the path still follows the cost if one exists) | The emergency exception covers **temporary repairs only**. The permanent fix still goes to bid. The suggested action for `act` says this in so many words. | Prevailing wage applies in every draft. ### Schedule “Today” for the engine is 5 December 2026. `earliest_start` is the day after the assigned crew's `BOOKED_THROUGH` date, or today, whichever is later. Extra constraints: - In-house crews cannot do deck concrete or joint work from 1 December 2026 through 31 March 2027 (`WINTER_ELEMS`: Deck, Joints, Wearing). If the tentative start falls in that window, it moves to 1 April 2027. - District 1 crews (`D1-BRG1`, `D1-BRG2`) are booked through 20 December 2026; District 6 crews (`D6-BRG1`, `D6-BRG2`, `D6-BRG3`) through 15 January 2027; both `*-CONTRACTOR` crews through 28 February 2027. - Contractor work is assigned to that district's `*-CONTRACTOR` crew. In-house work in the sample is assigned to `D{district}-BRG1`. - District comes from NBI Item 2: 60 bridges in District 1, 130 in District 6, 10 in District 4. The crew calendar only covers Districts 1 and 6. District 4 bridges are flagged “no crew data” and get no start date. - 127 work orders use crew `D1-BRG3`, which is not in the calendar. The engine should flag that and not crash. That crew is also missing from the calendar file used to schedule. ### How the email template changes by tier The Clerk output on this branch is a deterministic template in `ui/server/email_draft.py` (no LLM). If `engine/output/clerk_drafts/.json` (or `.json`) is present, that file wins. The engineer can still edit the text before approving. Recipients, subject and body are all editable. There are no email addresses on file, so To stays blank with the placeholder “contractor email (from MassDOT prequal list).” | Path | What the draft is | |---|---| | Under $10k | A quote request, usually to one firm (the engineer can add more). Cites c.30 §39M sound business practices. | | $10k to $50k | A request for a written quotation against the written scope. Three firms are pre-selected (eastern or western order based on the district). The same request is posted for two weeks on COMMBUYS, the Central Register and the website, with an office posting. Adds the 50% payment bond line when the estimate is over $25,000. Award to the lowest-priced responsible firm. | | Over $50k | **Not a direct solicitation.** A courtesy notice of an Invitation for Bids, pointing at the official advertisement (Central Register, local newspaper, COMMBUYS, two weeks, plus a one-week posting). 5% bid deposit, 100% performance and payment bonds within three days, award to the lowest responsible and eligible bidder under §39M(c), prequalification required. The body says not to return a bid in reply to the email. | | Cost unknown | Asks for a site visit and a quote, and says the cost tier is not yet known because no pay item matched. | Every draft includes the bridge ID, BIN, town, facility and feature when present, coordinates, the contractor-only findings (with quantity and unit when present), earliest start, a reply deadline two weeks out, a prevailing-wage line, a disclaimer that ratings are real and findings in the demonstration are simulated, and the sign-off “MassDOT District N Bridge Maintenance.” The shortlist is the eight real bidders on the three 2026 bid tabs in the event data, loaded from `ui/data/contractors.csv`. The page does not invent addresses and does not send mail. **Copy email** and **Open in mail app** (`mailto:`) are the only ways the text leaves the page, and only after the engineer has decided they are ready. ### Contractor profiles Each firm on the shortlist has a Profile expander built from `ui/data/contractor_profiles.json` (generated by `ui/data/build_profiles.py`). The profile shows the public website (checked with curl), MassDOT bid lines from the three real bid tabs (contract, rank, amount, and whether the firm was the low bidder / recommended award, each with a source URL), a short bridge-experience sentence quoted from the firm's own site with the URL, a link to the MassDOT prequalification program page, and a tag. **The tag is not a judgment of firm size or overall experience.** “Established” means the firm bid on two or more of the **three bid tabs in this dataset**. Otherwise the tag is “Limited history in our data.” That is why, for example, MIG Corporation is tagged “Limited history in our data” (it appears on one of the three tabs, as the recommended awardee on Revere R-05-015) even though its public site describes a much larger body of work. The profile itself says the bid lines are only these three contracts, not the firm's full history. Repair-type experience (bearings, diaphragms, scour) is “not found” in this first round. MassDOT does not publish a current official prequalified roster with emails or capacity ratings; unofficial lists are name and expiration date only. ## 4. Human sign-off Nothing in the recommendation becomes an outgoing request until an engineer clicks one of the three buttons. The question above them is “Do you agree with this recommendation?” | Button the engineer sees | Value written to the log | What it means | |---|---|---| | **Approve and prepare email** (or **Approve plan** when there is no contractor draft) | `Approve` | Agree with the group, the action, the cost and, if there is a draft, keep that text as the final version to send. The page also writes `engine/output/drafts/_contractor_email.txt` (git-ignored). A confirmation line appears, for example “Approved by Priya at 11:40 AM ET, email ready to send.” | | **Change something first** | `Edit` | Open the fields (group, suggested action, cost, buying path, start, crew, and the email text). At least one field must change. The log keeps `original` (what the bots showed) and `edited` (only the fields that changed) side by side. | | **Not right, dismiss** | `Reject` | The recommendation is wrong. A short reason is required. Nothing goes forward. The email draft is not stored on a Reject row. | The log values stay `Approve` / `Edit` / `Reject` so the CSV and the Excel Decision dropdown stay in sync. The engineer name is entered once (kept in the browser) and is the `who` column. Click the name in the header to change it. ### The shared decision log One file, one writer: `engine/output/decision_log.csv`, through `engine/decision_log.py`. The web UI and the Excel import both append to it. Rows are only ever appended; the latest row per bridge is the current decision. Columns, in order: | Column | What it holds | |---|---| | `who` | Engineer name | | `when` | ISO 8601 time with the America/New_York offset, e.g. `2026-12-05T11:42:07-05:00` | | `bridge` | Structure number, e.g. `A130240EFMUNNBI` | | `bdept` | Report ID, e.g. `A-13-024` | | `decision` | `Approve`, `Edit` or `Reject` | | `original` | JSON of `group`, `suggested_action`, `est_cost` exactly as shown | | `edited` | JSON of only the fields the engineer changed; empty when nothing changed | | `note` | Engineer's note / reason | | `source` | `ui` or `excel` | | `email_draft` | JSON of `to`, `subject`, `body` as approved or edited; empty on Reject, on Excel imports, and when there is no contractor draft | B2 should call `ensure_log()` and `import_review_xlsx("engine/output/review.xlsx", who="...")` from `outputs.py`, not write a second CSV. The import reads the Decision column and the Engineer's note, maps Bridge ID to the structure number through `bridges.json`, fills `original` from the engine values, and for an Edit row stores only the sheet values that differ. Blank Decision cells are skipped. Running the import twice skips a row that is identical to the latest Excel row for that bridge. Test rows are not committed; the log file is created on the first real decision. **The page does not send email or post a bid notice.** After Approve, the engineer copies the text or opens it in a mail app. ## 5. Data sources PUBLIC means a real published record. DERIVED means built from public sources by the organizers (joined, parsed or summarized); values trace back to a published source, but processing can introduce errors. SIMULATED means a synthetic stand-in for internal MassDOT or town records. Simulated inspection report pages are watermarked “SYNTHETIC - NOT A REAL INSPECTION.” The join key everywhere is NBI Item 8, `STRUCTURE_NUMBER_008` (for example `A130240EFMUNNBI`). The report ID “BR. DEPT. NO.” `A-13-024` is characters 1–6; the BIN is characters 7–9. Rating history joins on `CURRENT_STRUCTURE_NUMBER_008`. Coordinates are packed: `LAT_016` is DDMMSSss, `LONG_017` is DDDMMSSss and is west, so it is stored negative. | Field on the page | Where it comes from | Real, derived or simulated | Caveats | |---|---|---|---| | Structure number, bdept, BIN | `DERIVED_bridges.csv` (NBI Item 8) | Derived from real NBI | Real bridge identities | | Town | `DERIVED_bridges.csv` `TOWN` | Derived | Decoded from Census place code | | Facility carried, feature crossed, district, year built, ADT, open/closed/posted status | Same file, NBI items 7, 6A, 2, 27, 29, 41 | Derived from real NBI | Status E means a temporary structure is in place; K means closed. Those are called out in reasons. | | Latitude / longitude | `LAT_016`, `LONG_017`, converted by `reference.nbi_lat` / `nbi_lon` | Derived from real NBI | Packed degrees-minutes-seconds, not decimal in the source file | | NBI deck / super / sub and inspection date | Items 58, 59, 60 and 90 (`DATE_OF_INSPECT_090` is MMYY) | Real NBI ratings (in a derived table) | This is the official inventory record, which can lag a newer field report | | Report ratings (most bridges) | `data/parsed/reports.csv`, from `docs/SIMULATED_inspection_reports/` | Simulated | Newest `cycle == "current"` report only. 29 bridges also have a prior-cycle report, used for “what changed,” not as the current rating. | | Report ratings for six Ashfield bridges: A-13-024, A-13-020, A-13-015, A-13-023, A-13-025, A-13-028 | Real 2025 town reports in `docs/PUBLIC_inspection_reports/`, applied as an override (CONTEXT.md section 3) | Real, marked **to verify** until Person C confirms | The dataset folder also has other real reports (Pittsfield, two Plymouth reports, and an Ashfield Apple Valley report) that are not in this six-row override table. | | Findings (part, description, severity, urgency, quantity, unit) | `data/parsed/defs.csv`, parsed from the simulated reports | Simulated | The `contract` flag is derived from the keyword rule above, not from a column in the PDF. | | Evidence (source, page, text) | Built from the report file name and the ratings or urgent findings | Mix: real PDF names for the Ashfield overrides; simulated file names otherwise | Page is 1 for the overall condition line in the sample; some finding lines have no page. | | `group`, `reasons` | `reference.assign_group` and the reason text B1 (or the sample builder) writes | Derived from the inputs above | Rules are drafts until Person C confirms. Sample reasons are a stand-in for B1's `rules.py`. | | `records_disagree` | `reference.records_disagree`: any of deck / super / sub differs, ignoring blanks | Derived | False when there is no report. | | `contract_needed` | Any Immediate or ASAP finding that `needs_contractor` flags | Derived | Stored even when the group is `act`. | | `est_cost` | B2: quantities × `DERIVED_unit_costs.csv`. Sample: placeholder rates | Unit costs are real bid prices (derived from three 2026 contracts). Sample costs are **placeholders, not bid prices** | Null when there is no match (bearing replacement, scour protection, joints, and any other unmatched element). Never invent a price. | | `buying_path` | `reference.buying_path(est_cost)` | Derived from the cost, using the statute cited above | `unknown` when cost is null | | `earliest_start`, `crew` | `SIMULATED_crews_calendar.csv` plus `reference.earliest_start` | Simulated calendar, derived start date | See schedule notes and the District 4 / D1-BRG3 issues below | | Work orders (used by the engine for context, not the main page fields) | `SIMULATED_work_orders.csv` | Simulated | Covers 199 of the 200 bridges; `N05013066MUNNBI` has no work orders | | Contractor shortlist (name, city, address, bid ranks and amounts) | `ui/data/contractors.csv`, from the three PUBLIC bid tabulations (Revere R-05-015, Bernardston B-10-001, Deerfield D-06-001) | Real bidders and bid amounts | **No email addresses.** These three contracts are in Districts 4 and 2, not 1 or 6. There is no official public prequalified list. | | Contractor profiles | `ui/data/contractor_profiles.json`, from that CSV plus each firm's public website and a stale 2023 municipal CMS004 copy | Real bid lines and public-site quotes | The Established / Limited tag counts only these 3 bid tabs, not firm size. CMS004 expirations are 2023–2024 (stale). Repair-type experience is not found. | | Decision log and approved email text | Written by this UI or by the Excel import | Created in use, not source data | Append-only | | `BRIDGE_CONDITION` in the rating history (G/F/P) | `DERIVED_rating_history.csv` | Derived from NBI | Filled in only from 2019 on (0 of the earlier years; 2019 onward is complete for the bridges present that year). The current 2025 NBI extract has the letter for all 200 bridges. | Known data issues, verified in the event files: - Crew **D1-BRG3** appears on work orders but is missing from `SIMULATED_crews_calendar.csv`. - Work orders are missing one of the 200 bridges: **N05013066MUNNBI**. - **`BRIDGE_CONDITION` in the history file is blank before 2019.** ## 6. What is sample vs real right now, and how B1 and B2 plug in ```mermaid flowchart LR reports[Inspection reports: six real Ashfield 2025 town PDFs, plus simulated reports] inspector[Inspector: extracts ratings and findings with page citations] nbi[Real NBI record: DERIVED_bridges.csv] rules[Risk Engineer rules: engine/reference.py and B1 rules.py] costs[B2: real bid unit costs and the simulated crew calendar] json[engine/output/bridges.json] ui[This UI] excel[Excel review.xlsx] log[engine/output/decision_log.csv] clerk[Clerk drafts: contractor email or IFB, and draft work orders] reports --> inspector inspector --> rules nbi --> rules rules --> json costs --> json json --> ui json --> excel json --> clerk ui --> log excel --> log ``` **Right now, `engine/output/bridges.json` is not in the repo.** The page is running on `ui/sample/bridges.sample.json`: - Real: all 200 NBI identities, towns, coordinates, NBI ratings and dates; the six Ashfield 2025 report ratings (marked “to verify”). - Simulated: findings and most report ratings, from the parsed simulated reports; the crew calendar used for start dates. - Placeholder, not real: sample cost numbers (and therefore some buying-path assignments that depend on those costs). - The four test bridges listed in section 3 are in the sample. How the teammates plug in, without changing the page: - **B1** (`engine/rules.py`) writes `engine/output/bridges.json` with every field through `findings`, using the section 6 schema, the six Ashfield overrides, and the grouping rules. Re-running the script is enough: the server re-reads the file on change and the banner disappears. - **B2** (`engine/outputs.py`) adds `est_cost`, `buying_path`, `earliest_start` and `crew` using the real bid prices, writes `review.xlsx`, calls `decision_log.ensure_log()` and `import_review_xlsx()` (not a second CSV writer), and when ready replaces the map with `map/bridge-map.html` using the same map calls. The Excel link on the page starts working as soon as `review.xlsx` exists. - **Person A / Clerk.** A later Grok Bot can drop a JSON draft in `engine/output/clerk_drafts/` and replace the template text. The engineer still edits and approves it. - Optional `suggested_action`, `facility`, `feature`, `district`, and finding `qty` / `unit` are already understood by the page if B1 or B2 include them. If `suggested_action` is missing, the server fills one from the group and buying path. ## 7. Known limitations and next steps Already true on this branch, and worth saying out loud: - The grouping and contractor-needed rules, and the draft unit prices, are **drafts until Person C confirms them**. - Sample costs are placeholders. Do not treat them as engineer's estimates. - The six Ashfield report ratings are real but still marked **to verify**. - Findings and work orders are simulated. Any text that quotes those numbers should say so (the email disclaimer already does). - No contractor emails are on file. MassDOT does not publish a current official prequalified list with addresses; an unofficial name-and-expiration list can be requested from prequal.r109@dot.state.ma.us. - The Established / Limited history tag only reflects the three bid tabs in the dataset, not how large or experienced a firm is. - District 4 has no crew data. D1-BRG3 is missing from the calendar. One bridge has no work orders. `BRIDGE_CONDITION` in the history file starts in 2019. - The emergency path is temporary repairs only. - Profiles are a first round: repair-type experience is “not found,” and MassDOT history is only the three tabs. Not built yet (and not required for sign-off or the decision log): - The real Grok Bot webhook behind the bubble. - PDF intake / the Inspector trigger on the page. - `map/bridge-map.html` from B2 (the swap interface is ready). - B1/B2's real `bridges.json` and `review.xlsx`. - A live contractor-reply inbox (the panel only reads a local JSON file). - Any automatic send of email or bid advertisements.