eaglelandsonce commited on
Commit
972e677
1 Parent(s): 662683c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -101
app.py CHANGED
@@ -1,60 +1,45 @@
1
  import streamlit as st
2
  import json
3
  import matplotlib.pyplot as plt
4
- import time
5
-
6
 
 
7
  st.set_page_config(layout="wide")
8
 
9
-
10
-
11
-
12
- # HIN Number +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
- from SPARQLWrapper import SPARQLWrapper, JSON
14
- from streamlit_agraph import agraph, TripleStore, Node, Edge, Config
15
- import json
16
-
17
-
18
- # Green Village ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
-
20
-
21
- # Function to load and parse the JSON data
22
  def load_data(filename):
23
  with open(filename, 'r') as file:
24
  data = json.load(file)
25
  return data
26
 
27
- # Color codes updated with hexadecimal values for compatibility
28
  color_codes = {
29
- "residential": "#ADD8E6", # Light Blue
30
- "commercial": "#90EE90", # Light Green
31
- "community_facilities": "#FFFF00", # Yellow
32
- "school": "#FFFF00", # Yellow
33
- "healthcare_facility": "#FFFF00", # Yellow
34
- "green_space": "#90EE90", # Light Green
35
- "utility_infrastructure": "#90EE90", # Light Green
36
- "emergency_services": "#FF0000", # Red
37
- "cultural_facilities": "#D8BFD8", # Light Purple
38
- "recreational_facilities": "#D8BFD8", # Light Purple
39
- "innovation_center": "#90EE90", # Light Green
40
- "elderly_care_home": "#FFFF00", # Yellow
41
- "childcare_centers": "#FFFF00", # Yellow
42
- "places_of_worship": "#D8BFD8", # Light Purple
43
- "event_spaces": "#D8BFD8", # Light Purple
44
- "guest_housing": "#FFA500", # Orange
45
- "pet_care_facilities": "#FFA500", # Orange
46
- "public_sanitation_facilities": "#A0A0A0", # Grey
47
- "environmental_monitoring_stations": "#90EE90", # Light Green
48
- "disaster_preparedness_center": "#A0A0A0", # Grey
49
- "outdoor_community_spaces": "#90EE90" # Light Green
 
50
  }
51
 
52
- # Function to draw the grid layout with color coding
53
- def draw_grid(data):
54
- # Create a figure and a grid of subplots
55
  fig, ax = plt.subplots(figsize=(12, 12))
56
-
57
- # Setting the grid size
58
  nrows, ncols = data['size']['rows'], data['size']['columns']
59
  ax.set_xlim(0, ncols)
60
  ax.set_ylim(0, nrows)
@@ -62,99 +47,66 @@ def draw_grid(data):
62
  ax.set_yticks(range(nrows+1))
63
  ax.grid(True)
64
 
65
- # Plotting each building with its assigned color from the color_codes dictionary
66
  for building in data['buildings']:
67
- # Extracting the building details
68
  coords = building['coords']
69
  b_type = building['type']
70
  size = building['size']
71
  color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
72
 
73
- # Plotting the building on the grid with color
74
- ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
75
- ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
76
-
77
- # Draw roads
78
- for road in data.get('roads', []): # Check for roads in the data, default to empty list if not found
79
- start, end = road['start'], road['end']
80
- # Determine if the road is vertical or horizontal based on start and end coordinates
81
- if start[0] == end[0]: # Vertical road
82
- for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
83
- ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road['color']))
84
- else: # Horizontal road
85
- for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
86
- ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road['color']))
87
 
88
-
89
- # Reverse the y-axis numbers
90
- # ax.invert_yaxis()
91
- # Setting labels and title
92
  ax.set_xlabel('Columns')
93
  ax.set_ylabel('Rows')
94
  ax.set_title('Village Layout with Color Coding')
95
-
96
  return fig
97
 
98
-
99
-
100
- # Streamlit application starts here
101
  def main():
102
  st.title('Green Smart Village Application')
103
-
104
- # Creating three columns
105
  col1, col2, col3 = st.columns(3)
106
 
107
  with col1:
108
  st.header("Today's Agenda")
109
- # Example content for Today's Agenda
110
  st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up")
 
111
  st.header("Agent Advisors")
112
- st.write("Would you like to optimize your HIN number")
 
113
  st.header("My Incentive")
114
  st.write("Total incentive for HIN optimization")
115
 
116
  with col2:
117
  st.header("Green Smart Village Layout")
118
- # Load and display the data with color coding
119
  data = load_data('grid.json') # Ensure this path is correct
120
- fig = draw_grid(data)
121
- st.pyplot(fig)
122
-
123
- # Interactivity: Selecting a building to display sensor data
124
  building_options = [f"{bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']]
125
- selected_building = st.selectbox("Select a building to view sensors:", options=building_options)
126
  selected_index = building_options.index(selected_building)
127
- sensors = data['buildings'][selected_index]['sensors']
128
- st.write(f"Sensors in selected building: {', '.join(sensors)}")
129
-
130
-
131
 
 
 
 
 
 
 
 
 
132
  with col3:
133
  st.header("Check Your HIN Number")
134
- config = Config(height=400, width=400, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True,
135
- collapsible=True)
136
-
137
- #based on Insurance Fraud
138
- with open("data/fraud.json", encoding="utf8") as f:
139
- fraud_file = json.loads(f.read())
140
- st.session_state['fraud_topic'] = fraud_file
141
- fraud_store = TripleStore()
142
- for sub_graph in fraud_file["children"]:
143
- fraud_store.add_triple(fraud_file["name"], "has_subgroup", sub_graph["name"], picture=fraud_file["img"])
144
- for node in sub_graph["children"]:
145
- node1 = node["role"]
146
- link = "blongs_to"
147
- node2 = sub_graph["name"]
148
- pic = node["img"]
149
- fraud_store.add_triple(node1, link, node2, picture=pic)
150
- agraph(list(fraud_store.getNodes()), (fraud_store.getEdges()), config)
151
-
152
-
153
  hin_number = st.text_input("Enter your HIN number:")
154
  if hin_number:
155
  st.write("HIN number details...") # Placeholder for actual HIN number check
156
 
157
-
158
-
159
  if __name__ == "__main__":
160
  main()
 
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)
 
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()