Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. """
  2.  
  3. Copyright 2019 TomorrowData SRL
  4.  
  5. Licensed under the Software License Agreement ("Agreement") contained in the root
  6. directory of this project (LICENCE.txt).
  7.  
  8. You may not use this file except in compliance with the License.
  9. You may obtain a copy of the License writing to tomorrowdatasrl@legalmail.it
  10.  
  11. YOU ASSUME ALL RISKS AND ALL COSTS ASSOCIATED WITH YOUR USE
  12. OF THE SERVICE, INCLUDING, WITHOUT LIMITATION, ANY INTERNET ACCESS FEES, BACK-UP
  13. EXPENSES, COSTS INCURRED FOR THE USE OF YOUR DEVICE AND PERIPHERALS, AND ANY
  14. DAMAGE TO ANY EQUIPMENT, SOFTWARE, INFORMATION OR DATA.
  15.  
  16. See the License for the specific language governing permissions and
  17. limitations under the License.
  18.  
  19. """
  20.  
  21. from datetime import timedelta
  22. import monotonic
  23.  
  24. from plc.base_machine_data_processor import BaseNormalizer
  25.  
  26.  
  27. class Normalizer(BaseNormalizer):
  28.  
  29. def __init__(self, args, get_asac_data):
  30.  
  31. self.logger = self.get_logger()
  32. self.args = args
  33. self.get_asac_data = get_asac_data
  34. self.status = None
  35.  
  36. def elaborate_asac(self):
  37.  
  38. self.status = self.get_asac_data()
  39. self.logger.info(
  40. 'Custom normalizer asac elaboration with: {}'.format(self.status)
  41. )
  42.  
  43. def run(self, date, payload):
  44. """
  45. calculate oee parameters from payload
  46. """
  47.  
  48. active_time = self.active_time(payload)
  49. Local_1_CPt00FilterOffOn = self.Local_1_CPt00FilterOffOn(payload)
  50. Slot4Output_Select = self.Slot4Output_Select(payload)
  51. Slot4Test_IntervalPRE = self.Slot4Test_IntervalPRE(payload)
  52. combo = Local_1_CPt00FilterOffOn * Slot4Test_IntervalPRE
  53. return {
  54. "date": str(date),
  55. "Local_1_CPt00FilterOffOn": Local_1_CPt00FilterOffOn,
  56. "Slot4Output_Select": Slot4Output_Select,
  57. "Slot4Test_IntervalPRE": Slot4Test_IntervalPRE,
  58. "combo": combo,
  59. "comment": "'combo' is Local_1_CPt00FilterOffOn * Slot4Test_IntervalPRE"
  60. }
  61.  
  62. def active_time(self, payload):
  63. """
  64. override this function to customize your active time calculation
  65. """
  66.  
  67. try:
  68. active_time = timedelta(
  69. hours=payload.get(
  70. self.args['active_hours'].get('mem_ref_id'),
  71. self.args['active_hours'].get('default_value', None)
  72. ),
  73. minutes=payload.get(
  74. self.args['active_minutes'].get('mem_ref_id'),
  75. self.args['active_minutes'].get('default_value', None)
  76. ),
  77. seconds=payload.get(
  78. self.args['active_seconds'].get('mem_ref_id'),
  79. self.args['active_seconds'].get('default_value', None)
  80. )
  81. ).total_seconds()
  82.  
  83. except Exception as e:
  84. self.logger.error('Unable to calculate active time: {}'.format(e))
  85. raise
  86.  
  87. return active_time
  88.  
  89. def Local_1_CPt00FilterOffOn(self, payload):
  90. """
  91. override this function to customize your nominal_speed calculation
  92. """
  93.  
  94. try:
  95. Local_1_CPt00FilterOffOn = payload.get(
  96. self.args['Local_1_CPt00FilterOffOn'].get('mem_ref_id'),
  97. self.args['Local_1_CPt00FilterOffOn'].get('default_value', None)
  98. )
  99.  
  100. except Exception as e:
  101. self.logger.error('Unable to calculate Local_1_CPt00FilterOffOn: {}'.format(e))
  102. raise
  103.  
  104. return Local_1_CPt00FilterOffOn
  105.  
  106. def Slot4Output_Select(self, payload):
  107. """
  108. override this function to customize your pieces_produced calculation
  109. """
  110.  
  111. try:
  112. Slot4Output_Select = payload.get(
  113. self.args['Slot4Output_Select'].get('mem_ref_id'),
  114. self.args['Slot4Output_Select'].get('default_value', None)
  115. )
  116.  
  117. except Exception as e:
  118. self.logger.error('Unable to calculate Slot4Output_Select: {}'.format(e))
  119. raise
  120.  
  121. return Slot4Output_Select
  122.  
  123. def Slot4Test_IntervalPRE(self, payload):
  124. """
  125. override this function to customize your pieces_wasted calculation
  126. """
  127.  
  128. try:
  129. Slot4Test_IntervalPRE = payload.get(
  130. self.args['Slot4Test_IntervalPRE'].get('mem_ref_id'),
  131. self.args['Slot4Test_IntervalPRE'].get('default_value', None)
  132. )
  133.  
  134. except Exception as e:
  135. self.logger.error('Unable to calculate Slot4Test_IntervalPRE: {}'.format(e))
  136. raise
  137.  
  138. return Slot4Test_IntervalPRE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement