Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will play the role of a data engineer at a manufacturing company. The company has a legacy system that stores logs
In this assignment, you will play the role of a data engineer at a manufacturing company. The company
has a legacy system that stores logs of manufacturing batches in a pecullar string format. Your task is to
validste and extract information from these log strings.
A valid log string adheres to the followine format
Batch Prefix. Each batch within the strinc starts with the prefix case sersitive
Batch ID Following the preflx, there is a batch ID consisting of exactly four diges.
Product Code: Nert, there is a product code that starts with case sensitive followed by
eactly two letters uppercasecase senaitive
Quantity: Then, there is a quantty section that starts with case sencitive followed by an
integer above sero representing the quartity of products in the batch. Leading seros are ok for
eample, C is OK and is OK However, the leading zero should be eliminated once the
quantity number is extracted. For example, is once extracted. Note that the quarerty
output is an integer, not a strine.
Date: Finally, there is a date section that starts with Dcase sensitive followed by a date in the
format monhaudo
Its YrmMDO length should be eight characters.
The first four characters represent the year, which thould be between and
The neat two characters represent the month, which should be between and
The last two characters represent the day, which should be between and although
not all months have dara, we II igore this detal for simplicity no need to check for
leap year for example, is ok is ok
The string can contain multiple batches, each adhering to the format described above
Your task is to wribe a Python function that takes this log strine as input and retums a list of dictionaries
containing information about each batch if the string is valid. if the string is imalid, return "imalidr. The
"imalid" return value is a string value, not a Boclean value.
Example::
BPABCSD is valid and should returnc
IF'Datch ID: 'Product Code': A 'Quantity': 'Date':
bpasosos is imalid the botch arts with a lowercase b and should return
invald
BPBCSD is imalid product code contains a digit
invald
BPABCSODaAgs is invald dste contains a nondieit character
invalid
BPABCDSPXRCC is valid contains multiple valid batches
and should returnc
IBatch : 'Product Code': AB 'Quantity': 'Date': Batch : Y
'Product Code': XYr 'Quantity': 'Date':
BPABCBPKYOD is vald contains multiple valid
batches and should retum:
IBatch ID: Product Code': AB 'Quantity': 'Date': Batch ID: Y
"Product Code': Xr 'Qusntity': 'Date':
Implementation Details:
Use Pyehon builtin functions and data types to solve this task.
The function should be able to handle strings containing one or more batches.
IMPORTANT:
You must implement your function with the name validateandextractlog in a file named
manufacturelog py Your program will fail, and you will recelve a zero if you do not follow this naming
comention. The names are casesensitive
DO NOT include any print statements in your code. You should remove all print statements before
submitting your assignment code.
DO NOT include your own test cases or test functions for testing your validateandextractlog
function in your code.
It is OK if you have other supporting functions in addition to the validateandextractlogs
function.
You can only use Python builtin functions to write this program. You are not allowed to use any
imported modules, packages, or libraries such as pandas, NumPy, math, etc. The goal of this
assignment is to practice:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started