eaglelandsonce commited on
Commit
a3ff20d
·
verified ·
1 Parent(s): 958a2a6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -0
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import json
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Set Streamlit page configuration
6
+ st.set_page_config(layout="wide")
7
+
8
+ # Function to load JSON data
9
+ def load_data(filename):
10
+ with open(filename, 'r') as file:
11
+ data = json.load(file)
12
+ return data
13
+
14
+ # Dictionary for color codes
15
+ color_codes = {
16
+ "residential": "#ADD8E6",
17
+ "commercial": "#90EE90",
18
+ "community_facilities": "#FFFF00",
19
+ "school": "#FFFF00",
20
+ "healthcare_facility": "#FFFF00",
21
+ "green_space": "#90EE90",
22
+ "utility_infrastructure": "#90EE90",
23
+ "emergency_services": "#FF0000",
24
+ "cultural_facilities": "#D8BFD8",
25
+ "recreational_facilities": "#D8BFD8",
26
+ "innovation_center": "#90EE90",
27
+ "elderly_care_home": "#FFFF00",
28
+ "childcare_centers": "#FFFF00",
29
+ "places_of_worship": "#D8BFD8",
30
+ "event_spaces": "#D8BFD8",
31
+ "guest_housing": "#FFA500",
32
+ "pet_care_facilities": "#FFA500",
33
+ "public_sanitation_facilities": "#A0A0A0",
34
+ "environmental_monitoring_stations": "#90EE90",
35
+ "disaster_preparedness_center": "#A0A0A0",
36
+ "outdoor_community_spaces": "#90EE90",
37
+ }
38
+
39
+ # Function to draw the grid with optional highlighting and roads
40
+ def draw_grid(data, highlight_coords=None):
41
+ fig, ax = plt.subplots(figsize=(12, 12))
42
+ nrows, ncols = data['size']['rows'], data['size']['columns']
43
+ ax.set_xlim(0, ncols)
44
+ ax.set_ylim(0, nrows)
45
+ ax.set_xticks(range(ncols+1))
46
+ ax.set_yticks(range(nrows+1))
47
+ ax.grid(True)
48
+
49
+ for building in data['buildings']:
50
+ coords = building['coords']
51
+ b_type = building['type']
52
+ size = building['size']
53
+ color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
54
+
55
+ if highlight_coords and (coords[0], coords[1]) == tuple(highlight_coords):
56
+ highlighted_color = "#FFD700" # Gold for highlighting
57
+ ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=highlighted_color, edgecolor='black', linewidth=2))
58
+ else:
59
+ ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
60
+ ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
61
+
62
+ # Drawing roads
63
+ for road in data.get('roads', []): # Ensures compatibility if 'roads' key is missing
64
+ start, end = road['start'], road['end']
65
+ road_color = road.get('color', '#696969') # Dark gray as default road color
66
+ if start[0] == end[0]: # Vertical road
67
+ for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
68
+ ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road_color))
69
+ else: # Horizontal road
70
+ for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
71
+ ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road_color))
72
+
73
+ ax.set_xlabel('Columns')
74
+ ax.set_ylabel('Rows')
75
+ ax.set_title('Village Layout with Color Coding')
76
+ return fig
77
+
78
+ # Main Streamlit app function
79
+ def main():
80
+ st.title('Green Smart Village Application')
81
+
82
+ # Divide the page into three columns
83
+ col1, col2, col3 = st.columns(3)
84
+
85
+ with col1:
86
+ st.header("Today's Agenda")
87
+ st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up")
88
+
89
+ st.header("Agent Advisors")
90
+ st.write("Would you like to optimize your HIN number?")
91
+
92
+ st.header("My Incentive")
93
+ st.write("Total incentive for HIN optimization")
94
+
95
+ with col2:
96
+ st.header("Green Smart Village Layout")
97
+ data = load_data('grid.json') # Ensure this path is correct
98
+
99
+ # Dropdown for selecting a building
100
+ building_options = [f"{bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']]
101
+ selected_building = st.selectbox("Select a building to highlight:", options=building_options)
102
+ selected_index = building_options.index(selected_building)
103
+ selected_building_coords = data['buildings'][selected_index]['coords']
104
+
105
+ # Draw the grid with the selected building highlighted and roads
106
+ fig = draw_grid(data, highlight_coords=selected_building_coords)
107
+ st.pyplot(fig)
108
+
109
+ with col3:
110
+ st.header("Check Your HIN Number")
111
+ hin_number = st.text_input("Enter your HIN number:")
112
+ if hin_number:
113
+ st.write("HIN number details will be displayed here...") # Placeholder for actual HIN number check
114
+
115
+ if __name__ == "__main__":
116
+ main()