this is the question i am trying to solve
And this is the CSV file i am working with
Timestamp,Machine ID,Product Type,Product Name,Production Count,Defect Count,Environmental Impact,Maintenance Status,Maintenance Date
2024-03-14 08:00:00,M001,Product A,Engine Block,120,3,CO2: 50 kg,Done,2024-03-12
2024-03-14 08:15:00,M002,Product B,Brake Caliper,n/a,2,CO2: 60 kg,Done,2024-03-10
2024-03-14 08:30:00,M003,Product C,Fuel Pump,115,4,CO2: 70 kg,Not done,
2024-03-14 08:45:00,M001,Product A,Transmission,130,3,CO2: 55 kg,Done,2024-03-11
2024-03-14 09:00:00,M002,Product B,Crankshaft,n/a,5,CO2: 65 kg,Not done,
2024-03-14 09:15:00,M003,Product C,Exhaust Manifold,110,2,CO2: 75 kg,Done,2024-03-13
2024-03-14 09:30:00,M001,Product A,Piston,140,4,CO2: 60 kg,Done,2024-03-09
2024-03-14 09:45:00,M002,Product B,Suspension Arm,115,3,CO2: 70 kg,Not done,
2024-03-14 10:00:00,M003,Product C,Fuel Injector,120,2,CO2: 80 kg,Done,2024-03-08
2024-03-14 10:15:00,M001,Product A,Cylinder Head,125,4,CO2: 55 kg,Not done,
2024-03-14 10:30:00,M002,Product B,Starter Motor,130,3,CO2: 65 kg,Done,2024-03-07
2024-03-14 10:45:00,M003,Product C,Water Pump,115,5,CO2: 75 kg,Not done,
2024-03-14 11:00:00,M001,Product A,Alternator,140,2,CO2: 60 kg,Done,2024-03-06
2024-03-14 11:15:00,M002,Product B,Fuel Tank,120,4,CO2: 70 kg,Not done,
2024-03-14 11:30:00,M003,Product C,Air Filter,125,3,CO2: 80 kg,Done,2024-03-05
2024-03-14 11:45:00,M001,Product A,Spark Plug,130,2,CO2: 55 kg,Done,2024-03-04
2024-03-14 12:00:00,M002,Product B,Timing Belt,115,5,CO2: 65 kg,Not done,
2024-03-14 12:15:00,M003,Product C,Catalytic Converter,140,3,CO2: 75 kg,Done,2024-03-03
2024-03-14 12:30:00,M001,Product A,Radiator,125,4,CO2: 60 kg,Not done,
this is the code that i have writtensource code
def display_analysis():
display_header()
Total_number_of_products=20
low=0
med=0
high=0
input_file = open(RECORDS_FILE,'r')
headers = input_file.readline()
analysis_file = open('analysis.txt','w')
analysis_file.write(headers)
for asset in input_file.readlines():
Machine_ID, Timestamp, Product_Type, Product_Name, Production_Count, Defect_Count, Environmental_Impact, Maintenance_Status, Maintenance_Date = asset.split(',')
if Production_Count =="n/a":
Production_Count =0
else:
Production_Count= int(Production_Count)
Defect_Count=int(Defect_Count)
if Production_Count !=0:
Average_defects_per_product_type=Defect_Count/Production_Count
else:
Average_defects_per_product_type =0
print(Average_defects_per_product_type)
Average_defects_per_product_type= str(Average_defects_per_product_type)
analysis_file.write(Average_defects_per_product_type)
# make a tuple while iteration through a file:
tuple=list(zip(Product_Name,Average_defects_per_product_type))
print(tuple)
# number of machines with maintenance status as "Done" and "Not done"
#check maybe lab 9 has the contents
if Product_Type =="Done":
display(asset)
if Product_Type=="Not done":
display(asset)
# environmental score:
Environmental_Impact_strip= Environmental_Impact.lstrip('CO2:')
Environmental_Impact_strip= Environmental_Impact.rstrip('kg')
Environmental_Impact_strip= Environmental_Impact.strip()
print(Environmental_Impact_strip)
Environmental_Impact_strip=int(Environmental_Impact_strip)
if Environmental_Impact_strip<30:
low += 1
if 30<=Environmental_Impact_strip<55:
med +=1
if Environmental_Impact_strip>=55:
high +=1
lowest= (low/ Total_number_of_products)*100
print(lowest)
Medium= (med/ Total_number_of_products)*100
print(Medium)
Highest= (high/ Total_number_of_products)*100
print(Highest)
analysis_file.write(lowest)
analysis_file.write(Medium)
analysis_file.write(Highest)
Mohammad Kamrul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1