Projekt

Obecné

Profil

Stáhnout (1.32 KB) Statistiky
| Větev: | Revize:
1 d6ca840d petrh
from Utilities.CSV import csv_data_line
2
from Utilities import date_formating
3 af7609b5 Tomáš Ballák
from shared_types import DateDict
4 b0d2180b petrh
5
6 af7609b5 Tomáš Ballák
def process_file(filename: str) -> DateDict:
7 04a2b5a4 petrh
    """
8 342ea08a petrh
    Method that take path to crawled file and outputs date dictionary:
9 3692d853 petrh
    Date dictionary is a dictionary where keys are dates in format YYYY-mm-dd-hh (2018-04-08-15)
10 d6ca840d petrh
    and value is dictionary where keys are devices (specified in configuration file)
11
    and value is CSVDataLine.csv_data_line with device,date and occurrence
12 04a2b5a4 petrh
13
    Args:
14 342ea08a petrh
    filename: name of processed file
15 04a2b5a4 petrh
16
    Returns:
17 342ea08a petrh
    None if not implemented
18
    date_dict when implemented
19 04a2b5a4 petrh
    """
20 2d129043 petrh
    date_dict = dict()
21 342ea08a petrh
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 d6ca840d petrh
            date = date_formating.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 528cc257 petrh
                date_dict[date][name].occurrence = max(
37
                    date_dict[date][name].occurrence, int(occurrence))
38 b0d2180b petrh
            else:
39 528cc257 petrh
                date_dict[date][name] = csv_data_line.CSVDataLine(
40
                    name, date, int(occurrence))
41 b0d2180b petrh
42 2d129043 petrh
    return date_dict