From: Christophe Guyeux Date: Wed, 12 Feb 2020 14:46:52 +0000 (+0100) Subject: refactoring, and working on ToArea target X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/predictops.git/commitdiff_plain/1aa2671e4f047322d6957a58a7b44a568b25d67d?ds=sidebyside;hp=a3cc2abef295b99990b24b1c822319c80a59ffe2 refactoring, and working on ToArea target --- diff --git a/main.py b/main.py index a6a8d74..b43c188 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ -from lib.source.ephemeris import Ephemeris -from lib.source.meteofrance import MeteoFrance +from predictops.source.ephemeris import Ephemeris +from predictops.source.meteofrance import MeteoFrance +from predictops.target.toarea import ToArea from datetime import datetime from logging import getLogger @@ -7,6 +8,8 @@ from logging.config import fileConfig from pathlib import Path from shutil import rmtree +import geopandas as gpd + fileConfig((Path.cwd() / 'config') / 'logging.cfg') logger = getLogger() @@ -66,6 +69,11 @@ engine.add_feature(name = 'ephemeris', features = ['hour', 'dayInWeek', 'dayInMonth', 'dayInYear', 'weekInYear', 'month', 'year']) +print(engine.X[datetime.strptime('06/30/2010 21:00:00', '%m/%d/%Y %H:%M:%S')]) + +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) -print(engine.X[datetime.strptime('06/30/2010 21:00:00', '%m/%d/%Y %H:%M:%S')]) \ No newline at end of file diff --git a/lib/__init__.py b/predictops/__init__.py similarity index 100% rename from lib/__init__.py rename to predictops/__init__.py diff --git a/lib/learn/__init__.py b/predictops/learn/__init__.py similarity index 100% rename from lib/learn/__init__.py rename to predictops/learn/__init__.py diff --git a/lib/source/__init__.py b/predictops/source/__init__.py similarity index 100% rename from lib/source/__init__.py rename to predictops/source/__init__.py diff --git a/lib/source/ephemeris.py b/predictops/source/ephemeris.py similarity index 100% rename from lib/source/ephemeris.py rename to predictops/source/ephemeris.py diff --git a/lib/source/festivals.py b/predictops/source/festivals.py similarity index 100% rename from lib/source/festivals.py rename to predictops/source/festivals.py diff --git a/lib/source/hydro.py b/predictops/source/hydro.py similarity index 100% rename from lib/source/hydro.py rename to predictops/source/hydro.py diff --git a/lib/source/meteofrance.py b/predictops/source/meteofrance.py similarity index 97% rename from lib/source/meteofrance.py rename to predictops/source/meteofrance.py index 88706ea..2326e16 100644 --- a/lib/source/meteofrance.py +++ b/predictops/source/meteofrance.py @@ -4,7 +4,7 @@ from datetime import datetime from geopy.distance import vincenty from logging import getLogger from logging.config import fileConfig -from os import listdir, remove, system +from os import listdir, remove from os.path import isfile, basename from pathlib import Path from shutil import rmtree @@ -48,7 +48,7 @@ class MeteoFrance: self._end = end self._features = features - self._data_directory = (Path.cwd() / 'data') / 'meteo_france' + self._data_directory = (Path.cwd() / 'data') / 'features' / 'meteo_france' self._dated_features = None @@ -204,7 +204,7 @@ class MeteoFrance: 'type': row['type'] # qualitative (2) or quantitative (1) } for row in reader if row['name'] in self._features} - dir_data = Path.cwd() / 'data' / 'meteo_france' / 'historical' + dir_data = Path.cwd() / 'data' / 'features' / 'meteo_france' / 'historical' self._dated_features = {} for csv_meteo in listdir(dir_data): date = datetime.strptime(csv_meteo.split('.')[1], '%Y%m') diff --git a/lib/target/__init__.py b/predictops/target/__init__.py similarity index 100% rename from lib/target/__init__.py rename to predictops/target/__init__.py diff --git a/lib/target/barracks.py b/predictops/target/frombarrack.py similarity index 100% rename from lib/target/barracks.py rename to predictops/target/frombarrack.py diff --git a/predictops/target/toarea.py b/predictops/target/toarea.py new file mode 100644 index 0000000..72a8ad0 --- /dev/null +++ b/predictops/target/toarea.py @@ -0,0 +1,47 @@ +from csv import DictReader +from datetime import datetime +from os import listdir +from pathlib import Path + +class ToArea: + + def __init__(self, area = None, + start = datetime.strptime('19960101000000', '%Y%m%d%H%M%S'), + end = datetime.now()): + self._get_located_interventions() + + + + def _get_located_interventions(self): + self._data_directory = Path.cwd() / 'data' / 'targets' / 'sdis25' + self._dict_interv = {} + for year in range(2006,2018): + if year < 2012: + file_place = self._data_directory / 'interventions' / (str(year)+'.csv') + else: + file_place = self._data_directory / 'victims' / ('Liste_des_victimes_'+str(year)+'.csv') + with open(file_place, "r") as f: + reader = DictReader(f, delimiter='£') + for row in reader: + self._dict_interv.update({ + row['N° intervention']: { + 'X' : row['Coord X'], + 'Y' : row['Coord Y'] + } for row in reader + }) + for csv_file in listdir(self._data_directory / 'interventions'): + with open(self._data_directory / 'interventions' / csv_file, "r") as f: + reader = DictReader(f, delimiter='£') + for row in reader: + if row['N° intervention'] in self._dict_interv: + self._dict_interv[row['N° intervention']].update( + { + 'start': row['Début'], + 'end' : row['Fin'] + }) + else: + print(row['N° intervention']) + + + + diff --git a/requirements.txt b/requirements.txt index 0cf261a..3fdb9fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,17 @@ +attrs==19.3.0 +Click==7.0 +click-plugins==1.1.1 +cligj==0.5.0 +Fiona==1.8.13 geographiclib==1.50 +geopandas==0.6.3 geopy==1.21.0 +munch==2.5.0 +numpy==1.18.1 +pandas==1.0.1 +pyproj==2.4.2.post1 +python-dateutil==2.8.1 +pytz==2019.3 +Shapely==1.7.0 +six==1.14.0 +xlrd==1.2.0