File size: 6,941 Bytes
ab2028a
a3ff20d
 
a09b6d4
55b6a72
06a38bb
a3ff20d
a09b6d4
 
 
 
 
ff28ea7
06a38bb
 
 
 
 
ff28ea7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f98abe0
8bb3175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f98abe0
a3ff20d
 
 
654556e
a3ff20d
 
 
f98abe0
a3ff20d
 
 
 
f98abe0
 
 
 
 
ca883bf
f98abe0
 
662683c
a3ff20d
 
 
 
f98abe0
8bb3175
 
ff28ea7
a3ff20d
 
06a38bb
ff28ea7
a3ff20d
ff28ea7
a3ff20d
 
 
ff28ea7
a3ff20d
06a38bb
ff28ea7
a3ff20d
 
ff28ea7
a3ff20d
 
ff28ea7
06a38bb
ff28ea7
 
 
7d98fee
ff28ea7
55b6a72
ff28ea7
 
 
 
 
 
 
 
a3ff20d
 
700258a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3ff20d
 
ff28ea7
55b6a72
a3ff20d
06a38bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import streamlit as st
import json
import matplotlib.pyplot as plt
import time

st.set_page_config(layout="wide")

# HIN Number +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
from SPARQLWrapper import SPARQLWrapper, JSON
from streamlit_agraph import agraph, TripleStore, Node, Edge, Config
import json

# Function to load JSON data
def load_data(filename):
    with open(filename, 'r') as file:
        data = json.load(file)
    return data

# Dictionary for color codes
color_codes = {
    "residential": "#ADD8E6",
    "commercial": "#90EE90",
    "community_facilities": "#FFFF00",
    "school": "#FFFF00",
    "healthcare_facility": "#FFFF00",
    "green_space": "#90EE90",
    "utility_infrastructure": "#90EE90",
    "emergency_services": "#FF0000",
    "cultural_facilities": "#D8BFD8",
    "recreational_facilities": "#D8BFD8",
    "innovation_center": "#90EE90",
    "elderly_care_home": "#FFFF00",
    "childcare_centers": "#FFFF00",
    "places_of_worship": "#D8BFD8",
    "event_spaces": "#D8BFD8",
    "guest_housing": "#FFA500",
    "pet_care_facilities": "#FFA500",
    "public_sanitation_facilities": "#A0A0A0",
    "environmental_monitoring_stations": "#90EE90",
    "disaster_preparedness_center": "#A0A0A0",
    "outdoor_community_spaces": "#90EE90",
    # Add other types with their corresponding colors
}

# Function to draw the grid with optional highlighting

def draw_grid(data, highlight_coords=None):
    fig, ax = plt.subplots(figsize=(12, 12))
    nrows, ncols = data['size']['rows'], data['size']['columns']
    ax.set_xlim(0, ncols)
    ax.set_ylim(0, nrows)
    ax.set_xticks(range(ncols+1))
    ax.set_yticks(range(nrows+1))
    ax.grid(True)

    # Draw roads
    for road in data.get('roads', []):  # Default to empty list if no roads key
        start = road['start']
        end = road['end']
        color = color_codes.get("road", '#898989')  # Default color is gray for roads
        ax.plot([start[1], end[1]], [nrows-start[0], nrows-end[0]], color=color, linewidth=2)  # Adjust coordinates for matplotlib

    # Draw buildings
    for building in data['buildings']:
        coords = building['coords']
        b_type = building['type']
        size = building['size']
        color = color_codes.get(b_type, '#FFFFFF')  # Default color is white if not specified
        
        if highlight_coords and (coords[0], coords[1]) == tuple(highlight_coords):
            highlighted_color = "#FFD700"  # Gold for highlighting
            ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=highlighted_color, edgecolor='black', linewidth=2))
        else:
            ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
            ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')

    ax.set_xlabel('Columns')
    ax.set_ylabel('Rows')
    ax.set_title('Village Layout with Color Coding')
    return fig


"""
def draw_grid(data, highlight_coords=None):
    fig, ax = plt.subplots(figsize=(12, 12))
    nrows, ncols = data['size']['rows'], data['size']['columns']
    ax.set_xlim(0, ncols)
    ax.set_ylim(0, nrows)
    ax.set_xticks(range(ncols+1))
    ax.set_yticks(range(nrows+1))
    ax.grid(True)
    
    for building in data['buildings']:
        coords = building['coords']
        b_type = building['type']
        size = building['size']
        color = color_codes.get(b_type, '#FFFFFF')  # Default color is white if not specified
        
        if highlight_coords and (coords[0], coords[1]) == tuple(highlight_coords):
            highlighted_color = "#FFD700"  # Gold for highlighting
            ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=highlighted_color, edgecolor='black', linewidth=2))
        else:
            ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
            ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')

    ax.set_xlabel('Columns')
    ax.set_ylabel('Rows')
    ax.set_title('Village Layout with Color Coding')
    return fig

    """

# Main Streamlit app function
def main():
    st.title('Green Smart Village Application')

    # Divide the page into three columns
    col1, col2, col3 = st.columns(3)
    
    with col1:
        st.header("Today's Agenda")
        st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up")
        
        st.header("Agent Advisors")
        st.write("Would you like to optimize your HIN number?")
        
        st.header("My Incentive")
        st.write("Total incentive for HIN optimization")
    
    with col2:
        st.header("Green Smart Village Layout")
        data = load_data('grid.json')  # Ensure this path is correct
        
        # Dropdown for selecting a building
        building_options = [f"{bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']]
        selected_building = st.selectbox("Select a building to highlight:", options=building_options)
        selected_index = building_options.index(selected_building)
        selected_building_coords = data['buildings'][selected_index]['coords']

        # Draw the grid with the selected building highlighted
        fig = draw_grid(data, highlight_coords=selected_building_coords)
        st.pyplot(fig)
        
        # Assuming sensors are defined in your data, display them
        sensors = data['buildings'][selected_index].get('sensors', [])
        st.write(f"Sensors in selected building: {', '.join(sensors)}")
        
    with col3:
        st.header("Check Your HIN Number")
        config = Config(height=400, width=400, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True,
                  collapsible=True)

        #based on Insurance Fraud
        with open("data/fraud.json", encoding="utf8") as f:
          fraud_file = json.loads(f.read())
          st.session_state['fraud_topic'] = fraud_file
          fraud_store = TripleStore()
          for sub_graph in fraud_file["children"]:
            fraud_store.add_triple(fraud_file["name"], "has_subgroup", sub_graph["name"], picture=fraud_file["img"])
            for node in sub_graph["children"]:
              node1 = node["role"]
              link = "blongs_to"
              node2 = sub_graph["name"]
              pic = node["img"]
              fraud_store.add_triple(node1, link, node2, picture=pic)
          agraph(list(fraud_store.getNodes()), (fraud_store.getEdges()), config)


        hin_number = st.text_input("Enter your HIN number:")
        if hin_number:
            st.write("HIN number details...")  # Placeholder for actual HIN number check

if __name__ == "__main__":
    main()