예제 #1
0
def bookingClassTicketFrequencies(f, data, cabin):
    print "Grouping into unique flight/booking class combinations"
    flight_data = f.getUniqueFlightsAndBookings(data)

    bcs = Utils.mapCabinToBookingClasses(cabin)
    bcs = {bc: 0 for (bc, r) in bcs}

    print "Iterating through all booking classes"
    for flight, flight_df in flight_data:
        bc = flight[-1]
        keyday = -1 * flight_df["KEYDAY"]
        bkd = flight_df["BKD"]

        keyday, bkd = Utils.sortByIndex(keyday, bkd)

        bcs[bc] += bkd[-1]

    total_bkd = 0.0
    for bc, num_bkd in bcs.items():
        total_bkd += num_bkd

    for bc in bcs:
        bcs[bc] /= total_bkd

    ks, vs = zip(*bcs.items())
    ks, vs = zip(*sorted(zip(ks, vs), key=lambda tup: Utils.compareBCs(tup[0])))
    indices = np.arange(len(ks))
    width = 0.75

    fig, ax = plt.subplots()
    rects = ax.bar(indices, vs, width)
    ax.set_ylabel("Percent of Total Booked")
    ax.set_title("Booking Class Ticketing Distribution - Economy Cabin")
    ax.set_xticks(indices + width / 2.0)
    ax.set_xticklabels(ks)

    plt.grid()
    plt.show()
예제 #2
0
def bc_bars_base(y_cumsum):
    """
    args:
        y_cumsum: a sumcum deltabkd vector (either predict or actual)
    """
    totalbkd_vector = y_cumsum[:, -1]
    assert len(ids_test) == len(totalbkd_vector)

    bcs = {bc: 0 for (bc, r) in Utils.mapCabinToBookingClasses("Y")}

    for totalbkd, ids in zip(totalbkd_vector, ids_test):
        bc = ids[-1]
        bcs[bc] += totalbkd

    denom = sum(totalbkd_vector)

    for bc in bcs:
        bcs[bc] /= denom

    ks, vs = zip(*bcs.items())
    ks, vs = zip(*sorted(zip(ks, vs), key=lambda tup: Utils.compareBCs(tup[0])))
    indices = np.arange(len(ks))

    return ks, vs, indices
예제 #3
0
def sortBCGroupby(groupby):
    tups = [(bc, bc_df) for bc, bc_df in groupby]
    return sorted(tups, key=lambda tup: Utils.compareBCs(tup[0]))