Exemplo n.º 1
0
    try:
        db = client[config.get("mongo", "database")]
        user_col = db["users"]
        user_col.create_index([('user.id', pymongo.ASCENDING)], unique=True)
        user_col.create_index([('user.screen_name', pymongo.ASCENDING)])
    except NoOptionError:
        logging.critical(
            "Cannot connect to MongoDB database and collection. Config incorrect?"
        )
        sys.exit()

    # Get the tweet collection
    tweet_col = db[config.get("mongo", "collection")]

    cursor = tweet_col.find({'geo': {'$ne': None}, 'locinf.sl.test': None})
    infersl = InferSL(config, user_col, verbose=True)

    for tweet in cursor:
        print("\n\nNEXT USER", tweet['user']['screen_name'], ":\n")

        if input(tweet) == "s":
            continue

        inf = infersl.infer(tweet['user']['id'], test=True)

        print("\nInferred location:", inf)
        input(">")

        # Store inferred loc in db
        db.tweets.update_one({'_id': tweet['_id']},
                             {'$set': {
Exemplo n.º 2
0
    client = MongoClient(config.get("mongo", "address"), config.getint("mongo", "port"))
    logging.info("Connected to MongoDB")

    # select the database and collection based off config
    try:
        db = client[config.get("mongo", "database")]
        collection = db["users"]
        collection.create_index([('user.id', pymongo.ASCENDING)], unique=True)
        collection.create_index([('user.screen_name', pymongo.ASCENDING)])
    except NoOptionError:
        logging.critical("Cannot connect to MongoDB database and collection. Config incorrect?")
        sys.exit()

    user_test = int(input("Target user ID (eg 434500083):"))

    infersl = InferSL(config, collection, verbose=True)

    #input(infersl.infer(user_test))

    netw = infersl.get_network(user_test, hidegeo=True)

    net_users, net_connections = netw.users, netw.connections

    colors = {}
    ground_truth = {}
    true_users = {}
    target_user = {}
    for id, u in net_users.items():
        if len(u.get('locations', [])) > 0:
            locc = [p['coordinates'] for p in u.get('locations')]
            ground_truth[str(u['user']['id'])] = geometric_mean(locc)
Exemplo n.º 3
0
    # Select the database and collection based off config
    try:
        db = client[config.get("mongo", "database")]
        user_col = db["users"]
        user_col.create_index([('user.id', pymongo.ASCENDING)], unique=True)
        user_col.create_index([('user.screen_name', pymongo.ASCENDING)])
    except NoOptionError:
        logging.critical("Cannot connect to MongoDB database and collection. Config incorrect?")
        sys.exit()

    # Get the tweet collection
    tweet_col = db[config.get("mongo", "collection")]

    cursor = tweet_col.find({'geo': {'$ne': None}, 'locinf.sl.test': None})
    infersl = InferSL(config, user_col, verbose=True)

    for tweet in cursor:
        print("\n\nNEXT USER", tweet['user']['screen_name'], ":\n")

        if input(tweet) == "s":
            continue

        inf = infersl.infer(tweet['user']['id'], test=True)

        print("\nInferred location:", inf)
        input(">")

        # Store inferred loc in db
        db.tweets.update_one({'_id': tweet['_id']}, {
            '$set': {