Exemplo n.º 1
0
 def getActorAge(self, actorNodes, actorName):
     for node in actorNodes:
         if (ActorNode.getName(node) == actorName):
             if ActorNode.getAge(node) == '2017':
                 return 'Died'
             else:
                 return ActorNode.getAge(node)
Exemplo n.º 2
0
 def getOldestActor(self, actorNodes):
     maxAge = 0
     act = ''
     for node in actorNodes:
         if (int(ActorNode.getAge(node)) > maxAge):
             maxAge = int(ActorNode.getAge(node))
             act = ActorNode.getName(node)
     return act
Exemplo n.º 3
0
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')
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
 def addActor(self, actorNodes, actorNameDict, actorName, age):
     node = ActorNode(actorName, None, str(2017 - age))
     actorNodes.append(node)
     actorNameDict['actorName'] = actorName
Exemplo n.º 6
0
 def removeActor(self, actorNodes, actorNameDict, actorName):
     for node in actorNodes:
         if ActorNode.getName(node) == actorName:
             actorNodes.remove(node)
             actorNameDict.pop(actorName)
Exemplo n.º 7
0
 def getOtherActors(self, actorNodes, actorName):
     ret = []
     for node in actorNodes:
         if ActorNode.getName(node).find(actorName) == -1:
             ret.append(ActorNode.getName(node))
     return ret
Exemplo n.º 8
0
 def getAllActorsInYear(self, actorNodes, year):
     ret = []
     for node in actorNodes:
         if ActorNode.getYear(node) == str(year):
             ret.append(ActorNode.getName(node))
     return ret