1
|
from Utilities.CSV import csv_data_line
|
2
|
from Utilities import date_formating
|
3
|
|
4
|
|
5
|
def process_file(filename):
|
6
|
"""
|
7
|
Method that take path to crawled file and outputs date dictionary:
|
8
|
Date dictionary is a dictionary where keys are dates in format ddmmYYYYhh (0804201815)
|
9
|
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
|
|
12
|
Args:
|
13
|
filename: name of processed file
|
14
|
|
15
|
Returns:
|
16
|
None if not implemented
|
17
|
date_dict when implemented
|
18
|
"""
|
19
|
date_dict = dict()
|
20
|
|
21
|
with open(filename, "r", encoding="utf-8") as file:
|
22
|
|
23
|
for line in file:
|
24
|
|
25
|
array = line.split(";")
|
26
|
|
27
|
date = date_formating.date_time_formatter(array[1][1:-1])
|
28
|
name = array[0][1:-1]
|
29
|
occurrence = array[2][:-1]
|
30
|
|
31
|
if date not in date_dict:
|
32
|
date_dict[date] = dict()
|
33
|
|
34
|
if name in date_dict[date]:
|
35
|
date_dict[date][name].occurrence += int(occurrence)
|
36
|
else:
|
37
|
date_dict[date][name] = csv_data_line.CSVDataLine(name, date, occurrence)
|
38
|
|
39
|
return date_dict
|
40
|
|