Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. import pickle
  2. import os.path
  3.  
  4. class IrrigationProgram:
  5. program = 0
  6. units = 0
  7. water_before_1 = 0
  8. water_before_2 = 0
  9. water_after_1 = 0
  10. water_after_2 = 0
  11. water_total_1 = 0
  12. water_total_2 = 0
  13. kicks = 0
  14. fertilization_program = 0
  15. condition_program = 0
  16. time_start_1 = 0
  17. time_start_2 = 0
  18. time_between_1 = 0
  19. time_between_2 = 0
  20. valves = ""
  21.  
  22.  
  23. class FertilizationProgram:
  24. program = 0
  25. values_1 = 0.0
  26. values_2 = 0.0
  27. values_3 = 0.0
  28. values_4 = 0.0
  29. values_5 = 0.0
  30. values_6 = 0.0
  31. values_7 = 0.0
  32. values_8 = 0.0
  33. ec = 0.0
  34. ph = 0.0
  35.  
  36. class InyectionProgram:
  37. program = 1
  38. flow = 600
  39. time_on = 10
  40. litres_pulse = 100
  41. max_deviation = 70
  42. simulator = True
  43.  
  44.  
  45. class ControllerState:
  46. last_update = 0
  47. allIrrigation = dict()
  48. allFertilization = dict()
  49. allInyection = dict()
  50. username = None
  51. password = None
  52.  
  53. def load_from_file(path):
  54. if os.path.isfile(path):
  55. with open(path, 'rb') as in_file:
  56. return(pickle.load(in_file))
  57.  
  58. def load_from_json(self, json):
  59. self.last_update = int(json['update'])
  60. for fert in json["fertilizer_prog"]:
  61. fertProg = FertilizationProgram()
  62. fertProg.program = fert["program"]
  63. fertProg.ec = fert["ec"]
  64. fertProg.ph = fert["ph"]
  65. fertProg.values_1 = fert["value_1"]
  66. fertProg.values_2 = fert["value_2"]
  67. fertProg.values_3 = fert["value_3"]
  68. fertProg.values_4 = fert["value_4"]
  69. fertProg.values_5 = fert["value_5"]
  70. fertProg.values_6 = fert["value_6"]
  71. fertProg.values_7 = fert["value_7"]
  72. fertProg.values_8 = fert["value_8"]
  73. self.allFertilization[fertProg.program] = fertProg
  74. for irr in json["irrigation_prog"]:
  75. irrProg = IrrigationProgram()
  76. irrProg.program = irr["program"]
  77. irrProg.units = irr["units"]
  78. irrProg.water_before_1 = irr["water_before_1"]
  79. irrProg.water_before_2 = irr["water_before_2"]
  80. irrProg.water_after_1 = irr["water_after_1"]
  81. irrProg.water_after_2 = irr["water_after_2"]
  82. irrProg.water_total_1 = irr["water_total_1"]
  83. irrProg.water_total_2 = irr["water_total_2"]
  84. irrProg.kicks = irr["kicks"]
  85. irrProg.fertilization_program = irr["fertilization_program"]
  86. irrProg.condition_program = irr["condition_program"]
  87. irrProg.time_start_1 = irr["time_start_1"]
  88. irrProg.time_start_2 = irr["time_start_2"]
  89. irrProg.time_between_1 = irr["time_between_1"]
  90. irrProg.time_between_2 = irr["time_between_2"]
  91. irrProg.valves = irr["valves"]
  92. self.allIrrigation[irrProg.program] = irrProg
  93. # TODO valves
  94. for iny in json["inyection_prog"]:
  95. inyProg = InyectionProgram()
  96. inyProg.program = iny["program"]
  97. inyProg.flow = iny["flow"]
  98. inyProg.time_on = iny["time_on"]
  99. inyProg.litres_pulse = iny["litres_pulse"]
  100. inyProg.max_deviation = iny["max_deviation"]
  101. inyProg.simulator = iny["simulator"]
  102. self.allInyection[inyProg.program] = inyProg
  103.  
  104. def save_to_file(self, filename):
  105. pickle.dumps(self)
  106. with open(filename, 'wb') as out_file:
  107. pickle.dump(self, out_file)
  108. def __eq__(self, other):
  109. if self.last_update == other.last_update and\
  110. self.allInyection == other.allInyection and\
  111. self.allFertilization == other.allFertilization and\
  112. self.allIrrigation == other.allIrrigation:
  113. return True
  114. else:
  115. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement