Advertisement
canezzy

Untitled

Nov 5th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. """This module is main module for contestant's solution."""
  2.  
  3. from hackathon.utils.control import Control
  4. from hackathon.utils.utils import ResultsMessage, DataMessage, PVMode, \
  5. TYPHOON_DIR, config_outs
  6. from hackathon.framework.http_server import prepare_dot_dir
  7.  
  8.  
  9. def worker(msg: DataMessage) -> ResultsMessage:
  10. """TODO: This function should be implemented by contestants."""
  11. # Details about DataMessage and ResultsMessage objects can be found in /utils/utils.py
  12.  
  13. if msg.buying_price > 5:
  14. if msg.current_load > 2.5:
  15. if msg.solar_production - msg.current_load > 0:
  16. load3 = True
  17. else:
  18. load3 = False
  19. else:
  20. load3 = True
  21.  
  22. if msg.current_load > 6.17:
  23. if msg.solar_production - msg.current_load > 0:
  24. load2 = True
  25. else:
  26. load2 = False
  27. else:
  28. load2 = True
  29. else:
  30. load2 = True
  31. load3 = True
  32.  
  33. if (msg.selling_price < 3 and msg.bessSOC == 1 and msg.solar_production > msg.current_load):
  34. load2 = True
  35. if msg.solar_production - msg.current_load > 0.5 * msg.current_load:
  36. load3 = True
  37. else:
  38. if msg.bessSOC > 0.98 and msg.current_load < msg.solar_production:
  39. load2 = True
  40.  
  41. pr = calculatePowerReference(msg)
  42. pv = calculatePV(msg)
  43. return ResultsMessage(data_msg=msg,
  44. load_one=True,
  45. load_two=load2,
  46. load_three=load3,
  47. power_reference = pr,
  48. pv_mode = pv)
  49.  
  50. # Dummy result is returned in every cycle here
  51.  
  52.  
  53. def calculatePowerReference(msg : DataMessage):
  54. if msg.bessSOC != 1:
  55. if msg.solar_production > msg.current_load:
  56. return (-1)*(msg.solar_production - msg.current_load)
  57. if msg.bessSOC < 0.2:
  58. if not msg.grid_status:
  59. return (0.0)
  60. else:
  61. if msg.buying_price < 5:
  62. if msg.solar_production == 0:
  63. if msg.bessSOC < 0.8:
  64. return (-0.9)
  65. else:
  66. return (0.0)
  67. else:
  68. if msg.solar_production < 6:
  69. return ((-1) * msg.solar_production)
  70. else:
  71. return (-6.0)
  72. else:
  73. if msg.bessSOC > 0.6 and msg.selling_price > 0:
  74. return (6.0)
  75. else:
  76. return (0.0)
  77. else:
  78. if not msg.grid_status:
  79. return (0.0)
  80. else:
  81. if msg.buying_price < 5:
  82. if msg.solar_production == 0:
  83. return (-0.143)
  84. else:
  85. if msg.solar_production < 6:
  86. return ((-1) * msg.solar_production)
  87. else:
  88. return (-6.0)
  89. else:
  90. if msg.selling_price == 0:
  91. return (0.0)
  92. else:
  93. return (6.0)
  94.  
  95. def calculatePV(msg : DataMessage):
  96. if not msg.grid_status and msg.bessSOC == 1.0:
  97. return (PVMode.OFF)
  98. else:
  99. return (PVMode.ON)
  100.  
  101. def run(args) -> None:
  102. prepare_dot_dir()
  103. config_outs(args, 'solution')
  104.  
  105. cntrl = Control()
  106.  
  107. for data in cntrl.get_data():
  108. cntrl.push_results(worker(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement