Advertisement
Guest User

Untitled

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