Skip to content

Commit 7726944

Browse files
committed
Updated all notes
1 parent 2b1c044 commit 7726944

4 files changed

Lines changed: 67 additions & 9 deletions

File tree

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Apex Grid
22

3-
## Live app
3+
## 🚀 Live app
44

55
- Production (deployed): <https://apex-grid-transformer-tracker.vercel.app/>
66
- Want to run everything locally? Use the instructions in `Instructions.md`.
77

8-
## Auth
8+
## 🔒 Auth
99

1010
- Log in with `user1`..`user5` using the same value as the password (e.g., `user3`/`user3`).
1111
- Backend handles user creation/verification on first successful login at `/api/login`.
1212
- The UI shows “Logged in as username” and records `uploadedBy` for created/updated entities and images.
1313

14-
## Features
14+
## 💫 Features
1515

1616
- Transformers and Inspections CRUD (App Router API routes with Prisma)
1717
- Image uploads stored as base64 in the DB; baseline images can be added/removed
@@ -25,7 +25,7 @@
2525
- Cascade delete: deleting a Transformer removes its Inspections
2626
- Now available in dark mode!
2727

28-
## Project structure (high level)
28+
## 🤖 Project structure (high level)
2929

3030
- `frontend/` — Next.js frontend
3131
- `app/` — App Router pages
@@ -41,7 +41,7 @@
4141
- `repository/` — Spring Data JPA repositories
4242
- `service/` — business logic services
4343

44-
## Project Description
44+
## 📖 Project Description
4545

4646
- The project has 2 main pages: transformers and inspections.
4747
- The transformers page allows users to create, read, update, and delete (CRUD) transformer records.
@@ -55,7 +55,21 @@
5555
- An AI model can be used to analyze and generate insights from the thermal images of transformers.
5656
![Screenshot of AI inference page](ai_inference.png)
5757

58-
## For Improvements
58+
## 🔁 CI / CD
59+
60+
This project uses automated deployments for both frontend and backend:
61+
62+
- Frontend (Next.js) — deployed on Vercel
63+
- The `frontend/` directory is connected to Vercel via the GitHub integration. Pushes to `main` (or PR merges depending on your Vercel settings) trigger Vercel builds and automatic deployments of the site.
64+
65+
- Backend (Spring Boot) — deployed on Render via DockerHub
66+
- A GitHub Actions workflow builds the backend and pushes a Docker image to Docker Hub. See `.github/workflows/docker-image-deployed.yml` for the workflow (it sets up Java, runs `mvn -DskipTests package`, builds the image, and pushes it to Docker Hub).
67+
- The workflow expects the following GitHub Secrets to be configured in this repository:
68+
- `DOCKERHUB_USERNAME` — Docker Hub account name
69+
- `DOCKERHUB_TOKEN` — Docker Hub access token or password
70+
- Docker Hub is configured with a repository that Render watches. When the image is pushed, Docker Hub calls the Render deploy hook which triggers Render to deploy the new container image.
71+
72+
## 🤗 For Improvements
5973

6074
- Feel free to open issues or submit PRs for any bugs, improvements, or new features.
6175
- For your own use, you are free to customize the project as needed.

