Test Failed
Push — master ( 083155...926069 )
by Daniel
03:49
created

tableau_hyper_management.converter   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 0
1
"""
2
main - entry point of the package
3
4
This file is performing CSV read into HYPER file and measures time elapsed (performance)
5
"""
6
7
# standard Python packages
8
import os.path as os_path
9
from datetime import timedelta
10
# package to measure portions of code performance
11
from codetiming import Timer
12
13
# additional packages to be installed from PyPi
14
import pandas as pd
15
16
# Custom classes specific to this package
17
from tableau_hyper_management.LoggingNeeds import LoggingNeeds as ClassLN
18
from tableau_hyper_management.TypeDetermination import ClassBN
19
from tableau_hyper_management.TypeDetermination import TypeDetermination as ClassTD
20
from tableau_hyper_management.CommandLineArgumentsManagement import \
21
    CommandLineArgumentsManagement as ClassCLAM
22
from tableau_hyper_management.TableauHyperApiExtraLogic import \
23
    TableauHyperApiExtraLogic as ClassTHAEL
24
25
# main execution logic
26
if __name__ == '__main__':
27
    ClassBN.fn_load_configuration(ClassBN)
28
    parameters_in = ClassCLAM.parse_arguments(ClassCLAM,
29
                                              ClassBN.cfg_dtls['input_options']['converter'])
30
    # initiate logger
31
    ClassLN.initiate_logger(ClassLN, parameters_in.output_log_file, 'thm_converter')
32
    # define global timer to use
33
    t = Timer('thm',
34
              text      = 'Time spent is {seconds} ',
35
              logger    = ClassLN.logger.debug
36
              )
37
    t.start()
38
    # marking start of the Log
39
    ClassLN.logger.info('='*50)
40
    ClassLN.logger.info('Tableau Hyper Management started')
41
    # reflect input parameters given values
42
    ClassCLAM.listing_parameter_values(ClassCLAM, ClassLN.logger, parameters_in)
43
    t.stop()
44
    # initiate Data Frame from specified CSV file
45
    if os_path.isfile(parameters_in.input_file):
46
        # intake given CSV file into a Pandas Data Frame
47
        t.start()
48
        csv_content_df = pd.read_csv(filepath_or_buffer = parameters_in.input_file,
49
                                     delimiter          = parameters_in.csv_field_separator,
50
                                     cache_dates        = True,
51
                                     index_col          = None,
52
                                     memory_map         = True,
53
                                     low_memory         = False,
54
                                     encoding           = 'utf-8',
55
                                     )
56
        ClassLN.logger.info('Given CSV file ' + parameters_in.input_file
57
                            + ' has been loaded into a Pandas Data Frame successfully')
58
        t.stop()
59
        t.start()
60
        # advanced detection of data type within Data Frame
61
        detected_csv_structure = ClassTD.fn_detect_csv_structure(ClassTD, ClassLN.logger,
62
                                                                 csv_content_df, parameters_in)
63
        t.stop()
64
        t.start()
65
        # create HYPER from Data Frame
66
        ClassTHAEL.fn_run_hyper_creation(ClassTHAEL, ClassLN.logger, csv_content_df,
67
                                         detected_csv_structure, parameters_in)
68
        t.stop()
69
    else:
70
        # doesn't exist
71
        ClassLN.logger.error('Given file ' + parameters_in.input_file
72
                             + ' does not exist, please check your inputs!')
73
    ClassBN.fn_final_message(ClassBN, ClassLN.logger, t, parameters_in.output_log_file)
74