def run_data_update(): global corona_joined, county_cases, location_cube, country_location_cube, sex, age try: backend = Backend() backend.start_connection() corona_joined = backend.get_cube("corona_joined") county_cases = backend.get_cube("county_cases") location_cube = backend.get_cube(coronavirus_location.table_name) country_location_cube = country_location() sex = backend.get_cube("sex") age = backend.get_cube("age") except Exception as e: logger.error("Error fetching database: %s", e) schedule = datetime.datetime.now() while True: if datetime.datetime.now() >= schedule: logger.info("Updating database.") try: backend = Backend() backend.start_connection() backend.update_coronavirus_data() midnight_today = datetime.datetime.combine( datetime.date.today(), datetime.datetime.min.time()) schedule = midnight_today + datetime.timedelta( days=1, hours=UPDATE_TIME) corona_joined = backend.get_cube("corona_joined") county_cases = backend.get_cube("county_cases") location_cube = backend.get_cube( coronavirus_location.table_name) country_location_cube = country_location() sex = backend.get_cube("sex") age = backend.get_cube("age") logger.info("Update succeed. Scheduled for %s UTC", schedule) except Exception as e: logger.error("Error updating database: %s", e) time.sleep(3600)
# cube.show() # cube = cube.push("country_region") # cube.show() # cube = cube.pull("date") # cube.show() # predicate_func = lambda x:x=="Washington" # cube = cube.restriction("province_state", predicate_func) # cube.show() # cube = cube.destroy("date") # cube.show() # cube = cube.destroy("province_state") # cube.show() # corona_test = backend.get_cube("corona_test") # corona_test = corona_test.restriction("date", lambda x: x == datetime.date(2020, 3, 28)).destroy("date") # example_1d = backend.get_cube("example_1d", 2) example_2d = backend.get_cube("example_2d", 1) # example_3d = backend.get_cube("example_3d", 1) # example join operator on the paper C = backend.get_cube("example_join_left", 1) C.show() C1 = backend.get_cube("example_join_right", 1) C1.show() dimension_name = {"D1": "D1"} f1 = [lambda x: [int(x)]] f2 = [lambda x: [int(x)]] felem = lambda e1_row, e2_row: [int(e1_row[0]) / int(e2_row[0])] joined_C = C.join(C1, felem, ["merged_val"], dimension_name, f1, dimension_name, f2) # joined_C = C.join(C1) joined_C.show()