# BidBrain, Phase 1

The buying brain and the cockpit page, running on cars you enter by hand. No
scraping yet, no platform logins, no bids. It recommends only. You place every
bid yourself.

## What is here

- `bidbrain/pricing.py`  The buying brain. The bans, the hard gate and the
  pricing rule from section 3 of the brief. This is the part to trust.
- `bidbrain/db.py`  The single local database on this Mac. SQLite, one file at
  `data/bidbrain.db`. Nothing leaves the machine.
- `bidbrain/loader.py`  Reads your cars from `data/cars.json` and complains
  loudly if anything is wrong rather than guessing.
- `bidbrain/render.py`  Builds the cockpit page.
- `build.py`  The button. Loads your cars, runs the brain, writes the page.
- `serve.py`  Optional. Serves the page locally if you would rather open it at
  a web address than as a file.
- `data/cars.json`  Your cars. Edit this.
- `test_pricing.py`  Checks the brain still does what it should.

## How to run it

Open Terminal in this folder and run:

    python3 build.py

It writes `cockpit.html`. Open that file in any browser to see the day.

To check the brain by itself:

    python3 test_pricing.py

## Adding your own cars

Open `data/cars.json` and copy one of the blocks between the curly brackets.
Each car needs these fields. Leave a value blank with "" if you do not have it.

- `reg`  Registration, shown on the card.
- `make`, `model`, `derivative`  For example Ford, Fiesta, 1.1 Ti-VCT Zetec.
- `year`  The model year, for example 2019.
- `mileage`  Whole miles, for example 42000.
- `owners`  Number of previous owners.
- `grade`  Condition grade, 1 to 5. Only 1, 2 and 3 pass.
- `reserve`  The reserve price in pounds.
- `cap_clean`  CAP Clean in pounds.
- `distance_miles`  Distance from NE3 5HE in miles.
- `engine`  The engine, for example "1.2 PureTech" or "2.0 TFSI". If you cannot
  be sure which engine the car has, leave it blank. The brain then drops the
  car on purpose, to play safe.
- `service_history`  full, partial, or none.
- `vat_qualifying`  yes or no.
- `glass_retail`  Glass's retail value in pounds.
- `cazana_retail`  Cazana retail value in pounds. If either valuation is
  missing the car is held back, not priced on a guess.
- `source`  Motorway or Carwow.
- `actually_paid`  Optional. For a car you have already bought, put what you
  paid. The card then shows whether the recommendation would have let that buy
  through, so you can check the brain against real winners. Leave it out for a
  normal day.

## The pricing rule, in short

1. Add 15 percent to the Glass's retail and to the Cazana retail.
2. If the calculated Glass's value is over 10,000 pounds, that value governs.
   If it is under, take the higher of the two calculated values.
3. Recommended maximum bid is the governing value less the 3,000 pound spread.

## The hard gate

A car must pass all of these or it never shows on the shortlist: mileage under
90,000, reserve under 11,000 pounds, age 2 to 10 years, within 210 miles of
NE3 5HE, condition grade 1, 2 or 3, and 4 previous owners at most.
