Exemplo n.º 1
0
    def test_paths_error3(self):
        xs = [
            {
                'city_from': 'A',
                'city_to': 'B',
                'time1': 1
            },
        ]

        cities = [
            {
                'name': 'A',
                'x': 0,
                'y': 0,
                'quantity': 10
            },
            {
                'name': 'B',
                'x': 1,
                'y': 0,
                'quantity': 10
            },
        ]

        cities = pd.DataFrame(cities, columns=['name', 'x', 'y', 'quantity'])
        df = pd.DataFrame(xs, columns=['city_from', 'city_to', 'time1'])

        result: Result = validate_paths(df, cities)
        assert not result.status
        assert 'wrong columns' in result.msg.lower()
Exemplo n.º 2
0
    def upload_coordinates(content, name):
        if content is not None:
            if '.csv' not in name:
                return html.Div(['Only .csv files ar supported!']),
            df = parse_contents(content)
            result = fh.validate_paths(df)
            if not result.status:
                return html.P(result.msg),

            return comp.upload_table(name, df),
        return None,
Exemplo n.º 3
0
    def upload_paths(content, cities, name):
        if content:
            if '.csv' not in name:
                return html.Div(comp.error('Only .csv files ar supported!')),

            df = parse_contents(content)
            cities = parse_contents(cities)
            result = fh.validate_paths(df, cities)
            if not result.status:
                return comp.error(result.msg)

            return comp.upload_table(name, df)
        return [None]
Exemplo n.º 4
0
    def test_paths_ok_city_numbers(self):
        xs = [
            {
                'city_from': 1,
                'city_to': 2,
                'travel_time': 1
            },
            {
                'city_from': 2,
                'city_to': 3,
                'travel_time': 1
            },
        ]

        cities = [
            {
                'name': 1,
                'x': 0,
                'y': 0,
                'quantity': 10
            },
            {
                'name': 2,
                'x': 1,
                'y': 0,
                'quantity': 10
            },
            {
                'name': 3,
                'x': 2,
                'y': 0,
                'quantity': 10
            },
        ]

        cities = pd.DataFrame(cities, columns=['name', 'x', 'y', 'quantity'])
        df = pd.DataFrame(xs, columns=['city_from', 'city_to', 'travel_time'])

        result: Result = validate_paths(df, cities)
        assert result.status
        assert result.msg.lower() == 'success'
Exemplo n.º 5
0
    def test_paths_error4(self):
        xs = [
            {
                'city_from': 'A',
                'city_to': 'B',
                'travel_time': 1
            },
            {
                'city_from': 'A',
                'city_to': 'C',
                'travel_time': 1
            },
            {
                'city_from': 'A',
                'city_to': 'D',
                'travel_time': 1
            },
            {
                'city_from': 'A',
                'city_to': 'E',
                'travel_time': 1
            },
            {
                'city_from': 'A',
                'city_to': 'F',
                'travel_time': 1
            },
        ]

        cities = [
            {
                'name': 'A',
                'x': 0,
                'y': 0,
                'quantity': 10
            },
            {
                'name': 'B',
                'x': 1,
                'y': 0,
                'quantity': 10
            },
            {
                'name': 'C',
                'x': 2,
                'y': 0,
                'quantity': 10
            },
            {
                'name': 'D',
                'x': 3,
                'y': 0,
                'quantity': 10
            },
            {
                'name': 'E',
                'x': 4,
                'y': 0,
                'quantity': 10
            },
            {
                'name': 'F',
                'x': 5,
                'y': 0,
                'quantity': 10
            },
        ]

        cities = pd.DataFrame(cities, columns=['name', 'x', 'y', 'quantity'])
        df = pd.DataFrame(xs, columns=['city_from', 'city_to', 'travel_time'])

        result: Result = validate_paths(df, cities)
        assert not result.status
        assert 'more than 4' in result.msg.lower()