Working.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,26 @@
115115
- Triggered by `PUT /api/inspections/{id}/boxes/bulk` (unless the caller sets `tuneModel=false`).
116116
- Archives the previous AI snapshot via `archivePreviousAnalysis`, then records a `ParameterFeedback` row capturing AI/user box counts, diffs, serialized snapshots, and notes.
117117
- Writes the candidate image to disk, computes added/removed box sets (tolerant to ±0.5 px), and builds a payload with previous/final boxes, faults, annotators, comments, box tolerance, and the current parameter snapshot.
118-
- Invokes `backend/AI/tune_parameters.py`, which measures HSV statistics for each added/removed box and suggests parameter deltas (e.g., relax warm thresholds for missed hotspots, tighten thresholds for false positives). Small deltas (<1e-6) are filtered out.
119-
- Applies suggested deltas through `AiParameterService.adjustValue`, which clamps to configured min/max and persists to `ai_model_parameters` (Postgres). Updated values are immediately cached and will be used by subsequent analyses.
118+
- Invokes `backend/AI/tune_parameters.py`. The tuner runs a deterministic, heuristic adjustment routine based on per-box HSV statistics and the current parameter snapshot. Key points:
119+
- Input: the candidate PNG plus a JSON payload containing `parameters` (current values), `addedBoxes` and `removedBoxes` (arrays of `[x,y,w,h]`). The script computes a global `mean_value` from the candidate image's V channel and then measures each box.
120+
- Per-box measurements (from `measure_box`) returned for each box include: `pixel_count`, `area_ratio` (box area / image area), `mean_saturation`, `mean_value`, `mean_delta_value` (V − global mean), `warm_fraction` (fraction of pixels whose hue is inside the warm window), `mean_hue` (circular mean in [0,1]) and `max_value`.
121+
- Tuning constants (implemented in the script):
122+
- SATURATION_MARGIN = 0.01, VALUE_MARGIN = 0.01, CONTRAST_MARGIN = 0.01
123+
- HUE_STEP = 0.01, AREA_RATIO_STEP = 0.0005
124+
- Adjustment strategy (high-level):
125+
- For `added` boxes (human labeled hotspots that the AI missed) the tuner assumes thresholds are too strict. It decreases thresholds to make detection more permissive:
126+
- If `warm_sat_threshold - mean_saturation > SATURATION_MARGIN` then `warm_sat_threshold` is decreased by delta = -min(0.05, max(0.005, sat_diff * 0.5)).
127+
- Equivalent logic applies to `warm_val_threshold` and `contrast_threshold` using `mean_value` and `mean_delta_value`.
128+
- If `min_area_pixels` is larger than the observed `pixel_count`, it is reduced with a bounded step (delta = -min(50.0, max(5.0, pixel_diff * 0.25))).
129+
- If the observed area ratios are smaller than `min_area_ratio`, the script reduces `min_area_ratio` by a small step.
130+
- If the box's `warm_fraction >= 0.5`, tune the hue window by nudging `warm_hue_low` up or `warm_hue_high` down toward the measured `mean_hue` (bounded by `HUE_STEP`).
131+
- For `removed` boxes (AI boxes the user removed) the tuner assumes thresholds are too permissive. It increases thresholds to tighten detection:
132+
- If `mean_saturation - warm_sat_threshold < -SATURATION_MARGIN` then `warm_sat_threshold` is increased by a bounded delta (making it harder to count a pixel as warm).
133+
- Similar symmetric adjustments are applied for `warm_val_threshold`, `contrast_threshold`, `min_area_pixels` and `min_area_ratio` (using slightly different step factors and bounds).
134+
- Hue adjustments mirror the added-case logic but move the hue bounds away from the problematic `mean_hue`.
135+
- Update bookkeeping: updates are accumulated per-parameter (the `apply` helper) and tiny deltas (< 1e-6) are filtered out before returning.
136+
- Output: the script prints a JSON object containing `parameter_updates` (map of parameter → delta), `notes` (a short summary string), and counts (`addedCount`, `removedCount`).
137+
- The backend receives these suggested deltas, then `AiParameterService.adjustValue` clamps each new value to configured min/max, persists the update to `ai_model_parameters` (Postgres), and refreshes the in-memory cache so subsequent analyses immediately use the new parameters.
120138

121139
### Tuning Workflow
122140

backend/AI/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ Annotation edit endpoints (server‑side):
115115
- `DELETE /api/inspections/{id}/boxes?x=&y=&w=&h=` removes a box by geometry (with small tolerance) and updates `faulttypes` accordingly.
116116
- `POST /api/inspections/{id}/clear-analysis` clears `imageurl`, `boundingboxes`, `faulttypes`, and `lastanalysisweather`.
117117

