Chapter 8 — Validating repair jobs
Lesson map
Lesson 08 published. Map, example, EX022.
flowchart TD
N0["Learning outcomes"]
N1["8.1 The rules"]
N2["Lab — Priority code and date order checks on 6,000 s"]
N3["8.2 Results"]
N4["8.3 Causes"]
N5["8.4 Reporting"]
N0 --> N1 --> N2 --> N3 --> N4 --> N5
N5 --> EX["Worked example"]
EX --> Q["Exercise EX022"]
Logical drawing
flowchart LR
N0["Learning outcomes"]
N1["8.1 The rules"]
N2["Lab — Priority code and date order checks on 6,000 s"]
N3["8.2 Results"]
N4["8.3 Causes"]
N5["8.4 Reporting"]
N0 --> N1 --> N2 --> N3 --> N4 --> N5 --> Q["EX022"]
[Learning outcomes]
|
v
[8.1 The rules]
|
v
[Lab — Priority code and date order checks on 6,000 s]
|
v
[8.2 Results]
|
v
[8.3 Causes]
|
v
[8.4 Reporting]
|
v
[Worked example] --> [Exercise EX022]
Learning outcomes
You will (1) validate job records against two rules; (2) combine rule results; (3) report findings to the steward.
8.1 The rules
Ravi validates repair jobs with two rules agreed with the repairs steward. The priority code must be one of E for emergency, U for urgent, R for routine or P for planned. The completion date must not be earlier than the date the job was raised. Both rules matter for regulatory reporting, because priority determines the target time and dates determine whether the target was met. He writes each rule as a small function with a clear name. The steward approves both functions.
Lab — Priority code and date order checks on 6,000 synthetic repair jobs
"""Validate 6,000 synthetic repair job records: priority code and date order (stdlib only)."""
import random, datetime as dt
random.seed(21)
codes = ["E", "U", "R", "P"]
bad_code = bad_date = both = 0
for i in range(6000):
c = random.choice(codes) if random.random() > 0.03 else random.choice(["", "X", "e"])
raised = dt.date(2026, 1, 1) + dt.timedelta(days=random.randint(0, 180))
done = raised + dt.timedelta(days=random.randint(0, 30) if random.random() > 0.02 else -random.randint(1, 10))
bc, bd = c not in codes, done < raised
bad_code += bc; bad_date += bd; both += bc and bd
print(f"jobs 6000; invalid priority {bad_code}; completed before raised {bad_date}; both {both}")
print(f"valid on both rules {6000 - bad_code - bad_date + both} ({100*(6000 - bad_code - bad_date + both)/6000:.1f}%)")
Run with python3 lab_jobs.py. Verified output:
jobs 6000; invalid priority 167; completed before raised 122; both 8
valid on both rules 5719 (95.3%)
8.2 Results
The lab checks six thousand synthetic jobs. One hundred and sixty-seven have an invalid priority, such as a blank, an unknown letter or a lowercase e. One hundred and twenty-two were completed before they were raised. Eight fail both rules. In total, 5,719 jobs, 95.3 percent, pass both rules. Ravi notes that jobs failing both rules are counted once in the total, which is why the failures do not simply add up. Ravi presents the results in a small table with the combined figure shown first, followed by each rule's failure count.
8.3 Causes
Ravi samples failing jobs and discusses them with the steward. Lowercase e comes from a contractor portal that does not convert case. Blanks come from jobs created in a hurry during storms. Completion before raising usually means a call handler created the job after the contractor had already fixed an emergency, entering the raised date as the call date. Each cause suggests a different fix, from case conversion to clearer guidance for emergencies. Ravi records each cause with an example job number in his notes.
8.4 Reporting
Ravi reports to the steward with counts, the combined pass rate, examples with tenant details removed, likely causes and suggested fixes. The steward accepts the case conversion fix and asks call handlers to record the original report time for emergencies. Ravi adds both rules to the check library to run nightly. Ms. Moreau notes that reporting causes alongside counts helps the steward act rather than simply worry about a number. The steward presents Ravi's report at the monthly repairs meeting, where managers agree to monitor the pass rate each month from then on.
Worked example
Ravi validates 6,000 jobs, finding 167 invalid priorities, 122 completed before raised and 8 both, with 5,719 (95.3 percent) valid, traces causes and adds the rules to nightly checks.
Synthetic case. Jobs are synthetic; outputs come from lab_jobs.py.
Errors and limits
Adding failure counts double-counts records failing several rules.
Exercises
- EX022 — Valid share. What share of jobs pass both rules? Rubric: 3 = 95.3% (5,719);; 2 = partly correct;; 1 = wrong;; 0 = none.
- EX023 — Lowercase cause. Where does lowercase e come from? Rubric: 3 = a portal that does not convert case;; 2 = partly correct;; 1 = vague;; 0 = none.
- EX024 — Date cause. Why were some jobs completed before being raised? Rubric: 3 = emergency jobs created after the fix;; 2 = partly correct;; 1 = vague;; 0 = none.
Continue studying — lesson 08 (chapter 08 of 30)
← Chapter 07 · Course chapter index · Chapter 09 →
Continue to the next authored lesson.