Exemplo n.º 1
0
    def read_file_txt(self, all_my_employees):

        with open("test_data_txt.txt", "r") as file:
            data = file.readlines()
            clean = Cleaner()
            val = Validator()
            for line in data:
                valid = True
                emp = line.split(",")

                empid = clean.clean_empid(emp[0])
                if val.val_empid(all_my_employees, empid)[0] == False:
                    valid = False
                    print("empid")

                gender = clean.clean_gender(emp[1])
                if val.val_gender(gender)[0] == False:
                    valid = False
                    print("gender")

                age = clean.Clean_Age(emp[2])
                if val.Validate_Age(age[0])[0] == False:
                    valid = False
                    print("age")

                sales = emp[3]

                bmi = clean.clean_bmi(emp[4])
                if val.val_bmi(bmi)[0] == False:
                    valid = False
                    print("bmi")

                salary = emp[5]

                # there is an issue with the validation of the test data's birthdays
                birthday = clean.Clean_Birthday(emp[6])
                # if val.Validate_Birthday(birthday, age[0]+ 1 )[0]:
                #     pass
                # else:
                #     valid = False
                #     print("birthday")

                if valid != False:
                    employee = Employee(empid, gender, age[0], sales, bmi,
                                        salary, birthday[0])
                    all_my_employees[empid] = employee
                else:
                    print("Failed to add employee")
        return all_my_employees
Exemplo n.º 2
0
    def XML_Reader(self, file_Location, error_File_Location,
                   all_employees):  # Add validate
        MyCleaner = Cleaner()
        my_Employees = {}
        tree = ET.parse(file_Location)
        root = tree.getroot()
        for user in root.findall('user'):
            # Need to Validate all given data
            empid = user.get('EMPID')
            gender = user.find('gender').text
            age = user.find('age').text
            sales = user.find('sales').text
            bmi = user.find('BMI').text
            salary = user.find('salary').text
            birthday = user.find('birthday').text
            #For each item in new Employee need to check that they have a value after being vlaidated
            new_Employee = Employee(MyCleaner.clean_empid(empid),
                                    MyCleaner.clean_gender(gender),
                                    MyCleaner.Clean_Age(age)[0], int(sales),
                                    MyCleaner.clean_bmi(bmi),
                                    int(salary.replace(',', '')),
                                    MyCleaner.Clean_Birthday(birthday)[0])
            my_Employees[new_Employee.my_empid] = new_Employee

            # clean_Data = True
            #
            # for item in [empid, gender, age, sales, bmi, salary, birthday]:
            #     if item[0] == False:
            #         clean_Data = False
            #
            # if(clean_Data):
            #     new_Employee = Employee(MyCleaner.clean_empid(empid), MyCleaner.clean_gender(gender), MyCleaner.Clean_Age(age), MyValidator.Validate_Sales(sales), MyCleaner.clean_bmi(bmi), MyValidator.Validate_Salary(salary), MyCleaner.Clean_Birthday(birthday))
            #     my_Employees[new_Employee.EMPID] = new_Employee
            # else:
            #     #write to errorlogFile
            #     pass

        return my_Employees