118+
## AI Tuning Feedback Loop (`ParameterTuningService`)
119+
120+
- Triggered by `PUT /api/inspections/{id}/boxes/bulk` (unless the caller sets `tuneModel=false`).
121+
- Archives the previous AI snapshot via `archivePreviousAnalysis`, then records a `ParameterFeedback` row capturing AI/user box counts, diffs, serialized snapshots, and notes.
122+
- Writes the candidate image to disk, computes added/removed box sets (tolerant to ±0.5 px), and builds a payload with previous/final boxes, faults, annotators, comments, box tolerance, and the current parameter snapshot.
123+
- Invokes `backend/AI/tune_parameters.py`. The tuner runs a deterministic, heuristic adjustment routine based on per-box HSV statistics and the current parameter snapshot. Key points:
124+
- Input: the candidate PNG plus a JSON payload containing `parameters` (current values), `addedBoxes` and `removedBoxes` (arrays of `[x,y,w,h]`). The script computes a global `mean_value` from the candidate image's V channel and then measures each box.
125+
- Per-box measurements (from `measure_box`) returned for each box include: `pixel_count`, `area_ratio` (box area / image area), `mean_saturation`, `mean_value`, `mean_delta_value` (V − global mean), `warm_fraction` (fraction of pixels whose hue is inside the warm window), `mean_hue` (circular mean in [0,1]) and `max_value`.
126+
- Tuning constants (implemented in the script):
127+
- SATURATION_MARGIN = 0.01, VALUE_MARGIN = 0.01, CONTRAST_MARGIN = 0.01
128+
- HUE_STEP = 0.01, AREA_RATIO_STEP = 0.0005
129+
- Adjustment strategy (high-level):
130+
- For `added` boxes (human labeled hotspots that the AI missed) the tuner assumes thresholds are too strict. It decreases thresholds to make detection more permissive:
131+
- If `warm_sat_threshold - mean_saturation > SATURATION_MARGIN` then `warm_sat_threshold` is decreased by delta = -min(0.05, max(0.005, sat_diff * 0.5)).
132+
- Equivalent logic applies to `warm_val_threshold` and `contrast_threshold` using `mean_value` and `mean_delta_value`.
133+
- If `min_area_pixels` is larger than the observed `pixel_count`, it is reduced with a bounded step (delta = -min(50.0, max(5.0, pixel_diff * 0.25))).
134+
- If the observed area ratios are smaller than `min_area_ratio`, the script reduces `min_area_ratio` by a small step.
135+
- If the box's `warm_fraction >= 0.5`, tune the hue window by nudging `warm_hue_low` up or `warm_hue_high` down toward the measured `mean_hue` (bounded by `HUE_STEP`).
136+
- For `removed` boxes (AI boxes the user removed) the tuner assumes thresholds are too permissive. It increases thresholds to tighten detection:
137+
- If `mean_saturation - warm_sat_threshold < -SATURATION_MARGIN` then `warm_sat_threshold` is increased by a bounded delta (making it harder to count a pixel as warm).
138+
- Similar symmetric adjustments are applied for `warm_val_threshold`, `contrast_threshold`, `min_area_pixels` and `min_area_ratio` (using slightly different step factors and bounds).
139+
- Hue adjustments mirror the added-case logic but move the hue bounds away from the problematic `mean_hue`.
140+
- Update bookkeeping: updates are accumulated per-parameter (the `apply` helper) and tiny deltas (< 1e-6) are filtered out before returning.
141+
- Output: the script prints a JSON object containing `parameter_updates` (map of parameter → delta), `notes` (a short summary string), and counts (`addedCount`, `removedCount`).
142+
- The backend receives these suggested deltas, then `AiParameterService.adjustValue` clamps each new value to configured min/max, persists the update to `ai_model_parameters` (Postgres), and refreshes the in-memory cache so subsequent analyses immediately use the new parameters.
143+
118144
## Known bugs / limitations
119145

120146
- Alignment fragility: SIFT may fail on low‑texture or uniform images; homography requires sufficient matches. We fall back to unaligned comparison.

frontend/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
NEXT_PUBLIC_BACKEND_URL="<your-backend-url>"
1+
NEXT_PUBLIC_BACKEND_URL=<your-backend-url>

0 commit comments

Comments
 (0)