Projekt

Obecné

Profil

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