Exemple #1
0
def world_status():
    world = GeoLines('', **style.init_style)
    # 添加国际城市地理坐标
    sange = get_coordinate('Los Angeles', '美国')
    world.add_coordinate("Los Angeles", sange[0], sange[1])
    road = [
        ['Los Angeles', 'Los Angeles']
    ]
    world.add('', road, **style_geo)
    return world
Exemple #2
0
def test_with_full_example():
    line_data = [["广州", "上海"], ["广州", "北京"], ["广州", "南京"], ["广州", "A市"]]

    lines = GeoLines("GeoLines 示例", **style.init_style)

    with assert_raises(ValueError):
        lines.add("从广州出发", line_data, **style_geo)

    assert 0 == len(search_coordinates_by_keyword("A市"))

    lines.add_coordinate("A市", 119.3, 26.08)
    lines.add("从广州出发", line_data, **style_geo)
    lines.render()
Exemple #3
0
def test_with_full_example():
    line_data = [["广州", "上海"], ["广州", "北京"], ["广州", "南京"], ["广州", "A市"]]

    lines = GeoLines("GeoLines 示例", **style.init_style)

    with assert_raises(ValueError):
        lines.add("从广州出发", line_data, **style_geo)

    assert 0 == len(search_coordinates_by_keyword("A市"))

    lines.add_coordinate("A市", 119.3, 26.08)
    lines.add("从广州出发", line_data, **style_geo)
    lines.render()
Exemple #4
0
def reload_data(addrs, local, dataset, ip_from):
    local_coord = local[0]
    local_city = local[1]

    road = []
    # 实例化世界地图
    world = GeoLines('', **style.init_style)
    try:
        # 添加本机坐标
        world.add_coordinate(local_city, local_coord[0], local_coord[1])
    except:
        # 重复添加可能会出错?
        pass

    if addrs:
        for ips in addrs:
            ips = loads(ips)
            ip = list(ips.keys())[0]
            is_evil = list(ips.values())[0]
            try:
                info = dataset.city(ip)
                ip_city = info.city.name
                ip_country = info.country.name
                # 经纬度
                ip_coord = [info.location.longitude, info.location.latitude]
                if ip_city and ip_country:
                    world.add_coordinate(ip_city, ip_coord[0], ip_coord[1])
                    path = [ip_city, local_city]
                    road.append(path)
                    if ip_country not in ip_from:
                        ip_from[ip_country] = 1
                    else:
                        ip_from[ip_country] += 1
            except:
                pass
    else:
        road = [['Los Angeles', local_city]]

    world.add('', road, **style_geo)
    option = world.get_options()
    # options中存在 Tooltip 对象,无法直接使用 json.dumps 转换,需要理由 pyecharts 的 TRANSLATOR API函数
    option = TRANSLATOR.translate(option)
    option = option.as_snippet()

    return option, ip_from