Пример #1
0
 def test_11(self):
     e = ElementMaker.create_cartesian_layout_element(1, 1200, 1.11, 2.22, 3.33)
     self.assertEquals(e.get_name(), CxConstants.CARTESIAN_LAYOUT)
     d = e.get_data()
     self.assertEquals(d['view'], 1200)
     self.assertEquals(d['node'], 1)
     self.assertEquals(d['x'], 1.11)
     self.assertEquals(d['y'], 2.22)
     self.assertEquals(d['z'], 3.33)
Пример #2
0
 def test_11(self):
     e = ElementMaker.create_cartesian_layout_element(
         1, 1200, 1.11, 2.22, 3.33)
     self.assertEquals(e.get_name(), CxConstants.CARTESIAN_LAYOUT)
     d = e.get_data()
     self.assertEquals(d['view'], 1200)
     self.assertEquals(d['node'], 1)
     self.assertEquals(d['x'], 1.11)
     self.assertEquals(d['y'], 2.22)
     self.assertEquals(d['z'], 3.33)
Пример #3
0
    def test_x(self):
        n1 = ElementMaker.create_nodes_aspect_element(1, 'node 1', 'N1')
        n2 = ElementMaker.create_nodes_aspect_element(2, 'node 2', 'N2')
        e = ElementMaker.create_edges_aspect_element(3, 1, 2, '1->2')
        nea = ElementMaker.create_network_attributes_aspect_element(
            1200, 'size', 12.3, CxConstants.DATA_TYPE_DOUBLE)
        noa = ElementMaker.create_node_attributes_aspect_element(
            1200, 1, 'weight', '12.0', CxConstants.DATA_TYPE_DOUBLE)
        eda = ElementMaker.create_edge_attributes_aspect_element(
            1200, 3, 'length', 303.409883, CxConstants.DATA_TYPE_DOUBLE)
        neal = ElementMaker.create_network_attributes_aspect_element(
            1200, 'used', ['true', 'false'],
            CxConstants.DATA_TYPE_LIST_OF_BOOLEAN)
        noal = ElementMaker.create_node_attributes_aspect_element(
            1200, 1, 'weights', ['1.1', '2.2'],
            CxConstants.DATA_TYPE_LIST_OF_DOUBLE)
        edal = ElementMaker.create_edge_attributes_aspect_element(
            1200, 3, 'lengths', ['23.3', '13.34'],
            CxConstants.DATA_TYPE_LIST_OF_DOUBLE)

        ha = ElementMaker.create_hidden_attributes_aspect_element(
            1200, 'size', 12.3, CxConstants.DATA_TYPE_DOUBLE)
        hal = ElementMaker.create_hidden_attributes_aspect_element(
            1200, 'used', ['true', 'false'],
            CxConstants.DATA_TYPE_LIST_OF_BOOLEAN)

        c1 = ElementMaker.create_cartesian_layout_element(
            1, 2000, 100.11, 200.22, 3.33)
        c2 = ElementMaker.create_cartesian_layout_element(
            2, 2000, -100.11, -200.22)
        sn = ElementMaker.create_sub_networks_aspect_element(1200, [1, 2], [3])
        v = ElementMaker.create_views_aspect_element(2000, 1200)
        g = ElementMaker.create_groups_aspect_element(555, 1200, 'group 1',
                                                      [1, 2], [3], [3])
        nr1 = ElementMaker.create_network_relations_aspect_element(
            1200, 3000, 'subnetwork', 'child 1200')
        nr2 = ElementMaker.create_network_relations_aspect_element(
            2000, 1200, 'view', 'view 2000')
        tc = ElementMaker.create_table_column_aspect_element(
            1200, 'node table', 'weight', CxConstants.DATA_TYPE_INTEGER)

        properties = {
            "NODE_BORDER_PAINT": "#CCCCCC",
            "NODE_BORDER_STROKE": "SOLID",
            "NODE_BORDER_TRANSPARENCY": "255"
        }
        dependencies = {
            "nodeCustomGraphicsSizeSync": "true",
            "nodeSizeLocked": "false"
        }
        mappings = {
            "NODE_LABEL": {
                "type": "PASSTHROUGH",
                "definition": "COL=name,T=string"
            }
        }

        vp = ElementMaker.create_visual_properties_aspect_element(
            "nodes:default", 1, 1200, properties, dependencies, mappings)

        prmd = ElementMaker.create_pre_metadata_element(
            'nodes', 1, 'v2.2', 1234567, [], 2)
        pomd1 = ElementMaker.create_post_metadata_element('nodes', 2)
        pomd2 = ElementMaker.create_post_metadata_element('edges', 1)

        fo = io.StringIO('')

        w = CxWriter(fo)

        w.add_pre_meta_data([prmd])

        w.start()

        w.start_aspect_fragment(CxConstants.NODES)
        w.write_aspect_element(n1)
        w.write_aspect_element(n2)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.EDGES)
        w.write_aspect_element(e)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.CARTESIAN_LAYOUT)
        w.write_aspect_element(c1)
        w.write_aspect_element(c2)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.NETWORK_ATTRIBUTES)
        w.write_aspect_element(nea)
        w.write_aspect_element(neal)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.NODE_ATTRIBUTES)
        w.write_aspect_element(noa)
        w.write_aspect_element(noal)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.EDGE_ATTRIBUTES)
        w.write_aspect_element(eda)
        w.write_aspect_element(edal)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.HIDDEN_ATTRIBUTES)
        w.write_aspect_element(ha)
        w.write_aspect_element(hal)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.SUB_NETWORKS)
        w.write_aspect_element(sn)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.VIEWS)
        w.write_aspect_element(v)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.GROUPS)
        w.write_aspect_element(g)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.NETWORK_RELATIONS)
        w.write_aspect_element(nr1)
        w.write_aspect_element(nr2)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.TABLE_COLUMN)
        w.write_aspect_element(tc)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.VISUAL_PROPERTIES)
        w.write_aspect_element(vp)
        w.end_aspect_fragment()

        w.add_post_meta_data([pomd1, pomd2])

        w.end(True, "no error")

        json_str = fo.getvalue()
        print(json_str)

        # READING

        fi = io.StringIO(json_str)

        cx_reader = CxReader(fi)

        self.assertEquals(len(cx_reader.get_pre_meta_data()), 1)

        cx = cx_reader.parse_as_dictionary()

        self.assertEquals(cx_reader.get_error_msg(), "no error")
        self.assertEquals(cx_reader.get_is_success(), True)

        self.assertEquals(len(cx_reader.get_post_meta_data()), 2)

        self.assertEquals(len(cx[CxConstants.NODES]), 2)
        self.assertEquals(len(cx[CxConstants.EDGES]), 1)
        self.assertEquals(len(cx[CxConstants.CARTESIAN_LAYOUT]), 2)
        self.assertEquals(len(cx[CxConstants.NODE_ATTRIBUTES]), 2)
        self.assertEquals(len(cx[CxConstants.EDGE_ATTRIBUTES]), 2)
        self.assertEquals(len(cx[CxConstants.NETWORK_ATTRIBUTES]), 2)
        self.assertEquals(len(cx[CxConstants.HIDDEN_ATTRIBUTES]), 2)
        self.assertEquals(len(cx[CxConstants.SUB_NETWORKS]), 1)
        self.assertEquals(len(cx[CxConstants.VIEWS]), 1)
        self.assertEquals(len(cx[CxConstants.GROUPS]), 1)
        self.assertEquals(len(cx[CxConstants.NETWORK_RELATIONS]), 2)
        self.assertEquals(len(cx[CxConstants.TABLE_COLUMN]), 1)
        self.assertEquals(len(cx[CxConstants.VISUAL_PROPERTIES]), 1)

        sn2 = cx[CxConstants.SUB_NETWORKS][0]
        self.assertEquals(sn2.get_name(), CxConstants.SUB_NETWORKS)
        d = sn2.get_data()
        self.assertEquals(d['@id'], 1200)
        self.assertEquals(d['nodes'][0], 1)
        self.assertEquals(d['nodes'][1], 2)
        self.assertEquals(d['edges'][0], 3)

        v2 = cx[CxConstants.VIEWS][0]
        self.assertEquals(v2.get_name(), CxConstants.VIEWS)
        d = v2.get_data()
        self.assertEquals(d['@id'], 2000)
        self.assertEquals(d['s'], 1200)

        g2 = cx[CxConstants.GROUPS][0]
        self.assertEquals(g2.get_name(), CxConstants.GROUPS)
        d = g2.get_data()
        self.assertEquals(d['@id'], 555)
        self.assertEquals(d['name'], 'group 1')
        self.assertEquals(d['view'], 1200)
        self.assertEquals(len(d['internal_edges']), 1)
        self.assertEquals(len(d['external_edges']), 1)
        self.assertEquals(len(d['nodes']), 2)
        self.assertEquals(d['internal_edges'][0], 3)
        self.assertEquals(d['nodes'][0], 1)
        self.assertEquals(d['nodes'][1], 2)

        nr2 = cx[CxConstants.NETWORK_RELATIONS][0]
        self.assertEquals(nr2.get_name(), CxConstants.NETWORK_RELATIONS)
        d = nr2.get_data()
        self.assertEquals(d['c'], 1200)
        self.assertEquals(d['p'], 3000)
        self.assertEquals(d['r'], 'subnetwork')
        self.assertEquals(d['name'], 'child 1200')
