Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me generating a python code for the assignment: In this assignment, you will play the role of a data engineer at a manufacturing

Please help me generating a python code for the assignment:
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 peculiar string format. Your task is to
validate and extract information from these log strings.
A valid log string adheres to the following format:
Batch Prefix: Each batch within the string starts with the prefix 'B'(case sensitive).
Batch ID: Following the prefix, there is a batch ID consisting of exactly four digits.
Product Code: Next, there is a product code that starts with 'P'(case sensitive) followed by
exactly two letters (uppercase - case sensitive).
Quantity: Then, there is a quantity section that starts with 'Q'(case sensitive) followed by an
integer above zero representing the quantity of products in the batch. Leading zeros are ok. For
example, Q0050 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 quantity
output is an integer, not a string.
Date: Finally, there is a date section that starts with 'D'(case sensitive) followed by a date in the
format YYYYMMDD.
Its (YYYYMMDD) length should be eight characters.
The first four characters represent the year, which should be between 2000 and 2099.
The next 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 days, we'll ignore this detail 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 write a Python function that takes this log string as input and returns a list of dictionaries
containing information about each batch if the string is valid. If the string is invalid, return "invalid". The
"invalid" return value is a string value, not a Boolean value.
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

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions