__init__.py 2.0 KB

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