Skip to content

How to Use

Charitha Madusanka edited this page Jan 3, 2018 · 1 revision

Data Format

Here is a sample data file describing the players at Steam Sweden community. Edges represent the interactions of players, and the annotated node labels explain whether they are identified as cheater (C) or non-cheater (NC). Format: <Node1 Label> <Node1 Id> <Node2 Label> <Node2 Id>

NC 3162595 NC 4053086
NC 3307239 NC 4244268
NC 1197944 NC 3704039
NC 5981676 NC 4379996
NC 4654595 NC 2174764
NC 3658977 NC 5827812
NC 2483313 NC 2547559
NC 2120163 NC 2196787
NC 2870591 C 1639294
C 2182454 NC 2587586
NC 2483313 NC 2547794
C 2385612 NC 3063061
NC 2483313 NC 3470838
NC 4291980 NC 2382822
NC 3045783 NC 3080882
NC 6051101 NC 3893229
NC 1197944 C 1045880
NC 1546822 NC 2174764
NC 2404559 NC 819806
NC 4053059 NC 2470440
NC 2483313 NC 3287710
NC 7108788 C 5417890
NC 870511 NC 2676192
NC 2804813 NC 5234940

Query Class: using Snap Tables

if __name__ == '__main__':
    context = snap.TTableContext() 

    schema = snap.Schema()
    schema.Add(snap.TStrTAttrPr("srcLabel", snap.atStr))
    schema.Add(snap.TStrTAttrPr("srcId", snap.atInt))
    schema.Add(snap.TStrTAttrPr("dstLabel", snap.atStr))
    schema.Add(snap.TStrTAttrPr("dstId", snap.atInt))

    table = snap.TTable.LoadSS(schema, edgefilename, context, " ", snap.TBool(False))

    edgeattrv = snap.TStrV()
    edgeattrv.Add("srcLabel")
    edgeattrv.Add("dstLabel")

    srcnodeattrv = snap.TStrV()
    srcnodeattrv.Add("srcId")

    dstnodeattrv = snap.TStrV()
    dstnodeattrv.Add("dstId")

    # G will be an object of type snap.PNEANet
    G = snap.ToNetwork(snap.PNEANet, table, "srcId", "dstId", srcnodeattrv, dstnodeattrv, edgeattrv, snap.aaFirst)

    graph = MG.MultiGraph()

    graph.setGraph(G)

    ## Node level attributes
    NodeA = NodeA.NodeAttribute(G)

    ## Edge level attributes
    EdgeA = EdgeA.EdgeAttribute(G)

    graph.walkNodes()

    graph.walkEdges()

    ##### init edge attributes
    attribute_type = 3

    attribute_name = "srcLabel"

    EdgeA.walkGraphEdgeAttributes(attribute_type, attribute_name)

    structure = structure.Structure(G, graphName)

    structure.genGraphInfo()

Query Class: using Panda dataframe

if __name__ == '__main__':
    graph = MG.MultiGraph()
    G = graph.getGraph()

    ## Node level attributes
    NodeA = NodeA.NodeAttribute(G)

    ## Edge level attributes
    EdgeA = EdgeA.EdgeAttribute(G)

    df = pd.read_csv(filename, sep=' ')

    ##### init edge attributes
    attribute_type = 1
    attribute_name = "cheater_label"

    for row in df.itertuples():
        index, srcLabel, srcId, dstLabel, dstId = row
        EId = index
        graph.addNode(int(srcId))
        graph.addNode(int(dstId))
        graph.addEdge(srcId, dstId, EId)
        EAttr = srcLabel + "_" + dstLabel
        EdgeA.setEdgeAttribute(EId, attribute_type, attribute_name, EAttr)

    graph.walkNodes()
    graph.walkEdges()

    EdgeA.walkGraphEdgeAttributes(attribute_type, attribute_name)
Clone this wiki locally