def run(args) -> None: prepare_dot_dir() config_outs(args, 'solution') cntrl = Control() for data in cntrl.get_data(): cntrl.push_results(worker(data))
def run(args) -> None: prepare_dot_dir() config_outs(args, 'solution') cntrl = Control() #pozovi generate_profiles() #exploit #obrisi fajl data/profiles.json for data in cntrl.get_data(): cntrl.push_results(worker(data))
#!/usr/bin/env python """This module runs both contestant's solution and framework.""" import webbrowser from multiprocessing import Process import run_solution as solution import run_framework as framework from hackathon.utils.utils import CFG from hackathon.framework.http_server import prepare_dot_dir __author__ = "Novak Boskov" __copyright__ = "Typhoon HIL Inc." __license__ = "MIT" if __name__ == '__main__': prepare_dot_dir() solution = Process(target=solution.run, args=('log', )) solution.start() framework = Process(target=framework.run, args=('log', )) framework.start() webbrowser.open('http://localhost:{}/viz.html' .format(CFG.results_http_server_port))
def run(args) -> None: prepare_dot_dir() gp.generate_profiles() config_outs(args, 'framework') data_emit_socket, _ = bind_pub_socket(CFG.in_address, CFG.in_port) result_gather_socket, _ = bind_sub_socket(CFG.out_address, CFG.out_port) results_poll = zmq.Poller() results_poll.register(result_gather_socket, zmq.POLLIN) # Run http server in separate process http = Process(target=http_server_run, args=()) http.start() # Create results file, truncate if exists with open(CFG.results, 'w'): pass # Create results dump file, truncate if exists with open(CFG.results_dump, 'w'): pass # Open profile file with open(CFG.profile_file, 'r') as f: profile = json.load(f) print('Profile file from {} has loaded...'.format(CFG.profile_file)) print('Loading physics initialization file') with open(CFG.physics_init, 'r') as f: ini = json.load(f) lapse_time = CFG.framework_lapse_time or 1 print('Framework is booting with the lapse time of {}s ...'.format( lapse_time)) time.sleep(lapse_time) for i, rec in enumerate(profile): if i == 0: soc_bess, overload, mg, current_power = ini['bessSOC'], \ ini['bessOverload'], \ ini['mainGridPower'], \ ini['bessPower'] else: last = get_latest_result() soc_bess, overload, mg, current_power = last['bessSOC'], \ last['bessOverload'], \ last['mainGridPower'], \ last['bessPower'] data = DataMessage(i, rec['gridStatus'], rec['buyingPrice'], rec['sellingPrice'], rec['currentLoad'], rec['solarProduction'], soc_bess, overload, mg, current_power) if CFG.DBG: print('Framework emits {}'.format(data)) data_emit_socket.send_pyobj(data) rater(result_gather_socket, results_poll, data) # Send terminating message to the solution data_emit_socket.send_pyobj(False) # Write results json from dump with open(CFG.results, 'w') as f: json.dump(read_results(), f) if CFG.shutdown_http_server: # Gracefully terminate HTTP server process that serves results # to visualization web page time.sleep(2) http.terminate() print('Simple HTTP server has stopped.') else: print('Simple HTTP server is still running...')