Advertisement
canezzy

Untitled

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