
"""Discom Data Config File for Python

Configuration file required to use the methods and functions defined in the Discom Data Export library.

$Date: 2020-07-13 16:59:12 +0200 (Mo, 13 Jul 2020) $
$Revision: 26256 $

"""

# standard library
from datetime import datetime, date, time
from os.path import expanduser

###########################################    
# Network settings
###########################################    
class TCP_C:
    # IP of machine where the API is hosted (Historical/Live Data Service)
    HOST = '127.0.0.1'
    
    # Port number for the TCP/IP socket communication
    PORT = 31001
    
    # Name of the data client for the historical data service (DemoTestClient.py) 
    DataClientName = 'PythonDataClient'
    
    # Name of the control client (run from the Python console or scripted)
    ControlClientName = 'PythonControlClient'

    # Name of the data client for the real-time service (DemoTestClient.py) 
    LiveClientName = 'PythonLiveClient'

###########################################    
# Write to file option
###########################################    
class File_C:
    
    # If set to true, the requested data which is received over the socket will be written to file (see next line).
    # These files can be loaded and queried in Python using the functions "IndexFileMakro" and "IndexValueMakro" (DiscomDataExportLibrary.py) 
    WriteToFile = False
    
    # Full filename + path
    FilePath = 'D:/Archives/SampleData.txt'

    # On Unix this will lead to the UserHomeDirectory
    # FilePath = expanduser("~/SampleData.txt")

###########################################    
# SQL query options
# Filter options which narrow down the data search for requesting specific set of Quinters
###########################################      
class SQL_C:
    
    # The path to the location where the measurement files (archive files) are stored (local or network path)
    #ArchiveSearchPath = 'D:\Archives\"Customer-specific folder name"'
    #ArchiveSearchPath = '\\Network-Share\Archives'
    ArchiveSearchPath = 'D:\Archives\MQ200B'

    # Discom result database 
    Database = "MQ200B_ProdDb"

    # SQL Server connection string
    DbConnectionString = "Server=DISCOM-PYARE;Database=MQ200B_ProdDb;User Id=sa;Password=rotasadmin"

    DbCommandTimeout = 60

    # Client target for the SQL query (data client that queries for specific set of Quinters, receives and processes the data ):
    # If the configuration file is used, the ClientId must be the DataClientName
    ClientId = TCP_C.DataClientName
    
    # SQL query parameters (query parameters are linked together by using the "AND" operator).
    # An optional "OR" operator is not yet implemented.
    
    # Time frame: From
    DateFrom = datetime.combine(date(2015, 11, 23), time(0, 0))    
    
    # Time frame: Until
    DateUntil = datetime.combine(date(2019, 11, 23), time(23, 59))
    
    # If TopN is greater than zero, the time parameters defined above are ignored (Top N = the last N measurements)
    TopN = 1
    
    # Name list of base models/types which should be included in the query
    # If list is empty all base models/types will be included in the query
    BaseTypeIds = list()
    # Each base model/type needs to be appended to the list
    
    # Name list of models/types which should be included in the query
    # If list is empty all models/types will be included in the query
    TypeIds = list()
    # Each model/type needs to be appended to the list
    #TypeIds.append('3511')
    
    # Name list of test benches which should be included in the query
    # If list is empty all test benches will be included in the query
    TestBenchIds = list()
    
    # Name list of result codes from the database (1 = OK, 2 = NOK, 4 = System Error) 
    # If list is empty all result ids will be included in the query
    ResultIds = list()
    #ResultIds.append('OK')
    
    # Name list of test kind codes from the database
    # (1 = Production/normal measurement, 2 = Reference measurement, 3 = Special test, 4 = Test, 5 = Average, 6 = Recode, 7 = WavePlayback, 8 = Evaluation)
    # If list is empty all test kind ids will be included in the query
    TestKindIds = list()
    #TestKindIds.append('')
    
    # Name list of property codes from the database (1 = Normal measurement, 2 = Repaired)
    # If list is empty all property ids will be included in the query
    PropertyIds = list()
    #PropertyIds.append('')
    
    # Only show the last measurement of repetitive measurements
    OnlyLastMeasurement = False
   
    # Exclude the last measurement of repetitive measurements
    ExcludeLastMeasurement = False
   
    # Name list of ordinal codes from the database  (1 = First measurement, 2 = second measurement, etc.)
    # If list is empty all ordinal ids will be included in the query
    OrdinalIds = list()
    #OrdinalIds.append('1')

    # List of serial numbers to be included in the query
    # If variable is empty all serial numbers will be included in the query
    SerialNumbers = list()

    # List of PkIdents to be included in the query
    PkIdents = list()

    # List of error codes to be included in the query
    # If variable is empty all error codes will be included in the query
    ErrorCodes = list()

    # List of error sequence items to be included in the query
    # If variable is empty all sequential numbers will be included in the query
    ErrorSequence = list()

    # List of serial numbers to be included in the query
    # If variable is empty all serial numbers will be included in the query
    ExportErrors = True

