Example #1
0
    def test_bedcount_update(self):
        with tempfile.TemporaryDirectory() as tmp_folder:
            sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))

            # Make sure you can't insert without a valid icu_id
            with self.assertRaises(ValueError):
                sqldb.update_bedcount(1, "test", 10, 9, 8, 7, 6, 5, 4)
            sqldb.upsert_icu("ICU1", "dep1", "city1", 3.44, 42.3, "0102")
            sqldb.upsert_icu("ICU2", "dep1", "city1", 3.44, 42.3, "0102")

            # Generate some bed updates:
            for i in [1, 2]:
                for j in range(10):
                    time.sleep(0.5)  # Need to keep a delta of at least 0.5
                    sqldb.update_bedcount(i, "test", 10, 9, 8, 7, 6, 5, 4)
            bedcount = sqldb.get_bedcount()
            self.assertLen(bedcount, 2)

            # Make sure the returned updates are the most recent
            for i in [1, 2]:
                res = sqldb.pd_execute(
                    f"SELECT MAX(update_ts) as max_ts FROM bed_updates WHERE icu_id = {i}"
                )
                max_ts = res.iloc[0]["max_ts"]
                self.assertEqual(
                    bedcount[bedcount["icu_id"] == i].iloc[0]["update_ts"],
                    max_ts)
Example #2
0
def main(unused_argv):
    cfg = config.Config(FLAGS.config,
                        mode=FLAGS.mode,
                        env_path=FLAGS.dotenv_path)
    shdb = gsheets.SheetsDB(cfg.TOKEN_LOC, cfg.SHEET_ID)
    sqldb = sqlite.SQLiteDB(cfg.db.sqlite_path)
    import_sheet = shdb.get_sheet_as_pd("Import")
    sync = synchronizer.Synchronizer(shdb, sqldb)
    sync.sync_icus()
    sync.sync_users()
    sqldb.execute("DELETE FROM bed_updates")
    for row in import_sheet.iterrows():
        row_info = {
            "icu_name": row[1]["Hopital"],
            "n_covid_occ": row[1]["NbCOVID"],
            "n_covid_free": row[1]["NbLitDispo"],
            "n_ncovid_free": 0,
            "n_covid_deaths": row[1]["NbDeces"],
            "n_covid_healed": row[1]["NbSortieVivant"],
            "n_covid_refused": 0,
            "n_covid_transfered": 0,
        }
        icu_id = sqldb.get_icu_id_from_name(row_info["icu_name"])
        row_info["icu_id"] = icu_id
        print(row_info)
        sqldb.update_bedcount(**row_info)
Example #3
0
    def test_bedcount_where(self):
        with tempfile.TemporaryDirectory() as tmp_folder:
            sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))

            sqldb.upsert_icu("ICU1", "dep1", "city1", 3.44, 42.3, "0102")
            sqldb.upsert_icu("ICU2", "dep1", "city1", 3.44, 42.3, "0102")

            # Check that bedcounts can be select by icu_id:
            for i in range(10):
                sqldb.upsert_icu(f"ICU{i}", f"dep{i}", f"city{i}", 3.44, 42.3)
                sqldb.update_bedcount(i + 1, "test", 10, 9, 8, 7, 6, 5, 4)

            beds = sqldb.get_bedcount(icu_ids=(1, 2, 4, 7))
            self.assertEqual(len(beds), 4)

            cur_time = int(time.time())
            for i in range(10):
                for j in range(10):
                    sqldb.update_bedcount(i + 1,
                                          "test",
                                          10,
                                          9,
                                          8,
                                          7,
                                          6,
                                          5,
                                          4,
                                          update_ts=cur_time + j)

            max_time = sqldb.get_bedcount()['update_ts'].max()
            # import ipdb; ipdb.set_trace()
            new_max_time = sqldb.get_bedcount(max_ts=max_time -
                                              3)['update_ts'].max()
            self.assertEqual(new_max_time, max_time - 4)
Example #4
0
 def __init__(self, config, old_path):
     self.config = config
     self.old_db = sqlite.SQLiteDB(old_path)
     self.new_db = store.create_store_for_sqlite_db(config)
     admins = self.new_db.get_admins()
     if admins:
         self.admin_id = admins[0].user_id
     else:
         self.admin_id = self.new_db.add_default_admin()
Example #5
0
def main(unused_argv):
    cfg = config.Config(FLAGS.config,
                        mode=FLAGS.mode,
                        env_path=FLAGS.dotenv_path)
    shdb = gsheets.SheetsDB(cfg.TOKEN_LOC, cfg.SHEET_ID)
    sqldb = sqlite.SQLiteDB(cfg.db.sqlite_path)
    sync = synchronizer.Synchronizer(shdb, sqldb)
    reply = (str(
        input(
            "!!Are you sure you want to sync, this will drop all users!! (duh/nay)"
        )).lower().strip())
    if reply == "duh":
        sync.sync_icus()
        sync.sync_users()
