first commit

This commit is contained in:
Ben Vincent 2025-03-09 16:48:42 +11:00
commit 16d2ae6f60
4 changed files with 71 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.venv

12
Makefile Normal file
View File

@ -0,0 +1,12 @@
PYTHON := 3.12
VENV_PATH := .venv
PORT := 8502
.PHONY: venv
venv:
uv venv --python $(PYTHON) --allow-existing $(VENV_PATH)
source $(VENV_PATH)/bin/activate && uv pip install -r requirements.txt
run: venv
source $(VENV_PATH)/bin/activate && $(VENV_PATH)/bin/streamlit run app.py --server.port $(PORT)

54
app.py Normal file
View File

@ -0,0 +1,54 @@
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
# Function to process and plot CSV data
def process_and_plot_cumulative_csv(df):
"""Creates an interactive plot for each book in the dataset."""
# Extract book names and cumulative chapter values
book_names = df.iloc[:, 0] # First column contains book names
cumulative_books = df.iloc[:, 2:].apply(pd.to_numeric, errors='coerce').values # Convert chapter values to numeric
# Display each book separately
for i, book in enumerate(cumulative_books):
book = book[~pd.isna(book)] # Remove NaN values
# Create an interactive Plotly figure
fig = go.Figure()
fig.add_trace(go.Scatter(
x=list(range(1, len(book) + 1)),
y=book,
mode='lines+markers',
name=book_names[i],
marker=dict(size=6),
hoverinfo="x+y+name"
))
# Set layout for the plot
fig.update_layout(
title=f'{book_names[i]}',
xaxis_title="Chapter Index",
yaxis_title="Cumulative Change",
legend_title="Book",
hovermode="x unified",
template="plotly_white"
)
# Display the interactive plot in Streamlit
st.plotly_chart(fig)
# Streamlit UI
st.title("📖 Book Analysis: Individual Cumulative Chapter Changes (Interactive)")
# File uploader
uploaded_file = st.file_uploader("📂 Upload CSV File", type=["csv"])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file) # Read uploaded file
st.write("### 📊 Data Preview:")
st.dataframe(df) # Show uploaded data
st.write("### 📈 Interactive Plots for Each Book:")
process_and_plot_cumulative_csv(df) # Generate interactive plots

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
matplotlib==3.10.1
pandas==2.2.3
plotly==6.0.0
streamlit==1.43.1