def calcTripEffort(self): trip_time = 0 trip_effort = 0 pos = self.getPos() for elem in self.__trip_route: if Graph.queryTravelCost(pos, elem.getZoneID()) != 0: trip_effort = trip_effort + Graph.queryTravelCost( pos, elem.getZoneID()) else: trip_effort += 0.5 trip_time = trip_time + Graph.queryTravelCost( pos, elem.getZoneID()) elem.setEventTime(Driver.timestamp + trip_time) if elem.getEvent() == DROPOFF: rider = self.__riders[elem.getRiderID()] rider.setArrivalTimestamp(Driver.timestamp + trip_time) rider.calcDetourTime( trip_time ) #detour time is b/w the rerquest accepted and arrive at destination. pos = elem.getZoneID() if trip_effort < 0: self.__logger.warning(Driver.timestamp, "calcTripEffort", self.getID(), None, "Trip effort value is unresonable ") raise Exception("Trip effort value is unresonable ") else: self.__trip_effort += trip_effort
def test_add_node_to_graph(self): graph = Graph() graph.add_node("Actor", "Ann Hathaway", [], 2019) self.assertEqual(len(graph.nodes), 1) self.assertEqual(graph.nodes[0].group, "Actor") self.assertEqual(graph.nodes[0].name, "Ann Hathaway") self.assertEqual(graph.nodes[0].year, 2019)
def test_add_node_to_graph(self): graph = Graph() graph.add_node("Movie", "Princess Diaries", [], 2019) self.assertEqual(len(graph.nodes), 1) self.assertEqual(graph.nodes[0].group, "Movie") self.assertEqual(graph.nodes[0].name, "Princess Diaries") self.assertEqual(graph.nodes[0].year, 2019)
def test_add_edge_to_graph(self): graph = Graph() graph.add_edge("Ann Hathaway", "Princess Diaries", 100) self.assertEqual(len(graph.edges), 1) self.assertEqual(graph.edges[0].movie, "Princess Diaries") self.assertEqual(graph.edges[0].actor, "Ann Hathaway") self.assertEqual(graph.edges[0].weight, 100)
def testGraphAddEdge(self): """ Tests adding an edge """ graph = Graph() graph.parseFile(TESTFILE) tmp_movie = Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford") tmp_actor = Actors("Freeman Blah", 80, "BlahBlah") graph.add_movie(tmp_movie) graph.add_actor(tmp_actor) graph.add_edge(Edges(tmp_actor.name, tmp_movie.name, 222759050.0))
def __init__(self, uID, sT, sZ, dZ, dP, pat, srcX, srcY, destX, destY): # logger in Dispatcher self.__logger = Logger('Rider') #self.__logger.setLevel(logging.DEBUG) self.__logger.info(Rider.timestamp, "__INIT__", None, None, "Create A Rider Object") self.__id = uID self.__request_timestamp = sT self.__srcZone = sZ self.__destZone = dZ self.__default_price = dP self.__price = math.inf self.__patience = pat self.__dirID = self.__assignDirID(srcX, srcY, destX, destY) self.__shortest_time = Graph.queryTravelCost(sZ, dZ) self.__arrival_timestamp = None self.__groupID = None self.__status = WAITING self.__wait_time = 0 self.__detour_time = -1 self.__sat = 0 if self.__default_price > 100: self.__logger.warning(Rider.timestamp, "__INIT__", None, self.getID(), str(self))
def testGraphAddActor(self): """ Tests adding actor vertex """ graph = Graph() graph.parseFile(TESTFILE) graph.add_actor(Actors("Freeman Blah", 80, "BlahBlah"))
def testGetMoviesForActor(self): """ Tests getting films an actor has acted in """ graph = Graph() graph.parseFile(TESTFILE) graph.get_movies_for_actor("Faye Dunaway")
def testGraphAddMovie(self): """ Tests adding movie vertex """ graph = Graph() graph.parseFile(TESTFILE) graph.add_movie( Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford"))
def test_query_3(self): graph = Graph() edges = [] edge = graph.add_edge("Ann Hathaway", "Princess Diaries", 100) edges.append(edge) graph.add_node("Movie", "Princess Diaries", edges, 2019) self.assertEqual( len(graph.get_list_of_movies_from_actor("Ann Hathaway")), 1) self.assertEqual( graph.get_list_of_movies_from_actor("Ann Hathaway")[0], "Princess Diaries")
def test_query_2(self): graph = Graph() edges = [] edge = graph.add_edge("Ann Hathaway", "Princess Diaries", 100) edges.append(edge) graph.add_node("Movie", "Princess Diaries", edges, 2019) self.assertEqual(len(graph.edges), 1) self.assertEqual(graph.edges[0].weight, 100) self.assertEqual(graph.get_movie_gross("Princess Diaries"), 100)
def testMovieGross(self): """ Tests how much a movie grossed at Box Office """ graph = Graph() graph.parseFile(TESTFILE) tmp_movie = Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford") tmp_actor = Actors("Freeman Blah", 80, "BlahBlah") graph.add_movie(tmp_movie) graph.add_actor(tmp_actor) graph.add_edge(Edges(tmp_actor.name, tmp_movie.name, 222759050.0)) graph.get_movie_gross("The Thomas Crown Affair")
def testOldestActors(self): """ Tests finding oldest X actors """ graph = Graph() graph.parseFile(TESTFILE) tmp_movie = Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford") tmp_actor = Actors("Freeman Blah", 78, "BlahBlah") graph.add_movie(tmp_movie) graph.add_actor(tmp_actor) graph.add_edge(Edges(tmp_actor.name, tmp_movie.name, 222759050.0)) graph.find_oldest_actors(2)
def test_weight_sum_helper(self): graph = Graph() n = graph.weight_sum_helper(10) self.assertEqual(n, 55)
def testGraphExtract(self): """ Tests extraction from Json file and structure of Graph """ graph = Graph() graph.parseFile(TESTFILE)
def testHighestGrossing(self): """ Tests finding highest grossing X actors """ graph = Graph() graph.parseFile(TESTFILE) tmp_movie = Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford") tmp_actor = Actors("Freeman Blah", 80, "BlahBlah") graph.add_movie(tmp_movie) graph.add_actor(tmp_actor) graph.add_edge(Edges(tmp_actor.name, tmp_movie.name, 222759050.0)) graph.find_highest_grossing_actors(5)
def testQueryTravelCost(self): self.assertEqual(1, Graph.queryTravelCost(7, 6)) self.assertEqual(3, Graph.queryTravelCost(7, 19)) self.assertEqual(3, Graph.queryTravelCost(8, 30)) self.assertEqual(1, Graph.queryTravelCost(7, 6)) self.assertEqual(0, Graph.queryTravelCost(6, 6))
def testGetMoviesForYear(self): """ Tests getting movies for given year """ graph = Graph() graph.parseFile(TESTFILE) tmp_movie = Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford") tmp_actor = Actors("Freeman Blah", 80, "BlahBlah") graph.add_movie(tmp_movie) graph.add_actor(tmp_actor) graph.add_edge(Edges(tmp_actor.name, tmp_movie.name, 222759050.0)) graph.get_movies_for_year("1980")
def testMovieActors(self): """ Tests finding actors who acted in a given movie """ graph = Graph() graph.parseFile(TESTFILE) tmp_movie = Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford") tmp_actor = Actors("Freeman Blah", 80, "BlahBlah") graph.add_movie(tmp_movie) graph.add_actor(tmp_actor) graph.add_edge(Edges(tmp_actor.name, tmp_movie.name, 222759050.0)) graph.get_actors_for_movie("The Arrangement")
""" Tests finding oldest X actors """ graph = Graph() graph.parseFile(TESTFILE) tmp_movie = Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford") tmp_actor = Actors("Freeman Blah", 78, "BlahBlah") graph.add_movie(tmp_movie) graph.add_actor(tmp_actor) graph.add_edge(Edges(tmp_actor.name, tmp_movie.name, 222759050.0)) graph.find_oldest_actors(2) if __name__ == "__main__": #unittest.main() graph = Graph() graph.parseFile(TESTFILE) tmp_movie = Movies("BlahBlah", "1980", "$121,890,708", "Robert Redford") tmp_actor = Actors("Freeman Blah", 78, "BlahBlah") graph.add_movie(tmp_movie) graph.add_actor(tmp_actor) graph.add_edge(Edges(tmp_actor.name, tmp_movie.name, 222759050.0)) graph.get_movies_for_actor("Faye Dunaway") graph.get_movies_for_year("1980") graph.get_movie_actors_for_year("1980") graph.get_actors_for_movie("The Thomas Crown Affair") graph.get_movie_gross("The Thomas Crown Affair") graph.find_highest_grossing_actors(5) graph.find_oldest_actors(2)