Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. """This module is main module for contestant's solution."""
  2.  
  3.  
  4. from hackathon.utils.control import Control
  5. from hackathon.utils.utils import ResultsMessage, DataMessage, PVMode, \
  6. TYPHOON_DIR, config_outs
  7. from hackathon.framework.http_server import prepare_dot_dir
  8.  
  9. global blackout_happened
  10. blackout_happened = 0
  11.  
  12. def calcPerc(load1, load2, load3):
  13. perc = 0.0
  14. if load1:
  15. perc += 0.2
  16. if load2:
  17. perc += 0.4
  18. if load3:
  19. perc += 0.4
  20. return perc
  21.  
  22.  
  23.  
  24. def worker(msg: DataMessage) -> ResultsMessage:
  25. """TODO: This function should be implemented by contestants."""
  26. # Details about DataMessage and ResultsMessage objects can be found in /utils/utils.py
  27. print('hello')
  28. load_one = True
  29. load_two = True
  30. load_three = True
  31. power_reference = 0.0
  32. pv_mode = PVMode.ON
  33. global blackout_happened
  34. minBatteryLife = 0.18
  35.  
  36. #kada se desio blekaut onda mozemo bateriju od kraja da punimo
  37. if blackout_happened == 1 and msg.id % 1440 == 0:
  38. blackout_happened = 0
  39.  
  40. if msg.grid_status == 0 and blackout_happened == 0:
  41. blackout_happened = 1;
  42. print('another blackout')
  43.  
  44. if blackout_happened:
  45. minBatteryLife = 0.0
  46.  
  47.  
  48.  
  49.  
  50. # kada se vise isplati da placamo penale nego cenu struje
  51. if msg.buying_price > 6 and msg.current_load > 5.625:
  52. load_three = False
  53.  
  54. if msg.buying_price > 6 and msg.current_load > 6.5625:
  55. load_two = False
  56.  
  57.  
  58.  
  59. if 5 + msg.solar_production < msg.current_load and msg.grid_status == 0:
  60. load_three = False
  61.  
  62. if 5+msg.solar_production < msg.current_load * 0.6 and msg.grid_status == 0:
  63. load_two = False
  64. load_three = False
  65.  
  66.  
  67. # if msg.grid_status == 0:
  68. # load_three = False
  69.  
  70. # if msg.current_load < 2.5 and msg.solar_production > msg.current_load:
  71. # power_reference = msg.current_load - msg.solar_production
  72.  
  73. #ukoliko je skupa struja, a mala potrosnja koristimo bateriju da bi ustedeli
  74. #ukoliko imamo viska sunca punimo bateriju
  75. if msg.buying_price > 5 and load_two and load_one and msg.bessSOC > minBatteryLife:
  76. power_reference = msg.current_load*calcPerc(load_one,load_two,load_three) - msg.solar_production
  77. if power_reference > 5.0:
  78. power_reference = 5.0
  79.  
  80. #ukoliko imamo viska solarne energije a jako je prazna baterija punimo bateriju
  81. if msg.solar_production > msg.current_load*calcPerc(load_one,load_two,load_three) and msg.bessSOC < minBatteryLife:
  82. power_reference = msg.current_load*calcPerc(load_one,load_two,load_three) - msg.solar_production
  83.  
  84. # ukoliko je jeftina struja punimo bateriju do kraja
  85. if msg.buying_price < 6 and msg.bessSOC < 1 and msg.id < 7140:
  86. power_reference = -5.0
  87.  
  88. # ukoliko solarni panel proizvodi previse energije, cak i za sve loadove i maks punjenje baterije - gasimo panel
  89. if msg.solar_production > 5 + msg.current_load:
  90. pv_mode = pv_mode.OFF
  91.  
  92. #pred kraj poslednjeg dana trosimo sve iz baterije
  93. if (60*24*5 - msg.id) * 5 <= msg.bessSOC*20*60:
  94. power_reference = 5.0
  95.  
  96. # Dummy result is returned in every cycle here
  97. return ResultsMessage(data_msg=msg,
  98. load_one=load_one,
  99. load_two=load_two,
  100. load_three=load_three,
  101. power_reference=power_reference,
  102. pv_mode=pv_mode)
  103.  
  104.  
  105. def run(args) -> None:
  106. prepare_dot_dir()
  107. config_outs(args, 'solution')
  108.  
  109. cntrl = Control()
  110.  
  111. for data in cntrl.get_data():
  112. cntrl.push_results(worker(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement