canezzy

Untitled

Nov 5th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 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:
  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.  
  34. pr = calculatePowerReference(msg)
  35. pv = calculatePV(msg)
  36. return ResultsMessage(data_msg=msg,
  37. load_one=True,
  38. load_two=load2,
  39. load_three=load3,
  40. power_reference = pr,
  41. pv_mode = pv)
  42.  
  43. # Dummy result is returned in every cycle here
  44.  
  45.  
  46. def calculatePowerReference(msg : DataMessage):
  47. if msg.bessSOC != 1:
  48. if msg.solar_production > msg.current_load:
  49. return (-1)*(msg.solar_production - msg.current_load)
  50. if msg.bessSOC < 0.2:
  51. if not msg.grid_status:
  52. return (0.0)
  53. else:
  54. if msg.buying_price < 5:
  55. if msg.solar_production == 0:
  56. return (-0.143)
  57. else:
  58. if msg.solar_production < 6:
  59. return ((-1) * msg.solar_production)
  60. else:
  61. return (-6.0)
  62. else:
  63. return (0.0)
  64. else:
  65. if not msg.grid_status:
  66. return (0.0)
  67. else:
  68. if msg.buying_price < 5:
  69. if msg.solar_production == 0:
  70. return (-0.143)
  71. else:
  72. if msg.solar_production < 6:
  73. return ((-1) * msg.solar_production)
  74. else:
  75. return (-6.0)
  76. else:
  77. if msg.selling_price == 0:
  78. return (0.0)
  79. else:
  80. return (6.0)
  81.  
  82. def calculatePV(msg : DataMessage):
  83. if not msg.grid_status and msg.bessSOC == 1.0:
  84. return (PVMode.OFF)
  85. else:
  86. return (PVMode.ON)
  87.  
  88. def run(args) -> None:
  89. prepare_dot_dir()
  90. config_outs(args, 'solution')
  91.  
  92. cntrl = Control()
  93.  
  94. for data in cntrl.get_data():
  95. cntrl.push_results(worker(data))
Advertisement
Add Comment
Please, Sign In to add comment