From de4daf19d1ae5054e22c75bad91ae125bb7d8373 Mon Sep 17 00:00:00 2001 From: thomaswoehlke <thomas.woehlke@gmail.com> Date: Thu, 28 Jan 2021 13:06:48 +0100 Subject: [PATCH] work --- org/woehlke/covid19/europe/europe_model.py | 24 ++++++++++++++++++- .../covid19/europe/europe_service_update.py | 18 ++++---------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/org/woehlke/covid19/europe/europe_model.py b/org/woehlke/covid19/europe/europe_model.py index 1d652758..5b99e3d7 100644 --- a/org/woehlke/covid19/europe/europe_model.py +++ b/org/woehlke/covid19/europe/europe_model.py @@ -1,4 +1,5 @@ from sqlalchemy import and_ +from datetime import date from database import db, ITEMS_PER_PAGE @@ -16,7 +17,6 @@ class EuropeDataImportTable(db.Model): country_territory_code = db.Column(db.String(255), nullable=False) continent_exp = db.Column(db.String(255), nullable=False) notification_rate_per_100000_population_14days = db.Column(db.String(255), nullable=False) - row_imported = db.Column(db.Boolean, nullable=False, default=False) @classmethod def remove_all(cls): @@ -90,6 +90,28 @@ class EuropeDateReported(db.Model): datum = db.Column(db.Date, nullable=False, unique=True) date_rep = db.Column(db.String(255), nullable=False, unique=True) year_week = db.Column(db.String(255), nullable=False, unique=True) + week_of_year = db.Column(db.Integer, nullable=False) + year = db.Column(db.Integer, nullable=False) + month = db.Column(db.Integer, nullable=False) + day_of_month = db.Column(db.Integer, nullable=False) + + @classmethod + def create_new_object_factory(cls, my_date_rep, my_year_week): + my_date_reported = my_date_rep.split('/') + my_week_of_year = int(my_year_week.split("-")[1]) + my_year = int(my_date_reported[2]) + my_month = int(my_date_reported[1]) + my_day_of_month = int(my_date_reported[0]) + my_datum = date(year=my_year, month=my_month, day=my_day_of_month) + return EuropeDateReported( + datum=my_datum, + date_rep=my_date_rep, + year_week=my_year_week, + week_of_year=my_week_of_year, + year=my_year, + month=my_month, + day_of_month=my_day_of_month + ) @classmethod def remove_all(cls): diff --git a/org/woehlke/covid19/europe/europe_service_update.py b/org/woehlke/covid19/europe/europe_service_update.py index e05fde5f..15c4c681 100644 --- a/org/woehlke/covid19/europe/europe_service_update.py +++ b/org/woehlke/covid19/europe/europe_service_update.py @@ -1,5 +1,4 @@ import os -from datetime import date from database import db, app from org.woehlke.covid19.europe.europe_model import EuropeDataImportTable, \ EuropeDateReported, EuropeContinent, EuropeCountry, EuropeData @@ -19,14 +18,6 @@ class EuropeServiceUpdate: app.logger.info("------------------------------------------------------------") app.logger.info(" Europe Service Update [ready] ") - def __transform_datum(my_date): - my_date_reported = my_date.split('/') - my_year = int(my_date_reported[2]) - my_month = int(my_date_reported[1]) - my_day = int(my_date_reported[0]) - my_datum = date(year=my_year, month=my_month, day=my_day) - return my_datum - def __update_date_reported(self): app.logger.info(" __update_date_reported [begin]") app.logger.info("------------------------------------------------------------") @@ -36,13 +27,12 @@ class EuropeServiceUpdate: k += 1 my_date_rep = result_item['date_rep'] my_year_week = result_item['year_week'] - app.logger.info("| " + my_date_rep + " | " + my_year_week + " | (" + k + ")") - o = EuropeDateReported( - date_rep=my_date_rep, - year_week=my_year_week, - datum=self.__transform_datum(my_date_rep) + o = EuropeDateReported.create_new_object_factory( + my_date_rep=my_date_rep, + my_year_week=my_year_week ) db.session.add(o) + app.logger.info("| " + my_date_rep + " | " + my_year_week + " | " + k + " rows ") db.session.commit() app.logger.info(" __update_date_reported [done]") app.logger.info("------------------------------------------------------------") -- GitLab