Changeset 9577c79 for docs/P1-ConceptualModel/ERModelAIUsage.md
- Timestamp:
- 09/16/26 23:37:15 (13 days ago)
- Branches:
- main
- Children:
- 8b447ef
- Parents:
- df05838
- File:
-
- 1 edited
-
docs/P1-ConceptualModel/ERModelAIUsage.md (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/P1-ConceptualModel/ERModelAIUsage.md
rdf05838 r9577c79 34 34 by reading it back through TerraER's own reader and comparing the figure count 35 35 (144), and it opens and can be edited in TerraER 3.11 like any hand-drawn 36 diagram. Subsequent versions (`ERModel_v02.xml` onward) are edited by the student 37 in the GUI. 36 diagram. `ERModel_v02.xml` is the student's own review pass over v01, done by 37 hand in the GUI. 38 39 `ERModel_v03.xml` / `ERModel_v03.png` (session 3, 2026-09-16) were produced the 40 same way, this time as a genuine load–modify–save round trip through TerraER's 41 own classes rather than a from-scratch build: `ERModel_v02.xml` was read with 42 the application's real `DrawFigureFactory` and `DOMStorableInputOutputFormat` 43 into a live `QuadTreeDrawing`, one `AtributoFigure` was cloned from the 44 existing `quantity` attribute of `Holds` (to inherit its exact styling) and 45 relabelled `reserved_quantity`, a matching `LabeledLineConnectionFigure` was 46 added between it and the `Holds` diamond (`ChopDiamondConnector` / 47 `ChopEllipseConnector`, the same connector pair every other attribute of 48 `Holds` uses), and every entity and relationship — together with its own 49 attributes, moved by the same offset — was translated proportionally toward 50 the diagram's centroid to close up excess canvas space, after which every 51 connection figure had `updateConnection()` called so its drawn path follows 52 the moved figures. The result was written with the real writer and rendered to 53 PNG with TerraER's own `ImageOutputFormat`, and re-verified by reading 54 `ERModel_v03.xml` back and confirming the figure count (146 = 144 + the new 55 attribute + its line) and that all five attributes of `Holds` resolve with the 56 expected connector classes. No figure was hand-edited in XML. 38 57 39 58 ### Model description … … 43 62 ## Summary of AI involvement 44 63 45 Work on this project happened in t wo working sessions, several months apart.46 47 | | Session 1 | Session 2 | 48 |---|---|---| 49 | **When** | 2026-04-21 | 2026-08-06 / 2026-08-07 | 50 | **Model** | Claude Opus 4.7 (1M context) | Claude Opus 5 (1M context) | 51 | **Phases advanced** | P1, P2, P3 and the first working prototype | The ER diagram file, P4 documentation, bug fixes | 52 | **My starting material** | `ep-diagram.md`, `opis.md`, my existing Go backend and draft SQL | Everything from session 1, plus the phase rubric | 64 Work on this project happened in three working sessions. 65 66 | | Session 1 | Session 2 | Session 3 | 67 |---|---|---|---| 68 | **When** | 2026-04-21 | 2026-08-06 / 2026-08-07 | 2026-09-16 | 69 | **Model** | Claude Opus 4.7 (1M context) | Claude Opus 5 (1M context) | Claude Sonnet 5 | 70 | **Phases advanced** | P1, P2, P3 and the first working prototype | The ER diagram file, P4 documentation, bug fixes | `Holds.reserved_quantity` added across P1–P4 | 71 | **My starting material** | `ep-diagram.md`, `opis.md`, my existing Go backend and draft SQL | Everything from session 1, plus the phase rubric | Everything from sessions 1–2, plus a design review of the sell-order flow | 53 72 54 73 In **session 1** I brought my own data model (`ep-diagram.md`, written in … … 65 84 for a review pass over the database and Go code, which turned up three further 66 85 bugs (see [PrototypeImplementationAIUsage](../P4-Prototype/PrototypeImplementationAIUsage.md)). 86 87 In **session 3** I described a concrete edge case I'd spotted in the sell flow 88 — nothing stopped a user from placing a second sell order against crypto 89 already promised to a first, unsettled one — and asked the AI to fix it 90 starting from P1 and carry the fix through every phase. This added 91 `reserved_quantity` to `Holds` and changed the sell path in `trade.go` to use 92 it; see the model history on 93 [ERModel](ERModel.md#entity-relationship-model-history) (v03) and the log 94 below. 67 95 68 96 Below is the log, one entry per exchange. My prompts are quoted as **excerpts**: … … 176 204 > any further prompts. The complete transcript is in your Claude Code session 177 205 > history. 206 207 --- 208 209 ### Session 3 — 2026-09-16 210 211 **Intent:** describe a concrete gap I'd found in the sell-order design — the 212 model had no way to represent crypto committed to an order that had not yet 213 settled — and have the AI trace the fix through every phase rather than patch 214 `trade.go` alone. 215 216 **Prompt (student, excerpt):** 217 > Suppose the user owns 2 BTC and wants to sell 0.5 BTC at market price. […] You 218 > currently have Holds: quantity, avg_price but you don't have a concept of 219 > reserved/committed crypto. For cash, you already explicitly distinguish 220 > available_balance, invested_balance. For crypto, you probably want the 221 > equivalent: quantity, reserved_quantity, avg_price. […] Can you please start 222 > from Phase 1 and modify everything to make it work like it should, modify 223 > the AIUsage.md in every Phase, and can you make the ConceptualModel a little 224 > bit more put together not that much spread out. 225 226 **Response (AI, summarised):** 227 - Read every phase document and the live `server/trade.go`, `portfolio.go` and 228 `schema_creation.sql` to confirm the actual gap: the sell path checked 229 `holdings.quantity` directly, with nothing recording that part of a position 230 was already promised to another order. 231 - Added `reserved_quantity` to `Holds` (P1), `holdings` (P2), the sell scenario 232 SQL (P3), and `trade.go`/`portfolio.go`/`schema_creation.sql` (P4) — one 233 attribute threaded consistently through all four phases rather than a 234 patch confined to the Go code. 235 - Changed the sell path to lock the holding row, compute 236 `available = quantity − reserved_quantity`, reserve (`reserved_quantity += 237 qty`) and then settle (`quantity -= qty; reserved_quantity -= qty`) inside 238 the same transaction — keeping the existing all-or-nothing guarantee rather 239 than splitting into two commits, which would leave an unresolvable `open` 240 order if the process died in between and there is no cancel use case to 241 recover it. 242 - Made both buy and sell orders genuinely pass through `status='open'` before 243 `status='executed'`, instead of being inserted as `'executed'` directly, so 244 the lifecycle the ER model already claimed for `Orders` is real. 245 - Added a `CHECK (reserved_quantity >= 0 AND reserved_quantity <= quantity)` 246 constraint and exposed `reserved_quantity`/`available_quantity` on 247 `v_portfolio` and in the CLI's portfolio table, so the new field is 248 observable rather than a column nobody can see. 249 - Restructured this phase's [ERModel](ERModel.md) into short rationale + a 250 compact attribute table per entity/relationship, per the "more put together, 251 not that much spread out" request — no content was removed, only 252 reformatted. 253 - Verified the fix against the live database (`bp_database` on `localhost:5433`): 254 ran two concurrent `sell 1.0 BTC` attempts against a holding with only 1.5 255 BTC available — exactly one succeeded, the other correctly reported 256 insufficient holding — and ran the reserve/settle sequence by hand in `psql` 257 to show `reserved_quantity` at 0.5 mid-transaction. Both are recorded in 258 [UseCase0005Implementation](../P4-Prototype/UseCase0005Implementation.md). 259 260 **What I decided:** to keep reserve and settle inside one transaction rather 261 than two (see the AI's reasoning above — I agreed with it, since a stuck 262 `open` order with no cancel command would be a worse bug than the one being 263 fixed). 264 265 **Follow-up, same day:** I asked for `ERModel_v03.xml`/`.png` after all, 266 having noticed the PNG still showed v02 with no `reserved_quantity` on it, and 267 asked at the same time for the diagram to be a little more compact — it had a 268 lot of empty canvas in the middle. The AI drove TerraER's own classes directly 269 (load → clone the `quantity` attribute → relabel it → add its connecting line 270 → pull every cluster toward the centroid → save → render), described in full 271 under [Diagram](#diagram) above, rather than hand-editing the XML or asking me 272 to do it in the GUI. I reviewed the rendered PNG before accepting it. 273 274 **Second follow-up, same day:** the first `ERModel_v03.png` rendered with a 275 black background instead of white, unlike v01/v02. Cause: TerraER's 276 `ImageOutputFormat` defaults to an ARGB image and paints its background with 277 zero alpha (transparent), not opaque white; whatever displayed the PNG then 278 flattened that transparency onto black instead of white. Fixed by exporting 279 through the same `ImageOutputFormat.toImage(...)` call for figure geometry, 280 but compositing its result onto an explicitly white-filled opaque `RGB` image 281 before saving, rather than trusting the library's own (transparent) output. 282 Verified the fix by reading back the corner pixel of the written PNG as pure 283 white `(255,255,255)`, matching `ERModel_v02.png`. 284 285 > **Student action required.** Open `ERModel_v03.xml` in TerraER and read it 286 > end to end before submission — see the note at the end of 287 > [ERModel](ERModel.md). Everything else in this session's diff is already 288 > applied to the docs and to `server/`.
Note:
See TracChangeset
for help on using the changeset viewer.
