Skip to content
Snippets Groups Projects
Commit de4daf19 authored by thomaswoehlke's avatar thomaswoehlke
Browse files

work

parent 76235ba0
No related branches found
No related tags found
No related merge requests found
from sqlalchemy import and_ from sqlalchemy import and_
from datetime import date
from database import db, ITEMS_PER_PAGE from database import db, ITEMS_PER_PAGE
...@@ -16,7 +17,6 @@ class EuropeDataImportTable(db.Model): ...@@ -16,7 +17,6 @@ class EuropeDataImportTable(db.Model):
country_territory_code = db.Column(db.String(255), nullable=False) country_territory_code = db.Column(db.String(255), nullable=False)
continent_exp = 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) notification_rate_per_100000_population_14days = db.Column(db.String(255), nullable=False)
row_imported = db.Column(db.Boolean, nullable=False, default=False)
@classmethod @classmethod
def remove_all(cls): def remove_all(cls):
...@@ -90,6 +90,28 @@ class EuropeDateReported(db.Model): ...@@ -90,6 +90,28 @@ class EuropeDateReported(db.Model):
datum = db.Column(db.Date, nullable=False, unique=True) datum = db.Column(db.Date, nullable=False, unique=True)
date_rep = db.Column(db.String(255), 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) 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 @classmethod
def remove_all(cls): def remove_all(cls):
......
import os import os
from datetime import date
from database import db, app from database import db, app
from org.woehlke.covid19.europe.europe_model import EuropeDataImportTable, \ from org.woehlke.covid19.europe.europe_model import EuropeDataImportTable, \
EuropeDateReported, EuropeContinent, EuropeCountry, EuropeData EuropeDateReported, EuropeContinent, EuropeCountry, EuropeData
...@@ -19,14 +18,6 @@ class EuropeServiceUpdate: ...@@ -19,14 +18,6 @@ class EuropeServiceUpdate:
app.logger.info("------------------------------------------------------------") app.logger.info("------------------------------------------------------------")
app.logger.info(" Europe Service Update [ready] ") 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): def __update_date_reported(self):
app.logger.info(" __update_date_reported [begin]") app.logger.info(" __update_date_reported [begin]")
app.logger.info("------------------------------------------------------------") app.logger.info("------------------------------------------------------------")
...@@ -36,13 +27,12 @@ class EuropeServiceUpdate: ...@@ -36,13 +27,12 @@ class EuropeServiceUpdate:
k += 1 k += 1
my_date_rep = result_item['date_rep'] my_date_rep = result_item['date_rep']
my_year_week = result_item['year_week'] my_year_week = result_item['year_week']
app.logger.info("| " + my_date_rep + " | " + my_year_week + " | (" + k + ")") o = EuropeDateReported.create_new_object_factory(
o = EuropeDateReported( my_date_rep=my_date_rep,
date_rep=my_date_rep, my_year_week=my_year_week
year_week=my_year_week,
datum=self.__transform_datum(my_date_rep)
) )
db.session.add(o) db.session.add(o)
app.logger.info("| " + my_date_rep + " | " + my_year_week + " | " + k + " rows ")
db.session.commit() db.session.commit()
app.logger.info(" __update_date_reported [done]") app.logger.info(" __update_date_reported [done]")
app.logger.info("------------------------------------------------------------") app.logger.info("------------------------------------------------------------")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment