diff --git a/src/covid19/blueprints/owid/owid_model.py b/src/covid19/blueprints/owid/owid_model.py index 605f24d55b9265a91285b215059a981265c875ce..bdd53640915ab2771311da63d050c54084249439 100644 --- a/src/covid19/blueprints/owid/owid_model.py +++ b/src/covid19/blueprints/owid/owid_model.py @@ -249,11 +249,6 @@ class OwidData(db.Model): # TODO pass - @classmethod - def get_joungest_datum(cls): - # TODO - pass - @classmethod def get_data_for_one_day(cls, date_reported): return db.session.query(cls).filter( @@ -268,7 +263,22 @@ class OwidData(db.Model): cls.new_cases_per_million.desc() ).all() + @classmethod + def get_datum_of_all_data(cls): + datum_of_all_who_data = [] + for data in db.session.query(cls).options(subqueryload("date_reported").load_only("date_reported_import_str")): + datum = data.date_reported.date_reported_import_str + if not datum in datum_of_all_who_data: + datum_of_all_who_data.append(datum) + datum_of_all_who_data.sort() + return datum_of_all_who_data + + @classmethod + def get_joungest_datum(cls): + return cls.get_datum_of_all_data().pop() + @classmethod def delete_data_for_one_day(cls, date_reported): - # TODO - pass + for data in cls.get_data_for_one_day(): + db.session.remove(data) + db.session.commit() diff --git a/src/covid19/blueprints/owid/owid_model_import.py b/src/covid19/blueprints/owid/owid_model_import.py index b1cbc52d299b4e827bf0a57f198422423028dc1d..d3b47020e7b3d2fdaabea376cad0f6b4e26f0ba7 100644 --- a/src/covid19/blueprints/owid/owid_model_import.py +++ b/src/covid19/blueprints/owid/owid_model_import.py @@ -128,6 +128,10 @@ class OwidImport(db.Model): def get_new_dates_reported_as_array(cls): return cls.get_dates_reported_as_array() + @classmethod + def get_datum_of_all_import(cls): + return cls.get_dates_reported_as_array() + @classmethod def get_continents(cls, page): return db.session.query(cls.continent)\ diff --git a/src/covid19/blueprints/owid/owid_service_update.py b/src/covid19/blueprints/owid/owid_service_update.py index 2848fd3d9108ff03c3047d9541f070fc1e2c874c..549d5aa8b18994df5962fbaf5b6b7665d9220ee2 100644 --- a/src/covid19/blueprints/owid/owid_service_update.py +++ b/src/covid19/blueprints/owid/owid_service_update.py @@ -14,6 +14,14 @@ class OwidServiceUpdate: app.logger.debug("------------------------------------------------------------") app.logger.debug(" OWID Service Update [ready]") + def who_import_get_new_dates_as_array(self): + new_dates_reported_from_import = [] + list_datum_of_all_data = OwidData.get_datum_of_all_data() + for item in OwidImport.get_datum_of_all_import(): + if not item in list_datum_of_all_data: + new_dates_reported_from_import.append(item) + return new_dates_reported_from_import + def __update_date_reported(self): app.logger.info(" __update_date_reported [begin]") app.logger.info("------------------------------------------------------------") diff --git a/src/covid19/blueprints/owid_test/owid_test_views.py b/src/covid19/blueprints/owid_test/owid_test_views.py index 6e4b4e4a13eb31e05c131cc99528cbecdbca8705..07c31f39ba751a43c75e08bea14d2e161d5ad2da 100644 --- a/src/covid19/blueprints/owid_test/owid_test_views.py +++ b/src/covid19/blueprints/owid_test/owid_test_views.py @@ -84,40 +84,62 @@ def url_owid_test_owid_import_countries(): @app_owid_test.route('/owid_import/get_new_dates_as_array') @login_required def url_owid_test_owid_import_get_new_dates_as_array(): - app.logger.info("update_star_schema_initial - START") - flash("update_star_schema_initial - START") + app.logger.info("url_owid_test_owid_import_get_new_dates_as_array - START") + flash("url_owid_test_owid_import_get_new_dates_as_array - START") + i = 0 + for date_reported in OwidImport.get_new_dates_reported_as_array(): + i += 1 + line = " | " + str(i) + " | " + date_reported + " | " + app.logger.info(line) + app.logger.info("url_owid_test_owid_import_get_new_dates_as_array - DONE") + flash("url_owid_test_owid_import_get_new_dates_as_array - DONE") return redirect(url_for('owid_test.url_owid_test_tests')) @app_owid_test.route('/owid_data/get_datum_of_all_owid_data') @login_required def url_owid_test_owid_data_get_datum_of_all_owid_data(): - app.logger.info("update_star_schema_initial - START") - flash("update_star_schema_initial - START") + app.logger.info("url_owid_test_owid_data_get_datum_of_all_owid_data - START") + flash("url_owid_test_owid_data_get_datum_of_all_owid_data - START") + for datum in OwidData.get_datum_of_all_data(): + app.logger.info(str(datum)) + app.logger.info("url_owid_test_owid_data_get_datum_of_all_owid_data - DONE") + flash("url_owid_test_owid_data_get_datum_of_all_owid_data - DONE") return redirect(url_for('owid_test.url_owid_test_tests')) @app_owid_test.route('/owid_data/update_star_schema_initial') @login_required def url_owid_test_owid_data_get_datum_of_all_owid_import(): - app.logger.info("update_star_schema_initial - START") - flash("update_star_schema_initial - START") + app.logger.info("url_owid_test_owid_data_get_datum_of_all_owid_import - START") + flash("url_owid_test_owid_data_get_datum_of_all_owid_import - START") + for datum in OwidImport.get_datum_of_all_import(): + app.logger.info(str(datum)) + app.logger.info("url_owid_test_owid_data_get_datum_of_all_owid_import - DONE") + flash("url_owid_test_owid_data_get_datum_of_all_owid_import - DONE") return redirect(url_for('owid_test.url_owid_test_tests')) @app_owid_test.route('/owid_service/owid_import/get_new_dates_as_array') @login_required def url_owid_test_owid_service_owid_import_get_new_dates_as_array(): - app.logger.info("update_star_schema_initial - START") - flash("update_star_schema_initial - START") + app.logger.info("url_owid_test_owid_service_owid_import_get_new_dates_as_array - START") + flash("url_owid_test_owid_service_owid_import_get_new_dates_as_array - START") + for datum in owid_service.service_update.who_import_get_new_dates_as_array(): + app.logger.info(str(datum)) + app.logger.info("url_owid_test_owid_service_owid_import_get_new_dates_as_array - DONE") + flash("url_owid_test_owid_service_owid_import_get_new_dates_as_array - DONE") return redirect(url_for('owid_test.url_owid_test_tests')) @app_owid_test.route('/owid_test_service/delete_last_days_data') @login_required def url_owid_test_owid_test_service_delete_last_days_data(): - app.logger.info("update_star_schema_initial - START") - flash("update_star_schema_initial - START") + app.logger.info("url_owid_test_owid_test_service_delete_last_days_data - START") + flash("url_owid_test_owid_test_service_delete_last_days_data - START") + owid_test_service.delete_last_day() + app.logger.info("url_owid_test_owid_test_service_delete_last_days_data - DONE") + flash("url_owid_test_owid_test_service_delete_last_days_data - DONE") return redirect(url_for('owid_test.url_owid_test_tests')) diff --git a/src/covid19/blueprints/who/who_model.py b/src/covid19/blueprints/who/who_model.py index 0a8e3c64bd18c709b0a1d0555ba1dd4eda8b3fb1..12e0817b1408c488de0ea4153cfaaf9aa0384eed 100644 --- a/src/covid19/blueprints/who/who_model.py +++ b/src/covid19/blueprints/who/who_model.py @@ -344,7 +344,7 @@ class WhoData(db.Model): ).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod - def get_datum_of_all_who_data(cls): + def get_datum_of_all_data(cls): datum_of_all_who_data = [] for data in db.session.query(cls).options(subqueryload("date_reported").load_only("date_reported_import_str")): datum = data.date_reported.date_reported_import_str diff --git a/src/covid19/blueprints/who_test/who_test_views.py b/src/covid19/blueprints/who_test/who_test_views.py index 592ae7734f832744e1cc9f148dfb4d82cedc507a..48d487fc3df0f88863701cf0e5afeed568df68a8 100644 --- a/src/covid19/blueprints/who_test/who_test_views.py +++ b/src/covid19/blueprints/who_test/who_test_views.py @@ -69,7 +69,7 @@ def url_who_test_who_import_get_new_dates_as_array(): def url_who_test_who_data_get_datum_of_all_who_data(): app.logger.info("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()") flash("url_who_test_who_data_get_datum_of_all_who_data - START: WhoData.get_datum_of_all_who_data()") - for datum in WhoData.get_datum_of_all_who_data(): + for datum in WhoData.get_datum_of_all_data(): app.logger.info(str(datum)) flash("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()") app.logger.info("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()")