Reactor Cooling Diagnostics – Task 3

Your cooling reports have become essential to station operations. The crew relies on them every shift, and the critical threshold warnings have already prevented two potential incidents. But the station's chief engineer has noticed something troubling.

When she compares your reactor cooling reports with diagnostics from other subsystems, she sees the same pattern of code everywhere. The life support team wrote nearly identical logic to process oxygen sensor logs. The power distribution team did the same for their voltage monitors. Navigation diagnostics, thermal regulation, waste recycling—every team has independently written programs that read a log file, extract numerical values, compute an average, find a maximum, and count threshold violations.

This duplication is becoming a maintenance problem. When the log format changes, every team must update their code separately. When a calculation error is discovered, it must be fixed in a dozen different places. The chief engineer asks you to look at the power distribution logs and write a similar report for them, knowing full well that you will be copying most of your cooling monitor code.

The power distribution system logs voltage measurements in a similar format to reactor cooling:

09:23 PowerDistribution: voltage=118V
09:24 PowerDistribution: voltage=121V
09:25 PowerDistribution: voltage=115V
09:26 PowerDistribution: voltage=122V
09:27 PowerDistribution: voltage=119V
09:28 PowerDistribution: voltage=116V

The file is named power_log.txt and follows the same structure as the cooling log, but measures voltage instead of efficiency percentage. Station policy defines voltage below 117V as critical, as it indicates the power grid may be under excessive load.

Your program should read power_log.txt and produce a report in the same format you used for reactor cooling:

Measurements: 6
Average voltage: 118V
Highest voltage: 122V
Critical readings (below 117V): 2

As you write this program, you will notice how much of the logic is identical to your cooling monitor. The file reading code is the same. The logic for computing averages, finding maximums, and counting threshold violations is the same. Only the parsing details and the specific threshold value differ. Your program should accomplish this task using the same techniques as before: reading from a file, parsing each line, and using variables to accumulate totals.

When you finish, look at both programs side by side. The duplication is obvious and uncomfortable. The chief engineer knows this feeling well—it is the feeling that signals when code is ready to be reorganized. She mentions that next week, you will learn techniques for capturing repeated logic in a way that can be reused across different subsystems without copying and pasting. For now, the duplication is necessary. It shows you exactly what needs to be abstracted.