FUNDAMENTALS GBCMC
martes, 20 de octubre de 2026
retrieve
import requests
def retrieve():
url = "http://raw.githubusercontent.com/leviathantheesper-cmd/ESPsimulation/main/data.json"
data = requests.get(url).json()
return data
app_template.py
import streamlit as st
from utils import retrieve
import json
import pandas as pd
st.set_page_config(page_title="Monitoring System", layout="centered")
st.title("Rabbit Monitoring System")
st.logo("logo.jpg")
data=retrieve.retrieve()
with open("data.json","w",encoding="utf-8") as f:
json.dump(data,f,indent=4)
timestamp = data["timestamp"]
sht = data["SHT"]
hc = data["HCSR04"]
temp = sht["temperature"]
hum = sht["humidity"]
dist = hc["distance"]
df = pd.DataFrame({
"timestamp": timestamp,
"distance": dist,
"humidity": hum,
"temperature": temp,
})
st.header("Temperature and Humidity")
st.text("""To monitor the Ranch rabbits we need to analyze the different situations on the variable. In this case we see how an increase in temperature tends to cause a reduction of humidities, while also we can see that there are two different humidity trends on lower temperatures, one with high humidity, one with low humidity, while the coldest temperatures measured are always on the higher trend.""")
with st.container(border=True,width=600,height=400,horizontal_alignment="center"):
st.scatter_chart(sht,x="temperature", y="humidity")
st.header("Temperature and Humidity vs. Distance")
st.text("""In this case the HCSR04 can't really directly measure the behavior of rabbits. With our limited implementation, it can't even give us data in real time of when the rabbit passes through places! What we can do with it is measure tendencies of location preference. In the graph we analyze how temperature affects the preference of the rabbits. If the temperature is too cold, or too hot, rabbits won't like the spot. However, with a temperature of around 19ºC rabbits seem to be pretty content.""")
with st.container(border=True,width=600,height=400,horizontal_alignment="center"):
st.scatter_chart({"temperature":temp,"distance":dist},x="temperature", y="distance")
st.header("Variables changing with time")
st.text("The variation with time of the three variables we considered can be seen next:")
with st.container(border=True, width=600, height=400, horizontal_alignment="center"):
st.subheader("Temperature over Time")
st.line_chart(df, x="timestamp", y="temperature")
martes, 13 de octubre de 2026
CLASS ACTIVITY 2 WEEK 7
🐰 Python Exercise: Rabbit Monitoring System (Dictionaries)
🎯 Objective:
Learn how to create and structure nested dictionaries in Python by recording monitoring data for rabbits. Please complete the Bunny 2-3-4
1. Example Code (Teacher's Template)
Copy and paste this starter code into Spyder and run it:
# ======================================================
# RABBIT MONITORING SYSTEM
# ======================================================
# Step 1: Create the main dictionary with 1 example rabbit
rabbit_database = {
"Bunny1": {
"weight_g": 1850,
"temperature_c": 38.5,
"motion_status": "Active"
}
}
# Step 2: Print the data for the first rabbit
print("=== RABBIT MONITORING DATA ===")
print("Bunny1 Data:")
print("• Weight:", rabbit_database["Bunny1"]["weight_g"], "g")
print("• Temperature:", rabbit_database["Bunny1"]["temperature_c"], "°C")
print("• Motion Status:", rabbit_database["Bunny1"]["motion_status"])
domingo, 27 de septiembre de 2026
Streamlit directories version 8°
import streamlit as st
import time
# Configuración de la página
st.set_page_config(page_title="Smart System Monitor", layout="wide")
st.title("📡 Smart System Monitoring Dashboard")
st.write("Visualización en tiempo real de los módulos ESP32")
# --- DICCIONARIOS CON DATOS DE SENSORES ---
temp = {
"ESP1": 21.5,
"ESP2": None, # Módulo con falla o desconectado
"ESP3": 19.8
}
humid = {
"ESP1": 65,
"ESP2": 0,
"ESP3": 58
}
weight = {
"ESP1": 1.2,
"ESP2": None,
"ESP3": 1.5
}
# Botón para iniciar la simulación de lectura
if st.button("▶ Iniciar Lectura de Sensores"):
# 1. VISUALIZACIÓN DE TEMPERATURA
st.subheader("🌡️ Lecturas de Temperatura (°C)")
cols_temp = st.columns(len(temp))
for idx, (dispositivo, valor) in enumerate(temp.items()):
with cols_temp[idx]:
if valor is None:
st.metric(label=dispositivo, value="Sin señal", delta="Error", delta_color="inverse")
else:
st.metric(label=dispositivo, value=f"{valor} °C")
time.sleep(1) # Pausa para simular carga progresiva
# 2. VISUALIZACIÓN DE HUMEDAD
st.subheader("💧 Lecturas de Humedad (%)")
cols_humid = st.columns(len(humid))
for idx, (dispositivo, valor) in enumerate(humid.items()):
with cols_humid[idx]:
if valor == 0 or valor is None:
st.metric(label=dispositivo, value="0 %", delta="Falla Sensor", delta_color="inverse")
else:
st.metric(label=dispositivo, value=f"{valor} %")
time.sleep(1)
# 3. VISUALIZACIÓN DE PESO
st.subheader("⚖️ Lecturas de Peso (kg)")
cols_weight = st.columns(len(weight))
for idx, (dispositivo, valor) in enumerate(weight.items()):
with cols_weight[idx]:
if valor is None:
st.metric(label=dispositivo, value="N/A", delta="Offline", delta_color="inverse")
else:
st.metric(label=dispositivo, value=f"{valor} kg")
time.sleep(1)
st.success("✅ Monitoreo completado exitosamente.")
dictionaries.py
import time
# ==========================================
# 1. DICTIONARIES WITH SENSOR DATA
# ==========================================
# Each key represents the ESP32 identifier
# and its value is the sensor reading.
temp = {
"ESP1": 21.5,
"ESP2": None, # Simulates an error or device disconnection
"ESP3": 19.8
}
humid = {
"ESP1": 65,
"ESP2": 0, # Simulates a humidity reading failure
"ESP3": 58
}
weight = {
"ESP1": 1.2,
"ESP2": None, # Simulates missing weight reading
"ESP3": 1.5
}
# ==========================================
# 2. CONTINUOUS DATA PRINTING ON CONSOLE
# ==========================================
# Temperature Readings
print("--- Temperature Readings (°C) ---")
for device, value in temp.items():
print(f"Temperature at {device}: {value}°C")
time.sleep(2) # 2-second pause between each reading
# ==========================================
# 3. FINAL MESSAGE
# ==========================================
print("\nMonitoring completed.")
ACTIVITY CLASS
AUTOMATED SYSTEMS
What is the topic of Week #7?
What are the three evaluation pillars used to analyze prototypes?
What does "Efficiency" measure in a prototype?
What does "Precision" measure in a prototype?
What does "Usefulness" mean in system design?
Is a prototype successful if it works well but drains its battery in 1 hour?
Why does a solar garden light have lower precision on cloudy days?
Name the three subsystems evaluated in the Genius Solvers activity.
In your own words: What makes a prototype "Useful" in a real-world ecosystem?
What microcontroller and components are used to build the functional feeder prototype?
