CP1 / COURSE HOME

Week 06 / Organise observations

Choose a useful summary

Decide what the report needs before calculating a statistic.

We can now collect repeated observations and stop deliberately. The next question is what to tell a reader about those observations.

Two current logs are [4, 4, 4, 4] A and [2, 2, 4, 8] A. Both have a mean of 4 A. Our reporting rule flags sampled values strictly above 6 A.

Start with the problem

Try this first.

Give each log a one-line report. What must you add to the mean so that a reader notices the difference?

Why this week's tool?

Running totals, counts and maximum trackers answer different questions. We will combine these small patterns instead of treating the average as the whole result.

By the end: Choose and justify a summary that reveals the 8 A sample, and describe what it cannot tell us about unsampled moments.

The idea behind the program

Choose the pattern from the question

A mean describes a central level. A maximum describes the largest sampled value. A threshold count describes how many samples satisfy a rule. None of these quantities is a substitute for the others.

Keep the denominator honest

Mean = sum / count. If invalid values are removed later in the course, the denominator must count retained values. For now, all supplied values are valid and equally spaced.

A sample count is not automatically a duration

Two high samples indicate two observations above the threshold. Turning that into an overload duration needs timing and an explicit assumption about the behaviour between samples. Keep the claim narrow.

A short Python example

Read the example alongside the explanation. Run it in a new notebook cell and change one input to see how it behaves.

readings_a = [4, 4, 4, 8, 0]
total = 0
count = 0
peak = readings_a[0]
over_limit = 0
for value in readings_a:
    total += value
    count += 1
    if value > peak:
        peak = value
    if value > 6:
        over_limit += 1
print('Mean, peak, high samples:', total / count, peak, over_limit)

Example output

Mean, peak, high samples: 4.0 8 1

Choose a pattern by what must be remembered

A sum remembers accumulated amount; a count remembers how many; a search remembers whether or where a match was found; a maximum remembers the greatest value seen so far. These are different questions about the same observations.

Draw or trace

For readings −5, −2 and −7, create separate columns for running sum, count and maximum. For a nonempty sequence initialise the maximum from its first reading.

Predict before running. Why does maximum = 0 give a misleading result when all readings are negative?

Trace and explanation — after your prediction
  1. Sum after each reading: −5, −7, −14; count: 1, 2, 3.
  2. Maximum starts at −5, becomes −2, and stays −2.
  3. Starting at 0 leaves a value that never occurred in the data.

The correct maximum is −2. An initial value must match the question and allowed inputs. For no readings, define a separate no-data result rather than inventing a maximum.

Change one thing. Change the question from maximum to first reading above a threshold. Explain why stopping early is now possible and why it would be wrong when finding the overall maximum.

Türkçe: Çözüm kalıbını istenen bilgiye göre seç. Başlangıç değeri, özellikle negatif ve boş girdilerde, sonucun anlamını belirler.

Examples and variations

Each example changes something about the same problem. Open the ones you want to explore and follow the worked explanation.

01Steady current

[4, 4, 4, 4, 4] A; flag > 6 A

Question: Predict mean, peak and high-sample count.

  1. Sum = 20 A across 5 readings
  2. Mean = 4 A; maximum = 4 A
  3. No reading exceeds 6 A

Mean 4 A · peak 4 A · high count 0

The three summaries agree that no sampled value exceeded the threshold.

02Hidden spike

[4, 4, 4, 8, 0] A; flag > 6 A

Question: Can the mean distinguish this log from the steady log?

  1. Sum = 20; count = 5
  2. Mean = 4 A; maximum = 8 A
  3. Only the 8 A reading exceeds 6 A

Mean 4 A · peak 8 A · high count 1

The mean alone hides the spike. Preserve a peak or event count when those answer the engineering question.

03Exactly at the limit

[6, 6, 6] A; flag strictly > 6 A

Question: How many values are flagged under the stated rule?

  1. Mean = 6 A
  2. Maximum = 6 A
  3. Each comparison 6 > 6 is False

Mean 6 A · peak 6 A · high count 0

Changing > to >= changes the policy. Your report should state which rule it uses.

See the Colab code run

Interactive walkthroughs of Problem-Solving Patterns. Enable JavaScript to step through code, variables, collections and output. The companion notebook remains available below.

Work on it in Colab

Use the notebook to try the ideas yourself. The steps below connect this week's example to the programming practice.

  1. Compute the three summaries for the steady and spiky logs on paper. Explain why identical means do not imply identical behaviour.
  2. Implement the one-pass model, then change one reading while keeping the total unchanged. Observe which summaries move.
  3. Consider an empty list before running it. Identify both the first-element access and division that would need a defined policy.
  4. Write a report for a teammate who needs to investigate the spike. Include the threshold definition and the limitation of sampled data.

Something to take away: Two contrasted logs, their mean/peak/count summaries, and a short recommendation supported by the appropriate metric.

Suggested exercises, downloads & solutions

Read the notebook's teaching cells before these exercises.

  • EX03 Find Maximum (Medium)
  • EX05 Average Calculator (Medium)
  • EX06 Count Above Average (Medium)
Download notebookWorked solutions

Use the notebook's core and optional labels to choose your workload. This activity fits within guided class time.

Optional notes & guidance
My notes
Using AI or working with a partner

Ask AI for a current-log summary. If it returns only an average, challenge it with the two equal-mean datasets. Require it to justify each reported metric and define the empty-input behaviour.

You can also review the supplied example with a partner. Use the same inputs to compare the reasoning. Follow the syllabus rules for assessed work.