__init__.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from sqlite3 import Cursor
  2. from game import CURRENCY_NAME, MRO_NAME
  3. def seed(cursor: Cursor):
  4. print(' - Seeding initial data...')
  5. # ₭ollar
  6. cursor.executemany('''
  7. INSERT OR IGNORE INTO ownables
  8. (name)
  9. VALUES (?)
  10. ''', [
  11. (CURRENCY_NAME,),
  12. (MRO_NAME,),
  13. ])
  14. # The bank/external investors
  15. cursor.execute('''
  16. INSERT OR IGNORE INTO users
  17. (username,password)
  18. VALUES ('bank','')
  19. ''')
  20. # bank owns some stuff
  21. cursor.execute('''
  22. INSERT OR IGNORE INTO ownership
  23. (user_id, ownable_id, amount)
  24. SELECT (SELECT rowid FROM users WHERE username = 'bank'),
  25. ownables.rowid,
  26. (SELECT COALESCE(SUM(amount),0) FROM ownership WHERE ownable_id = ownables.rowid)
  27. FROM ownables
  28. ''')
  29. cursor.executemany('''
  30. INSERT INTO global_control_values (value_name, value)
  31. WITH new_value AS (SELECT ? AS name, ? AS value)
  32. SELECT new_value.name, new_value.value
  33. FROM new_value
  34. WHERE NOT EXISTS(SELECT * -- TODO test if this works
  35. FROM global_control_values v2
  36. WHERE v2.value_name = new_value.name
  37. AND v2.value = new_value.value
  38. AND v2.dt = (SELECT MAX(v3.dt)
  39. FROM global_control_values v3
  40. WHERE v3.value_name = new_value.name
  41. AND v3.value = new_value.value))
  42. ''', [('banking_license_price', 5e6),
  43. ('personal_loan_interest_rate', 0.1), # may seem a lot but actually this is a credit that you get without any assessment involved
  44. ('deposit_facility', -0.005), # ECB 2020
  45. ('marginal_lending_facility', 0.0025), # ECB 2020
  46. ('cash_reserve_ratio', 0.01), # Eurozone 2020
  47. ('cash_reserve_free_amount', 1e5), # Eurozone 2020
  48. ('main_refinancing_operations', 0.0000), # ECB 2020
  49. ])