Spaces:
Runtime error
Runtime error
from flask import Flask, render_template, jsonify | |
from flask_socketio import SocketIO | |
import random | |
import time | |
import threading | |
app = Flask(__name__) | |
socketio = SocketIO(app) | |
# Zone Pressure Monitor | |
class ZonePressureMonitor: | |
def __init__(self): | |
self.pressures = {'Zone A': 30, 'Zone B': 45} | |
def update_pressure(self): | |
# Simulate real-time pressure updates | |
for zone in self.pressures: | |
self.pressures[zone] = random.randint(20, 50) | |
def get_pressures(self): | |
return self.pressures | |
# Reward System | |
class RewardSystem: | |
def __init__(self): | |
self.units = {} | |
def record_efficiency(self, unit_id, efficiency): | |
self.units[unit_id] = efficiency | |
def calculate_rewards(self, pressures): | |
rewards = {} | |
for unit, efficiency in self.units.items(): | |
pressure_factor = sum(pressures.values()) / len(pressures) | |
reward = efficiency - pressure_factor / 10 | |
rewards[unit] = max(0, reward) | |
return rewards | |
zone_pressure_monitor = ZonePressureMonitor() | |
reward_system = RewardSystem() | |
def update_pressures(): | |
while True: | |
zone_pressure_monitor.update_pressure() | |
pressures = zone_pressure_monitor.get_pressures() | |
socketio.emit('update_pressure', pressures) | |
time.sleep(5) # Update every 5 seconds | |
def pressure_dashboard(): | |
pressures = zone_pressure_monitor.get_pressures() | |
reward_system.record_efficiency('Vehicle1', 80) | |
reward_system.record_efficiency('Vehicle2', 45) | |
rewards = reward_system.calculate_rewards(pressures) | |
return render_template('pressure.html', pressures=pressures, rewards=rewards) | |
def handle_connect(): | |
pressures = zone_pressure_monitor.get_pressures() | |
socketio.emit('update_pressure', pressures) | |
if __name__ == '__main__': | |
threading.Thread(target=update_pressures).start() | |
socketio.run(app, debug=True) |