eaglelandsonce commited on
Commit
99f82fd
·
verified ·
1 Parent(s): 60c337d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -0
app.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Add other types with their corresponding colors
38
+ }
39
+
40
+ # Function to draw the grid with optional highlighting
41
+ def draw_grid(data, highlight_coords=None):
42
+ fig, ax = plt.subplots(figsize=(12, 12))
43
+ nrows, ncols = data['size']['rows'], data['size']['columns']
44
+ ax.set_xlim(0, ncols)
45
+ ax.set_ylim(0, nrows)
46
+ ax.set_xticks(range(ncols+1))
47
+ ax.set_yticks(range(nrows+1))
48
+ ax.grid(True)
49
+
50
+ for building in data['buildings']:
51
+ coords = building['coords']
52
+ b_type = building['type']
53
+ size = building['size']
54
+ color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
55
+
56
+ if highlight_coords and (coords[0], coords[1]) == tuple(highlight_coords):
57
+ highlighted_color = "#FFD700" # Gold for highlighting
58
+ ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=highlighted_color, edgecolor='black', linewidth=2))
59
+ else:
60
+ ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
61
+ ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
62
+
63
+ ax.set_xlabel('Columns')
64
+ ax.set_ylabel('Rows')
65
+ ax.set_title('Village Layout with Color Coding')
66
+ return fig
67
+
68
+ # Main Streamlit app function
69
+ def main():
70
+ st.title('Green Smart Village Application')
71
+
72
+ # Divide the page into three columns
73
+ col1, col2, col3 = st.columns(3)
74
+
75
+ with col1:
76
+ st.header("Today's Agenda")
77
+ st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up")
78
+
79
+ st.header("Agent Advisors")
80
+ st.write("Would you like to optimize your HIN number?")
81
+
82
+ st.header("My Incentive")
83
+ st.write("Total incentive for HIN optimization")
84
+
85
+ with col2:
86
+ st.header("Green Smart Village Layout")
87
+ data = load_data('grid.json') # Ensure this path is correct
88
+
89
+ # Dropdown for selecting a building
90
+ building_options = [f"{bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']]
91
+ selected_building = st.selectbox("Select a building to highlight:", options=building_options)
92
+ selected_index = building_options.index(selected_building)
93
+ selected_building_coords = data['buildings'][selected_index]['coords']
94
+
95
+ # Draw the grid with the selected building highlighted
96
+ fig = draw_grid(data, highlight_coords=selected_building_coords)
97
+ st.pyplot(fig)
98
+
99
+ # Assuming sensors are defined in your data, display them
100
+ sensors = data['buildings'][selected_index].get('sensors', [])
101
+ st.write(f"Sensors in selected building: {', '.join(sensors)}")
102
+
103
+ with col3:
104
+ st.header("Check Your HIN Number")
105
+ # Placeholder for HIN number functionality
106
+ st.write("Enter your HIN number to check details...")
107
+ hin_number = st.text_input("Enter your HIN number:")
108
+ if hin_number:
109
+ st.write("HIN number details...") # Placeholder for actual HIN number check
110
+
111
+ if __name__ == "__main__":
112
+ main()