add balance audit table#460
Conversation
| insertStatement.executeUpdate() | ||
| insertStatement.close() | ||
|
|
||
|
|
There was a problem hiding this comment.
Let's keep the setCycle w/o side effects.
Currently we purge stuff on the cycle simulation end :
But i think it's probably better to do it at the AirlineSimulation, right before we save the balance audit perhaps
| updateStatement.executeUpdate() | ||
| updateStatement.close() | ||
|
|
||
| // update balance audit table |
There was a problem hiding this comment.
I'm kinda on the fence for this, in a way it's nice that :
- It has the potentials to keep entries on every single
adjustAirlineBalancecall and not just the final balance at the end of the cycle. But this would require changing the schema - no longer beUNIQUE KEYbalance_audit_UN(airline,cycle),otherwise it's kinda meaningless, as entries just overwrite eachother and at the end it will be overwritten by the simulation on airline at cycle end
But the cons are:
- This is not the only place that set balance (though the most common)
- With the current schema it's kinda meaningless to write to DB for all the updates during the week by user action, since at the end it will just be replaced by the
AirlineSimulationbefore the week ticks
I lean towards setting it in the AirlineSimulation instead (and the purge too) - somewhere here , as for cash flow during the week, the cash_flow_item table is supposed to keep track of it.
| val AIRLINE_CASH_FLOW_ITEM_TABLE = "airline_cash_flow_item" | ||
| val AIRLINE_BASE_SPECIALIZATION_TABLE = "airline_base_specialization" | ||
| val AIRLINE_REPUTATION_BREAKDOWN = "airline_reputation_breakdown" | ||
| val BALANCE_AUDIT = "balance_audit" |
There was a problem hiding this comment.
small nit - let's name this val BALANCE_AUDIT_TABLE, most vals follow this naming convention, i might as well fix the AIRLINE_REPUTATION_BREAKDOWN lol
| statement.execute() | ||
| statement.close() | ||
|
|
||
| val sql = s""" |
There was a problem hiding this comment.
Looks nicer than my other sql statements 😊
| @@ -0,0 +1,7 @@ | |||
| CREATE TABLE `balance_audit` ( | |||
There was a problem hiding this comment.
Ah forgot to mention, if it's new table, we dun need a script here . As a dev, i can just run airline-data/src/main/scala/com/patson/data/QuickCreateSchema.scala :)
|
|
||
| // also clean up old (-48) balance audit entries | ||
| val cleanupStatement = connection.prepareStatement(s"DELETE FROM $BALANCE_AUDIT WHERE cycle <= ?") | ||
| cleanupStatement.setInt(1, cycle - 48) |
There was a problem hiding this comment.
since the cost is very low, we probably want to keep balance for way longer, like maybe 1000 cycles are okay
patsonluk
left a comment
There was a problem hiding this comment.
Please lemme know your thoughts!
add a table called "balance audit" which keeps tracking the latest balance of a given cycle
keep a history of 48 cycles (24 hours in the real world)
Manual Test
Unit Test
Schema