Пример #4
0
 def emit_cx_cartesian_layout_element(self, node_id, view_id, x, y, z=None):
     self.__process_element(
         ElementMaker.create_cartesian_layout_element(node_id, view_id, x, y, z))
Пример #5
0
    def test_x(self):
        n1 = ElementMaker.create_nodes_aspect_element(1, 'node 1', 'N1')
        n2 = ElementMaker.create_nodes_aspect_element(2, 'node 2', 'N2')
        e = ElementMaker.create_edges_aspect_element(3, 1, 2, '1->2')
        nea = ElementMaker.create_network_attributes_aspect_element(1200, 'size', 12.3, CxConstants.DATA_TYPE_DOUBLE)
        noa = ElementMaker.create_node_attributes_aspect_element(1200, 1, 'weight', '12.0',
                                                                 CxConstants.DATA_TYPE_DOUBLE)
        eda = ElementMaker.create_edge_attributes_aspect_element(1200, 3, 'length', 303.409883,
                                                                 CxConstants.DATA_TYPE_DOUBLE)
        neal = ElementMaker.create_network_attributes_aspect_element(1200, 'used', ['true', 'false'],
                                                                     CxConstants.DATA_TYPE_LIST_OF_BOOLEAN)
        noal = ElementMaker.create_node_attributes_aspect_element(1200, 1, 'weights', ['1.1', '2.2'],
                                                                  CxConstants.DATA_TYPE_LIST_OF_DOUBLE)
        edal = ElementMaker.create_edge_attributes_aspect_element(1200, 3, 'lengths', ['23.3', '13.34'],
                                                                  CxConstants.DATA_TYPE_LIST_OF_DOUBLE)

        ha = ElementMaker.create_hidden_attributes_aspect_element(1200, 'size', 12.3, CxConstants.DATA_TYPE_DOUBLE)
        hal = ElementMaker.create_hidden_attributes_aspect_element(1200, 'used', ['true', 'false'],
                                                                   CxConstants.DATA_TYPE_LIST_OF_BOOLEAN)

        c1 = ElementMaker.create_cartesian_layout_element(1, 2000, 100.11, 200.22, 3.33)
        c2 = ElementMaker.create_cartesian_layout_element(2, 2000, -100.11, -200.22)
        sn = ElementMaker.create_sub_networks_aspect_element(1200, [1, 2], [3])
        v = ElementMaker.create_views_aspect_element(2000, 1200)
        g = ElementMaker.create_groups_aspect_element(555, 1200, 'group 1', [1, 2], [3], [3])
        nr1 = ElementMaker.create_network_relations_aspect_element(1200, 3000, 'subnetwork', 'child 1200')
        nr2 = ElementMaker.create_network_relations_aspect_element(2000, 1200, 'view', 'view 2000')
        tc = ElementMaker.create_table_column_aspect_element(1200, 'node table', 'weight',
                                                             CxConstants.DATA_TYPE_INTEGER)

        properties = {"NODE_BORDER_PAINT": "#CCCCCC",
                      "NODE_BORDER_STROKE": "SOLID",
                      "NODE_BORDER_TRANSPARENCY": "255"}
        dependencies = {"nodeCustomGraphicsSizeSync": "true",
                        "nodeSizeLocked": "false"}
        mappings = {"NODE_LABEL": {
            "type": "PASSTHROUGH",
            "definition": "COL=name,T=string"}}

        vp = ElementMaker.create_visual_properties_aspect_element("nodes:default", 1, 1200, properties, dependencies,
                                                                  mappings)

        prmd = ElementMaker.create_pre_metadata_element('nodes', 1, 'v2.2', 1234567, [], 2)
        pomd1 = ElementMaker.create_post_metadata_element('nodes', 2)
        pomd2 = ElementMaker.create_post_metadata_element('edges', 1)

        fo = io.StringIO('')

        w = CxWriter(fo)

        w.add_pre_meta_data([prmd])

        w.start()

        w.start_aspect_fragment(CxConstants.NODES)
        w.write_aspect_element(n1)
        w.write_aspect_element(n2)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.EDGES)
        w.write_aspect_element(e)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.CARTESIAN_LAYOUT)
        w.write_aspect_element(c1)
        w.write_aspect_element(c2)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.NETWORK_ATTRIBUTES)
        w.write_aspect_element(nea)
        w.write_aspect_element(neal)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.NODE_ATTRIBUTES)
        w.write_aspect_element(noa)
        w.write_aspect_element(noal)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.EDGE_ATTRIBUTES)
        w.write_aspect_element(eda)
        w.write_aspect_element(edal)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.HIDDEN_ATTRIBUTES)
        w.write_aspect_element(ha)
        w.write_aspect_element(hal)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.SUB_NETWORKS)
        w.write_aspect_element(sn)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.VIEWS)
        w.write_aspect_element(v)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.GROUPS)
        w.write_aspect_element(g)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.NETWORK_RELATIONS)
        w.write_aspect_element(nr1)
        w.write_aspect_element(nr2)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.TABLE_COLUMN)
        w.write_aspect_element(tc)
        w.end_aspect_fragment()

        w.start_aspect_fragment(CxConstants.VISUAL_PROPERTIES)
        w.write_aspect_element(vp)
        w.end_aspect_fragment()

        w.add_post_meta_data([pomd1, pomd2])

        w.end(True, "no error")

        json_str = fo.getvalue()
        print(json_str)

        # READING

        fi = io.StringIO(json_str)

        cx_reader = CxReader(fi)

        self.assertEquals(len(cx_reader.get_pre_meta_data()), 1)

        cx = cx_reader.parse_as_dictionary()

        self.assertEquals(cx_reader.get_error_msg(), "no error")
        self.assertEquals(cx_reader.get_is_success(), True)

        self.assertEquals(len(cx_reader.get_post_meta_data()), 2)

        self.assertEquals(len(cx[CxConstants.NODES]), 2)
        self.assertEquals(len(cx[CxConstants.EDGES]), 1)
        self.assertEquals(len(cx[CxConstants.CARTESIAN_LAYOUT]), 2)
        self.assertEquals(len(cx[CxConstants.NODE_ATTRIBUTES]), 2)
        self.assertEquals(len(cx[CxConstants.EDGE_ATTRIBUTES]), 2)
        self.assertEquals(len(cx[CxConstants.NETWORK_ATTRIBUTES]), 2)
        self.assertEquals(len(cx[CxConstants.HIDDEN_ATTRIBUTES]), 2)
        self.assertEquals(len(cx[CxConstants.SUB_NETWORKS]), 1)
        self.assertEquals(len(cx[CxConstants.VIEWS]), 1)
        self.assertEquals(len(cx[CxConstants.GROUPS]), 1)
        self.assertEquals(len(cx[CxConstants.NETWORK_RELATIONS]), 2)
        self.assertEquals(len(cx[CxConstants.TABLE_COLUMN]), 1)
        self.assertEquals(len(cx[CxConstants.VISUAL_PROPERTIES]), 1)

        sn2 = cx[CxConstants.SUB_NETWORKS][0]
        self.assertEquals(sn2.get_name(), CxConstants.SUB_NETWORKS)
        d = sn2.get_data()
        self.assertEquals(d['@id'], 1200)
        self.assertEquals(d['nodes'][0], 1)
        self.assertEquals(d['nodes'][1], 2)
        self.assertEquals(d['edges'][0], 3)

        v2 = cx[CxConstants.VIEWS][0]
        self.assertEquals(v2.get_name(), CxConstants.VIEWS)
        d = v2.get_data()
        self.assertEquals(d['@id'], 2000)
        self.assertEquals(d['s'], 1200)

        g2 = cx[CxConstants.GROUPS][0]
        self.assertEquals(g2.get_name(), CxConstants.GROUPS)
        d = g2.get_data()
        self.assertEquals(d['@id'], 555)
        self.assertEquals(d['name'], 'group 1')
        self.assertEquals(d['view'], 1200)
        self.assertEquals(len(d['internal_edges']), 1)
        self.assertEquals(len(d['external_edges']), 1)
        self.assertEquals(len(d['nodes']), 2)
        self.assertEquals(d['internal_edges'][0], 3)
        self.assertEquals(d['nodes'][0], 1)
        self.assertEquals(d['nodes'][1], 2)

        nr2 = cx[CxConstants.NETWORK_RELATIONS][0]
        self.assertEquals(nr2.get_name(), CxConstants.NETWORK_RELATIONS)
        d = nr2.get_data()
        self.assertEquals(d['c'], 1200)
        self.assertEquals(d['p'], 3000)
        self.assertEquals(d['r'], 'subnetwork')
        self.assertEquals(d['name'], 'child 1200')
Пример #6
0
 def emit_cx_cartesian_layout_element(self, node_id, view_id, x, y, z=None):
     self.__process_element(
         ElementMaker.create_cartesian_layout_element(
             node_id, view_id, x, y, z))