Ejemplo n.º 1
0
    grapher = RetweetGrapher()
    grapher.save_metadata()
    grapher.start()

    if DRY_RUN:
        grapher.counter = 7500
        grapher.results = [{
            "ts": "2020-01-01 10:00:00",
            "counter": 2500,
            "nodes": 100_000,
            "edges": 150_000
        }, {
            "ts": "2020-01-01 10:00:00",
            "counter": 5000,
            "nodes": 200_000,
            "edges": 400_000
        }, {
            "ts": "2020-01-01 10:00:00",
            "counter": 7500,
            "nodes": 300_000,
            "edges": 900_000
        }]
        grapher.graph = compile_mock_rt_graph()
    else:
        grapher.perform()

    grapher.end()
    grapher.report()
    grapher.save_results()
    grapher.save_graph()
Ejemplo n.º 2
0
        print("-------------------")
        print(type(self.graph))
        print("  NODES:", fmt_n(self.node_count))
        print("  EDGES:", fmt_n(self.edge_count))
        print("  FILE SIZE:", fmt_n(file_size))
        print("-------------------")

        return {
            "nodes": self.node_count,
            "edges": self.edge_count,
            "file_size": file_size
        }

    #@property
    #def graph_metadata(self):
    #    return {"nodes": self.node_count, "edges": self.edge_count}


if __name__ == "__main__":

    storage = GraphStorage()

    if DRY_RUN:
        storage.graph = compile_mock_rt_graph()
        storage.report()
        storage.write_graph_to_file()
        storage.graph = None

    storage.load_graph()
    storage.report()
Ejemplo n.º 3
0
def test_link_energy_nonactivation():
    #
    # setup
    #
    graph = compile_mock_rt_graph([
        # add some examples of users retweeting others:
        {
            "user_screen_name": "user1",
            "retweet_user_screen_name": "leader1",
            "retweet_count": 4
        },
        {
            "user_screen_name": "user2",
            "retweet_user_screen_name": "leader1",
            "retweet_count": 6
        },
        {
            "user_screen_name": "user3",
            "retweet_user_screen_name": "leader2",
            "retweet_count": 4
        },
        {
            "user_screen_name": "user4",
            "retweet_user_screen_name": "leader2",
            "retweet_count": 2
        },
        {
            "user_screen_name": "user5",
            "retweet_user_screen_name": "leader3",
            "retweet_count": 4
        },
        # add some examples of users retweeting eachother:
        {
            "user_screen_name": "colead1",
            "retweet_user_screen_name": "colead2",
            "retweet_count": 3
        },
        {
            "user_screen_name": "colead2",
            "retweet_user_screen_name": "colead1",
            "retweet_count": 2
        },
        {
            "user_screen_name": "colead3",
            "retweet_user_screen_name": "colead4",
            "retweet_count": 1
        },
        {
            "user_screen_name": "colead4",
            "retweet_user_screen_name": "colead3",
            "retweet_count": 4
        }
    ])
    in_degrees = dict(
        graph.in_degree(weight="rt_count"))  # users receiving retweets
    out_degrees = dict(
        graph.out_degree(weight="rt_count"))  # users doing the retweeting
    assert in_degrees == {
        'user1': 0,
        'leader1': 10.0,
        'user2': 0,
        'user3': 0,
        'leader2': 6.0,
        'user4': 0,
        'user5': 0,
        'leader3': 4.0,
        'colead1': 2.0,
        'colead2': 3.0,
        'colead3': 4.0,
        'colead4': 1.0
    }
    assert out_degrees == {
        'user1': 4.0,
        'leader1': 0,
        'user2': 6.0,
        'user3': 4.0,
        'leader2': 0,
        'user4': 2.0,
        'user5': 4.0,
        'leader3': 0,
        'colead1': 3.0,
        'colead2': 2.0,
        'colead3': 1.0,
        'colead4': 4.0
    }

    #
    # w/o sufficient number of retweets, given default hyperparams, not enough to activate, energy is zero
    #
    energy = compute_link_energy('colead1',
                                 'colead2',
                                 3.0,
                                 in_degrees,
                                 out_degrees,
                                 alpha=[1, 100, 100])
    assert energy == [0.0, 0.0, 0.0, 0.0]
    assert sum(energy) == 0

    #
    # w/ sufficient number of retweets, given different hyperparams, energy is positive
    #
    energy = compute_link_energy('colead1',
                                 'colead2',
                                 3.0,
                                 in_degrees,
                                 out_degrees,
                                 alpha=[1, 10, 10])
    assert energy == [
        0.01676872682112003, 0.027947878035200054, 0.01120709909211522,
        0.022358302428160046
    ]
    assert sum(energy) > 0