configuration.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. """
  2. @author: Juegen Pannosch (welser project), modified by Tanja Zolotareva
  3. @description: Here we define a data-structure that contains arguments
  4. used throughout the project. Arguments (like data locations) that can differ
  5. from person to person are loaded from the ./.config file, arguments that should
  6. be the same fro everyone are defined directly in the data structure. All
  7. all changes in this script should be committed to git.
  8. """
  9. # -*- coding: utf-8 -*-
  10. import os
  11. import configparser
  12. class Configuration:
  13. def __init__(self,
  14. config_file: str = os.path.join(os.getcwd(), ".env")):
  15. '''
  16. '''
  17. assert isinstance(config_file, str), "the config_file must be a string"
  18. assert os.path.isfile(config_file), "config file was not found"
  19. self._parse_ini_file(config_file)
  20. def __getitem__(self, item):
  21. '''
  22. '''
  23. if item in self._config:
  24. return self._config[item]
  25. else:
  26. return None
  27. def _parse_ini_file(self, config_file: str):
  28. '''
  29. '''
  30. self._config = dict()
  31. config = configparser.ConfigParser()
  32. config.read(config_file)
  33. for key in config:
  34. self._config[key] = {}
  35. sub_config = config[key]
  36. for sub_key in sub_config:
  37. name = sub_key.upper()
  38. value = sub_config[sub_key]
  39. self._config[key][name] = value if (value != '') else None
  40. @property
  41. def labeled_history_folder(self):
  42. '''
  43. '''
  44. return os.path.join(self._config["LOCATIONS"]["DATA_DIR"],
  45. "Aufarbeitungsdaten/2018/Datenextrakt einsatzfähige Radsätze 2018")
  46. @property
  47. def unlabeled_history_yearly_folders(self):
  48. '''
  49. '''
  50. folders = []
  51. for year in ["2016", "2017", "2018"]:
  52. folders.append(os.path.join(self._config["LOCATIONS"]["DATA_DIR"],
  53. "Aufarbeitungsdaten",
  54. year,
  55. "Datenextrakt alle Radsätze {} ausgehend von der Station 110").format(year))
  56. return folders
  57. @property
  58. def additional_data_folder(self):
  59. '''
  60. '''
  61. return os.path.join(self._config["LOCATIONS"]["DATA_DIR"],
  62. "Info-Austausch")
  63. @property
  64. def columns_rs516(self):
  65. '''
  66. '''
  67. return {0: "radsatznummer",
  68. 1: "positionsnummer",
  69. 2: "status",
  70. 3: "taetigkeitsname",
  71. 4: "datum",
  72. 5: "presskrafdiagram_min",
  73. 6: "presskrafdiagram_max",
  74. 7: "presskrafdiagram_wert"}
  75. @property
  76. def ihs_labels(self):
  77. '''
  78. For analysis we replace replace string IHS by an integer value,
  79. can be useful for comparing IHS of two wheelsets
  80. '''
  81. ihs_labels = {"null": -1,
  82. "IS1": 0,
  83. "IS1L": 1,
  84. "IS2": 2,
  85. "IS3": 3}
  86. return ihs_labels
  87. @property
  88. def schrott_schadcodes(self):
  89. '''
  90. If during the process one of the following schadcodes is assigned,
  91. then the wheelset is scap and is removed from the process.
  92. This should correspond to aufarbeitungstyp = 2 in rs0, but if there
  93. was a delay (or a mistake) in the maintainance of the table
  94. rs0, this might not be the case. Count as scap anyway.
  95. '''
  96. schadcodes_schrott = ["RSAUS"]
  97. return schadcodes_schrott
  98. @property
  99. def schrott_taetigkeiten(self):
  100. '''
  101. If during the process one of the folling tätigkeiten is assigned,
  102. then the wheelset is scap and is removed from the process.
  103. This should correspond to aufarbeitungstyp = 2 in rs0 and (or)
  104. to assignment of a corresponding schadcode. Data might contain
  105. inconsistencies. If such an activity is assigned, count as scrap.
  106. '''
  107. taetigkeiten_schrott = ["RADSATZ AUSSCHEIDEN"]
  108. return taetigkeiten_schrott
  109. @property
  110. def status_labels(self):
  111. '''
  112. Used to uniformize the column "Status" in the table rs1,
  113. integer values convenient for analysis
  114. '''
  115. status_labels = {"Scheiden": 2,
  116. "Schlecht": 1,
  117. "Fertig": 0,
  118. "Gut": 0}
  119. return status_labels
  120. @property
  121. def process_stages(self):
  122. '''
  123. For machine learning predictions we divide the process into
  124. big stages, stages can be skipped dependeing on the IHS of the
  125. wheelset. We use all information geathered during the previous
  126. process stages to make predictions for the next stage.
  127. '''
  128. import networkx as nx
  129. critical_stations = {"A": [421, 110]}
  130. critical_stations["B"] = [130, 131]
  131. critical_stations["C"] = [140, 141, 142, 150]
  132. critical_stations["D"] = [410, 420]
  133. critical_stations["E"] = [510, 511, 520, 521, 535,
  134. 530, 531, 516, 550]
  135. critical_stations["F"] = [490, 480, 430, 170]
  136. critical_stations["G"] = [595, 190, 630]
  137. critical_stations["H"] = [640, 641]
  138. critical_stations["I"] = [650, 560]
  139. critical_stations["J"] = [675]
  140. critical_stations["K"] = [690]
  141. critical_stations["L"] = [710, 670]
  142. stages_graph = nx.DiGraph()
  143. for stage in critical_stations:
  144. stages_graph.add_node(stage, stations=critical_stations[stage])
  145. stages_graph.add_edge("A", "B")
  146. stages_graph.add_edge("B", "C")
  147. stages_graph.add_edge("C", "D")
  148. stages_graph.add_edge("D", "E")
  149. stages_graph.add_edge("D", "F")
  150. stages_graph.add_edge("E", "G")
  151. stages_graph.add_edge("F", "G")
  152. stages_graph.add_edge("G", "H")
  153. stages_graph.add_edge("H", "I")
  154. stages_graph.add_edge("I", "J")
  155. stages_graph.add_edge("J", "K")
  156. stages_graph.add_edge("K", "L")
  157. return stages_graph
  158. # singleton
  159. default = Configuration()