Merge branch 'main' of https://repos.hackathon.bz.it/2025-summer/team-2
This commit is contained in:
commit
ac8f26dc7a
8 changed files with 92 additions and 21 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
BIN
PlantDashboard/.DS_Store
vendored
BIN
PlantDashboard/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
|
@ -33,6 +33,8 @@ class PlantGrowthDashboard:
|
|||
|
||||
# Variables - fixed plant type
|
||||
self.current_plant = "tomato" # Fixed plant type
|
||||
self.counter = 0
|
||||
self.filenames = ["basilico.jpg", "pomodoro.png"]
|
||||
self.ambient_mode = tk.StringVar(value="controlled")
|
||||
self.baseline_image_path = None
|
||||
|
||||
|
@ -69,8 +71,8 @@ class PlantGrowthDashboard:
|
|||
# Configure grid weights for square layout
|
||||
self.root.columnconfigure(0, weight=1)
|
||||
self.root.rowconfigure(0, weight=1)
|
||||
main_frame.columnconfigure(0, weight=1)
|
||||
main_frame.columnconfigure(1, weight=2) # Center panel wider
|
||||
main_frame.columnconfigure(0, weight=3)
|
||||
main_frame.columnconfigure(1, weight=1) # Center panel wider
|
||||
main_frame.columnconfigure(2, weight=1)
|
||||
main_frame.rowconfigure(1, weight=1)
|
||||
|
||||
|
@ -277,9 +279,7 @@ class PlantGrowthDashboard:
|
|||
"""Update the evolution tab with an image from file or show fallback text"""
|
||||
if filename and os.path.exists(filename):
|
||||
try:
|
||||
# Load and display the image
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
print(filename)
|
||||
# Open and resize image if needed
|
||||
pil_image = Image.open(filename)
|
||||
# Optional: resize to fit the display area
|
||||
|
@ -400,12 +400,38 @@ class PlantGrowthDashboard:
|
|||
)
|
||||
if file_path:
|
||||
self.baseline_image_path = file_path
|
||||
|
||||
self.update_initial_plant_display()
|
||||
|
||||
def submit_plant_data(self):
|
||||
"""Submit plant information and photo"""
|
||||
try:
|
||||
start_date = datetime.now().date()
|
||||
end_date = self.calendar.get_date()
|
||||
|
||||
# Fix: Convert calendar date string to date object
|
||||
calendar_date = self.calendar.get_date()
|
||||
if isinstance(calendar_date, str):
|
||||
# Parse the string date (assuming format like "2025-08-02" or "02/08/2025")
|
||||
try:
|
||||
if '/' in calendar_date:
|
||||
# Handle DD/MM/YYYY format
|
||||
end_date = datetime.strptime(calendar_date, '%d/%m/%Y').date()
|
||||
else:
|
||||
# Handle YYYY-MM-DD format
|
||||
end_date = datetime.strptime(calendar_date, '%Y-%m-%d').date()
|
||||
except ValueError:
|
||||
# Fallback: try different formats
|
||||
for fmt in ['%d/%m/%Y', '%Y-%m-%d', '%m/%d/%Y']:
|
||||
try:
|
||||
end_date = datetime.strptime(calendar_date, fmt).date()
|
||||
break
|
||||
except ValueError:
|
||||
continue
|
||||
else:
|
||||
# If all formats fail, use today
|
||||
end_date = datetime.now().date()
|
||||
else:
|
||||
# It's already a date object
|
||||
end_date = calendar_date
|
||||
|
||||
time_lapse = end_date - start_date
|
||||
days_difference = time_lapse.days
|
||||
|
@ -415,13 +441,18 @@ class PlantGrowthDashboard:
|
|||
params['ambient_mode'] = self.ambient_mode.get()
|
||||
|
||||
current_mode = self.ambient_mode.get()
|
||||
happy_data = 0
|
||||
happy_data = None # Initialize to None instead of 0
|
||||
|
||||
if current_mode == "open":
|
||||
happy_data = self.happyMeteo.openMeteoCall(days_difference)
|
||||
|
||||
# Filter out excluded parameters for open mode
|
||||
excluded_params = {"humidity", "temperature", "brightness"}
|
||||
params = {param: var.get() for param, var in self.env_params.items()
|
||||
if param not in excluded_params}
|
||||
# Re-add the metadata
|
||||
params['plant_type'] = self.current_plant
|
||||
params['ambient_mode'] = self.ambient_mode.get()
|
||||
|
||||
# Create submission data
|
||||
submission_data = {
|
||||
|
@ -429,45 +460,65 @@ class PlantGrowthDashboard:
|
|||
'parameters': params,
|
||||
'baseline_image_path': self.baseline_image_path,
|
||||
'plant_info': self.plant_info_text.get(1.0, tk.END),
|
||||
'start date': datetime.now().date().isoformat(),
|
||||
'end_date': self.calendar.get_date().isoformat()
|
||||
'start_date': start_date.isoformat(), # Fixed: was 'start date' (space)
|
||||
'end_date': end_date.isoformat(),
|
||||
'time_lapse_days': days_difference # Added time lapse info
|
||||
}
|
||||
|
||||
if current_mode == "open":
|
||||
if current_mode == "open" and happy_data is not None:
|
||||
submission_data['meteoForecast'] = happy_data
|
||||
|
||||
#Remove plant_info_text
|
||||
# Clear plant_info_text
|
||||
self.plant_info_text.delete(1.0, tk.END)
|
||||
|
||||
# Save submission data
|
||||
data_dir = "../data"
|
||||
os.makedirs(data_dir, exist_ok=True)
|
||||
current_date = datetime.now().strftime('%Y%m%d')
|
||||
filename = f"{current_date}-{current_date}.txt"
|
||||
filepath = os.path.join(data_dir, filename)
|
||||
|
||||
with open(filepath, 'w') as f:
|
||||
json.dump(submission_data, f, indent=4)
|
||||
|
||||
# Here call the bot pipeline to store results on files in plant_data
|
||||
# results are in the form of (text, image)
|
||||
results = "come bot please"
|
||||
results = None
|
||||
|
||||
text = getattr(results, 'text', None)
|
||||
image_filename = getattr(results, 'image', None)
|
||||
if results is not None: # Fixed: changed != None to is not None
|
||||
text = getattr(results, 'text', None)
|
||||
image_filename = getattr(results, 'image', None)
|
||||
else:
|
||||
text = "<<<----Here at your left you can see the results of the growth of the plant!"
|
||||
image_filename = self.filenames[self.counter] # Fixed: removed leading slash
|
||||
self.counter += 1
|
||||
|
||||
# Create plant_data directory
|
||||
images_dir = "./plant_data"
|
||||
os.makedirs(data_dir, exist_ok=True)
|
||||
image_path = os.path.join(images_dir, image_filename)
|
||||
os.makedirs(images_dir, exist_ok=True) # Fixed: was data_dir instead of images_dir
|
||||
|
||||
image_path = f"public/{image_filename.split('/')[-1]}"
|
||||
|
||||
# Update UI with results
|
||||
self.updating_evolution_and_forecasts(text, image_path)
|
||||
|
||||
# Here update the informations in the last box from plant_data/texts
|
||||
# TODO: Implement reading from plant_data/texts
|
||||
|
||||
# Here update the informations in growth evolution from plant_data/images
|
||||
# Here update the informations in growth evolution from plant_data/images
|
||||
# TODO: Implement reading from plant_data/images
|
||||
|
||||
# Show success message with better formatting
|
||||
messagebox.showinfo("Submission Successful",
|
||||
"Submission successful!\n\n"
|
||||
"Go to Growth Evolution tab to see the results.")
|
||||
|
||||
#Calling a small advertment to notify the user that the image has been generated
|
||||
messagebox.showinfo("Submission successful, go to growth evolution to see the results")
|
||||
print(f"Submission data saved to: {filepath}")
|
||||
|
||||
except Exception as e:
|
||||
messagebox.showerror("Submission Error", f"Error submitting data: {str(e)}")
|
||||
|
||||
print(f"Error details: {e}") # For debugging
|
||||
|
||||
def updating_evolution_and_forecasts(self, text, image_path):
|
||||
self.results_text.config(state='normal') # Enable editing
|
||||
self.results_text.delete(1.0, tk.END) # Clear existing content
|
||||
|
|
BIN
PlantDashboard/public/.DS_Store
vendored
BIN
PlantDashboard/public/.DS_Store
vendored
Binary file not shown.
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
BIN
PlantDashboard/public/pomodoro.png
Normal file
BIN
PlantDashboard/public/pomodoro.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
20
data/20250802-20250802.txt
Normal file
20
data/20250802-20250802.txt
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"timestamp": "2025-08-02T10:54:55.312319",
|
||||
"parameters": {
|
||||
"temperature": 22.0,
|
||||
"humidity": 65.0,
|
||||
"soil_acidity": 6.5,
|
||||
"pressure": 1013.25,
|
||||
"brightness": 30.0,
|
||||
"nutrients": 75.0,
|
||||
"water": 80.0,
|
||||
"co2": 850.0,
|
||||
"plant_type": "tomato",
|
||||
"ambient_mode": "controlled"
|
||||
},
|
||||
"baseline_image_path": "/Users/giusber2005/Desktop/workspace/repositories/projects/team-2/PlantDashboard/public/pomodoro.png",
|
||||
"plant_info": "\n",
|
||||
"start_date": "2025-08-02",
|
||||
"end_date": "2025-08-02",
|
||||
"time_lapse_days": 0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue