eaglelandsonce commited on
Commit
8e5029d
·
verified ·
1 Parent(s): 58bba3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -23
app.py CHANGED
@@ -84,28 +84,7 @@ def draw_grid(data, highlight_coords=None):
84
  ax.set_title('Village Layout with Color Coding')
85
  return fig
86
 
87
- # Assuming sensors are defined in your data, display them
88
- sensors = data['buildings'][selected_index].get('sensors', [])
89
- st.write(f"Sensors in selected building: {', '.join(sensors)}")
90
-
91
- # Only attempt to display the graph if sensors are available
92
- if sensors:
93
- st.header("Building Sensor Network")
94
- sensor_store = TripleStore()
95
- building_name = f"{data['buildings'][selected_index]['type']} ({selected_building_coords[0]}, {selected_building_coords[1]})"
96
-
97
- # Create a node for the building
98
- sensor_store.add_node(Node(id=building_name, label=building_name, color="#FFD700"))
99
-
100
- # Create nodes for each sensor and add edges from the building to the sensors
101
- for sensor in sensors:
102
- sensor_id = f"{sensor}-{selected_building_coords}" # Unique identifier for each sensor
103
- sensor_store.add_node(Node(id=sensor_id, label=sensor, color="#90EE90"))
104
- sensor_store.add_edge(Edge(source=building_name, target=sensor_id, label="contains"))
105
-
106
- agraph_config = Config(height=400, width=400, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True, collapsible=True)
107
- agraph(list(sensor_store.getNodes()), list(sensor_store.getEdges()), config=agraph_config)
108
-
109
  # Main Streamlit app function
110
  def main():
111
  st.title('Green Smart Village Application')
@@ -146,6 +125,45 @@ def main():
146
  config = Config(height=400, width=400, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True,
147
  collapsible=True)
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  #based on Insurance Fraud
150
  with open("data/fraud.json", encoding="utf8") as f:
151
  fraud_file = json.loads(f.read())
@@ -160,7 +178,7 @@ def main():
160
  pic = node["img"]
161
  fraud_store.add_triple(node1, link, node2, picture=pic)
162
  agraph(list(fraud_store.getNodes()), (fraud_store.getEdges()), config)
163
-
164
 
165
  hin_number = st.text_input("Enter your HIN number:")
166
  if hin_number:
 
84
  ax.set_title('Village Layout with Color Coding')
85
  return fig
86
 
87
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  # Main Streamlit app function
89
  def main():
90
  st.title('Green Smart Village Application')
 
125
  config = Config(height=400, width=400, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True,
126
  collapsible=True)
127
 
128
+
129
+
130
+
131
+ if sensors: # Check if there are sensors to display
132
+ st.header("Building Sensor Network")
133
+ sensor_store = TripleStore()
134
+ building_name = f"{data['buildings'][selected_index]['type']} ({selected_building_coords[0]}, {selected_building_coords[1]})"
135
+
136
+ # Create a central node for the building
137
+ central_node_color = "#FFD700" # Gold color for the central node (building)
138
+ sensor_store.add_node(Node(id=building_name, label=building_name, color=central_node_color, size=400))
139
+
140
+ # Define a color for sensor nodes
141
+ sensor_node_color = "#90EE90" # Light green for sensor nodes
142
+
143
+ # Create nodes for each sensor and link them to the central building node
144
+ for sensor in sensors:
145
+ sensor_id = f"{sensor}-{selected_building_coords}" # Ensuring uniqueness
146
+ sensor_label = f"Sensor: {sensor}" # Label for the sensor nodes
147
+
148
+ # Add sensor node to the store
149
+ sensor_store.add_node(Node(id=sensor_id, label=sensor_label, color=sensor_node_color, size=300))
150
+
151
+ # Connect each sensor node to the central building node
152
+ sensor_store.add_edge(Edge(source=building_name, target=sensor_id, label=""))
153
+
154
+ # Configuration for the graph visualization
155
+ agraph_config = Config(height=600, width=600, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True, collapsible=True, node={'labelProperty':'label'})
156
+
157
+ # Display the graph
158
+ agraph(nodes=list(sensor_store.getNodes()), edges=list(sensor_store.getEdges()), config=agraph_config)
159
+
160
+
161
+
162
+
163
+
164
+
165
+ """
166
+
167
  #based on Insurance Fraud
168
  with open("data/fraud.json", encoding="utf8") as f:
169
  fraud_file = json.loads(f.read())
 
178
  pic = node["img"]
179
  fraud_store.add_triple(node1, link, node2, picture=pic)
180
  agraph(list(fraud_store.getNodes()), (fraud_store.getEdges()), config)
181
+ """
182
 
183
  hin_number = st.text_input("Enter your HIN number:")
184
  if hin_number: