the_espada / feed_back_llm.py
HEMANTH
first all files
abc9746
import json
import random
# Function to read the JSON from the file
def read_json(file_path):
with open(file_path, 'r') as json_file:
return json.load(json_file)
# Function to add a new day's progress
def add_next_day_progress(data, next_day_progress):
# Extract the current day count (last day in the list)
last_day_number = int(data["daily_progress"][-1]["day"].split(" ")[1]) if data["daily_progress"] else 0
# Construct the new day's entry
next_day_number = last_day_number + 1
next_day_name = f"Day {next_day_number}"
# Add the next day's data with the LOINC-like identifier
new_day_entry = { # Unique identifier for the day
"day": next_day_name,
"progress": next_day_progress["progress"],
"rest_time": next_day_progress["rest_time"],
"workout_time": next_day_progress["workout_time"]
}
data["daily_progress"].append(new_day_entry)
# Update weekly summary (rest_time and workout_time)
total_rest_time = sum(day["rest_time"] for day in data["daily_progress"])
total_workout_time = sum(day["workout_time"] for day in data["daily_progress"])
data["weekly_summary"]["rest_time"] = total_rest_time
data["weekly_summary"]["workout_time"] = total_workout_time
return data
# Function to save the updated data to a file
def save_json(data, file_path):
with open(file_path, 'w') as json_file:
json.dump(data, json_file, indent=2)
def update_feed_back():
# Path to the JSON file
file_path = r'static\feedback.json'
# Step 1: Read the existing JSON data
data = read_json(file_path)
# Example new day data to add (Day 8)
# Generating random values for progress, rest_time, and workout_time
next_day_progress = {
"progress": random.randint(50, 100), # Random progress between 50 and 100
"rest_time": random.randint(4, 10), # Random rest time between 4 and 10 hours
"workout_time": random.randint(1, 5) # Random workout time between 1 and 5 hours
}
# Step 2: Add the new day to the data and update the weekly summary
updated_data = add_next_day_progress(data, next_day_progress)
# Step 3: Save the updated data back to the file
save_json(updated_data, file_path)
print(f"Updated data saved to {file_path}")