Projekt

Obecné

Profil

Stáhnout (1.54 KB) Statistiky
| Větev: | Revize:
1
import inspect
2
from Utilities.CSV import CSVDataLine
3

    
4
# Path to processed data
5
PROCESSED_DATA_PATH = "ProcessedData/"
6

    
7

    
8
def get_unique_names_from_file(filename, column_number):
9
    """
10
        Extract set of unique names from file
11
    Args:
12
        filename: path to processed file
13
        column_number: unique names are expected in csv file on column_number
14

    
15
    Returns:
16
        set of unique names
17
    """
18
    # create set of unique names
19
    name_set = set()
20

    
21
    with open(filename, "r") as file:
22
        # go through every line of line
23
        for x in file:
24
            # split by csv splitter ;
25
            array = x.split(";")
26
            # add string from chosen column to set
27
            name_set.add(array[column_number])
28

    
29
    return name_set
30

    
31

    
32
def export_data_to_csv(filename, data_dict):
33
    """
34
        Takes data_dict and export it into a csv file
35
    Args:
36
        filename: name of exported file
37
        data_dict: dictionary containing data from DatasetProcessor
38
    """
39
    with open(PROCESSED_DATA_PATH + filename[12:], "w+") as file:
40

    
41
        for date in data_dict:
42
            if len(date) != 13:
43
                raise ValueError("Invalid date format for key value --> YYYY-mm-dd-hh expected!")   
44
            for data in data_dict[date]:
45
                csv_line = data_dict[date][data]
46
                if not isinstance(csv_line,CSVDataLine.CSVDataLine):
47
                    raise ValueError("data_dict is expected to have CSVDataLine as values")
48
                file.write(csv_line.to_csv() + '\n')
(2-2/2)