Example #6
0
 def __init__(self, config, port=8889):
   self.config = config
   self.db = sqlite.SQLiteDB(self.config.db.sqlite_path)
   self.port = port
   self.sender = sms_sender.get_sender(self.config)
   self.queue = queues.Queue()
   self.scheduler = scheduler.MessageScheduler(
     db=self.db,
     queue=self.queue,
     token_encoder=token.TokenEncoder(self.config),
     base_url=self.config.server.base_url,
     max_retries=self.config.scheduler.max_retries,
     reminder_delay=self.config.scheduler.reminder_delay,
     when=self.config.scheduler.ping,
   )
Example #7
0
    def test_user_creation(self):
        with tempfile.TemporaryDirectory() as tmp_folder:
            sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))

            # Make sure you can't add a user with non-existant ICU
            with self.assertRaises(ValueError):
                sqldb.add_user("ICU1", "Bob", "+33698158092", "Chercheur")

            # Check normal insertion
            sqldb.upsert_icu("ICU1", "dep1", "city1", 3.44, 42.3, "0102")
            sqldb.add_user("ICU1", "Bob", "+33698158092", "Chercheur")

            with self.assertRaises(sqlalchemy.exc.IntegrityError):
                sqldb.add_user("ICU1", "Bob", "+33698158092", "Chercheur")
            users = sqldb.get_users()
Example #8
0
    def test_icu_creation(self):
        with tempfile.TemporaryDirectory() as tmp_folder:
            sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))
            sqldb.upsert_icu("ICU1", "dep1", "city1", 3.44, 42.3, "0102")
            icus = sqldb.get_icus()
            self.assertEqual(icus[icus["icu_name"] == "ICU1"].iloc[0]["dept"],
                             "dep1")

            sqldb.upsert_icu("ICU2", "dep2", "city2", 3.44, 42.3)
            icus = sqldb.get_icus()
            self.assertEqual(icus[icus["icu_name"] == "ICU2"].iloc[0]["dept"],
                             "dep2")

            sqldb.upsert_icu("ICU1", "dep3", "city3", 3.44, 42.3, "0103")
            icus = sqldb.get_icus()
            self.assertEqual(icus[icus["icu_name"] == "ICU1"].iloc[0]["dept"],
                             "dep3")
            self.assertEqual(
                icus[icus["icu_name"] == "ICU1"].iloc[0]["telephone"], "0103")
            self.assertEqual(sqldb.get_icu_id_from_name("ICU1"), 1)
            self.assertEqual(sqldb.get_icu_id_from_name("ICU2"), 2)
Example #9
0
def main(unused_argv):
  cfg = config.Config(FLAGS.config, mode=FLAGS.mode)
  sdb = sqlite.SQLiteDB(cfg.db.sqlite_path)

  sdb.upsert_icu(
    'A. Beclere', '92', 'Clamart', 48.788055555555545, 2.2547222222222216, 'test_tel')
  sdb.upsert_icu(
    'A. Pare', '93', 'Unknown', 48.84916666666667, 2.2355555555555555, 'test_tel')
  sdb.upsert_icu(
    'Avicenne', '93', 'Bobigny', 48.914722222222224, 2.4241666666666664, 'test_tel')
  sdb.upsert_icu(
    'Beaujon', '93', 'Bobigny', 48.90833333333333, 2.310277777777777, 'test_tel')
  sdb.upsert_icu(
    'Bicetre', '93', 'Kremelin-Bicetre', 48.81, 2.353888888888889, 'test_tel')

  sdb.update_bedcount(1, 'A. Beclere', 23, 4, 12, 200, 34, 7, 1)
  sdb.update_bedcount(2, 'A. Pare', 3, 14, 12, 200, 3, 7, 1)
  sdb.update_bedcount(3, 'Avicenne', 12, 23, 12, 200, 34, 12, 1)
  sdb.update_bedcount(4, 'Beaujon', 5, 6, 12, 200, 34, 7, 1)
  sdb.update_bedcount(5, 'Bicetre', 9, 2, 12, 200, 34, 44, 1)

  sdb.add_user('Bicetre', 'user1', '+336666666', 'wtf')
  sdb.add_user('Avicenne', 'user2', '+336699999', 'wthjhf')
Example #10
0
 def test_init(self):
     with tempfile.TemporaryDirectory() as tmp_folder:
         sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))