Naruto9 commited on
Commit
3020712
·
verified ·
1 Parent(s): 2cef86e

Create zone.py

Browse files
Files changed (1) hide show
  1. zone.py +105 -0
zone.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, jsonify
2
+ import folium
3
+ import numpy as np
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ from io import BytesIO
7
+ import base64
8
+
9
+ # Zone Pressure Monitor
10
+ class ZonePressureMonitor:
11
+ def __init__(self):
12
+ self.pressures = {}
13
+
14
+ def update_pressure(self, zone, pressure):
15
+ self.pressures[zone] = pressure
16
+
17
+ def get_pressures(self):
18
+ return self.pressures
19
+
20
+ # Heatmap Generator
21
+ class HeatmapGenerator:
22
+ def __init__(self, pressure_data):
23
+ self.pressure_data = pressure_data
24
+
25
+ def generate_heatmap(self):
26
+ zones = list(self.pressure_data.keys())
27
+ pressures = list(self.pressure_data.values())
28
+ zone_grid = np.array(pressures).reshape(len(zones), 1)
29
+
30
+ plt.figure(figsize=(6, 4))
31
+ sns.heatmap(zone_grid, annot=True, xticklabels=zones, yticklabels=["Pressure"], cmap='YlGnBu')
32
+ plt.title('Zone Pressure Heatmap')
33
+ plt.xlabel('Zones')
34
+ plt.ylabel('Pressure Levels')
35
+
36
+ buf = BytesIO()
37
+ plt.savefig(buf, format="png")
38
+ plt.close()
39
+ return base64.b64encode(buf.getvalue()).decode('utf-8')
40
+
41
+ # Reward System
42
+ class RewardSystem:
43
+ def __init__(self):
44
+ self.units = {}
45
+
46
+ def record_efficiency(self, unit_id, efficiency):
47
+ self.units[unit_id] = efficiency
48
+
49
+ def calculate_rewards(self):
50
+ rewards = {}
51
+ for unit, efficiency in self.units.items():
52
+ if efficiency >= 75:
53
+ rewards[unit] = 100
54
+ elif efficiency >= 50:
55
+ rewards[unit] = 50
56
+ else:
57
+ rewards[unit] = 0
58
+ return rewards
59
+
60
+ # Driver Assignment
61
+ class DriverAssignment:
62
+ def __init__(self, zone_pressures):
63
+ self.zone_pressures = zone_pressures
64
+
65
+ def optimize_assignments(self, drivers):
66
+ assignments = {}
67
+ sorted_zones = sorted(self.zone_pressures.items(), key=lambda item: item[1])
68
+ for i, driver in enumerate(drivers):
69
+ if i < len(sorted_zones):
70
+ assignments[driver] = sorted_zones[i][0]
71
+ else:
72
+ assignments[driver] = 'No Zone Available'
73
+ return assignments
74
+
75
+ app = Flask(__name__)
76
+
77
+ # Initialize components
78
+ zone_pressure_monitor = ZonePressureMonitor()
79
+ reward_system = RewardSystem()
80
+
81
+ @app.route('/pressure')
82
+ def pressure_dashboard():
83
+ # Update and get zone pressures
84
+ zone_pressure_monitor.update_pressure('Zone A', 30)
85
+ zone_pressure_monitor.update_pressure('Zone B', 45)
86
+ pressures = zone_pressure_monitor.get_pressures()
87
+
88
+ # Generate heatmap
89
+ heatmap_generator = HeatmapGenerator(pressures)
90
+ heatmap_img = heatmap_generator.generate_heatmap()
91
+
92
+ # Calculate rewards
93
+ reward_system.record_efficiency('Vehicle1', 80)
94
+ reward_system.record_efficiency('Vehicle2', 45)
95
+ rewards = reward_system.calculate_rewards()
96
+
97
+ # Optimize driver assignments
98
+ drivers = ['Driver1', 'Driver2', 'Driver3']
99
+ driver_assignment_system = DriverAssignment(pressures)
100
+ assignments = driver_assignment_system.optimize_assignments(drivers)
101
+
102
+ return render_template('pressure.html', heatmap_img=heatmap_img, rewards=rewards, assignments=assignments)
103
+
104
+ if __name__ == '__main__':
105
+ app.run(debug=True)