cowsmilk / app.py
yougandar's picture
Update app.py
aa363c6 verified
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Cow breeds based on the given types and their capacities
cow_breeds = ['Girolando', 'Jersey', 'Holstein Friesian (HF)', 'Sahiwal', 'Kankrej', 'Gir / Gyr', 'Red Sindhi']
# Creating a sample dataframe for milk yield data over 4 days
tag_ids = [i for i in range(1, 8)] # Tag IDs for 7 cows
# Create a dataframe for 4 days of data
days = pd.date_range(start='2025-04-01', periods=4, freq='D')
# Create a day-wise dataframe with capacity variations
data = {
'Tag ID': [tag_ids[i % 7] for i in range(28)], # Assign tag IDs to rows in sequence
'Cow Breed': [cow_breeds[i % 7] for i in range(28)],
'Date': np.tile(days, 7), # Repeat dates for each cow breed (4 days per cow)
'Milk Yield (L)': [round(np.random.uniform(10, 22), 2) for _ in range(28)], # Adjusted milk yield for each breed
'Fat %': [round(np.random.uniform(3, 6), 2) for _ in range(28)],
'SNF': [round(np.random.uniform(8, 12), 2) for _ in range(28)],
'Conductivity (mS/cm)': [round(np.random.uniform(4, 7), 2) for _ in range(28)],
}
df = pd.DataFrame(data)
# Create a pivot table for better visualization (day-wise trends)
pivot_df = df.pivot(index='Date', columns='Cow Breed', values=['Milk Yield (L)', 'Fat %', 'SNF', 'Conductivity (mS/cm)'])
# Streamlit app UI
st.title('Milk Unit Simulator Dashboard')
# Display the master data link
st.subheader('Master Data Link')
st.markdown('[Click here to view the Master Data](https://yougandar-mastersheetcows.hf.space/?embed=true&embed_options=show_toolbar#92ef4034)')
# Display the pivot table for a better overview
st.subheader('Cow Milk Data (Day-wise for 7 Cows)')
st.dataframe(pivot_df)
# Day-wise trends visualization
st.subheader('Day-wise Milk Yield Trend for Each Cow')
plt.figure(figsize=(10, 6))
sns.lineplot(data=df, x='Date', y='Milk Yield (L)', hue='Cow Breed', marker='o')
plt.title('Milk Yield Trend (Day-wise for Each Cow)')
plt.xlabel('Date')
plt.ylabel('Milk Yield (L)')
plt.xticks(rotation=45)
st.pyplot()
st.subheader('Day-wise Fat % Trend for Each Cow')
plt.figure(figsize=(10, 6))
sns.lineplot(data=df, x='Date', y='Fat %', hue='Cow Breed', marker='o')
plt.title('Fat % Trend (Day-wise for Each Cow)')
plt.xlabel('Date')
plt.ylabel('Fat %')
plt.xticks(rotation=45)
st.pyplot()
st.subheader('Day-wise SNF Trend for Each Cow')
plt.figure(figsize=(10, 6))
sns.lineplot(data=df, x='Date', y='SNF', hue='Cow Breed', marker='o')
plt.title('SNF Trend (Day-wise for Each Cow)')
plt.xlabel('Date')
plt.ylabel('SNF')
plt.xticks(rotation=45)
st.pyplot()
st.subheader('Day-wise Conductivity Trend for Each Cow')
plt.figure(figsize=(10, 6))
sns.lineplot(data=df, x='Date', y='Conductivity (mS/cm)', hue='Cow Breed', marker='o')
plt.title('Conductivity Trend (Day-wise for Each Cow)')
plt.xlabel('Date')
plt.ylabel('Conductivity (mS/cm)')
plt.xticks(rotation=45)
st.pyplot()