eaglelandsonce commited on
Commit
a43ae41
1 Parent(s): f63cb2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -8
app.py CHANGED
@@ -8,7 +8,73 @@ def load_data(filename):
8
  data = json.load(file)
9
  return data
10
 
11
- # Your existing color codes and draw_grid function go here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # Streamlit application starts here
14
  def main():
@@ -19,25 +85,21 @@ def main():
19
 
20
  with col1:
21
  st.header("Today's Agenda")
22
- # You can add content to Today's Agenda here
23
  st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up")
24
 
25
  with col2:
26
  st.header("Green Smart Village Layout")
27
  # Load and display the data with color coding
28
- data = load_data('grid.json') # Make sure this path is correct
29
- # Drawing and displaying the grid layout with color coding
30
  fig = draw_grid(data)
31
  st.pyplot(fig)
32
 
33
  with col3:
34
  st.header("Check Your HIN Number")
35
- # You can add an input form or information related to HIN numbers here
36
  hin_number = st.text_input("Enter your HIN number:")
37
  if hin_number:
38
- # Perform HIN number validation or lookup here
39
- st.write("HIN number details...")
40
- # You might want to replace the placeholder text with actual code to check HIN numbers
41
 
42
  if __name__ == "__main__":
43
  main()
 
8
  data = json.load(file)
9
  return data
10
 
11
+ # Color codes updated with hexadecimal values for compatibility
12
+ color_codes = {
13
+ "residential": "#ADD8E6", # Light Blue
14
+ "commercial": "#90EE90", # Light Green
15
+ "community_facilities": "#FFFF00", # Yellow
16
+ "school": "#FFFF00", # Yellow
17
+ "healthcare_facility": "#FFFF00", # Yellow
18
+ "green_space": "#90EE90", # Light Green
19
+ "utility_infrastructure": "#90EE90", # Light Green
20
+ "emergency_services": "#FF0000", # Red
21
+ "cultural_facilities": "#D8BFD8", # Light Purple
22
+ "recreational_facilities": "#D8BFD8", # Light Purple
23
+ "innovation_center": "#90EE90", # Light Green
24
+ "elderly_care_home": "#FFFF00", # Yellow
25
+ "childcare_centers": "#FFFF00", # Yellow
26
+ "places_of_worship": "#D8BFD8", # Light Purple
27
+ "event_spaces": "#D8BFD8", # Light Purple
28
+ "guest_housing": "#FFA500", # Orange
29
+ "pet_care_facilities": "#FFA500", # Orange
30
+ "public_sanitation_facilities": "#A0A0A0", # Grey
31
+ "environmental_monitoring_stations": "#90EE90", # Light Green
32
+ "disaster_preparedness_center": "#A0A0A0", # Grey
33
+ "outdoor_community_spaces": "#90EE90" # Light Green
34
+ }
35
+
36
+ # Function to draw the grid layout with color coding
37
+ def draw_grid(data):
38
+ # Create a figure and a grid of subplots
39
+ fig, ax = plt.subplots(figsize=(12, 12))
40
+
41
+ # Setting the grid size
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
+ # Plotting each building with its assigned color from the color_codes dictionary
50
+ for building in data['buildings']:
51
+ # Extracting the building details
52
+ coords = building['coords']
53
+ b_type = building['type']
54
+ size = building['size']
55
+ color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
56
+
57
+ # Plotting the building on the grid with color
58
+ ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
59
+ ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
60
+
61
+ # Draw roads
62
+ for road in data.get('roads', []): # Check for roads in the data, default to empty list if not found
63
+ start, end = road['start'], road['end']
64
+ # Determine if the road is vertical or horizontal based on start and end coordinates
65
+ if start[0] == end[0]: # Vertical road
66
+ for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
67
+ ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road['color']))
68
+ else: # Horizontal road
69
+ for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
70
+ ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road['color']))
71
+
72
+ # Setting labels and title
73
+ ax.set_xlabel('Columns')
74
+ ax.set_ylabel('Rows')
75
+ ax.set_title('Village Layout with Color Coding')
76
+
77
+ return fig
78
 
79
  # Streamlit application starts here
80
  def main():
 
85
 
86
  with col1:
87
  st.header("Today's Agenda")
88
+ # Example content for Today's Agenda
89
  st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up")
90
 
91
  with col2:
92
  st.header("Green Smart Village Layout")
93
  # Load and display the data with color coding
94
+ data = load_data('grid.json') # Ensure this path is correct
 
95
  fig = draw_grid(data)
96
  st.pyplot(fig)
97
 
98
  with col3:
99
  st.header("Check Your HIN Number")
 
100
  hin_number = st.text_input("Enter your HIN number:")
101
  if hin_number:
102
+ st.write("HIN number details...") # Placeholder for actual HIN number check
 
 
103
 
104
  if __name__ == "__main__":
105
  main()