###########################################    
# Archive query options
# Options to specify a List of Archives to be processed
###########################################      
class Archive_C:
    
    # The path to the location where the measurement files (archive files) are stored (local or network path)
    #ArchiveSearchPath = 'D:\Archives\"Customer-specific folder name"'
    #ArchiveSearchPath = '\\Network-Share\Archives\Magna'
    Archives = list()
    
    # Client target for the SQL query (data client that queries for specific set of Quinters, receives and processes the data ):
    # If the configuration file is used, the ClientId must be the DataClientName
    ClientId = TCP_C.DataClientName
    
    # Archive query parameters (query parameters are linked together by using the "AND" operator).
    # An optional "OR" operator is not yet implemented.
    
    # Time frame: From
    DateFrom = datetime.combine(date(2015, 11, 23), time(0, 0))    
    
    # Time frame: Until
    DateUntil = datetime.combine(date(2019, 11, 23), time(23, 59))
    
    # If TopN is greater than zero, the time parameters defined above are ignored (Top N = the last N measurements)
    TopN = 0
    
    # Name list of base models/types which should be included in the query
    # If list is empty all base models/types will be included in the query
    BaseTypeIds = list()
    # Each base model/type needs to be appended to the list
    
    # Name list of models/types which should be included in the query
    # If list is empty all models/types will be included in the query
    TypeIds = list()
    # Each model/type needs to be appended to the list
    
    # Name list of test benches which should be included in the query
    # If list is empty all test benches will be included in the query
    TestBenchIds = list()
    
    # Name list of result codes from the database (1 = OK, 2 = NOK, 4 = System Error) 
    # If list is empty all result ids will be included in the query
    ResultIds = list()
    
    # Name list of test kind codes from the database
    # (1 = Production/normal measurement, 2 = Reference measurement, 3 = Special test, 4 = Test, 5 = Average, 6 = Recode, 7 = WavePlayback, 8 = Evaluation)
    # If list is empty all test kind ids will be included in the query
    TestKindIds = list()
    
    # Name list of property codes from the database (1 = Normal measurement, 2 = Repaired)
    # If list is empty all property ids will be included in the query
    PropertyIds = list()
  
    # List of serial numbers to be included in the query
    # If variable is empty all serial numbers will be included in the query
    SerialNumbers = list()

###########################################    
# Quinter requests
# Specific set of Quinters for which data is to be exported from the data subset as defined by the SQL query above
###########################################    
class Quinter_C:
    
    # Each QuinterRequest object contains the following objects: Quinter / DataTransformation / ExportLimits / Encoding / ValuesEncoding
    # Multiple QuinterRequests are added to the following lists which are then used to construct the QuinterRequest objects
    Quinters = list()
    DataTransformation = list()
    ExportLimits = list()
    ValuesEncoding = list()

    ## Quinter (Mode/Instrument/Parameter/Channel/Sensor/Location)
    Quinters.append(["2-B", "SpecReport", "-", "Mix", "VS", "Prim"])
    # Data transformation object used to transform the data from its original data represenation into a fixed grid (increment) representation e.g. Polygon2D => Vector, VectorList => Matrix
    # Bool OriginalData, Len, Delta, Zero
    DataTransformation.append([ True, 0, 0, 0 ])
    # Export the limits (which are used to evaluate the values)
    ExportLimits.append(True)
    #  Encoding of the actual data (Values and Limits properties of the data subclasses 'Vector', 'Polygon2D', 'VectorList', 'Matrix'   0 = JSON, 1 = JSONARY
    ValuesEncoding.append(0)