Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Batch Reporting
📖 Scenario: You work in a factory using a SCADA system to monitor production batches. Each batch has a unique ID and a status indicating if it passed quality checks.Your manager wants a quick report showing which batches passed.
🎯 Goal: Create a batch report that lists only the batch IDs that passed quality checks.
📋 What You'll Learn
Create a dictionary called batches with batch IDs as keys and status strings as values
Create a variable called passed_status with the value 'Passed'
Use a dictionary comprehension to create a new dictionary passed_batches containing only batches with status equal to passed_status
Print the passed_batches dictionary
💡 Why This Matters
🌍 Real World
Factories use SCADA systems to monitor production batches and quickly identify which batches passed quality checks for reporting and decision-making.
💼 Career
DevOps and automation engineers often write scripts to process and report system data, helping teams monitor production and maintain quality.
Progress0 / 4 steps
1
Create the batch data
Create a dictionary called batches with these exact entries: 'B001': 'Passed', 'B002': 'Failed', 'B003': 'Passed', 'B004': 'Failed', 'B005': 'Passed'
SCADA systems
Hint
Use curly braces to create a dictionary. Each entry has a batch ID as a string key and a status string as value.
2
Set the passed status variable
Create a variable called passed_status and set it to the string 'Passed'
SCADA systems
Hint
Use a simple assignment to create the variable.
3
Filter batches that passed
Use a dictionary comprehension to create a new dictionary called passed_batches that contains only the batches from batches where the status equals passed_status
SCADA systems
Hint
Use {key: value for key, value in dict.items() if condition} syntax.
4
Print the passed batches report
Print the passed_batches dictionary to display the batches that passed quality checks
SCADA systems
Hint
Use print(passed_batches) to show the filtered dictionary.
Practice
(1/5)
1. What is the main purpose of batch reporting in SCADA systems?
easy
A. To replace manual quality checks completely
B. To control the speed of individual machines
C. To monitor only the temperature of a single product
D. To collect and summarize data about groups of products made together
Solution
Step 1: Understand batch reporting concept
Batch reporting gathers data about a group of products made in one production run.
Step 2: Identify main purpose
This data helps track quality, timing, and conditions for the entire batch, not just one machine or product.
Final Answer:
To collect and summarize data about groups of products made together -> Option D
Quick Check:
Batch reporting = group data collection [OK]
Hint: Batch reporting = data about product groups, not single items [OK]
Common Mistakes:
Thinking batch reporting controls machine speed
Confusing batch data with single product data
Assuming it replaces all manual checks
2. Which of the following is the correct way to represent a batch report entry in a SCADA system configuration?
B. batch_report = [batch_id: 101, start_time: '08:00', status: 'complete']
C. batch_report = (batch_id=101, start_time='08:00', status='complete')
D. batch_report = 'batch_id=101; start_time=08:00; status=complete'
Solution
Step 1: Identify correct data structure syntax
In SCADA system configs, batch reports are often stored as key-value pairs in dictionaries or JSON-like objects.
Step 2: Check each option
batch_report = { 'batch_id': 101, 'start_time': '08:00', 'status': 'complete' } uses correct dictionary syntax with keys and values. Options A and C use invalid syntax for dictionaries. batch_report = 'batch_id=101; start_time=08:00; status=complete' is a string, not a structured entry.
Which Python code correctly calculates and prints the summary?
hard
A. duration = batch['end'] - batch['start']
print(f"Batch {batch['id']} took {duration} minutes and is {batch['status']}")
B. from datetime import datetime
start = datetime.strptime(batch['start'], '%H:%M')
end = datetime.strptime(batch['end'], '%H:%M')
duration = (end - start).seconds // 60
print(f"Batch {batch['id']} took {duration} minutes and is {batch['status']}")
C. duration = int(batch['end']) - int(batch['start'])
print(f"Batch {batch['id']} took {duration} minutes and is {batch['status']}")
D. print(f"Batch {batch['id']} took {batch['end'] - batch['start']} minutes and is {batch['status']}")
Solution
Step 1: Parse time strings to datetime objects
Use datetime.strptime with '%H:%M' format to convert 'start' and 'end' strings to datetime objects.
Step 2: Calculate duration in minutes
Subtract start from end to get timedelta, then convert seconds to minutes using integer division.
Step 3: Print formatted summary
Use f-string to print batch ID, duration, and status clearly.
Final Answer:
from datetime import datetime
start = datetime.strptime(batch['start'], '%H:%M')
end = datetime.strptime(batch['end'], '%H:%M')
duration = (end - start).seconds // 60
print(f"Batch {batch['id']} took {duration} minutes and is {batch['status']}") -> Option B
Quick Check:
Parse times + timedelta = correct duration [OK]
Hint: Convert times to datetime before subtracting [OK]