Answered step by step
Verified Expert Solution
Link Copied!

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 'B'(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 'P'(case sensitive) followed by
eactly two letters (uppercase-case senaitive).
Quantity: Then, there is a quantty section that starts with 'Q'(case sencitive) followed by an
integer above sero representing the quartity of products in the batch. Leading seros are ok, for
eample, C0050 is OK, and 050 is OK. However, the leading zero should be eliminated once the
quantity number is extracted. For example, 0050 is 50 once extracted. Note that the quarerty
output is an integer, not a strine.
Date: Finally, there is a date section that starts with 'D'(case 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 2000 and 2019.
The neat two characters represent the month, which should be between 01 and 12.
The last two characters represent the day, which should be between 01 and 31(although
not all months have 31 dara, we II igore this detal for simplicity - no need to check for
leap year for example, 20230229 is ok,20230931 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::
"B1234PABCS0D20230908" is valid and should returnc
IF'Datch ID': '1234', 'Product Code': 'A8', 'Quantity': 50, 'Date': '202309087]
"b1234pasoso0202s0905" is imalid (the botch arts with a lowercase "b) and should return
invald
"B1234P3BCS0D20230908" is imalid (product code contains a digit).
invald
"B1234PABCSODa023Ag0s" is invald (dste contains a non-dieit character).
invalid
"B1234PABC50D202305085S673PXRC30C20230909" is valid [contains multiple valid batches)
and should returnc
I[Batch 10': '1236', 'Product Code': 'AB', 'Quantity': 50, 'Date': '202309002,[Batch 10': 'Y678',
'Product Code': 'XYr, 'Quantity': 30, 'Date': '20230909'1]
"B1234PABC0050020230903B5678PKYO0030D20230909" is vald (contains multiple valid
batches) and should retum:
I[Batch ID': '1234', Product Code': 'AB', 'Quantity': 50, 'Date': '202309087,(Batch ID': 'Y678',
"Product Code': 'Xr 'Qusntity': 30, 'Date': '20230909'1]
Implementation Details:
Use Pyehon built-in 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 validate_and_extract_log 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 case-sensitive.
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 validate_and_extract_log))
function) in your code.
It is OK if you have other supporting functions in addition to the validate_and_extract_log(s)
function.
You can only use Python built-in 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:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

What is the definition of cash on the SCF?

Answered: 1 week ago