Projekt

Obecné

Profil

Stáhnout (1.18 KB) Statistiky
| Větev: | Revize:
1 d6ca840d petrh
from Utilities.CSV import csv_data_line
2
from Utilities import date_formating
3 c8f3051b petrh
4 af7609b5 Tomáš Ballák
from shared_types import DateDict
5 c8f3051b petrh
6 af7609b5 Tomáš Ballák
7
def process_file(filename: str) -> DateDict:
8 04a2b5a4 petrh
    """
9 342ea08a petrh
    Method that take path to crawled file and outputs date dictionary:
10 3692d853 petrh
    Date dictionary is a dictionary where keys are dates in format YYYY-mm-dd-hh (2018-04-08-15)
11 d6ca840d petrh
    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 04a2b5a4 petrh
14
    Args:
15 342ea08a petrh
    filename: name of processed file
16 04a2b5a4 petrh
17
    Returns:
18 342ea08a petrh
    None if not implemented
19
    date_dict when implemented
20 04a2b5a4 petrh
    """
21 af7609b5 Tomáš Ballák
    date_dict = {}
22 c8f3051b petrh
23 2d129043 petrh
    with open(filename, "r") as file:
24 c8f3051b petrh
25
        for line in file:
26
27
            array = line.split(";")
28
29 d6ca840d petrh
            date = date_formating.date_time_formatter(array[0][1:-1])
30 c8f3051b petrh
            name = array[1][1:-1]
31
32
            if date not in date_dict:
33 af7609b5 Tomáš Ballák
                date_dict[date] = {}
34 c8f3051b petrh
35
            if name in date_dict[date]:
36 1187e871 petrh
                date_dict[date][name].occurrence += 1
37 c8f3051b petrh
            else:
38 af7609b5 Tomáš Ballák
                date_dict[date][name] = csv_data_line.CSVDataLine(
39
                    name, date, 1)
40 c8f3051b petrh
41 2d129043 petrh
    return date_dict