Beispiel #1
0
def data_vis_avg_delay():
    """ This route gets both the number of delayed flights between each airport, but
    also calculates a weighted average of delayed flights between each city.  these
    two matrices are then passed along to datavisavgdelay.html for display in a D3
    chord chart """

    matrix = get_data_for_vis(AVG_DELAY, cur_airports)
    matrix2 = get_data_for_vis(NUM_DELAY, cur_airports)
    all_scores = build_stats(AVG_DELAY)

    return render_template("datavisavgdelay.html", names=cur_airports, min_delay=matrix, num_delay=matrix2, all_scores=all_scores)
Beispiel #2
0
def data_vis_pct_delay():
    """ This route gets both the volume of all flights, and the number of flights 
    delayed between selected airports.  From these results, we then created a 3rd
    matrix containing the percentage of flights delayed between each selected airport.
    This new matrix is then passed to datavispctdelay.html as input for the D3 chord
    chart visualization.  We also pass in vol_flights so we can display overall stats
    for each airport """

    matrix = get_data_for_vis(VOL, cur_airports)
    matrix2 = get_data_for_vis(NUM_DELAY, cur_airports)
    matrix3 = get_pct_delay(matrix, matrix2, cur_airports)
    all_scores = build_stats(PCT_DELAY)

    return render_template("datavispctdelay.html", names=cur_airports, vol_flights=matrix, num_delay=matrix2, pct_delay=matrix3, all_scores=all_scores)
Beispiel #3
0
def data_vis():
    """ This route gets the volume of all flights between selected cities from the
    database and puts them into a matrix format which will be the input for our D3
    data visualization of airport traffic """

    matrix = get_data_for_vis(VOL, cur_airports)
    all_scores = build_stats(VOL)

    return render_template("datavis.html", names=cur_airports, vol_flights=matrix, all_scores=all_scores)
Beispiel #4
0
def calculate_scores():
    """ This function calculates the FlightScore for every airport, looking at the
    performance data of all flights originating and departing from that airport in
    2017. These calculated scores and stored in a dictionary whose keys are the 
    corresponding airport code."""

    all_scores = {}
    sum_scores = sum_pct_delays = sum_volumes = sum_delays = num_legs = 0
    i = j = 0

    # Query the database to get all FlightScores between all airports
    scores = get_data_for_vis(SCORE, all_airports.keys())

    # Query the database to get Flight Volume and Delays between all airports
    volumes = get_data_for_vis(VOL, all_airports.keys())
    num_delays = get_data_for_vis(NUM_DELAY, all_airports.keys())
    pct_delays = get_pct_delay(volumes, num_delays, all_airports.keys())
    avg_delays = get_data_for_vis(AVG_DELAY, all_airports.keys())

    # Calculate average FlightScore for each airport between all airports in all_airports
    for origin_code in all_airports.keys():
        for j in range(len(all_airports)):
            sum_scores += (scores[i][j] + scores[j][i])
            sum_volumes += (volumes[i][j] + volumes[j][i])
            sum_pct_delays += (pct_delays[i][j] + pct_delays[j][i])
            sum_delays += (avg_delays[i][j] + avg_delays[j][i])

            if scores[i][j] != 0:
                num_legs = num_legs + 2

        all_scores[origin_code] = [
            sum_scores / num_legs, sum_volumes,
            sum_pct_delays / float(num_legs), sum_delays / num_legs
        ]
        print origin_code, all_scores[origin_code]

        sum_scores = sum_pct_delays = sum_volumes = sum_delays = num_legs = 0
        i += 1

    return all_scores
Beispiel #5
0
def data_vis_score():
    """ This route gets both the number of delayed flights between each airport, but
    also calculates a weighted average of delayed flights between each city.  these
    two matrices are then passed along to datavisavgdelay.html for display in a D3
    chord chart """

    # Get matrix of scores for 10 busiest airports for D3 vis
    matrix = get_data_for_vis(SCORE, cur_airports)

    # Create a list of lists containing airport code, city name and score to pass to client
    # for ALL 50 airports for table display
    all_scores = build_stats(SCORE)
    
    return render_template("datavisscore.html", names=cur_airports, score=matrix, all_scores=all_scores)