def getMaxBoxOfficeFilm(self, filmNodes): maxVal = 0 act = '' for node in filmNodes: if (float(FilmNode.getValue(node)) > maxVal): maxVal = float(FilmNode.getValue(node)) act = FilmNode.getName(node) return act
def show_age_gross_relation(): ret = {} for film in InitGraph.filmNodes: if film is not None: value = FilmNode.getValue(film) name = FilmNode.getName(film) actors = GraphQuery.getActorsInFilm(GraphQuery(), InitGraph.filmNameDict, name) for actor in actors: if actor is not None: for node in InitGraph.actorNodes: if ActorNode.getName(node) == actor: ret[ActorNode.getAge(node)] = value trace = go.Pie(labels=list(ret.keys()), values=list(ret.values())) py.plot([trace], filename='basic_pie_chart')
def show_actor_earnings(): ret = {} for film in InitGraph.filmNodes: if film is not None: value = float(FilmNode.getValue(film)) name = FilmNode.getName(film) actors = GraphQuery.getActorsInFilm(GraphQuery(), InitGraph.filmNameDict, name) for actor in actors: if actor is not None: if ret.get(actor) is None: ret[actor] = 0.0 ret[actor] += value labels = list(ret.keys()) values = list(ret.values()) trace = go.Pie(labels=labels, values=values) py.plot([trace], filename='basic_pie_chart')
class InitGraph: ## set up all the film/actor nodes as Dictionary: ## key: url, value: film/actor node ## store the edges as a list with starting node of actor and ending node as movie filmNodes = [] actorNodes = [] filmNameDict = {} actorNameDict = {} edges = [] nodes = {} hub = {} #parse a json file with open( '/Users/Jenny/Desktop/cs242/Assignment2.0/Scraper/Scraper/quotes.json', 'r') as content_file: content = content_file.read() data = json.loads(content) for i in range(len(data)): temp = data[i] name = None edge = None ## when we discover the current index of the json file is an actor if temp['isActor'] == True: node = ActorNode(temp['actorName'], temp['url'], temp['year']) nodes[temp['url']] = node actorNodes.append(node) actorNameDict[temp['actorName']] = [] for cast in temp['castings']: for ch in cast: actorNameDict[temp['actorName']].append(ch) for url in temp['films']: if nodes.get(url) is not None: edge = Edge(node, nodes.get(url)) ## when we discover the current index of the json file is a film elif temp['isFilm'] == True: node = FilmNode(temp['filmName'], temp['url'], temp['year'], temp['filmValue']) nodes[temp['url']] = node filmNodes.append(node) filmNameDict[temp['filmName']] = temp['starrings'] for url in temp['actors']: if nodes.get(url) is not None: edge = Edge(nodes.get(url), node) if edge is not None: edges.append(edge)
def getFilmValue(self, filmNodes, filmName): for node in filmNodes: if (FilmNode.getName(node) == filmName): return FilmNode.getValue(node)
def addFilm(self, filmNodes, filmNameDict, filmName, value): node = FilmNode(filmName, None, None, str(value)) filmNodes.append(node) filmNameDict['filmName'] = filmName
def removeFilm(self, filmNodes, filmNameDict, filmName): for node in filmNodes: if FilmNode.getName(node) == filmName: filmNodes.remove(node) filmNameDict.pop(filmName)
def getOtherFilms(self, filmNodes, filmName): ret = [] for node in filmNodes: if FilmNode.getName(node).find(filmName) == -1: ret.append(FilmNode.getName(node)) return ret
def getAllFilmsInYear(self, filmNodes, year): ret = [] for node in filmNodes: if FilmNode.getYear(node) == str(year): ret.append(FilmNode.getName(node)) return ret