def addTracking(trip: dict, DataBase: dict) -> None: bikeID = int(trip["bikeid"]) tracking: map = DataBase['tracking'] startDate = datetime.strptime(trip["starttime"], '%Y-%m-%d %H:%M:%S.%f') if not map.contains(tracking, bikeID): element = Structure.newBike() map.put(tracking, bikeID, element) DataBase['bikes'] += 1 bike = map.get(tracking, bikeID) bike = mapentry.getValue(bike) if not map.contains(bike, startDate.date()): element = Structure.newDate() map.put(bike, startDate.date(), element) date = map.get(bike, startDate.date()) date = mapentry.getValue(date) date['useTime'] += int(trip["tripduration"]) date['stopTime'] -= int(trip["tripduration"]) if list.isPresent(date['stations'], trip["start station name"]) == 0: list.addLast(date['stations'], trip["start station name"]) if list.isPresent(date['stations'], trip['end station name']) == 0: list.addLast(date['stations'], trip['end station name'])
def bikeTracking(dataBase, bikeID, date): tracking = Structure.newDate() if map.contains(dataBase['tracking'], bikeID): bike = map.get(dataBase['tracking'], bikeID) bike = mapentry.getValue(bike) if map.contains(bike, date): tracking = map.get(bike, date) tracking = mapentry.getValue(tracking) return tracking
def addStation(type: int, trip: dict, DataBase: dict) -> None: types = ('start station ', 'end station ') station = Structure.newStation() id = int(trip[types[type] + 'id']) station['name'] = trip[types[type] + 'name'] station['latitude'] = trip[types[type] + 'latitude'] station['longitude'] = trip[types[type] + 'longitude'] map.put(DataBase['station'], id, station) graph.insertVertex(DataBase['graph'], id)
def updateRoute(trip: dict, DataBase: dict) -> None: startId = int(trip["start station id"]) endId = int(trip["end station id"]) tripTime = int(trip["tripduration"]) edgeRoute = graph.getEdge(DataBase['graph'], startId, endId) if edgeRoute is None: weight = Structure.newWeight() graph.addEdge(DataBase['graph'], startId, endId, weight) edgeRoute = graph.getEdge(DataBase['graph'], startId, endId) weight = edge.weight(edgeRoute) weight['time'] = aveTime(weight, tripTime) weight['users'] += 1
def getTargetEdge(trip: dict, DataBase: dict) -> edge: startId = int(trip["start station id"]) endId = int(trip["end station id"]) target = selectTarget(trip) if not (map.contains(DataBase['target'], target)): targetGraph = Structure.newTargetGraph() map.put(DataBase['target'], target, targetGraph) targetGraph = mapentry.getValue(map.get(DataBase['target'], target)) if not (graph.containsVertex(targetGraph, startId)): graph.insertVertex(targetGraph, startId) if not (graph.containsVertex(targetGraph, endId)): graph.insertVertex(targetGraph, endId) edgeRoute = graph.getEdge(targetGraph, startId, endId) if edgeRoute is None: graph.addEdge(targetGraph, startId, endId, 0) edgeRoute = graph.getEdge(targetGraph, startId, endId) return edgeRoute
def initDataBase() -> dict: return Structure.initDataBase()
def initTracking(dataBase): Structure.initTracking(dataBase)