Projekt

Obecné

Profil

Stáhnout (1.32 KB) Statistiky
| Větev: | Revize:
1
from Utilities.CSV import csv_data_line
2
from Utilities import date_formating
3
from shared_types import DateDict
4

    
5

    
6
def process_file(filename: str) -> DateDict:
7
    """
8
    Method that take path to crawled file and outputs date dictionary:
9
    Date dictionary is a dictionary where keys are dates in format YYYY-mm-dd-hh (2018-04-08-15)
10
    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

    
13
    Args:
14
    filename: name of processed file
15

    
16
    Returns:
17
    None if not implemented
18
    date_dict when implemented
19
    """
20
    date_dict = dict()
21

    
22
    with open(filename, "r", encoding="utf-8") as file:
23

    
24
        for line in file:
25

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

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

    
32
            if date not in date_dict:
33
                date_dict[date] = dict()
34

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

    
42
    return date_dict
(4-4/4)