Battery Model Simulation Thing
A fun challenge, did this all by hand with no AI assistance (as that seemed more relevant).
To run
uv sync
uv run python -m batterymodel --market1 srcdata/market1.csv --market2 srcdata/market2.csv
A quick architectural overview.
The battery module (src/batterymodel/models/battery.py:BatteryModel) is doing all the decision logic really.
Its passed the current timesteps market data and does a buch of figuring out from there. at the moment a good chunk is in
market_decision and could/should be broken out to make it testable.
Each iteration the update function is called and it then goes through and does the calculations. Didn't quite get all the decisions in, but I got it to the point where adding in the additional rules should be simple.
The market module needs some work. There is one function where the flamegraph is saying 80.9% of all time is being used, and thats trying to get the market data for the current time stamp. This might be better being done as an sqlite database in memory rather than just a big OrderedDict. It would be easy to test as everything is nicely contained in this class, so it should be easy to have a go, given some time.
Tests
All are pytest tests, to run them do uv run pytest they should be poassing. There coule be more coverage, the ones I've added
mainly cover areas I was having issues.
Source data
I converted the source data into CSV's to save faffing around with pandas. If it was a hard requirement to come from .xls files, pandas could do the conversion.
Other notes
- Should have CI wrapped around it to run the tests.
- Assumes you can only CHARGE or DISCHARGE or IDLE at any one time. You could make this assumption go away, but it would add complexity for something done in a short time span
- Handling the different times is a bit of a thing. I've done it in what I know as game loop, with a set interval of 10 minutes, as there is a jump in one data set from being on the hour to 59 minutes. This should be configurable.
- I've assumed the model can't look into the future
- I've assumed there's no weightings or limits for buying/selling values.
- This was surprisingly fun.
- You could probably vibe code this rediculously quicky as the rules are very clear, but I assumed this was to measure my ability rather than the machines.