Пример #1
0
 def loadData(self, f):
     '''
     function to load the data from file f into the repository
     :param f: the file
     '''
     corruptFile = False
     for line in f:
         args = line.split(',')
         cur = Route(int(args[0]), args[1], int(args[2]), int(args[3]))
         if cur.isValid() and self.checkUnique(cur):
             self.addRoute(cur)
         else:
             corruptFile = True
     return corruptFile
Пример #2
0
 def loadData(self, f):
     '''
     function to load the data from file f into the repository
     :param f: the file
     '''
     corruptFile = False
     for line in f:
         args = line.split(',')
         cur = Route(int(args[0]), args[1], int(args[2]), int(args[3]))
         if cur.isValid() and self.checkUnique(cur):
             self.addRoute(cur)
         else:
             corruptFile = True
     return corruptFile
Пример #3
0
def poisPorRota(rota, pois, distance):
    pontos_de_rota = polyline.decode(rota['overview_polyline']['points'])

    pois_retorno = []
    for p in pontos_de_rota:
        pois_add = poi.poisInDistance(p, pois, distance)
        for poi_to_add in pois_add:
            if poi_to_add not in pois_retorno:
                pois_retorno.append(poi_to_add)
    return Route(rota, pois_retorno)
Пример #4
0
    def _buildRoute(self, chunk):
        segment_list = []
        try:
            # First/last lines have special formatting. Need to process first
            route_id_line = chunk.pop(0).split(None, 1)
            route_name = route_id_line[0]
            route_desc = route_id_line[1]

            start_line = chunk.pop(0).split(",", 3)
            start = start_line[:3]
            desc = start_line[3]
            route_end = chunk.pop().split(",")
            for l in chunk:
                line = l.split(",", 3)
                end = line[:3]
                segment_list.append(self._buildSegment(start, end, desc))
                start = end
                desc = line[3]
            # build final segment using route end
            segment_list.append(self._buildSegment(start, route_end, desc))
            return Route(route_name, route_desc, segment_list)
        except IndexError:
            raise RouteFormatError("Unable to build route from raw data: " \
            "missing required information in block '{0}'".format(route_id_line[0]))
Пример #5
0
 def test(self):
     x = Route(1,"24b",93,3)
     assert(x.getId() == 1)
     x.setId(2)
     assert(x.getId() == 2)
     assert(x.getRouteCode() == "24b")
     x.setRouteCode("24")
     assert(x.getRouteCode() == "24")
     assert(x.getUsage() == 93)
     x.setUsage(95)
     assert(x.getUsage() == 95)
     assert(x.getBuses() == 3)
     x.setBuses(x.getBuses() + 1)
     assert(x.getBuses() == 4)
     x = Route(1,"24b",93,3)
     repo = Repository()
     repo.add(x)
     assert(repo.getRoutes() == [Route(1,"24b",93,3)])
     y = Route(13,"25",93,7)
     repo.add(y)
     assert(repo.getRoutes() == [Route(1,"24b",93,3), Route(13,"25",93,7)])
     repo.add(y)
     assert(repo.getRoutes() == [Route(1,"24b",93,3), Route(13,"25",93,7), Route(13,"25",93,7)])
Пример #6
0
 def getRouteFromInput(self):
     id = input("Insert id: ")
     rc = input("Insert Route Code: ")
     usage = input("Insert usage percent: ")
     buses = input("Insert the number of buses: ")
     return Route(int(id), rc, int(usage), int(buses))
Пример #7
0
def read():
    data = DataAccess.fetch_all('select * from route', [])
    return jsonify([Route(*a) for a in data])
Пример #8
0
 def test(self):
     x = Route(1, "24b", 93, 3)
     assert (x.getId() == 1)
     x.setId(2)
     assert (x.getId() == 2)
     assert (x.getRouteCode() == "24b")
     x.setRouteCode("24")
     assert (x.getRouteCode() == "24")
     assert (x.getUsage() == 93)
     x.setUsage(95)
     assert (x.getUsage() == 95)
     assert (x.getBuses() == 3)
     x.setBuses(x.getBuses() + 1)
     assert (x.getBuses() == 4)
     x = Route(1, "24b", 93, 3)
     repo = Repository()
     repo.add(x)
     assert (repo.getRoutes() == [Route(1, "24b", 93, 3)])
     y = Route(13, "25", 93, 7)
     repo.add(y)
     assert (repo.getRoutes() == [
         Route(1, "24b", 93, 3),
         Route(13, "25", 93, 7)
     ])
     repo.add(y)
     assert (repo.getRoutes() == [
         Route(1, "24b", 93, 3),
         Route(13, "25", 93, 7),
         Route(13, "25", 93, 7)
     ])