Bird
0
0

You want to build a real-time dashboard on Raspberry Pi that updates sensor data every second and shows the average of last 5 readings. Which approach is best?

hard📝 Scenario Q15 of 15
Raspberry Pi - Web Server and API
You want to build a real-time dashboard on Raspberry Pi that updates sensor data every second and shows the average of last 5 readings. Which approach is best?
ACalculate average once at start, then display static value
BStore all readings forever and calculate average of all data each second
CUpdate dashboard only when sensor value changes, ignoring average
DStore last 5 readings in a list, update every second, calculate average, then update dashboard
Step-by-Step Solution
Solution:
  1. Step 1: Understand real-time averaging requirement

    To show average of last 5 readings updated every second, you must keep a rolling list of last 5 values.
  2. Step 2: Evaluate options for efficiency and accuracy

    Store last 5 readings in a list, update every second, calculate average, then update dashboard correctly stores last 5 readings, updates average each second, and refreshes dashboard. Calculate average once at start, then display static value is static, C ignores averaging, D is inefficient and grows data indefinitely.
  3. Final Answer:

    Store last 5 readings in a list, update every second, calculate average, then update dashboard -> Option D
  4. Quick Check:

    Rolling average needs recent 5 values updated regularly [OK]
Quick Trick: Keep fixed-size list for rolling average updates [OK]
Common Mistakes:
MISTAKES
  • Calculating average only once
  • Ignoring rolling window for average
  • Storing unlimited data causing slowdowns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes