コード例 #1
0
    def update_parameters(self):

        print "Updating parameters"

        nodefile = self.nodes.get()
        edgefile = self.edges.get()
        debug = self.debugVar.get()
        if debug == 'True':
            debug = True
        else:
            debug = False

        hive = Hive(debug=debug)
        properties = list(hive.get_nodes(nodefile).keys()) + assignmentOptions
        self.assignmentVar = self.reset_option_menu(self.assignmentOpt,
                                                    self.assignmentVar,
                                                    properties,
                                                    index=2)

        properties = list(hive.get_nodes(nodefile).keys()) + positionOptions
        self.positionVar = self.reset_option_menu(self.positionOpt,
                                                  self.positionVar, properties)

        properties = list(hive.get_edges(edgefile)) + edgeStyleOptions
        self.edgeStyleVar = self.reset_option_menu(self.edgeStyleOpt,
                                                   self.edgeStyleVar,
                                                   properties)
コード例 #2
0
ファイル: gui.py プロジェクト: LeastAction/HivePlotter
    def update_parameters(self):
        nodefile = self.nodes.get()
        edgefile = self.edges.get()
        
        hive = Hive(debug = False)
        properties = list(hive.get_nodes(nodefile).keys()) + assignmentOptions
        self.assignmentVar = self.reset_option_menu(self.assignmentOpt, self.assignmentVar, properties, index = 2) 
        
        properties = list(hive.get_nodes(nodefile).keys()) + positionOptions
        self.positionVar = self.reset_option_menu(self.positionOpt, self.positionVar, properties) 

        properties = list(hive.get_edges(edgefile)) + edgeStyleOptions
        self.edgeStyleVar = self.reset_option_menu(self.edgeStyleOpt, self.edgeStyleVar, properties)
コード例 #3
0
    def update_parameters(self):
        
        print "Updating parameters"
        
        nodefile = self.nodes.get()
        edgefile = self.edges.get()
        debug = self.debugVar.get()
        if debug == 'True':
            debug = True
        else: 
            debug = False
        
        hive = Hive(debug = debug)
        properties = list(hive.get_nodes(nodefile).keys()) + assignmentOptions
        self.assignmentVar = self.reset_option_menu(self.assignmentOpt, self.assignmentVar, properties, index = 2) 
        
        properties = list(hive.get_nodes(nodefile).keys()) + positionOptions
        self.positionVar = self.reset_option_menu(self.positionOpt, self.positionVar, properties) 

        properties = list(hive.get_edges(edgefile)) + edgeStyleOptions
        self.edgeStyleVar = self.reset_option_menu(self.edgeStyleOpt, self.edgeStyleVar, properties)
コード例 #4
0
class TestHive(unittest.TestCase):
    def setUp(self):
        #example hive
        self.emptyhive = Hive(debug = False)
        self.friendsHive = Hive(debug = False)
        self.friendsHiveDouble = Hive(debug = False, doubleAxes = True)
        nodefile = _root_dir + '/tests/test_nodes_friends.csv'
        edgefile = _root_dir + '/tests/test_edges_friends.csv'

        self.friendsHive.get_nodes(nodefile)
        self.friendsHive.get_edges(edgefile)
        self.friendsHiveDouble.get_nodes(nodefile)
        self.friendsHiveDouble.get_edges(edgefile)
        
        self.friendsNodesValuesInt = {'Alice': 4, 'Eric': 2, 'Daniella': 2, 'Fatima': 3, 'Cam': 3, 'Bob': 4, 'George': 2}
        self.friendsNodesValuesFloat = {'Daniella': 0.8, 'George': 0.9, 'Fatima': 0, 'Cam': 0.9, 'Bob': 0.2, 'Alice': 1.9, 'Eric': 1.6}
        self.friendsNodesValuesString = {'Daniella': 'girl', 'George': 'alien', 'Fatima': 'girl', 'Cam': 'boy', 'Bob': 'boy', 'Alice': 'girl', 'Eric': 'boy'}
        
        self.numAxesOptions = [(True, 2), (True, 3), (False, 5), (False, 4), (False, 3), (False, 2)]
        self.axesOptions = {(False,2):[0,pi], (False,3):[0, pi*2/3, pi*4/3], (False,4):[0,pi/2,pi,pi*3/2], (False,5):[0,pi*2/5,pi*4/5,pi*6/5,pi*8/5], (True,2):[-pi/6,pi/6,pi*5/6,pi*7/6], (True,3):[-pi/9,pi/9,pi*5/9,pi*7/9,pi*11/9,pi*13/9]}
        
        self.rules = [(),2,'degree', 'clustering', 'closeness', 'centrality', 'betweeness','average neighbor degree']

    def test_make_axes(self):
        hive = self.emptyhive
        for (doubleAxes, numAxes), angles in self.axesOptions.iteritems():
            hive.doubleAxes = doubleAxes
            hive.numAxes = numAxes
            hive.make_axes()
            angles = [0.0001 if a == 0 else round(a,2) for a in angles]
            self.assertListEqual(angles, hive.angles)

    def test_get_assignment_values(self):
        hive = self.friendsHive
        values = hive.get_assignment_values(1)
        correctValues = {'Daniella': 'girl', 'George': 'alien', 'Fatima': 'girl', 'Cam': 'boy', 'Bob': 'boy', 'Alice': 'girl', 'Eric': 'boy'}
        self.assertEqual(values, correctValues)

        hive = self.friendsHiveDouble
        values = hive.get_assignment_values(1)
        correctValues = {'Eric.2': 'boy', 'Cam.2': 'boy', 'Cam.1': 'boy', 'Daniella.1': 'girl', 'Daniella.2': 'girl', 'George.2': 'alien', 'Fatima.2': 'girl', 'Fatima.1': 'girl', 'Eric.1': 'boy', 'Alice.1': 'girl', 'Alice.2': 'girl', 'Bob.2': 'boy', 'George.1': 'alien', 'Bob.1': 'boy'}
        self.assertEqual(values, correctValues)
        
        hive = self.friendsHive
        values = hive.get_assignment_values(2)
        correctValues = {'Daniella': 0.8, 'George': 0.9, 'Fatima': 0, 'Cam': 0.9, 'Bob': 0.2, 'Alice': 1.9, 'Eric': 1.6}
        self.assertEqual(values, correctValues)
        
        hive = self.friendsHiveDouble
        values = hive.get_assignment_values(2)
        correctValues = {'Eric.2': 1.6, 'Cam.2': 0.9, 'Cam.1': 0.9, 'Daniella.1': 0.8, 'Daniella.2': 0.8, 'George.2': 0.9, 'Fatima.2': 0, 'Fatima.1': 0, 'Eric.1': 1.6, 'Alice.1': 1.9, 'Alice.2': 1.9, 'Bob.2': 0.2, 'George.1': 0.9, 'Bob.1': 0.2}
        self.assertEqual(values, correctValues)
        
        hive = self.friendsHive
        values = hive.get_assignment_values('degree')
        correctValues = {'Alice': 4, 'Eric': 2, 'Daniella': 2, 'Fatima': 3, 'Cam': 3, 'Bob': 4, 'George': 2}
        self.assertEqual(values, correctValues)     

        hive = self.friendsHiveDouble
        values = hive.get_assignment_values('degree')
        correctValues = {'Bob.1': 4, 'Cam.2': 3, 'Cam.1': 3, 'Daniella.1': 2, 'Daniella.2': 2, 'George.2': 2, 'Fatima.2': 3, 'Fatima.1': 3, 'Bob.2': 4, 'Alice.1': 4, 'Alice.2': 4, 'Eric.1': 2, 'George.1': 2, 'Eric.2': 2}
        self.assertEqual(values, correctValues)  

    def test_node_assignment(self):
        hive = self.friendsHive
        for (double,numAxes),assignmentValues in zip(self.numAxesOptions,(self.friendsNodesValuesString, self.friendsNodesValuesInt, self.friendsNodesValuesFloat)):
            hive.numAxes = numAxes
            hive.doubleAxes = double
            hive.node_assignment(assignmentValues = assignmentValues)
            assignment = hive.axisAssignment
            #now we check that the axis assignment variable 
            #is a dictionary
            self.assertIsInstance(assignment, dict)
            #has an entry for every node
            self.assertEqual(set(assignment.keys()), set(hive.nodes))
            #that the values are integers corresponding to axes numbers
            [self.assertIsInstance(v,int) for v in assignment.values()]
