Esempio n. 1
0
class Controller:
    file = PrintClass()
    chart = ChartMaker()

    @staticmethod
    def load_file(infile):
        r"""
        >>> Controller.load_file("C:\\Users\Luna\ICT\python\\uml.csv")
        Incorrect file type, please check with help load
        >>> Controller.load_file("test.docx")
        True
        >>> Controller.load_file("test.txt")
        True
        >>> Controller.load_file("C:\\Users\Luna\ICT\\uml.docx")
        File is not found
        """
        try:
            if path.isfile(infile):
                if ".txt" in infile[-4:] or ".docx" in infile[-5:]:
                    Controller.file.class_handler(infile)
                    return True
                else:
                    raise NameError

            else:
                raise FileNotFoundError

        except NameError:
            print("Incorrect file type, please check with help load")
        except FileNotFoundError:
            print("File is not found")
        except Exception as e:
            print(e)

    def save_file(self, file_location):
        try:
            if path.exists(file_location):
                self.file.output_classes(file_location)
            else:
                raise FileNotFoundError
        except FileNotFoundError:
            print("No such directory")
        except Exception as e:
            print(e)

    def create_bar_chart(self):
        all_num = self.file.get_all_num()
        if all_num == [0, 0, 0]:
            return False
        else:
            self.chart.create_bar_chart(all_num)

    def create_pie_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_pie_chart(all_num)

    def create_line_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_line_graph(all_num)
Esempio n. 2
0
class Controller:
    file = PrintClass()
    chart = ChartMaker()

    @staticmethod
    def load_file(infile):
        r"""
        >>> Controller.load_file("test_read_file.csv")
        Incorrect file type, please see help load
        >>> Controller.load_file("test.docx")
        The PlantUML file is loaded
        [['class ToyBox {\n', '}\n'], ['class Toy {\n', '}\n']]
        >>> Controller.load_file("test.txt")
        The PlantUML file is loaded
        [['class ToyBox {\n', '}\n'], ['class Toy {\n', '}\n']]
        >>> Controller.load_file("C:\\Users\Luna\ICT\\test2.docx")
        File is not found
        """
        try:
            if ".txt" in infile[-4:] or ".docx" in infile[-5:]:
                Controller.file.class_handler(infile)
                content = Controller.file.class_list
                print("The PlantUML file is loaded")
                return content

            else:
                message = "Incorrect file type, please see help load"
                raise NameError(message)

        except NameError as e:
            print(e)
        except FileNotFoundError:
            print("File is not found")
        except Exception as e:
            print(e)

    def save_file(self, file_location):
        self.file.output_classes(file_location)

    def create_bar_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_bar_chart(all_num)

    def create_pie_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_pie_chart(all_num)

    def create_line_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_line_graph(all_num)
Esempio n. 3
0
class Controller:
    file = FileReader()
    chart = ChartMaker()

    @staticmethod
    def load_file(infile):
        try:
            if path.isfile(infile):
                if ".txt" in infile[-4:] or ".docx" in infile[-5:]:
                    Controller.file.class_handler(infile)
                    Controller.file.find_classes()
                    return True
                else:
                    raise NameError

            else:
                raise FileNotFoundError

        except NameError:
            print("Incorrect file type, please check with help load")
        except FileNotFoundError:
            print("File is not found")
        except Exception as e:
            print(e)

    def save_file(self, file_location):
        try:
            if path.exists(file_location):
                self.file.output_file(file_location)
                print("created")
            else:
                raise FileNotFoundError
        except FileNotFoundError:
            print("No such directory")
        except Exception as e:
            print(e)

    @staticmethod
    def get_chart_data():
        class_num = len(Controller.file.all_my_classes)
        attribute_num = 0
        method_num = 0
        for x in Controller.file.all_my_classes:
            attribute_num += x.get_attribute_length()
            method_num += x.get_method_length()
        data = [class_num, attribute_num, method_num]
        return data

    def create_bar_chart(self):
        data = self.get_chart_data()
        if data == [0, 0, 0]:
            return False
        else:
            self.chart.create_bar_chart(data)

    def create_pie_chart(self):
        data = self.get_chart_data()
        self.chart.create_pie_chart(data)

    def create_line_chart(self):
        data = self.get_chart_data()
        self.chart.create_line_graph(data)
