Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,284 +1,276 @@
|
|
| 1 |
-
# Import Packages
|
| 2 |
-
from google.cloud import bigquery
|
| 3 |
-
import numpy as np
|
| 4 |
-
import os
|
| 5 |
-
import time
|
| 6 |
-
import datetime
|
| 7 |
-
import streamlit as st
|
| 8 |
-
import requests
|
| 9 |
-
import pandas as pd
|
| 10 |
-
import xml.etree.ElementTree as ET
|
| 11 |
-
import pyrebase
|
| 12 |
-
|
| 13 |
-
# Set Page Layout
|
| 14 |
-
st.set_page_config(page_title='Weather Data in Kenya',layout='wide')
|
| 15 |
-
|
| 16 |
-
# Set Padding
|
| 17 |
-
st.markdown('<style>div.block-container{padding-top:2.0rem}</style>',unsafe_allow_html=True)
|
| 18 |
-
|
| 19 |
-
# Set Page Header
|
| 20 |
-
title = """
|
| 21 |
-
<style>
|
| 22 |
-
.header{
|
| 23 |
-
font-size : 2.5rem;
|
| 24 |
-
font-family : sana-serif;
|
| 25 |
-
}
|
| 26 |
-
</style>
|
| 27 |
-
<b><center class='header'>🌤️ Open Weather Map🇰🇪</center></b>
|
| 28 |
-
"""
|
| 29 |
-
st.markdown(title,unsafe_allow_html=True)
|
| 30 |
-
|
| 31 |
-
# Firebase initialization
|
| 32 |
-
config = {
|
| 33 |
-
'apiKey': "AIzaSyAQHikJeQ7Sru-Gdy9K3YNjz0adnmTSvuQ",
|
| 34 |
-
'authDomain': "disaster-tweets-manageme-72580.firebaseapp.com",
|
| 35 |
-
'databaseURL': "https://disaster-tweets-manageme-72580-default-rtdb.firebaseio.com",
|
| 36 |
-
'projectId': "disaster-tweets-manageme-72580",
|
| 37 |
-
'storageBucket': "disaster-tweets-manageme-72580.appspot.com"
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
firebase = pyrebase.initialize_app(config)
|
| 41 |
-
auth = firebase.auth()
|
| 42 |
-
|
| 43 |
-
# Initialize user as None
|
| 44 |
-
if 'user' not in st.session_state:
|
| 45 |
-
st.session_state.user = None
|
| 46 |
-
|
| 47 |
-
# User registration and sign-in
|
| 48 |
-
if st.session_state.user is None:
|
| 49 |
-
tab1, tab2 = st.tabs(['Sign In','Reset Password'])
|
| 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 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
)
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
st.download_button(label='Download as csv',data=data.to_csv().encode('utf-8'),mime='text/csv',file_name='Open Weather Data in Kenya.csv')
|
| 278 |
-
|
| 279 |
-
st.divider()
|
| 280 |
-
|
| 281 |
-
if st.button("Sign Out"):
|
| 282 |
-
st.session_state.user = None
|
| 283 |
-
st.success("User successfully logged out")
|
| 284 |
-
st.rerun() # Refresh the app to show the login section again
|
|
|
|
| 1 |
+
# Import Packages
|
| 2 |
+
from google.cloud import bigquery
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import datetime
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import requests
|
| 9 |
+
import pandas as pd
|
| 10 |
+
import xml.etree.ElementTree as ET
|
| 11 |
+
import pyrebase
|
| 12 |
+
|
| 13 |
+
# Set Page Layout
|
| 14 |
+
st.set_page_config(page_title='Weather Data in Kenya',layout='wide')
|
| 15 |
+
|
| 16 |
+
# Set Padding
|
| 17 |
+
st.markdown('<style>div.block-container{padding-top:2.0rem}</style>',unsafe_allow_html=True)
|
| 18 |
+
|
| 19 |
+
# Set Page Header
|
| 20 |
+
title = """
|
| 21 |
+
<style>
|
| 22 |
+
.header{
|
| 23 |
+
font-size : 2.5rem;
|
| 24 |
+
font-family : sana-serif;
|
| 25 |
+
}
|
| 26 |
+
</style>
|
| 27 |
+
<b><center class='header'>🌤️ Open Weather Map🇰🇪</center></b>
|
| 28 |
+
"""
|
| 29 |
+
st.markdown(title,unsafe_allow_html=True)
|
| 30 |
+
|
| 31 |
+
# Firebase initialization
|
| 32 |
+
config = {
|
| 33 |
+
'apiKey': "AIzaSyAQHikJeQ7Sru-Gdy9K3YNjz0adnmTSvuQ",
|
| 34 |
+
'authDomain': "disaster-tweets-manageme-72580.firebaseapp.com",
|
| 35 |
+
'databaseURL': "https://disaster-tweets-manageme-72580-default-rtdb.firebaseio.com",
|
| 36 |
+
'projectId': "disaster-tweets-manageme-72580",
|
| 37 |
+
'storageBucket': "disaster-tweets-manageme-72580.appspot.com"
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
firebase = pyrebase.initialize_app(config)
|
| 41 |
+
auth = firebase.auth()
|
| 42 |
+
|
| 43 |
+
# Initialize user as None
|
| 44 |
+
if 'user' not in st.session_state:
|
| 45 |
+
st.session_state.user = None
|
| 46 |
+
|
| 47 |
+
# User registration and sign-in
|
| 48 |
+
if st.session_state.user is None:
|
| 49 |
+
tab1, tab2 = st.tabs(['Sign In','Reset Password'])
|
| 50 |
+
|
| 51 |
+
with tab1:
|
| 52 |
+
email = st.text_input("Sign In Email")
|
| 53 |
+
password = st.text_input("Sign In Password", type="password")
|
| 54 |
+
if st.button("Sign In"):
|
| 55 |
+
try:
|
| 56 |
+
user = auth.sign_in_with_email_and_password(email, password)
|
| 57 |
+
if user:
|
| 58 |
+
st.session_state.user = user
|
| 59 |
+
st.success(f"Successfully signed in with email: {email}")
|
| 60 |
+
st.rerun() # Refresh the app to show the new section
|
| 61 |
+
else:
|
| 62 |
+
st.warning("Your email is not verified. Please check your email for a verification link.")
|
| 63 |
+
except Exception as e:
|
| 64 |
+
error_message = str(e)
|
| 65 |
+
if "INVALID_EMAIL" in error_message:
|
| 66 |
+
st.error("Invalid email. Please enter a valid email address.")
|
| 67 |
+
else:
|
| 68 |
+
st.error("Invalid password. Please check your password and try again.")
|
| 69 |
+
|
| 70 |
+
with tab2:
|
| 71 |
+
st.subheader("Password Reset")
|
| 72 |
+
reset_email = st.text_input("Email to reset password")
|
| 73 |
+
if st.button("Reset Password"):
|
| 74 |
+
try:
|
| 75 |
+
auth.send_password_reset_email(reset_email)
|
| 76 |
+
st.success("Password reset email sent. Please check your email for instructions.")
|
| 77 |
+
except Exception as e:
|
| 78 |
+
st.error(f"Error: {e}")
|
| 79 |
+
|
| 80 |
+
else:
|
| 81 |
+
st.success(f"Logged in as: {st.session_state.user['email']}! 🎉")
|
| 82 |
+
|
| 83 |
+
# define tabs for easy accessibility
|
| 84 |
+
tab1, tab2, tab3 = st.tabs(['Home','Get Data','View Data'])
|
| 85 |
+
with tab1:
|
| 86 |
+
header = """
|
| 87 |
+
<style>
|
| 88 |
+
.subheader{
|
| 89 |
+
font-size: 1.5rem;
|
| 90 |
+
font-family : sana-serif;
|
| 91 |
+
}
|
| 92 |
+
</style>
|
| 93 |
+
<h3 class='subheader'><b>Welcome to Open Weather Map Data Collection Site for Counties in Kenya.</b></h3>
|
| 94 |
+
"""
|
| 95 |
+
st.markdown(header,unsafe_allow_html=True)
|
| 96 |
+
st.markdown('This Streamlit app collects weather data from various locations across Kenya using the OpenWeatherMap API.')
|
| 97 |
+
st.markdown("""
|
| 98 |
+
<b>Data Collection Steps;</b>\n
|
| 99 |
+
- Fetch weather data from multiple locations in Kenya.
|
| 100 |
+
- Append collected data to a BigQuery database for further analysis.
|
| 101 |
+
""", unsafe_allow_html=True)
|
| 102 |
+
|
| 103 |
+
# Initialize Environment Variable
|
| 104 |
+
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'adrianjuliusaluoch.json'
|
| 105 |
+
|
| 106 |
+
# Initialize Client Variable
|
| 107 |
+
client = bigquery.Client()
|
| 108 |
+
|
| 109 |
+
# Function to extract text from XML element safely
|
| 110 |
+
def get_xml_text(parent, tag, attrib=None):
|
| 111 |
+
element = parent.find(tag)
|
| 112 |
+
if element is not None:
|
| 113 |
+
if attrib:
|
| 114 |
+
return element.get(attrib)
|
| 115 |
+
return element.text
|
| 116 |
+
return None
|
| 117 |
+
|
| 118 |
+
# create function to retrieve data from the api
|
| 119 |
+
def get_weather():
|
| 120 |
+
def get_weather(api_key, location):
|
| 121 |
+
base_url = "http://api.openweathermap.org/data/2.5/weather"
|
| 122 |
+
|
| 123 |
+
params = {
|
| 124 |
+
'q': location,
|
| 125 |
+
'appid': api_key,
|
| 126 |
+
'units': 'metric', # You can use 'imperial' for Fahrenheit
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
try:
|
| 130 |
+
response = requests.get(base_url, params=params)
|
| 131 |
+
data = response.json()
|
| 132 |
+
|
| 133 |
+
# Check if the request was successful
|
| 134 |
+
if response.status_code == 200:
|
| 135 |
+
|
| 136 |
+
# Extract additional features from XML
|
| 137 |
+
xml_url = f'http://api.openweathermap.org/data/2.5/weather?q={location}&mode=xml&appid={api_key}'
|
| 138 |
+
xml_response = requests.get(xml_url)
|
| 139 |
+
xml_root = ET.fromstring(xml_response.content)
|
| 140 |
+
|
| 141 |
+
# Create a DataFrame with the relevant weather information
|
| 142 |
+
weather_data = {
|
| 143 |
+
'City': [location],
|
| 144 |
+
'Time_of_Data_Calculation': [pd.to_datetime(data['dt'], unit='s', utc=True)],
|
| 145 |
+
'Latitude': [data['coord']['lat']],
|
| 146 |
+
'Longitude': [data['coord']['lon']],
|
| 147 |
+
'Weather_ID': [data['weather'][0]['id']],
|
| 148 |
+
'Weather_Main': [data['weather'][0]['main']],
|
| 149 |
+
'Weather_Description': [data['weather'][0]['description']],
|
| 150 |
+
'Temperature': [data['main']['temp']],
|
| 151 |
+
'Feels_Like': [data['main']['feels_like']],
|
| 152 |
+
'Temp_Min': [data['main']['temp_min']],
|
| 153 |
+
'Temp_Max': [data['main']['temp_max']],
|
| 154 |
+
'Pressure': [data['main']['pressure']],
|
| 155 |
+
'Humidity': [data['main']['humidity']],
|
| 156 |
+
'Sea_Level': [data['main']['sea_level']] if 'sea_level' in data['main'] else None,
|
| 157 |
+
'Ground_Level': [data['main']['grnd_level']] if 'grnd_level' in data['main'] else None,
|
| 158 |
+
'Visibility': [data['visibility']],
|
| 159 |
+
'Wind_Speed': [data['wind']['speed']],
|
| 160 |
+
'Wind_Degree': [data['wind']['deg']],
|
| 161 |
+
'Wind_Gust': [data['wind']['gust']] if 'gust' in data['wind'] else None,
|
| 162 |
+
'Cloudiness': [data['clouds']['all']],
|
| 163 |
+
'Cloudiness_Name': [get_xml_text(xml_root, 'clouds', 'name')],
|
| 164 |
+
'Rain_1h': [data['rain']['1h']] if 'rain' in data and '1h' in data['rain'] else None,
|
| 165 |
+
'Rain_3h': [data['rain']['3h']] if 'rain' in data and '3h' in data['rain'] else None,
|
| 166 |
+
'Snow_1h': [data['snow']['1h']] if 'snow' in data and '1h' in data['snow'] else None,
|
| 167 |
+
'Snow_3h': [data['snow']['3h']] if 'snow' in data and '3h' in data['snow'] else None,
|
| 168 |
+
'Country_Code': [data['sys']['country']],
|
| 169 |
+
'Sunrise_Time': [pd.to_datetime(data['sys']['sunrise'], unit='s', utc=True)],
|
| 170 |
+
'Sunset_Time': [pd.to_datetime(data['sys']['sunset'], unit='s', utc=True)],
|
| 171 |
+
'Timezone': [data['timezone']],
|
| 172 |
+
'City_ID': [data['id']],
|
| 173 |
+
'City_Name': [data['name']]
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
df = pd.DataFrame(weather_data)
|
| 178 |
+
return df
|
| 179 |
+
else:
|
| 180 |
+
print(f"{location} not found in the OpenWeatherMap DataBase.")
|
| 181 |
+
return None
|
| 182 |
+
|
| 183 |
+
except Exception as e:
|
| 184 |
+
print(f"An error occurred: {str(e)}")
|
| 185 |
+
return None
|
| 186 |
+
|
| 187 |
+
if __name__ == "__main__":
|
| 188 |
+
# Replace 'YOUR_API_KEY' with your actual OpenWeatherMap API key
|
| 189 |
+
api_key = '30bc8c5f44c2f641d15a7f617af532c0'
|
| 190 |
+
|
| 191 |
+
# List of locations (cities or counties) for which you want to get weather data
|
| 192 |
+
locations = [
|
| 193 |
+
'Baringo', 'Bomet', 'Bungoma', 'Busia', 'Mandeni, KE', 'Embu, KE', 'Garissa', 'Homa Bay', 'Isiolo', 'Kajiado',
|
| 194 |
+
'Kakamega', 'Kericho', 'Kiambu', 'Kilifi', 'Kerugoya', 'Kisii', 'Kisumu', 'Kitui', 'Kwale, KE', 'Nanyuki',
|
| 195 |
+
'Lamu', 'Machakos', 'Makueni', 'Mandera', 'Marsabit', 'Meru', 'Migori', 'Mombasa', "Murang'a", 'Nairobi',
|
| 196 |
+
'Nakuru', 'Nandi, KE', 'Narok', 'Nyamira', 'Oljoro Orok', 'Nyeri', 'Maralal', 'Siaya, KE', 'Taveta',
|
| 197 |
+
'Chogoria', 'Kitale', 'Lodwar', 'Eldoret', 'Vihiga', 'Wajir', 'Kapenguria']
|
| 198 |
+
|
| 199 |
+
# Create an empty DataFrame to store the results
|
| 200 |
+
all_weather_data = pd.DataFrame()
|
| 201 |
+
|
| 202 |
+
# Loop through the list of locations and concatenate DataFrames
|
| 203 |
+
for location in locations:
|
| 204 |
+
weather_data = get_weather(api_key, location)
|
| 205 |
+
if weather_data is not None:
|
| 206 |
+
all_weather_data = pd.concat([all_weather_data, weather_data], ignore_index=True)
|
| 207 |
+
|
| 208 |
+
# Print the final DataFrame
|
| 209 |
+
st.write(f'Data Collection Successful for all {len(all_weather_data)} Counties in Kenya.')
|
| 210 |
+
|
| 211 |
+
all_weather_data.to_parquet('weather_data.gzip',compression='gzip',index=False)
|
| 212 |
+
st.dataframe(all_weather_data)
|
| 213 |
+
|
| 214 |
+
# Load data into cloud database
|
| 215 |
+
def append_data():
|
| 216 |
+
dataframe = pd.read_parquet('weather_data.gzip')
|
| 217 |
+
|
| 218 |
+
table_id = 'project-adrian-julius-aluoch.central_database.openweathermap'
|
| 219 |
+
|
| 220 |
+
job = client.load_table_from_dataframe(dataframe,table_id)
|
| 221 |
+
|
| 222 |
+
while job.state != 'DONE':
|
| 223 |
+
time.sleep(2)
|
| 224 |
+
job.reload()
|
| 225 |
+
st.write(job.state)
|
| 226 |
+
|
| 227 |
+
with tab2:
|
| 228 |
+
st.markdown("""
|
| 229 |
+
This section allows you to retrieve weather data from various locations across Kenya using the OpenWeatherMap API.\n
|
| 230 |
+
To get started, simply click the "Get Data" button below.\n
|
| 231 |
+
The app will collect real-time weather data for all specified locations and export the data to Google Cloud BigQuery Database for Storage.
|
| 232 |
+
""", unsafe_allow_html=True)
|
| 233 |
+
# add widgets
|
| 234 |
+
if st.button('Get Data from API'):
|
| 235 |
+
with st.spinner('In progress....'):
|
| 236 |
+
get_weather()
|
| 237 |
+
append_data()
|
| 238 |
+
st.success('Open Weather Data Successfully Exported to Google Cloud BigQuery', icon="✅")
|
| 239 |
+
|
| 240 |
+
with tab3:
|
| 241 |
+
st.markdown("""
|
| 242 |
+
**Data Viewing and Analysis:**
|
| 243 |
+
|
| 244 |
+
Welcome to the data viewing section. Here, you can explore the collected weather data for various regions in Kenya.
|
| 245 |
+
|
| 246 |
+
Click the "View Data" button below to display the collected data in a table format. You can verify the data and ensure that all necessary information has been successfully collected.
|
| 247 |
+
|
| 248 |
+
Additionally, you can download the data as a CSV file for offline analysis or sharing with others.
|
| 249 |
+
""")
|
| 250 |
+
if st.button('View Data'):
|
| 251 |
+
with st.spinner('In progress....'):
|
| 252 |
+
sql = (
|
| 253 |
+
'SELECT *'
|
| 254 |
+
'FROM `central_database.openweathermap`'
|
| 255 |
+
)
|
| 256 |
+
data = client.query(sql).to_dataframe()
|
| 257 |
+
data = data.sort_values(by='Time_of_Data_Calculation',ascending=False).copy().reset_index(drop=True)
|
| 258 |
+
today_date = datetime.date.today()
|
| 259 |
+
today_data = data[data['Time_of_Data_Calculation'].dt.date == today_date]
|
| 260 |
+
num_today = len(today_data)
|
| 261 |
+
st.dataframe(data)
|
| 262 |
+
st.divider()
|
| 263 |
+
st.markdown('<b><u>Open Weather Map Statistics</u></b>',unsafe_allow_html=True)
|
| 264 |
+
st.text(f"Data Collection Began : {data['Time_of_Data_Calculation'].min()}\nLast Collection Date : {data['Time_of_Data_Calculation'].max()}\nToday's Date : {datetime.datetime.now()}")
|
| 265 |
+
st.text(f"Time elapsed since data collection began: {np.subtract(data['Time_of_Data_Calculation'].max(),data['Time_of_Data_Calculation'].min())}")
|
| 266 |
+
st.text(f"Number of Runs Today: {num_today / 46}")
|
| 267 |
+
st.text(f"Rows : {data.shape[0]:,.0f}\nColumns : {data.shape[1]}\nCounties : {len(data['City'].unique())}")
|
| 268 |
+
|
| 269 |
+
st.download_button(label='Download as csv',data=data.to_csv().encode('utf-8'),mime='text/csv',file_name='Open Weather Data in Kenya.csv')
|
| 270 |
+
|
| 271 |
+
st.divider()
|
| 272 |
+
|
| 273 |
+
if st.button("Sign Out"):
|
| 274 |
+
st.session_state.user = None
|
| 275 |
+
st.success("User successfully logged out")
|
| 276 |
+
st.rerun() # Refresh the app to show the login section again
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|