コード例 #5
0
def main(*argv):
    '''handles user input and runs plsa'''
    parser = argparse.ArgumentParser(
        description=
        'This scripts produces hive plots given user data without the use of the gui.'
    )
    parser.add_argument('-t', help='Title of hive plot', default=gui.TITLE)
    parser.add_argument('-n', help='The node file', default=gui.NODES)
    parser.add_argument('-e', help='The edge file', default=gui.EDGES)
    parser.add_argument('-path',
                        help='Path where hive plot will be saved',
                        default=TEMP_FOLDER)
    parser.add_argument('-axes', help='Number of axes', type=int)
    parser.add_argument('-double',
                        help='Doubles the number of axes',
                        action='store_true')
    parser.add_argument('-assignment', help=assignmentHelp)
    parser.add_argument('-position', help=positionHelp)
    parser.add_argument('-size',
                        help='Size of hive plot: big or small',
                        default='small')
    parser.add_argument('-nodecolor', help='Color of nodes', default='purple')
    parser.add_argument('-edgestyle', help=edgeStyleHelp)
    parser.add_argument('-palette', help=paletteHelp, default='purple')
    parser.add_argument('-numcolors',
                        help='The number of colors to use to style edges',
                        default=1)
    parser.add_argument('-open',
                        help='Open the hive plot in the browser',
                        action='store_true')
    parser.add_argument('-debug',
                        help='Print verbatim to debug',
                        action='store_true')
    parser.add_argument('-properties',
                        help='Shows properties that can be used to plot hives',
                        action='store_true')
    args = parser.parse_args()

    if (args.n == '' and args.e != '') or (args.n != '' and args.e == ''):
        print "\n***You must specify both a node and an edge file if specifying either.***\n"
        parser.print_help()
        sys.exit()

    title = args.t
    nodeFile = args.n
    edgeFile = args.e
    axes = args.axes
    double = args.double
    assignment = args.assignment
    position = args.position
    size = gui_options.sizes[args.size]
    nodeColor = args.nodecolor
    edgeStyle = args.edgestyle
    numColors = args.numcolors
    palette = gui_utilities.get_palette(args.palette, int(numColors))
    open = args.open
    debug = args.debug
    folder = args.path

    if args.properties:
        hive = Hive(debug=debug)
        properties = list(
            hive.get_nodes(nodeFile).keys()) + gui_options.assignmentOptions
        print '\nNode properties:\n\t"' + '", "'.join(properties) + '"\n'
        properties = list(
            hive.get_edges(edgeFile)) + gui_options.edgeStyleOptions
        print 'Edge properties:\n\t"' + '", "'.join(properties) + '"\n'
        sys.exit()
    else:
        if not axes:
            print "You must specify a number of axes"
            sys.exit()
        if not assignment:
            print "You must specify a node assignment rule"
            sys.exit()
        if not position:
            print "You must specify a node position rule"
            sys.exit()

    hive = Hive(debug=debug,
                numAxes=axes,
                doubleAxes=double,
                axisAssignRule=assignment,
                axisPositRule=position,
                edgePalette=palette,
                edgeStyleRule=edgeStyle,
                nodeColor=nodeColor)
    hive.make_hive(nodeFile, edgeFile)

    rules = {}
    rules['assignment'] = assignment
    rules['position'] = position
    rules['edges'] = edgeStyle

    url = make_html(title, hive, size, rules=rules, folder=folder)

    if open:
        webbrowser.open("file://" + url, new=1)
