# Browser — Compact DB + Floorplan Editor

This is the combined, slightly-improved replacement for the old `db_browser.py` and `floorplan.py`. Think of it as the same toolbox, but 1 file to rule them all — cleaner, friendlier, and less likely to make you hunt for which script does what.

Yes, it still uses Tkinter + OpenCV. No, I didn't introduce a web app. You're welcome.

---

## What it does (quick and punchy)

- Lets you pick a `Diagnostic/` source folder and edit `param.db` and `multiZone.db` without touching SQLite directly.
- Lets you pick floorplan points side-by-side (rectified vs floorplan) and write `LocalPolygon` / `GlobalPolygon` into `param.db`.
- Draws zones on the rectified image (uses `zone_colors.csv` when available).

It keeps the original behavior but tidies the workflow and UI.

---

## Requirements

- Python 3.8+
- `opencv-python`, `numpy`

Install with your favorite venv and pip (same as before):

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

---

## Yoink Diagnostic Tool (`yoink.py`)

This tool retrieves diagnostic data from the Raspberry Pi camera system over SSH and downloads it locally.

### Usage

```bash
python yoink.py --ip localhost --user pi --password meta.Vince --port 6001
```

Optional: you can adjust the raspicam for Extract --mode = 1 (default 0), --port for frp --sleep for extract raspicam starup (default 20s):

```bash
python yoink.py --ip <raspi-ip> --user <username> --password <password> --mode 1 --port 6000 --sleep 25
```

### Notes

Notes
-  Stops the raspicam service on the Pi.
-  Starts raspicam manually.
-  Waits for it to initialize.
-  Collects configuration and captures images.
-  Bundles them into a tar archive.
-  Downloads and extracts them locally.
-  Cleans up temporary files on the Pi.
-  All extracted files will appear in your current working directory.

---

## Deployment Tool (`yeet.py`)

`yeet.py` is the deployment tool for uploading and deploying modified `Diagnostic` folders to a Raspberry Pi.  

It handles:

- Backing up existing database folders on the Pi (creating `*_bak` copies).  
- Uploading your local `Diagnostic` folder as a tar archive.  
- Extracting the tar on the Pi.  
- Moving each `Diagnostic/<key>` folder into its corresponding target folder as specified in `imageSourceConfig.json`.  
- Refreshing the Pi camera system.  
- Cleaning up temporary files on the Pi.

### Usage

```bash
# same like in yoink just change to yeet
python yeet.py --ip localhost --user pi --password meta.Vince --port 6001
```

### Optional arguments
- `--port <ssh-port>` : Default is 22.
- All folders specified in imageSourceConfig.json will be backed up automatically.

### Example

```bash
python yeet.py --ip 192.168.1.10 --user pi --password raspberry
```

This will:
1. Backup any existing database folders on the Pi.
1. Upload your Diagnostic folder.
1. Replace the database folders with the new content from Diagnostic.
1. Refresh the raspicam system.
1. Clean up temporary files.

---

## DB Browser — the visual tour

New browser look with their own floor plan and browswer button and another button to check on rectified image  
![browser](./db_assets/newbrowser.png)
![rectified](./db_assets/rectifiedimgtest.png)

```bash
python browser.py
```

Click `Open DB Browser` and you get a left-hand list of tables and a large editable pane on the right.

1) Param editor — `FloorplanTransformParam` is presented as friendly fields.

![max](./db_assets/maximise.png)

2) Switch source or change which images are used;

![change](./db_assets/changesource.png)

3) You get quick access to both `param.db` and `multiZone.db` tables.

![multidb](./db_assets/multidb.png)

4) Edit floorplan params easily (Orientation / LocalPolygon / GlobalPolygon / FloorplanId).

![paramedit](./db_assets/paramedit.png)

5) Edit, insert, delete zones in the multiZone tables.

![editzone](./db_assets/edit.png)

6) The point picker lets you draw polygonal points for zone entries.

![zonedraw](./db_assets/zonedraw.png)

Controls in the point picker (same as before):
- `left click` to add points
- `a` to undo last point
- `c` to clear
- `enter` to confirm
- `q` / `Esc` to cancel

---

## Floorplan editor — side-by-side picker

Click `Open Floorplan Editor` to open the side-by-side tool. Use the rectified camera image on the left and your floorplan image on the right to establish mapping points.

1) Change the image source if needed

![change](./db_assets/fpchangesource.png)

2) Edit params

![editparam](./db_assets/fpeditparam.png)

3) Click `Select Image` to choose your floorplan image (right side)
![fpselpoint1](./db_assets/fpselpoint1.png)

4) Click `Select Floorplan Points` and pick matching points on both images
![fpselpoint2](./db_assets/fpselpoint2.png)

Same controls as the other picker; `LocalPolygon` will be normalized (0-1) and `GlobalPolygon` saved as integer pixel coords.

Note: `FloorplanId` is not auto-filled — set it if you need it.

5) Click `Preview Floorplan Points` to see both images side by side, with the polygons and points drawn in read-only mode. This lets you visually verify the mapping before saving.

![preview](./db_assets/fp_preview.png)

---

## Files you should know about

- `param.db` — contains `FloorplanTransformParam` (Orientation, GlobalPolygon, LocalPolygon, FloorplanId).
- `multiZone.db` — holds zone/category tables with `points` fields like `x,y|x,y|...`.
- `zone_colors.csv` — optional: `ZoneName,#RRGGBB` to color polygons.

---

## Quick workflow

1. Drop your source into `Diagnostic/YourSource/`.
2. Put rectified images under `Diagnostic/Images/Raw/YourSource.jpg` if you want visual pickers.
3. Run the browser and click `Open DB Browser`.
4. Edit `param.db` or `multiZone.db` via the UI. Use `Select Points` to visually capture polygons.
5. Use `Open Floorplan Editor` for side-by-side point picking and click `Save Changes` to write back to the DB.

---

## Troubleshooting quick hits

- If pickers show a blank canvas: check `Diagnostic/Images/Raw/<source>.jpg`.
- If DB edits fail: ensure the table schema wasn't modified by hand (the editor expects predictable columns and uses `rowid`).

---

If you want the README trimmed, or prefer fewer screenshots and a quickstart only, say the word and I will shrink it down.
