add a AI chatbot, rename course names
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,7 +4,7 @@ import yfinance as yf
|
||||
import plotly.express as px
|
||||
from webpages import code_editor as ce
|
||||
|
||||
def pythonx_lesson3():
|
||||
def pythonx_finance():
|
||||
|
||||
st.title("Lesson 3: Collecting Stock Data Through API")
|
||||
st.header(":one: What is API")
|
||||
@@ -1,17 +1,17 @@
|
||||
|
||||
import streamlit as st
|
||||
import pandas as pd
|
||||
import folium
|
||||
from streamlit_folium import folium_static
|
||||
from geopy.geocoders import Nominatim
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
from folium.features import CustomIcon
|
||||
import pandas as pd # package for database connection
|
||||
import folium # package for creating maps
|
||||
from streamlit_folium import folium_static # package for displaying maps on streamlit
|
||||
from geopy.geocoders import Nominatim # package for geolocation conversion
|
||||
import sqlite3 # package for database connection
|
||||
from datetime import datetime # package for timestamp
|
||||
from folium.features import CustomIcon # package for custom icons on map
|
||||
|
||||
|
||||
def pythonx_lesson4():
|
||||
def pythonx_geomap():
|
||||
# Initialize the database
|
||||
conn = sqlite3.connect('./files/student_locations.db')
|
||||
# Create a table to store student locations
|
||||
c = conn.cursor()
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS students
|
||||
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -24,16 +24,40 @@ def pythonx_lesson4():
|
||||
conn.commit()
|
||||
|
||||
|
||||
st.title('Where are Members From')
|
||||
|
||||
st.title("Lesson 4: Geographical Data Visualization")
|
||||
st.markdown("""
|
||||
This lesson demonstrates how to handle geolocation data and visualize it using maps in Python.
|
||||
|
||||
The main functionalities include:
|
||||
|
||||
- **User Input for Location**: Users can input their city and state or city and country through a form.
|
||||
|
||||
- **Geolocation Processing**: The input location is processed to obtain latitude and longitude coordinates.
|
||||
|
||||
- **Data Storage**: The processed location data is saved to a [SQLite](https://www.geeksforgeeks.org/python-sqlite/) database.
|
||||
|
||||
- **Map Visualization**: All stored student locations are displayed on an interactive map.
|
||||
|
||||
- **Statistics Display**: The code also provides statistics on the total number of students, unique cities, and unique countries, along with the top 5 cities.
|
||||
""")
|
||||
|
||||
# Display the source code
|
||||
with st.expander("See Source Code"):
|
||||
with open(__file__, "r", encoding="utf-8") as f:
|
||||
st.code(f.read(), language="python")
|
||||
|
||||
st.subheader("Student Location Tracker")
|
||||
# Input form for student location
|
||||
with st.form("student_form"):
|
||||
input_city = st.text_input("Enter your City, State (e.g.: Amarillo,TX), or City, Country (Toronto, Canada):")
|
||||
|
||||
submitted = st.form_submit_button("Submit")
|
||||
|
||||
if submitted:
|
||||
if submitted:
|
||||
# converting addresses (like "Mountain View, CA") into geographic
|
||||
# coordinates (like latitude 37.423021 and longitude -122.083739)
|
||||
lat, lon, city, state, country = get_location(input_city)
|
||||
# Save the location data to the database
|
||||
if lat and lon:
|
||||
save_student(conn, city, state, country, lat, lon)
|
||||
st.success(f"Location saved: {city}, {country}")
|
||||
@@ -66,7 +90,7 @@ def pythonx_lesson4():
|
||||
conn.close()
|
||||
|
||||
|
||||
|
||||
# convert address to latitude and longitude
|
||||
def get_location(city):
|
||||
geolocator = Nominatim(user_agent="student_location_app")
|
||||
try:
|
||||
@@ -82,7 +106,7 @@ def get_location(city):
|
||||
st.write(e)
|
||||
return None, None, None, None, None
|
||||
|
||||
|
||||
# save student location to database
|
||||
def save_student(conn, city, state, country, lat, lon):
|
||||
c = conn.cursor()
|
||||
timestamp = datetime.now()
|
||||
@@ -90,11 +114,14 @@ def save_student(conn, city, state, country, lat, lon):
|
||||
(city, state, country, lat, lon, timestamp))
|
||||
conn.commit()
|
||||
|
||||
# get all student locations from database
|
||||
def get_all_students(conn):
|
||||
df = pd.read_sql_query("SELECT * from students", conn)
|
||||
return df
|
||||
|
||||
# create map with student locations
|
||||
def create_map(df):
|
||||
# Create a map centered at the US
|
||||
m = folium.Map(location=[41.2706, -97.1749], zoom_start=4)
|
||||
|
||||
# Group by city and count occurrences
|
||||
@@ -104,6 +131,7 @@ def create_map(df):
|
||||
max_count = city_counts['count'].max()
|
||||
min_size, max_size = 5, 20 # min and max marker sizes
|
||||
|
||||
# Add markers for each city
|
||||
for _, row in city_counts.iterrows():
|
||||
# Create a custom icon
|
||||
icon = CustomIcon(
|
||||
@@ -112,7 +140,7 @@ def create_map(df):
|
||||
icon_anchor=(15, 30), # Adjust anchor point if needed
|
||||
popup_anchor=(0, -30) # Adjust popup anchor if needed
|
||||
)
|
||||
|
||||
# Calculate marker size based on count
|
||||
folium.Marker(
|
||||
location=[row['latitude'], row['longitude']],
|
||||
popup=f"{row['city']} <br> {row['count']}",
|
||||
@@ -3,7 +3,7 @@ from webpages import code_editor as ce
|
||||
|
||||
|
||||
|
||||
def pythonx_lesson1():
|
||||
def pythonx_introduction():
|
||||
st.title("Lesson 1: Introduction to Python")
|
||||
# Lesson1-Part1: what is programming
|
||||
st.header(":one: From Idea to Program")
|
||||
@@ -4,7 +4,7 @@ from wordcloud import WordCloud
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def pythonx_lesson2():
|
||||
def pythonx_wordcloud():
|
||||
st.title("Lesson 2: Create WordClouds in Python")
|
||||
st.header(":one: What is WordClouds")
|
||||
st.markdown("""
|
||||
Reference in New Issue
Block a user