コード例 #6
0
class TestHive(unittest.TestCase):
    def setUp(self):
        #example hive
        self.emptyhive = Hive(debug=False)
        self.friendsHive = Hive(debug=False)
        self.friendsHiveDouble = Hive(debug=False, doubleAxes=True)
        nodefile = _root_dir + '/tests/test_nodes_friends.csv'
        edgefile = _root_dir + '/tests/test_edges_friends.csv'

        self.friendsHive.get_nodes(nodefile)
        self.friendsHive.get_edges(edgefile)
        self.friendsHiveDouble.get_nodes(nodefile)
        self.friendsHiveDouble.get_edges(edgefile)

        self.friendsNodesValuesInt = {
            'Alice': 4,
            'Eric': 2,
            'Daniella': 2,
            'Fatima': 3,
            'Cam': 3,
            'Bob': 4,
            'George': 2
        }
        self.friendsNodesValuesFloat = {
            'Daniella': 0.8,
            'George': 0.9,
            'Fatima': 0,
            'Cam': 0.9,
            'Bob': 0.2,
            'Alice': 1.9,
            'Eric': 1.6
        }
        self.friendsNodesValuesString = {
            'Daniella': 'girl',
            'George': 'alien',
            'Fatima': 'girl',
            'Cam': 'boy',
            'Bob': 'boy',
            'Alice': 'girl',
            'Eric': 'boy'
        }

        self.numAxesOptions = [(True, 2), (True, 3), (False, 5), (False, 4),
                               (False, 3), (False, 2)]
        self.axesOptions = {
            (False, 2): [0, pi],
            (False, 3): [0, pi * 2 / 3, pi * 4 / 3],
            (False, 4): [0, pi / 2, pi, pi * 3 / 2],
            (False, 5): [0, pi * 2 / 5, pi * 4 / 5, pi * 6 / 5, pi * 8 / 5],
            (True, 2): [-pi / 6, pi / 6, pi * 5 / 6, pi * 7 / 6],
            (True, 3): [
                -pi / 9, pi / 9, pi * 5 / 9, pi * 7 / 9, pi * 11 / 9,
                pi * 13 / 9
            ]
        }

        self.rules = [(), 2, 'degree', 'clustering', 'closeness', 'centrality',
                      'betweeness', 'average neighbor degree']

    def test_make_axes(self):
        hive = self.emptyhive
        for (doubleAxes, numAxes), angles in self.axesOptions.iteritems():
            hive.doubleAxes = doubleAxes
            hive.numAxes = numAxes
            hive.make_axes()
            angles = [0.0001 if a == 0 else round(a, 2) for a in angles]
            self.assertListEqual(angles, hive.angles)

    def test_get_assignment_values(self):
        hive = self.friendsHive
        values = hive.get_assignment_values(1)
        correctValues = {
            'Daniella': 'girl',
            'George': 'alien',
            'Fatima': 'girl',
            'Cam': 'boy',
            'Bob': 'boy',
            'Alice': 'girl',
            'Eric': 'boy'
        }
        self.assertEqual(values, correctValues)

        hive = self.friendsHiveDouble
        values = hive.get_assignment_values(1)
        correctValues = {
            'Eric.2': 'boy',
            'Cam.2': 'boy',
            'Cam.1': 'boy',
            'Daniella.1': 'girl',
            'Daniella.2': 'girl',
            'George.2': 'alien',
            'Fatima.2': 'girl',
            'Fatima.1': 'girl',
            'Eric.1': 'boy',
            'Alice.1': 'girl',
            'Alice.2': 'girl',
            'Bob.2': 'boy',
            'George.1': 'alien',
            'Bob.1': 'boy'
        }
        self.assertEqual(values, correctValues)

        hive = self.friendsHive
        values = hive.get_assignment_values(2)
        correctValues = {
            'Daniella': 0.8,
            'George': 0.9,
            'Fatima': 0,
            'Cam': 0.9,
            'Bob': 0.2,
            'Alice': 1.9,
            'Eric': 1.6
        }
        self.assertEqual(values, correctValues)

        hive = self.friendsHiveDouble
        values = hive.get_assignment_values(2)
        correctValues = {
            'Eric.2': 1.6,
            'Cam.2': 0.9,
            'Cam.1': 0.9,
            'Daniella.1': 0.8,
            'Daniella.2': 0.8,
            'George.2': 0.9,
            'Fatima.2': 0,
            'Fatima.1': 0,
            'Eric.1': 1.6,
            'Alice.1': 1.9,
            'Alice.2': 1.9,
            'Bob.2': 0.2,
            'George.1': 0.9,
            'Bob.1': 0.2
        }
        self.assertEqual(values, correctValues)

        hive = self.friendsHive
        values = hive.get_assignment_values('degree')
        correctValues = {
            'Alice': 4,
            'Eric': 2,
            'Daniella': 2,
            'Fatima': 3,
            'Cam': 3,
            'Bob': 4,
            'George': 2
        }
        self.assertEqual(values, correctValues)

        hive = self.friendsHiveDouble
        values = hive.get_assignment_values('degree')
        correctValues = {
            'Bob.1': 4,
            'Cam.2': 3,
            'Cam.1': 3,
            'Daniella.1': 2,
            'Daniella.2': 2,
            'George.2': 2,
            'Fatima.2': 3,
            'Fatima.1': 3,
            'Bob.2': 4,
            'Alice.1': 4,
            'Alice.2': 4,
            'Eric.1': 2,
            'George.1': 2,
            'Eric.2': 2
        }
        self.assertEqual(values, correctValues)

    def test_node_assignment(self):
        hive = self.friendsHive
        for (double, numAxes), assignmentValues in zip(
                self.numAxesOptions,
            (self.friendsNodesValuesString, self.friendsNodesValuesInt,
             self.friendsNodesValuesFloat)):
            hive.numAxes = numAxes
            hive.doubleAxes = double
            hive.node_assignment(assignmentValues=assignmentValues)
            assignment = hive.axisAssignment
            #now we check that the axis assignment variable
            #is a dictionary
            self.assertIsInstance(assignment, dict)
            #has an entry for every node
            self.assertEqual(set(assignment.keys()), set(hive.nodes))
            #that the values are integers corresponding to axes numbers
            [self.assertIsInstance(v, int) for v in assignment.values()]