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