Projekt

Obecné

Profil

Stáhnout (1.26 KB) Statistiky
| Větev: | Revize:
1 b0d2180b petrh
from Utilities.CSV import CSVDataLine, CSVutils
2
from Utilities import DateFormating
3
4
5 32566ad0 petrh
def process_file(filename):
6 04a2b5a4 petrh
    """
7
    Method that take path to crawled file and outputs date dictionary using method:
8
    CSVutils.export_data_to_csv(filename, date_dict)
9
    Date dictionary is a dictionary where keys are dates in format ddmmYYYYhh (0804201815)
10
    and value is dictionary where keys devices (specified in configuration file)
11
    and value is CSVDataLine.CSVDataLine with device,date and occurrence
12
13
    Args:
14
        filename: name of processed file
15
16
    Returns:
17
        False if not implemented
18
        True when implemented
19
    """
20 2d129043 petrh
    date_dict = dict()
21
    
22 b0d2180b petrh
    with open(filename, "r", encoding="utf-8") as file:
23
24
        for line in file:
25
26
            array = line.split(";")
27
28 04a2b5a4 petrh
            date = DateFormating.date_time_formatter(array[4][1:-2])
29 b0d2180b petrh
            name = array[1][1:-1]
30 1187e871 petrh
            occurrence = array[0]
31 b0d2180b petrh
32
            if date not in date_dict:
33
                date_dict[date] = dict()
34
35
            if name in date_dict[date]:
36 1187e871 petrh
                date_dict[date][name].occurrence += int(occurrence)
37 b0d2180b petrh
            else:
38 1187e871 petrh
                date_dict[date][name] = CSVDataLine.CSVDataLine(name, date, int(occurrence))
39 b0d2180b petrh
40 2d129043 petrh
    return date_dict
41 04a2b5a4 petrh