]> AND Private Git Repository - predictops.git/blob - predictops/target/toarea.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Adding trends.py source module
[predictops.git] / predictops / target / toarea.py
1 from csv import DictReader
2 from datetime import datetime
3 from os import listdir
4 from pathlib import Path
5
6 class ToArea:
7
8     def __init__(self, area = None,
9                  start = datetime.strptime('19960101000000', '%Y%m%d%H%M%S'),
10                  end = datetime.now()):
11         self._get_located_interventions()
12
13
14
15     def _get_located_interventions(self):
16         self._data_directory = Path.cwd() / 'data' / 'targets' / 'sdis25'
17         self._dict_interv = {}
18         for year in range(2006,2018):
19             if year < 2012:
20                 file_place = self._data_directory / 'interventions' / (str(year)+'.csv')
21             else:
22                 file_place = self._data_directory / 'victims' / ('Liste_des_victimes_'+str(year)+'.csv')
23             with open(file_place, "r") as f:
24                 reader = DictReader(f, delimiter='£')
25                 for row in reader:
26                     self._dict_interv.update({
27                         row['N° intervention']: {
28                             'X' : row['Coord X'],
29                             'Y' : row['Coord Y']
30                         } for row in reader
31                     })
32         for csv_file in listdir(self._data_directory / 'interventions'):
33             with open(self._data_directory / 'interventions' / csv_file, "r") as f:
34                 reader = DictReader(f, delimiter='£')
35                 for row in reader:
36                     if row['N° intervention'] in self._dict_interv:
37                         self._dict_interv[row['N° intervention']].update(
38                             {
39                                 'start': row['Début'],
40                                 'end'  : row['Fin']
41                             })
42                     else:
43                         print(row['N° intervention'])
44
45
46
47