| 1 | # Advanced Reports AI Usage
|
|---|
| 2 |
|
|---|
| 3 | ## Name of AI service/solution that was used
|
|---|
| 4 |
|
|---|
| 5 | **Claude Code** (Anthropic)
|
|---|
| 6 |
|
|---|
| 7 | - **URL:** https://claude.com/claude-code
|
|---|
| 8 | - **Type of service/subscription:** Claude subscription, model Claude Sonnet 5.
|
|---|
| 9 |
|
|---|
| 10 | ## Final result
|
|---|
| 11 |
|
|---|
| 12 | ### Diagram
|
|---|
| 13 |
|
|---|
| 14 | None. Both reports read `transactions`, `market_trades`, `orders`, `markets`, `crypto` and
|
|---|
| 15 | `users` exactly as they already existed after
|
|---|
| 16 | [Normalization](../P5-Normalization/Normalization.md) — no attribute or relation was missing,
|
|---|
| 17 | so [ERModel](../P1-ConceptualModel/ERModel.md) and
|
|---|
| 18 | [RelationalDesign](../P2-RelationalDesign/RelationalDesign.md) needed no changes and there is
|
|---|
| 19 | no new diagram for this phase. This is stated explicitly rather than left implicit because the
|
|---|
| 20 | phase rubric specifically calls out modifying the design as the fallback when a good report
|
|---|
| 21 | idea can't be answered by the data on hand — it wasn't needed here.
|
|---|
| 22 |
|
|---|
| 23 | ### Results in details / description
|
|---|
| 24 |
|
|---|
| 25 | The AI:
|
|---|
| 26 |
|
|---|
| 27 | - Turned my two fully-specified report questions (the exact P/L, ROI, consistency, volume,
|
|---|
| 28 | return, volatility and participation formulas were mine) into two single-statement SQL
|
|---|
| 29 | queries, each wrapped as a `LANGUAGE sql STABLE` function
|
|---|
| 30 | (`project.report_top_traders`, `project.report_market_performance`) in
|
|---|
| 31 | [`schema_creation.sql`](../../server/db/schema_creation.sql), so the phase's "just one SQL
|
|---|
| 32 | query" requirement is met by the query text itself, while still giving the prototype a
|
|---|
| 33 | clean, parameterised, named thing to call.
|
|---|
| 34 | - Wired both into the running CLI as real menu options — `server/reports.go`, options
|
|---|
| 35 | `[10]`/`[11]` in `server/cli.go` — rather than leaving them as documentation-only SQL, per
|
|---|
| 36 | the phase's own framing ("used as reports within your application").
|
|---|
| 37 | - Wrote the relational-algebra equivalent of each query, including how to express
|
|---|
| 38 | `FIRST_VALUE`/`LAST_VALUE` (which have no classical RA equivalent) as an aggregation for the
|
|---|
| 39 | boundary timestamp followed by a self-join, and how to express `FILTER (WHERE …)`-style
|
|---|
| 40 | conditional counts as separate groupings recombined with left outer joins.
|
|---|
| 41 | - Noticed that the existing `data_load.sql` seed data (a few minutes of trade history) cannot
|
|---|
| 42 | demonstrate either report meaningfully — everything falls into one quarter, so "consistency"
|
|---|
| 43 | and "market return over time" have nothing to show — and wrote
|
|---|
| 44 | [`reports_demo_data.sql`](../../server/db/reports_demo_data.sql), an optional, separate,
|
|---|
| 45 | idempotent script adding five quarters of synthetic transactions, market trades and executed
|
|---|
| 46 | orders, deliberately excluded from `-init`/`-load-data` so it cannot disturb the balances the
|
|---|
| 47 | other use cases' documented "verified run" sections depend on.
|
|---|
| 48 | - Ran both reports against a live PostgreSQL 16 database with that demo data loaded, through
|
|---|
| 49 | the actual CLI, and used the real output (including a run where alice's seeded quarter
|
|---|
| 50 | interacted with a pre-existing `data_load.sql` transaction and flipped a profitable quarter
|
|---|
| 51 | into a loss) as the verified evidence in [AdvancedReports.md](AdvancedReports.md), rather
|
|---|
| 52 | than inventing example numbers.
|
|---|
| 53 |
|
|---|
| 54 | ## Summary of AI involvement
|
|---|
| 55 |
|
|---|
| 56 | | | This session — 2026-09-16 |
|
|---|
| 57 | |---|---|
|
|---|
| 58 | | **What I brought** | The phase rubric, plus both report questions fully specified down to the exact aggregate formulas |
|
|---|
| 59 | | **What the AI did** | Wrote the SQL, wrote the relational algebra, wired the reports into the CLI, designed and ran the demonstration data, verified everything against a live database |
|
|---|
| 60 | | **What I decided** | To keep both reports as SQL functions rather than plain ad-hoc queries so they are actually usable from the application; to accept the AI's synthetic multi-quarter demo dataset rather than wait for enough real usage history to accumulate |
|
|---|
| 61 |
|
|---|
| 62 | The two ideas and their formulas were mine, specified in enough detail (P/L as the sum of
|
|---|
| 63 | buy+sell+fee transactions, ROI relative to total buys, consistency as a share of profitable
|
|---|
| 64 | quarters, market return as first-vs-last trade price, volatility as price standard deviation,
|
|---|
| 65 | participation from orders rather than trades) that there was no separate "AI alternative
|
|---|
| 66 | idea" to borrow from and document a change against, unlike the more open-ended P1–P3 phases —
|
|---|
| 67 | the AI's job here was implementation and verification of a fully-specified design, which is
|
|---|
| 68 | what is logged above and in the prompt below.
|
|---|
| 69 |
|
|---|
| 70 | ## Entire AI usage log
|
|---|
| 71 |
|
|---|
| 72 | ### 2026-09-16
|
|---|
| 73 |
|
|---|
| 74 | **Intent:** hand over the P6 rubric together with both report ideas, fully specified, and
|
|---|
| 75 | have the whole phase — SQL, relational algebra, prototype integration, and demonstration data
|
|---|
| 76 | — produced and verified in one pass.
|
|---|
| 77 |
|
|---|
| 78 | **Prompt (student, verbatim):**
|
|---|
| 79 | > Phase P6: Complex DB Reports (SQL, Stored Procedures, Relational Algebra)
|
|---|
| 80 | > [the full phase rubric was pasted: 2 complex analytical reports solvable each with one SQL
|
|---|
| 81 | > query, usable as reports within the application, with a note that helper views/functions/
|
|---|
| 82 | > procedures are acceptable when pure SQL isn't enough, that the design should be extended if
|
|---|
| 83 | > a good idea needs data that doesn't exist yet, a requirement for the corresponding relational
|
|---|
| 84 | > algebra, the exact `AdvancedReports`/`AdvancedReportsAIUsage` wiki templates, and the phase's
|
|---|
| 85 | > AI-use rules]
|
|---|
| 86 | >
|
|---|
| 87 | > I will describe for you the 2 more complex sql queries:
|
|---|
| 88 | > 1. Find the users who performed the best in a selected quarter, year, or multi-year period
|
|---|
| 89 | > based on their realized trading performance, and show their total profit/loss, total
|
|---|
| 90 | > amount invested, ROI, number of profitable and losing periods, and consistency of
|
|---|
| 91 | > returns. Calculate realized P/L as SUM(sell transactions + buy transactions + fee
|
|---|
| 92 | > transactions), calculate ROI as realized P/L / absolute value of total buy transactions ×
|
|---|
| 93 | > 100, and calculate consistency as profitable periods / total periods × 100.
|
|---|
| 94 | > 2. Find which cryptocurrency markets performed best during a selected quarter, year, or
|
|---|
| 95 | > multi-year period based on trading activity and price behavior, and report the markets
|
|---|
| 96 | > with the highest trading volume, number of trades, number of participating users, and
|
|---|
| 97 | > price return. Calculate total volume as SUM(trade quantity), average trading price as
|
|---|
| 98 | > AVG(price), market return as (last trade price − first trade price) / first trade price ×
|
|---|
| 99 | > 100, price volatility as standard deviation of trade prices, and user participation as
|
|---|
| 100 | > COUNT(DISTINCT user_id) from the related executed orders.
|
|---|
| 101 |
|
|---|
| 102 | **Response (AI, summarised):**
|
|---|
| 103 | - Confirmed both report questions were answerable from the existing schema with no new
|
|---|
| 104 | columns or tables, and said so explicitly rather than silently skipping that check.
|
|---|
| 105 | - Wrote `report_top_traders` and `report_market_performance` as SQL functions, added to
|
|---|
| 106 | `schema_creation.sql` under a new `REPORTS (P6)` section.
|
|---|
| 107 | - Wrote `server/reports.go` (`ShowTopTraders`, `ShowMarketPerformance`, a shared
|
|---|
| 108 | `promptPeriod` helper) and added menu options `[10]`/`[11]` to `server/cli.go`.
|
|---|
| 109 | - Wrote `server/db/reports_demo_data.sql` for a richer, multi-quarter demonstration, and
|
|---|
| 110 | documented in its own header exactly why it is optional and what it deliberately does not
|
|---|
| 111 | touch (user balances, holdings).
|
|---|
| 112 | - Built the prototype, ran both reports against the live database with the demo data loaded,
|
|---|
| 113 | cross-checked the SQL output against hand-computed expected values for both seeded users,
|
|---|
| 114 | and used that real output as the verified evidence.
|
|---|
| 115 | - Wrote out the relational-algebra derivation for each query and [AdvancedReports.md](AdvancedReports.md).
|
|---|
| 116 |
|
|---|
| 117 | **What I decided:** to keep the demo dataset out of `-init`/`-load-data` rather than merge it
|
|---|
| 118 | into `data_load.sql`, since the other phases' documented expected values (specific balances in
|
|---|
| 119 | [BuildInstructions](../P4-Prototype/BuildInstructions.md)) depend on the seed data staying
|
|---|
| 120 | exactly as it is.
|
|---|
| 121 |
|
|---|
| 122 | > **Student action required.** Read [AdvancedReports.md](AdvancedReports.md) end to end
|
|---|
| 123 | > before the defense, and be ready to compute one period's realized P/L or one market's return
|
|---|
| 124 | > by hand from the raw `transactions`/`market_trades` rows — the numbers in the verified run
|
|---|
| 125 | > are real output, not invented, so they can be checked against
|
|---|
| 126 | > [`reports_demo_data.sql`](../../server/db/reports_demo_data.sql) directly. Append any further
|
|---|
| 127 | > prompts here if you ask for revisions.
|
|---|
| 128 |
|
|---|
| 129 | ### Follow-up — 2026-09-17
|
|---|
| 130 |
|
|---|
| 131 | **Intent:** simplify the market performance report after seeing it run — with only a handful
|
|---|
| 132 | of trades per market in most periods, price volatility read as noise rather than a useful
|
|---|
| 133 | signal.
|
|---|
| 134 |
|
|---|
| 135 | **Prompt (student, verbatim):**
|
|---|
| 136 | > Can you tell me the exact database_url so I can execute the schema creating and the data_load?
|
|---|
| 137 | >
|
|---|
| 138 | > From the Market Performance can we remove Volatility, I don't think that is that useful, also
|
|---|
| 139 | > can you tell me what is users column?
|
|---|
| 140 |
|
|---|
| 141 | **Response (AI, summarised):**
|
|---|
| 142 | - Gave the local dev connection string (`postgresql://bp_project:1234@localhost:5433/bp_database`,
|
|---|
| 143 | from `.env`) and explained `participating_users` is `COUNT(DISTINCT user_id)` from that
|
|---|
| 144 | market's executed orders, not from `market_trades` (which has no `user_id`).
|
|---|
| 145 | - Removed `price_volatility`/`STDDEV(price)` from `report_market_performance()` in
|
|---|
| 146 | `schema_creation.sql`, from its `RETURNS TABLE` and its `SELECT`, and from the corresponding
|
|---|
| 147 | column in `server/reports.go`'s `ShowMarketPerformance`.
|
|---|
| 148 | - Updated the relational algebra (`Stats`, `Result`) and the SQL listing, verified run output,
|
|---|
| 149 | and prose in [AdvancedReports.md](AdvancedReports.md) to match, and added a short note
|
|---|
| 150 | explaining why the column was dropped.
|
|---|
| 151 | - Rebuilt, re-ran `-init` and `reports_demo_data.sql` against the live database, and
|
|---|
| 152 | re-verified the market performance report through the actual CLI before and after the
|
|---|
| 153 | change to confirm only the one column disappeared and every other number is unchanged.
|
|---|
| 154 |
|
|---|
| 155 | **What I decided:** to drop the column entirely rather than keep it computed-but-hidden,
|
|---|
| 156 | since an unused computation left in the query is exactly the kind of thing that should not
|
|---|
| 157 | survive a review.
|
|---|