示例#1
0
def test_MapDirection_Transit():
    direction = MapDirection(AK, SK)
    origin = "23.137903,113.34348"
    destination = "22.544383,114.062203"
    coord_type = "wgs84"
    # 测试交通工具
    content = direction._get_raw_transit(origin, destination, coord_type=coord_type)
    result = json.loads(content)
    assert result["status"] == 0
    TransitObject = direction.transit(origin, destination, coord_type=coord_type)
    print(TransitObject)
    assert len(TransitObject.to_dataframe().columns) == 13
示例#2
0
def test_MapDirection_Driving():
    direction = MapDirection(AK, SK)
    origin = "23.137903,113.34348"
    destination = "22.544383,114.062203"
    coord_type = "wgs84"
    # 测试自驾出行
    content = direction._get_raw_driving(origin, destination, coord_type=coord_type)
    result = json.loads(content)
    assert result["status"] == 0
    DriveObject = direction.driving(origin, destination, coord_type=coord_type)
    print(DriveObject)
    assert len(DriveObject.to_dataframe().columns) == 8
示例#3
0
def test_MapDirection():
    direction = MapDirection(AK, SK)
    origin = "23.137903,113.34348"
    destination = "22.544383,114.062203"
    coord_type = "wgs84"
    content = direction.transit(origin, destination, coord_type=coord_type)
    result = json.loads(content)
    assert result["status"] == 0

    content = direction.riding(origin, destination, coord_type=coord_type)
    result = json.loads(content)
    assert result["status"] == 0

    content = direction.driving(origin, destination, coord_type=coord_type)
    result = json.loads(content)
    assert result["status"] == 0
示例#4
0
 def __init__(self, ak, sk):
     self.origin = list()
     self.destination = list()
     self.place = SearchPlace(ak, sk)
     self.dirction = MapDirection(ak, sk)
     self.recov = recovsys()
示例#5
0
class BaiduMap:
    def __init__(self, ak, sk):
        self.origin = list()
        self.destination = list()
        self.place = SearchPlace(ak, sk)
        self.dirction = MapDirection(ak, sk)
        self.recov = recovsys()

    def load_data(self, origin, destination):
        self.origin.append(origin)
        self.destination.append(destination)

    def get_train_data(self):
        self.recov.clean()
        # 火车优先
        for o_loc in self.origin:
            for d_loc in self.destination:
                result = list()
                try:
                    data = self.dirction.transit(o_loc,
                                                 d_loc,
                                                 tactics_intercity=0,
                                                 trans_type_intercity=0,
                                                 coord_type="wgs84")
                    data = data.to_dict()
                    for d in data:
                        d["transit_type"] = "火车"
                        d["origin_location_lat"] = d["origin_location"][0]
                        d["origin_location_lng"] = d["origin_location"][1]
                        d["destination_location_lat"] = d[
                            "destination_location"][0]
                        d["destination_location_lng"] = d["origin_location"][1]
                        result.append(d)
                    logger.info("完成{}到{}的数据写入".format(o_loc, d_loc))
                except Exception as e:
                    back_data = {"origin": o_loc, "destination": d_loc}
                    self.recov.backup(back_data)
                    logger.error("起始地: %s, 目的地: %s" % (o_loc, d_loc))
                yield result

    def get_plane_data(self):
        self.recov.clean()
        # 飞机优先
        for o_loc in self.origin:
            for d_loc in self.destination:
                result = list()
                try:
                    data = self.dirction.transit(o_loc,
                                                 d_loc,
                                                 tactics_intercity=0,
                                                 trans_type_intercity=1,
                                                 coord_type="wgs84")
                    data = data.to_dict()
                    for d in data:
                        d["transit_type"] = "飞机"
                        d["origin_location_lat"] = d["origin_location"][0]
                        d["origin_location_lng"] = d["origin_location"][1]
                        d["destination_location_lat"] = d[
                            "destination_location"][0]
                        d["destination_location_lng"] = d["origin_location"][1]
                        result.append(d)
                    logger.info("完成{}到{}的数据写入".format(o_loc, d_loc))
                except Exception:
                    back_data = {"origin": o_loc, "destination": d_loc}
                    self.recov.backup(back_data)
                    logger.error("起始地: %s, 目的地: %s" % (o_loc, d_loc))
                yield result

    def get_bus_data(self, departure=None):
        self.recov.clean()
        # 巴士
        for o_loc in self.origin:
            for d_loc in self.destination:
                result = list()
                try:
                    data = self.dirction.transit(o_loc,
                                                 d_loc,
                                                 tactics_intercity=0,
                                                 trans_type_intercity=2,
                                                 coord_type="wgs84")
                    data = data.to_dict()
                    for d in data:
                        d["transit_type"] = "大巴"
                        d["origin_location_lat"] = d["origin_location"][0]
                        d["origin_location_lng"] = d["origin_location"][1]
                        d["destination_location_lat"] = d[
                            "destination_location"][0]
                        d["destination_location_lng"] = d["origin_location"][1]
                        result.append(d)
                    logger.info("完成{}到{}的数据写入".format(o_loc, d_loc))
                except Exception:
                    back_data = {"origin": o_loc, "destination": d_loc}
                    self.recov.backup(back_data)
                    logger.error("起始地: %s, 目的地: %s" % (o_loc, d_loc))
                yield result
示例#6
0
origins_data = pd.read_csv("data/exmaple_citydata_coords.csv",
                           encoding="utf-8")
targets_name = {
    "香港": "香港国际机场",
    "广州": "广州白云国际机场",
    "深圳": "深圳宝安国际机场",
    "珠海": "珠海金湾国际机场",
    "澳门": "澳门国际机场",
    "佛山": "佛山沙堤机场",
    "惠州": "惠州平潭机场"
}

place = SearchPlace(AK, SK)

dirction = MapDirection(AK, SK)

fw = open("transit_plane_result.csv", "w", encoding="utf-8")
fw.write(
    "origin\t target\t distance\t duration\t price\t vehicle\t description \n")

for name in targets_name:
    pois = place.search(targets_name[name], region=name)
    poi = pois[0]

    loc = poi.get_location()

    for i in origins_data.index:
        obj = TransitObject()
        coords = (round(origins_data["lat"][i],
                        5), round(origins_data["lng"][i], 5))
示例#7
0
def test_BaiduResultExport():
    direction = MapDirection(AK, SK)
    origin = "23.137903,113.34348"
    destination = "22.638172,113.821705"
    content = direction.transit(origin, destination)
    BaiduResultExport(content)
示例#8
0
origins_data = pd.read_csv("data/exmaple_citydata_coords.csv",
                           encoding="utf-8")
targets_name = {
    "香港": "香港国际机场",
    "广州": "广州白云国际机场",
    "深圳": "深圳宝安国际机场",
    "珠海": "珠海金湾国际机场",
    "澳门": "澳门国际机场",
    "佛山": "佛山沙堤机场",
    "惠州": "惠州平潭机场"
}

place = SearchPlace(AK, SK)

dirction = MapDirection(AK, SK)

fw = open("driving_result.csv", "w", encoding="utf-8")
fw.write("origin, target, distance, duration, toll \n")

for name in targets_name:
    pois = place.search(targets_name[name], region=name)
    poi = pois[0]

    loc = poi.get_location()

    for i in origins_data.index:
        coords = (round(origins_data["lat"][i],
                        5), round(origins_data["lng"][i], 5))
        print(coords)
        content = dirction.driving(loc, coords)