canezzy

Untitled

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