src/graph.py
def aris_distance(self, author_id: int):
        '''
        Gets the shortest distance between author_id and Aris
        Args:
            author_id: The integer id of an author
        Returns:
            A path as a tuple where element 0 is the author id, 
            element 1 is the distance between the author and aris
            and element 2 is the authors name.
            If author_id does not exist on graph it returns None
        '''

        aris_node = None
        # Find Aris
        for node in self.graph.nodes():
            author_name = self.graph.node[node]['data']['author']['name']
            if author_name.lower() == 'aris anagnostopoulos':
                aris_node = node
                break
        if aris_node is None:
            print('Aris not found')
            return None
        distances, prev = self.shortest_path(start=aris_node, finish=author_id, graph=self.graph)
        if prev is not None:
            try:
                prev[author_id]
            except KeyError:
                return None
            path = [(author_id, distances[author_id], self.get_author_name(author_id))]
            control = prev[author_id]
            while control != aris_node:
                aut_name = self.get_author_name(control)
                path.append((control, distances[control], aut_name))
                control = prev[control]
            path.append((aris_node, 0, 'Aris Anagnostopoulos'))
            return path[::-1]
        else:
            return None

        Gets the shortest distance between author_id and Aris
        Args:
            author_id: The integer id of an author
        Returns:
            A path as a tuple where element 0 is the author id, 
            element 1 is the distance between the author and aris
            and element 2 is the authors name.
            If author_id does not exist on graph it returns None
        
Gets the shortest distance between author_id and Aris
Gets the shortest distance between author_id and Aris
def aris_distance(self, author_id: int):
        aris_node = None
        for node in self.graph.nodes():
            author_name = self.graph.node[node]['data']['author']['name']
            if author_name.lower() == 'aris anagnostopoulos':
                aris_node = node
                break
        if aris_node is None:
            print('Aris not found')
            return None
        distances, prev = self.shortest_path(start=aris_node, finish=author_id, graph=self.graph)
        if prev is not None:
            try:
                prev[author_id]
            except KeyError:
                return None
            path = [(author_id, distances[author_id], self.get_author_name(author_id))]
            control = prev[author_id]
            while control != aris_node:
                aut_name = self.get_author_name(control)
                path.append((control, distances[control], aut_name))
                control = prev[control]
            path.append((aris_node, 0, 'Aris Anagnostopoulos'))
            return path[::-1]
        else:
            return None
def aris_distance ( self , author_id : int ) : aris_node = None for node in self . graph . nodes ( ) : author_name = self . graph . node [ node ] [ 'data' ] [ 'author' ] [ 'name' ] if author_name . lower ( ) == 'aris anagnostopoulos' : aris_node = node break if aris_node is None : print ( 'Aris not found' ) return None distances , prev = self . shortest_path ( start = aris_node , finish = author_id , graph = self . graph ) if prev is not None : try : prev [ author_id ] except KeyError : return None path = [ ( author_id , distances [ author_id ] , self . get_author_name ( author_id ) ) ] control = prev [ author_id ] while control != aris_node : aut_name = self . get_author_name ( control ) path . append ( ( control , distances [ control ] , aut_name ) ) control = prev [ control ] path . append ( ( aris_node , 0 , 'Aris Anagnostopoulos' ) ) return path [ : : - 1 ] else : return None
Gets the shortest distance between author_id and Aris
Gets the shortest distance between author_id and Aris
'''
        Gets the shortest distance between author_id and Aris
        Args:
            author_id: The integer id of an author
        Returns:
            A path as a tuple where element 0 is the author id, 
            element 1 is the distance between the author and aris
            and element 2 is the authors name.
            If author_id does not exist on graph it returns None
        ''' # Find Aris
A path as a tuple where element 0 is the author id,
element 1 is the distance between the author and aris
and element 2 is the authors name.
If author_id does not exist on graph it returns None
A path as a tuple where element 0 is the author id element 1 is the distance between the author and aris and element 2 is the authors name . If author_id does not exist on graph it returns None
self
author_id
int
The integer id of an author
The integer id of an author