Skip to content

add balance audit table#460

Open
tp-cai wants to merge 2 commits intopatsonluk:masterfrom
tp-cai:balance-audit
Open

add balance audit table#460
tp-cai wants to merge 2 commits intopatsonluk:masterfrom
tp-cai:balance-audit

Conversation

@tp-cai
Copy link
Copy Markdown

@tp-cai tp-cai commented Sep 28, 2021

  • 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

insertStatement.executeUpdate()
insertStatement.close()


Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kinda on the fence for this, in a way it's nice that :

  1. It has the potentials to keep entries on every single adjustAirlineBalance call and not just the final balance at the end of the cycle. But this would require changing the schema - no longer be UNIQUE KEY balance_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:

  1. This is not the only place that set balance (though the most common)
  2. 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 AirlineSimulation before 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"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"""
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nicer than my other sql statements 😊

@@ -0,0 +1,7 @@
CREATE TABLE `balance_audit` (
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the cost is very low, we probably want to keep balance for way longer, like maybe 1000 cycles are okay

Copy link
Copy Markdown
Owner

@patsonluk patsonluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please lemme know your thoughts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants