Projekt

Obecné

Profil

Stáhnout (1.26 KB) Statistiky
| Větev: | Revize:
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", encoding="utf-8") as file:
24

    
25
        for line in file:
26

    
27
            array = line.split(";")
28

    
29
            date = date_formating.date_time_formatter(array[1][1:-1])
30
            name = array[0][1:-1]
31
            occurrence = array[2][:-1]
32

    
33
            if date not in date_dict:
34
                date_dict[date] = {}
35

    
36
            if name in date_dict[date]:
37
                date_dict[date][name].occurrence += int(occurrence)
38
            else:
39
                date_dict[date][name] = csv_data_line.CSVDataLine(
40
                    name, date, occurrence)
41

    
42
    return date_dict
(1-1/4)