Exemple #1
0
def toTime(list):
    newList = tool.getTopTen(timeCost(list), 10)
    for i in range(0, len(newList) - 1):
        for j in range(0, len(newList) - i - 1):
            toTime = tool.timeToMin(newList[j]['to_time'])
            toTime1 = tool.timeToMin(newList[j + 1]['to_time'])
            if toTime > toTime1:
                newList[j], newList[j + 1] = newList[j + 1], newList[j]
    return newList
Exemple #2
0
def computeResult(list):
    for i in range(0, len(list) - 1):
        for j in range(0, len(list) - i - 1):
            time = tool.timeToMin(list[j][0]['cost']) + tool.timeToMin(list[j][1]['cost']) + (
                        tool.timeToMin(list[j][1]['start_time']) - tool.timeToMin(list[j][0]['to_time']))
            time1 = tool.timeToMin(list[j + 1][0]['cost']) + tool.timeToMin(list[j + 1][1]['cost']) + (
                        tool.timeToMin(list[j + 1][1]['start_time']) - tool.timeToMin(list[j + 1][0]['to_time']))
            if time > time1:
                list[j], list[j + 1] = list[j + 1], list[j]
    return tool.getTopTen(list,10)
Exemple #3
0
def computeResult(list):
    for i in range(0, len(list) - 1):
        for j in range(0, len(list) - i - 1):
            price = tool.priceToFloat(list[j][0]['price']) + tool.priceToFloat(
                list[j][1]['price'])
            price1 = tool.priceToFloat(
                list[j + 1][0]['price']) + tool.priceToFloat(
                    list[j + 1][1]['price'])
            if price > price1:
                list[j], list[j + 1] = list[j + 1], list[j]
    return tool.getTopTen(list, 10)
def computeResult(list):
    for i in range(0, len(list) - 1):
        for j in range(0, len(list) - i - 1):
            price = int(tool.priceToFloat(list[j][0]['price'])) + int(
                tool.priceToFloat(list[j][1]['price']))
            price1 = int(tool.priceToFloat(list[j + 1][0]['price'])) + int(
                tool.priceToFloat(list[j + 1][1]['price']))
            costTime = tool.timeChineseToMin(list[j][2]['whole_cost'])
            costTime1 = tool.timeChineseToMin(list[j + 1][2]['whole_cost'])
            multIn = price + costTime * 0.4
            multIn1 = price1 + costTime1 * 0.4
            if multIn > multIn1:
                list[j], list[j + 1] = list[j + 1], list[j]
    return tool.getTopTen(list, 10)
def connectedDistanceList(start, end):
    listDitail = []
    list = Interface.connected.connectedTheoryList(start, end)
    for i in list:
        dis = SqlDir.distance_table.selectDistance(
            SqlDir.city_table.selectNameChineseByCode(start),
            SqlDir.city_table.selectNameChineseByCode(i))
        dis2 = SqlDir.distance_table.selectDistance(
            SqlDir.city_table.selectNameChineseByCode(i),
            SqlDir.city_table.selectNameChineseByCode(end))
        directDis = SqlDir.distance_table.selectDistance(
            SqlDir.city_table.selectNameChineseByCode(start),
            SqlDir.city_table.selectNameChineseByCode(end))
        if ((dis + dis2) < directDis * 1.1):
            listDitail.append(SqlDir.city_table.selectNameChineseByCode(i))
            print('   中转城市:' + SqlDir.city_table.selectNameChineseByCode(i))
    if len(listDitail) > 4:
        return listDitail
    else:
        listDitail2 = []
        for i in list:
            dis = SqlDir.distance_table.selectDistance(
                SqlDir.city_table.selectNameChineseByCode(start),
                SqlDir.city_table.selectNameChineseByCode(i))
            dis2 = SqlDir.distance_table.selectDistance(
                SqlDir.city_table.selectNameChineseByCode(i),
                SqlDir.city_table.selectNameChineseByCode(end))
            collection = []
            collection.append(i)
            collection.append(dis + dis2)
            listDitail2.append(collection)
        for i in range(0, len(listDitail2) - 1):
            for j in range(0, len(listDitail2) - i - 1):
                dis = listDitail2[j][1]
                dis2 = listDitail2[j + 1][1]
                if dis > dis2:
                    listDitail2[j], listDitail2[j + 1] = listDitail2[
                        j + 1], listDitail2[j]
        finalList = tool.getTopTen(listDitail2, 3)
        subList = []
        for i in finalList:
            subList.append(SqlDir.city_table.selectNameChineseByCode(i[0]))
        return subList
def firstArrive(start, mid, end, typeFirstSql, typeSecondSql):
    flag = 1
    resultList = []
    list = Interface.sort.toTime(
        SqlDir.train_table.selectByCity(start, mid, typeFirstSql))
    listNext = Interface.sort.toTime(
        SqlDir.train_table.selectByCity(mid, end, typeSecondSql))
    if len(list) == 0 or len(listNext) == 0:
        return
    elif len(list) <= 3 or len(listNext) <= 3:
        flag = 0
    for i in list:
        midTimeStart = tool.timeToMin(i['to_time'])
        for j in listNext:
            midTimeEnd = tool.timeToMin(j['start_time'])
            if (midTimeEnd > midTimeStart + 60):
                collection = []
                stayTime = tool.timeToHoure(midTimeEnd - midTimeStart)
                wholeCost = tool.timeToHoure(
                    tool.timeToMin(i['cost']) + tool.timeToMin(j['cost']) +
                    midTimeEnd - midTimeStart)
                wholePrice = '¥' + str(
                    tool.priceToFloat(i['price']) +
                    tool.priceToFloat(j['price']))
                list3 = {
                    'stay_time': stayTime,
                    'whole_cost': wholeCost,
                    'whole_price': wholePrice
                }
                collection.append(i)
                collection.append(j)
                collection.append(list3)
                resultList.append(collection)
                if flag == 1:
                    break
            else:
                if listNext.index(j) == len(listNext) - 1:
                    break
    return tool.getTopTen(resultList, 10)