Esempio n. 1
0
def test():
    flag_error = False
    today = datetime.datetime.now()

    # IP -> Coord
    supposed_ip = '8.8.8.8'
    geo_helper.getCoordFromIpAndPublish(supposed_ip, categ)
    rep = geo_helper.getTopCoord(today)
    excpected_result = [[
        '{"lat": 37.751, "lon": -97.822, "categ": "Network Activity", "value": "8.8.8.8"}',
        1.0
    ]]
    if rep != excpected_result:
        print('ip to coord result not matching')
        flag_error = True

    # gethitmap
    rep = geo_helper.getHitMap(today)
    excpected_result = [['US', 1.0]]
    if rep != excpected_result:
        print('getHitMap result not matching')
        flag_error = True

    # getCoordsByRadius
    rep = geo_helper.getCoordsByRadius(today, today, 0.000, 0.000, '1')
    excpected_result = []
    if rep != excpected_result:
        print('getCoordsByRadius result not matching')
        flag_error = True

    rep = geo_helper.getCoordsByRadius(today, today, 37.750, -97.821, '10')
    excpected_result = [[['{"categ": "Network Activity", "value": "8.8.8.8"}'],
                         [-97.82200008630753, 37.75100012475438]]]
    if rep != excpected_result:
        print('getCoordsByRadius result not matching')
        flag_error = True

    wipeRedis()

    # Phone -> Coord
    phoneNumber = '(+352) 247-82000'
    geo_helper.getCoordFromPhoneAndPublish(phoneNumber, categ)
    rep = geo_helper.getTopCoord(datetime.datetime.now())[0]
    excpected_result = ['{"lat": "49.7500", "lon": "6.1667"}', 1.0]
    if rep != excpected_result:
        print('Phone to coord result not matching')
        flag_error = True

    return flag_error
Esempio n. 2
0
def getCoordsByRadius():
    try:
        dateStart = datetime.datetime.fromtimestamp(float(request.args.get('dateStart')))
        dateEnd = datetime.datetime.fromtimestamp(float(request.args.get('dateEnd')))
        centerLat = request.args.get('centerLat')
        centerLon = request.args.get('centerLon')
        radius = int(math.ceil(float(request.args.get('radius'))))
    except:
        return jsonify([])

    data = geo_helper.getCoordsByRadius(dateStart, dateEnd, centerLat, centerLon, radius)
    return jsonify(data)