.config
.gitignore
data-mariana.csv
data.csv
main-shecodes.py
main.py
Packager files
.pythonlibs
poetry.lock
pyproject.toml
Config files
.replit
replit.nix
import csv
import matplotlib.pyplot as plt
def generate_2024_data_from_csv(filename):
"""
Generate workout, gluten, and sugar data by month from a CSV file.
Return a dictionary following this structure:
{
1: { "Workout": [1, 1, 0, ...], "Gluten_Free": [1, 0, 1, ...], "Sugar_Free": [1, 1, 0, ...] },
2: { "Workout": [0, 1, 1, ...], "Gluten_Free": [1, 0, 1, ...], "Sugar_Free": [1, 1, 1, ...] }
}
"""
output = {} # Empty dictionary to store monthly data
# Open and read the CSV file
with open(filename, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for line in reader:
month = int(line['Month']) # Get month as integer
workout = 1 if line['Workout'] == "Sim" else 0
gluten_free = 1 if line['Gluten'] == "Não" else 0
sugar_free = 1 if line['Sugar'] == "Não" else 0
# Ensure the month exists in the dictionary
if month not in output:
output[month] = {"Workout": [], "Gluten_Free": [], "Sugar_Free": []}
# Append the data to the correct lists
output[month]["Workout"].append(workout)
output[month]["Gluten_Free"].append(gluten_free)
output[month]["Sugar_Free"].append(sugar_free)
return output
def generate_monthly_summary_plots(data):
"""
Generate plots for workout, gluten-free, and sugar-free days by month.
"""
months = sorted(data.keys())
workouts = [sum(data[month]["Workout"]) for month in months]
gluten_free_days = [sum(data[month]["Gluten_Free"]) for month in months]
sugar_free_days = [sum(data[month]["Sugar_Free"]) for month in months]
# Plot each dataset as a line chart
plt.plot(months, workouts, label="Workout Days", marker='o', alpha=0.7)
plt.plot(months, gluten_free_days, label="Gluten-Free Days", marker='o', alpha=0.7)
plt.plot(months, sugar_free_days, label="Sugar-Free Days", marker='o', alpha=0.7)
# Chart settings
plt.title("Monthly Summary: Workouts, Gluten-Free, and Sugar-Free Days")
plt.xlabel("Month")
plt.ylabel("Total Days")
plt.xticks(months) # Ensure all months are labeled
plt.grid(True)
plt.legend()
plt.tight_layout()
# Display the plot
plt.show()
# Main Program
filename = 'data-mariana.csv' # Replace with your CSV file path
# Generate the data from the CSV
data = generate_2024_data_from_csv(filename)
# Generate the plots from the data
generate_monthly_summary_plots(data)