Spaces:
Runtime error
Runtime error
File size: 1,967 Bytes
5a9fd85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
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
@app.route('/pressure')
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)
@socketio.on('connect')
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) |