Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import csv import sys from datetime import datetime def read _ ssn _ eid _ mapping ( file _ path ) : ssn _ eid

import csv
import sys
from datetime import datetime
def read_ssn_eid_mapping(file_path):
ssn_eid_map ={}
with open(file_path, mode='r') as file:
reader = csv.reader(file)
for row in reader:
ssn, eid = row
ssn_eid_map[ssn[-4:]]= eid
return ssn_eid_map
def process_sdf(file_path, ssn_eid_map, pp_end_dates):
pp_data =[]
bw_data =[]
with open(file_path, mode='r') as file:
for line in file:
if line.startswith('!'):
continue
if line.startswith('X') or line.startswith('W'):
employee_type ='PP' if line.startswith('X') else 'BW'
ssn = line[2:11].strip()
if '611EMS' in line and ssn[-4:] in ssn_eid_map:
eid = ssn_eid_map[ssn[-4:]]
columns =[float(x) for x in line[11:].split()]
if employee_type =='PP':
pp_data.append([
eid, pp_end_dates[1], 'Performances', sum(columns[1:3])
])
else:
bw_data.extend([
[eid, pp_end_dates[1], 'Vacation Used Info', columns[8]],
[eid, pp_end_dates[0], 'Shift Pay City', columns[0]],
[eid, pp_end_dates[1], 'Shift Pay City', columns[4]],
[eid, pp_end_dates[0],'ST Overtime', columns[2]+ columns[3]],
[eid, pp_end_dates[1],'ST Overtime', columns[5]+ columns[6]],
[eid, pp_end_dates[1], 'Docked Pay', columns[7]],
[eid, pp_end_dates[1], 'Medical Used Info', columns[14]],
[eid, pp_end_dates[1], 'Sick Used Info', columns[9]]
])
return pp_data, bw_data
def write_csv(file_name, data):
with open(file_name, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Employee ID', 'End Date', 'Category', 'Hours'])
for row in data:
row[3]= f"{row[3]:.2f}"
writer.writerow(row)
def main():
# Prompt for input values
sdf_file = input("Enter the path to the SDF file: ")
ems_file = input("Enter the path to the EMS file: ")
pp_end_date1= input("Enter the first PP end date (YYYY-MM-DD): ")
pp_end_date2= input("Enter the second PP end date (YYYY-MM-DD): ")
pp_end_dates =[pp_end_date1, pp_end_date2]
# Read SSN to EID mapping
ssn_eid_map = read_ssn_eid_mapping(ems_file)
# Process the SDF file
pp_data, bw_data = process_sdf(sdf_file, ssn_eid_map, pp_end_dates)
# Write output files
pp_file_name = f"611-EMS-PP-{pp_end_dates[1]}.csv"
bw_file_name = f"611-EMS-BW-{pp_end_dates[1]}.csv"
write_csv(pp_file_name, pp_data)
write_csv(bw_file_name, bw_data)
if __name__=="__main__":
main()
Input information:
Enter the path to the SDF file: F:\SDF_Translation\DP611.SDF
Enter the path to the EMS file: F:\SDF_Translation\Dept611EMS\EMS_Person_Number_To_Last5.csv
Enter the first PP end date (YYYY-MM-DD): 2024-05-25
Enter the second PP end date (YYYY-MM-DD): 2024-06-01
The Python script provided aims to automate the translation of data from an input file format (SDF) to specific output formats for per-performance (PP) and regular employees (BW). The script follows detailed instructions regarding data extraction, transformation, and output formatting.
Need to amend the script with a print output folder results in the following format as dated "Outputfloder_(YYYY-MM-DD) and must print the containing the two produced files titled
(611-EMS-PP)=PER-PERF-EMPLOYEES
(611-EMS-bw)=REGULAR-EMPLOYEES

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

More Books

Students also viewed these Databases questions

Question

Analyze the impact of labor unions on health care.

Answered: 1 week ago

Question

Assess three motivational theories as they apply to health care.

Answered: 1 week ago

Question

Discuss the history of U.S. labor unions.

Answered: 1 week ago