X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/predictops.git/blobdiff_plain/844b558b71ac568d904e8845ce203d31b68c776d..910a056eaa0181df00d21fa836f3c68504051717:/main.py?ds=sidebyside diff --git a/main.py b/main.py index 3d3739f..fe8ed20 100644 --- a/main.py +++ b/main.py @@ -1,26 +1,26 @@ -from extomeAI.source import MeteoFrance +from predictops.source.ephemeris import Ephemeris +from predictops.source.meteofrance import MeteoFrance +from predictops.learn.preprocessing import Preprocessing +from predictops.target.toarea import ToArea -from celery import Celery -from configparser import ConfigParser -from logging.config import fileConfig +from datetime import datetime, timedelta from logging import getLogger +from logging.config import fileConfig from pathlib import Path from shutil import rmtree -from subprocess import Popen, PIPE +import geopandas as gpd fileConfig((Path.cwd() / 'config') / 'logging.cfg') logger = getLogger() -class ExtomeEngine: - def __init__(self, clean = False): - logger.info("Extome-IA engine launched") - if clean: - self.clean() - print("Ne pas oublier d'exporter la BDD dans pgModeler") - print("Ni de copier l'archive dans la data") - +class Engine: + def __init__(self, start = None, end = None, time_step = None): + self._X = {} + self._Y = {} + + def clean(self): # Cleaning the data directory logger.info("Cleaning and restoring data directory") @@ -29,30 +29,59 @@ class ExtomeEngine: rmtree(directory) p = Path(Path.cwd() / 'data') p.mkdir() - - # Cleaning the postgresql database - config = ConfigParser() - config.read((Path.cwd() / 'config') / 'main.cfg') - - host = config['postgresql']['host'] - user = config['postgresql']['user'] - port = config['postgresql']['port'] - dbname = config['postgresql']['dbname'] - - logger.info("PostgreSQL database deletion") - command = ['dropdb', '-h', host, '-U', user, '-p', port, dbname] - process = Popen(command, stdout=PIPE, stderr=PIPE) - process.communicate() - - logger.info("PostgreSQL database creation") - command = ['createdb', '-h', host, '-U', user, '-p', port, dbname] - process = Popen(command, stdout=PIPE, stderr=PIPE) - process.communicate() - - def add_meteofrance(self): - self.meteofrance = MeteoFrance() - - - -engine = ExtomeEngine(clean = False) -engine.add_meteofrance() \ No newline at end of file + + + def add_feature(self, name, **kw): + + if name == 'meteofrance': + meteofeature = MeteoFrance(**kw) + meteofeature.update() + dated_features = meteofeature.dated_features + for date in dated_features: + self._X.setdefault(date,{}).update(dated_features[date]) + elif name == 'ephemeris': + ephemerides = Ephemeris(**kw) + dated_features = ephemerides.dated_features + for date in dated_features: + self._X.setdefault(date,{}).update(dated_features[date]) + + + @property + def X(self): + return self._X + + @X.setter + def X(self, x): + self._X = x + + +start = datetime.strptime('01/01/2010 00:00:00', '%m/%d/%Y %H:%M:%S') +end = datetime.strptime('12/31/2010 23:00:00', '%m/%d/%Y %H:%M:%S') + +engine = Engine() +engine.add_feature(name = 'meteofrance', + start = start, end = end, + latitude = 47.25, longitude = 6.0333, nb_stations = 3, + features = ['temperature', 'pressure']) + +engine.add_feature(name = 'ephemeris', + start = start, end = end, + features = ['hour', 'dayInWeek', 'dayInMonth', 'dayInYear', + 'weekInYear', 'month', 'year']) + +process = Preprocessing(dict_features = engine.X, + start = start, end = end, timestep = timedelta(hours=1)) + +process.fill_na() +print(process.dataframe.head(n=20)) +#print(engine.X[datetime.strptime('06/30/2010 21:00:00', '%m/%d/%Y %H:%M:%S')]) + +exit() + +depts = gpd.read_file( Path.cwd() / 'data' / 'targets' / 'departments' / "departements-20180101.shp") +Doubs = depts.loc[depts['nom'] == 'Doubs'].iloc[0] + +ToArea(area=Doubs.geometry, + start = start, end = end, + csv_file = Path.cwd() / 'data' / 'targets' / 'sdis25' / 'interventions.csv') +