update covid search
Browse files
pages/1_🗺️_COVID_Navigator.py
CHANGED
@@ -2,6 +2,27 @@ import streamlit as st
|
|
2 |
import duckdb
|
3 |
import pandas as pd
|
4 |
from st_aggrid import AgGrid, GridOptionsBuilder, GridUpdateMode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Constants for raw data categories
|
7 |
GDELT_CATEGORIES = {
|
@@ -28,7 +49,7 @@ def initialize_db():
|
|
28 |
""")
|
29 |
return con
|
30 |
|
31 |
-
def fetch_data(con, source_filter=None,
|
32 |
start_date=None, end_date=None, limit=50, include_all_columns=False):
|
33 |
"""Fetch filtered data from the database"""
|
34 |
if include_all_columns:
|
@@ -97,6 +118,24 @@ def render_data_grid(df):
|
|
97 |
return selected[0]
|
98 |
return None
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
def render_raw_data(record):
|
101 |
"""Render raw GDELT data in expandable sections."""
|
102 |
st.header("Full Record Details")
|
@@ -160,15 +199,19 @@ def main():
|
|
160 |
# Find the full record in the original DataFrame using the selected ID
|
161 |
selected_id = selected_row['ID']
|
162 |
full_record = df_full[df_full['GKGRECORDID'] == selected_id].iloc[0]
|
163 |
-
|
|
|
|
|
|
|
164 |
# Display the raw data below the grid
|
165 |
render_raw_data(full_record)
|
166 |
else:
|
167 |
st.info("Select a record above to view its complete details.")
|
|
|
168 |
else:
|
169 |
st.warning("No matching records found.")
|
170 |
|
171 |
# Close database connection
|
172 |
con.close()
|
173 |
|
174 |
-
main()
|
|
|
2 |
import duckdb
|
3 |
import pandas as pd
|
4 |
from st_aggrid import AgGrid, GridOptionsBuilder, GridUpdateMode
|
5 |
+
from st_link_analysis import st_link_analysis, NodeStyle, EdgeStyle
|
6 |
+
from graph_builder import StLinkBuilder
|
7 |
+
|
8 |
+
# Node styles configuration
|
9 |
+
NODE_STYLES = [
|
10 |
+
NodeStyle("EVENT", "#FF7F3E", "name", "description"),
|
11 |
+
NodeStyle("PERSON", "#4CAF50", "name", "person"),
|
12 |
+
NodeStyle("NAME", "#2A629A", "created_at", "badge"),
|
13 |
+
NodeStyle("ORGANIZATION", "#9C27B0", "name", "business"),
|
14 |
+
NodeStyle("LOCATION", "#2196F3", "name", "place"),
|
15 |
+
NodeStyle("THEME", "#FFC107", "name", "sell"),
|
16 |
+
NodeStyle("COUNT", "#795548", "name", "inventory"),
|
17 |
+
NodeStyle("AMOUNT", "#607D8B", "name", "wallet"),
|
18 |
+
]
|
19 |
+
|
20 |
+
# Edge styles configuration
|
21 |
+
EDGE_STYLES = [
|
22 |
+
EdgeStyle("MENTIONED_IN", caption="label", directed=True),
|
23 |
+
EdgeStyle("LOCATED_IN", caption="label", directed=True),
|
24 |
+
EdgeStyle("CATEGORIZED_AS", caption="label", directed=True)
|
25 |
+
]
|
26 |
|
27 |
# Constants for raw data categories
|
28 |
GDELT_CATEGORIES = {
|
|
|
49 |
""")
|
50 |
return con
|
51 |
|
52 |
+
def fetch_data(con, source_filter=None,
|
53 |
start_date=None, end_date=None, limit=50, include_all_columns=False):
|
54 |
"""Fetch filtered data from the database"""
|
55 |
if include_all_columns:
|
|
|
118 |
return selected[0]
|
119 |
return None
|
120 |
|
121 |
+
def render_graph(record):
|
122 |
+
"""
|
123 |
+
Render a graph visualization for the selected record.
|
124 |
+
Uses StLinkBuilder to convert the record into graph format and then
|
125 |
+
displays the graph using st_link_analysis.
|
126 |
+
"""
|
127 |
+
st.subheader(f"Event Graph: {record.get('GKGRECORDID', 'Unknown')}")
|
128 |
+
stlink_builder = StLinkBuilder()
|
129 |
+
# Convert the record (a Series) into a DataFrame with one row
|
130 |
+
record_df = pd.DataFrame([record])
|
131 |
+
graph_data = stlink_builder.build_graph(record_df)
|
132 |
+
return st_link_analysis(
|
133 |
+
elements=graph_data,
|
134 |
+
layout="fcose", # Column configuration for data grid - cose, fcose, breadthfirst, cola
|
135 |
+
node_styles=NODE_STYLES,
|
136 |
+
edge_styles=EDGE_STYLES
|
137 |
+
)
|
138 |
+
|
139 |
def render_raw_data(record):
|
140 |
"""Render raw GDELT data in expandable sections."""
|
141 |
st.header("Full Record Details")
|
|
|
199 |
# Find the full record in the original DataFrame using the selected ID
|
200 |
selected_id = selected_row['ID']
|
201 |
full_record = df_full[df_full['GKGRECORDID'] == selected_id].iloc[0]
|
202 |
+
|
203 |
+
# Display the graph and raw data below the grid
|
204 |
+
render_graph(full_record)
|
205 |
+
|
206 |
# Display the raw data below the grid
|
207 |
render_raw_data(full_record)
|
208 |
else:
|
209 |
st.info("Select a record above to view its complete details.")
|
210 |
+
|
211 |
else:
|
212 |
st.warning("No matching records found.")
|
213 |
|
214 |
# Close database connection
|
215 |
con.close()
|
216 |
|
217 |
+
main()
|
pages/2_🔍_COVID_Event_Graph.py
CHANGED
@@ -142,7 +142,7 @@ def main():
|
|
142 |
start_date = st.text_input("Start date (YYYYMMDD)", "20200314")
|
143 |
end_date = st.text_input("End date (YYYYMMDD)", "20200315")
|
144 |
limit = st.slider("Number of results to display", 10, 500, 100)
|
145 |
-
|
146 |
# Fetch initial data view
|
147 |
df_initial = fetch_data(
|
148 |
con=con,
|
@@ -162,19 +162,19 @@ def main():
|
|
162 |
limit=limit,
|
163 |
include_all_columns=True
|
164 |
)
|
165 |
-
|
166 |
# Create a DataFrame for the grid with only the key columns
|
167 |
grid_df = df_initial[['GKGRECORDID', 'DATE', 'SourceCommonName', 'tone', 'DocumentIdentifier', 'SourceCollectionIdentifier']].copy()
|
168 |
grid_df.columns = ['ID', 'Date', 'Source', 'Tone', 'Doc ID', 'Source Collection ID']
|
169 |
|
170 |
# Render the interactive data grid at the top
|
171 |
selected_row = render_data_grid(grid_df)
|
172 |
-
|
173 |
if selected_row:
|
174 |
# Find the full record in the original DataFrame using the selected ID
|
175 |
selected_id = selected_row['ID']
|
176 |
full_record = df_full[df_full['GKGRECORDID'] == selected_id].iloc[0]
|
177 |
-
|
178 |
# Display the graph and raw data below the grid
|
179 |
render_graph(full_record)
|
180 |
else:
|
|
|
142 |
start_date = st.text_input("Start date (YYYYMMDD)", "20200314")
|
143 |
end_date = st.text_input("End date (YYYYMMDD)", "20200315")
|
144 |
limit = st.slider("Number of results to display", 10, 500, 100)
|
145 |
+
|
146 |
# Fetch initial data view
|
147 |
df_initial = fetch_data(
|
148 |
con=con,
|
|
|
162 |
limit=limit,
|
163 |
include_all_columns=True
|
164 |
)
|
165 |
+
|
166 |
# Create a DataFrame for the grid with only the key columns
|
167 |
grid_df = df_initial[['GKGRECORDID', 'DATE', 'SourceCommonName', 'tone', 'DocumentIdentifier', 'SourceCollectionIdentifier']].copy()
|
168 |
grid_df.columns = ['ID', 'Date', 'Source', 'Tone', 'Doc ID', 'Source Collection ID']
|
169 |
|
170 |
# Render the interactive data grid at the top
|
171 |
selected_row = render_data_grid(grid_df)
|
172 |
+
|
173 |
if selected_row:
|
174 |
# Find the full record in the original DataFrame using the selected ID
|
175 |
selected_id = selected_row['ID']
|
176 |
full_record = df_full[df_full['GKGRECORDID'] == selected_id].iloc[0]
|
177 |
+
|
178 |
# Display the graph and raw data below the grid
|
179 |
render_graph(full_record)
|
180 |
else:
|