__init__.py 1.9 KB

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