Esempio n. 4
0
class Controller:
    f = Filer()
    v = Validator()
    db = EmployeeDatabase()
    chart = ChartMaker()
    gd = GetData()

    # Jono's
    def load_file(self, file):
        try:
            if ".csv" in file[-4:]:
                content = self.f.read_csv(file)
            elif ".xlsx" in file[-5:]:
                content = self.f.read_excel(file)
            elif ".txt" in file[-4:]:
                content = self.f.read_txt(file)
            else:
                message = "incorrect format please see help load"
                raise NameError(message)
            validated_employees = self.validate_items(content)
            return validated_employees
        except NameError as e:
            print(e)
        except FileNotFoundError:
            print("File not found")
        except Exception as e:
            print(e)

    def validate_items(self, content):
        valid_employees = []
        invalid_employees = []
        for employee in content:
            item = self.v.validate_all(employee)
            if False in item:
                invalid_employees.append(employee)
            else:
                valid_employees.append(employee)
            emp = {'Valid': valid_employees, 'Invalid': invalid_employees}
        return emp

    def add_to_database(self, content_list):
        for item in content_list:
            self.gd.insert_employee(item)

    def get_all_employees(self):
        try:
            employees = self.gd.get_all_employee()
            if len(employees) > 0:
                return employees
            else:
                raise IndexError
        except IndexError:
            print("No employees in database")
        except Exception as e:
            print(e)

    # renee
    def print_chart_average(self):
        ave_sales = self.gd.get_ave_sales()
        ave_salary = self.gd.get_ave_salary()
        self.chart.make_bar_average(ave_sales, ave_salary)

    def print_chart_sales(self):
        employees = self.gd.get_all_employee()
        self.chart.make_bar_sales(employees)

    def print_chart_pie(self):
        employees = self.gd.get_all_employee()
        self.chart.make_pie(employees)

    def print_chart_line(self):
        employees = self.gd.get_all_employee()
        self.chart.make_line(employees)

    # Chami
    def save_file(self, file_format, employee_list):
        """
        # Chami -- added 19-03-2018
        >>> Controller.save_file('test1.txt', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991'],['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: save_file() missing 1 required positional argument: 'employee_list'

        >>> Controller.save_file('test1.txt',)
        Traceback (most recent call last):
        TypeError: save_file() missing 2 required positional arguments: 'file_format' and 'employee_list'

        >>> Controller.save_file()
        Traceback (most recent call last):
        TypeError: save_file() missing 3 required positional arguments: 'self', 'file_format', and 'employee_list'

        >>> Controller.save_file('test1.txt', [[],[]])
        Traceback (most recent call last):
        TypeError: save_file() missing 1 required positional argument: 'employee_list'

        >>> Controller.save_file('test1.txt', [[,[]])
        Traceback (most recent call last):
        SyntaxError: invalid syntax

        >>> Controller.save_file('test1.txt', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        >>> Controller.save_file(' ', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        >>> Controller.save_file(' .csv', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        >>> Controller.save_file('test1.', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        >>> Controller.save_file('.txt', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        >>> Controller.save_file('.xlsx', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        >>> Controller.save_file('.', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        >>> Controller.save_file(' .xlsx', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        >>> Controller.save_file('.xxx', [['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']['A001', 'M', '26', '200', 'Normal', '20', '08-10-1991']])
        Traceback (most recent call last):
        TypeError: list indices must be integers or slices, not tuple

        """
        try:
            if ".csv" in file_format:
                self.f.save_csv(file_format, employee_list)
            elif ".xlsx" in file_format:
                self.f.save_excel(file_format, employee_list)
            elif ".txt" in file_format:
                self.f.save_txt_file(file_format, employee_list)
            else:
                raise NameError("can not save that file type")
        except NameError as e:
            print(e)
        # except exception part needed

    def save_invalid(self, invalid_employees):
        try:
            self.f.save_txt_file("invalid.csv", invalid_employees)
        except:
            print("Whoops something went wrong")
Esempio n. 5
0
 def create_line_chart(self):
     chart = ChartMaker(LineGraphMaker())
     chart.draw(self.file.get_all_num())
Esempio n. 6
0
 def create_pie_chart(self):
     chart = ChartMaker(PieChartMaker())
     chart.draw(self.file.get_all_num())
Esempio n. 7
0
 def create_bar_chart(self):
     chart = ChartMaker(BarChartMaker())
     chart.draw(self.file.get_all_num())
 def __init__(self):
     self.cf = CSVFactory()
     self.f = Filer()
     self.v = Validator()
     self.db = EmployeeDatabase()
     self.chart = ChartMaker()