1 |
d6ca840d
|
petrh
|
from Utilities.CSV import csv_data_line
|
2 |
|
|
from Utilities import date_formating
|
3 |
c8f3051b
|
petrh
|
|
4 |
|
|
|
5 |
|
|
def process_file(filename):
|
6 |
04a2b5a4
|
petrh
|
"""
|
7 |
342ea08a
|
petrh
|
Method that take path to crawled file and outputs date dictionary:
|
8 |
3692d853
|
petrh
|
Date dictionary is a dictionary where keys are dates in format YYYY-mm-dd-hh (2018-04-08-15)
|
9 |
d6ca840d
|
petrh
|
and value is dictionary where keys are devices (specified in configuration file)
|
10 |
|
|
and value is CSVDataLine.csv_data_line with device,date and occurrence
|
11 |
04a2b5a4
|
petrh
|
|
12 |
|
|
Args:
|
13 |
342ea08a
|
petrh
|
filename: name of processed file
|
14 |
04a2b5a4
|
petrh
|
|
15 |
|
|
Returns:
|
16 |
342ea08a
|
petrh
|
None if not implemented
|
17 |
|
|
date_dict when implemented
|
18 |
04a2b5a4
|
petrh
|
"""
|
19 |
2d129043
|
petrh
|
date_dict = dict()
|
20 |
c8f3051b
|
petrh
|
|
21 |
2d129043
|
petrh
|
with open(filename, "r") as file:
|
22 |
c8f3051b
|
petrh
|
|
23 |
|
|
for line in file:
|
24 |
|
|
|
25 |
|
|
array = line.split(";")
|
26 |
|
|
|
27 |
d6ca840d
|
petrh
|
date = date_formating.date_time_formatter(array[0][1:-1])
|
28 |
c8f3051b
|
petrh
|
name = array[1][1:-1]
|
29 |
|
|
|
30 |
|
|
if date not in date_dict:
|
31 |
|
|
date_dict[date] = dict()
|
32 |
|
|
|
33 |
|
|
if name in date_dict[date]:
|
34 |
1187e871
|
petrh
|
date_dict[date][name].occurrence += 1
|
35 |
c8f3051b
|
petrh
|
else:
|
36 |
d6ca840d
|
petrh
|
date_dict[date][name] = csv_data_line.CSVDataLine(name, date, 1)
|
37 |
c8f3051b
|
petrh
|
|
38 |
2d129043
|
petrh
|
return date_dict
|
39 |
04a2b5a4
|
petrh
|
|