Beispiel #1
0
def airp_info(data, units):
    """Gets the air pressure info."""

    # Get the data.
    num_days = len(data)
    airp_data1, airp_data2 = datasets.split_list(datasets.get_column(data, 6))
    airp_data1 = datasets.convert_float(airp_data1)
    airp_low = min(airp_data1)
    airp_high = max(airp_data1)
    airp_avg = calculations.mean(airp_data1)
    airp_median = calculations.median(airp_data1)
    airp_range = calculations.range(airp_data1)
    airp_mode, airp_mode_count = calculations.mode(airp_data1)
    airp_steady = 0
    airp_rising = 0
    airp_falling = 0
    for i in airp_data2:
        if i == "Steady":
            airp_steady += 1
        elif i == "Rising":
            airp_rising += 1
        elif i == "Falling":
            airp_falling += 1

    # Create the data list.
    data2 = [
        ["Lowest air pressure",
         "%.2f %s" % (airp_low, units["airp"])],
        ["Highest air pressure",
         "%.2f %s" % (airp_high, units["airp"])],
        ["Average air pressure",
         "%.2f %s" % (airp_avg, units["airp"])],
        ["Median air pressure",
         "%.2f %s" % (airp_median, units["airp"])],
        ["Range of air pressures",
         "%.2f %s" % (airp_range, units["airp"])],
        [
            "Most common air pressure",
            "%.2f %s (%d occurrences)" %
            (airp_mode, units["airp"], airp_mode_count)
        ],
        [
            "Days with steady pressure",
            "%d day%s (%d%%)" % (airp_steady, "" if airp_steady == 1 else "s",
                                 (airp_steady / num_days) * 100)
        ],
        [
            "Days with rising pressure",
            "%d day%s (%d%%)" % (airp_rising, "" if airp_rising == 1 else "s",
                                 (airp_rising / num_days) * 100)
        ],
        [
            "Days with falling pressure",
            "%d day%s (%d%%)" %
            (airp_falling, "" if airp_falling == 1 else "s",
             (airp_falling / num_days) * 100)
        ]
    ]

    return data2
Beispiel #2
0
def wind_info(data, units):
    """Gets the wind info."""

    # Get the data.
    wind_data1, wind_data2 = datasets.split_list(datasets.get_column(data, 4))
    wind_data1 = datasets.none_to_zero(wind_data1)
    wind_data1 = datasets.convert_float(wind_data1)
    try:
        wind_low = min(wind_data1)
        wind_high = max(wind_data1)
        wind_avg = calculations.mean(wind_data1)
        wind_median = calculations.median(wind_data1)
        wind_range = calculations.range(wind_data1)
    except ZeroDivisionError:
        wind_low = "None"
        wind_high = "None"
        wind_avg = "None"
        wind_median = "None"
        wind_range = "None"
    wind_mode, wind_mode_count = calculations.mode(wind_data2)

    # Change any values, if needed.
    wind_low = "None" if wind_low == "None" else ("%.2f %s" %
                                                  (wind_low, units["wind"]))
    wind_high = "None" if wind_high == "None" else ("%.2f %s" %
                                                    (wind_high, units["wind"]))
    wind_avg = "None" if wind_avg == "None" else ("%.2f %s" %
                                                  (wind_avg, units["wind"]))
    wind_median = "None" if wind_median == "None" else (
        "%.2f %s" % (wind_median, units["wind"]))
    wind_range = "None" if wind_range == "None" else (
        "%.2f %s" % (wind_range, units["wind"]))

    # Create the data list.
    data2 = [["Lowest wind speed",
              wind_low], ["Highest wind speed", wind_high],
             ["Average wind speed", wind_avg],
             ["Median wind speed", wind_median],
             ["Range of wind speeds", wind_range],
             [
                 "Most common wind direction",
                 "%s (%d occurrences)" %
                 (wind_mode if wind_mode != "" else "None", wind_mode_count)
             ]]

    return data2
Beispiel #3
0
def airp_info(data, units):
    """Gets the air pressure info."""
    
    # Get the data.
    num_days = len(data)
    airp_data1, airp_data2 = datasets.split_list(datasets.get_column(data, 6))
    airp_data1 = datasets.convert_float(airp_data1)
    airp_low = min(airp_data1)
    airp_high = max(airp_data1)
    airp_avg = calculations.mean(airp_data1)
    airp_median = calculations.median(airp_data1)
    airp_range = calculations.range(airp_data1)
    airp_mode, airp_mode_count = calculations.mode(airp_data1)
    airp_steady = 0
    airp_rising = 0
    airp_falling = 0
    for i in airp_data2:
        if i == "Steady":
            airp_steady += 1
        elif i == "Rising":
            airp_rising += 1
        elif i == "Falling":
            airp_falling += 1
    
    # Create the data list.
    data2 = [
        ["Lowest air pressure", "%.2f %s" % (airp_low, units["airp"])],
        ["Highest air pressure", "%.2f %s" % (airp_high, units["airp"])],
        ["Average air pressure", "%.2f %s" % (airp_avg, units["airp"])],
        ["Median air pressure", "%.2f %s" % (airp_median, units["airp"])],
        ["Range of air pressures", "%.2f %s" % (airp_range, units["airp"])],
        ["Most common air pressure", "%.2f %s (%d occurrences)" %
            (airp_mode, units["airp"], airp_mode_count)],
        ["Days with steady pressure", "%d day%s (%d%%)" %
            (airp_steady, "" if airp_steady == 1 else "s", (airp_steady / num_days) * 100)],
        ["Days with rising pressure", "%d day%s (%d%%)" %
            (airp_rising, "" if airp_rising == 1 else "s", (airp_rising / num_days) * 100)],
        ["Days with falling pressure", "%d day%s (%d%%)" %
            (airp_falling, "" if airp_falling == 1 else "s", (airp_falling / num_days) * 100)]
    ]
    
    return data2
Beispiel #4
0
def airp_table(data, units):
    """"Gets the air pressure table data."""
    
    # Get the data.
    airp_data1, airp_data2 = datasets.split_list(datasets.get_column(data, 6))
    airp_data1 = datasets.convert_float(airp_data1)
    airp_low = min(airp_data1)
    airp_high = max(airp_data1)
    airp_avg = calculations.mean(airp_data1)
    airp_median = calculations.median(airp_data1)
    
    # Calculate and add the data.
    data2 = []
    for i in range(0, len(data)):
        
        airp = [data[i][0], "%.2f %s" % (airp_data1[i], units["airp"])]
        airp += build_table(airp_data1[i], airp_low, airp_high, airp_avg, airp_median, units["airp"])
        data2.append(airp)
    
    return data2
Beispiel #5
0
def wind_table(data, units):
    """"Gets the wind table data."""
    
    # Get the data.
    wind_data1, wind_data2 = datasets.split_list(datasets.get_column(data, 4))
    wind_data1 = datasets.none_to_zero(wind_data1)
    wind_data1 = datasets.convert_float(wind_data1)
    wind_low = min(wind_data1)
    wind_high = max(wind_data1)
    wind_avg = calculations.mean(wind_data1)
    wind_median = calculations.median(wind_data1)
    
    # Calculate and add the data.
    data2 = []
    for i in range(0, len(data)):
        
        wind = [data[i][0], "%.2f %s" % (wind_data1[i], units["wind"])]
        wind += build_table(wind_data1[i], wind_low, wind_high, wind_avg, wind_median, units["wind"])
        data2.append(wind)
    
    return data2
Beispiel #6
0
def prec_table(data, units):
    """"Gets the precipitation table data."""
    
    # Get the data.
    prec_data1, prec_data2 = datasets.split_list(datasets.get_column(data, 3))
    prec_data1 = datasets.none_to_zero(prec_data1)
    prec_data1 = datasets.convert_float(prec_data1)
    prec_low = min(prec_data1)
    prec_high = max(prec_data1)
    prec_avg = calculations.mean(prec_data1)
    prec_median = calculations.median(prec_data1)
    
    # Calculate and add the data.
    data2 = []
    for i in range(0, len(data)):
        
        prec = [data[i][0], "%.2f %s" % (prec_data1[i], units["prec"])]
        prec += build_table(prec_data1[i], prec_low, prec_high, prec_avg, prec_median, units["prec"])
        data2.append(prec)
    
    return data2
Beispiel #7
0
def wind_info(data, units):
    """Gets the wind info."""
    
    # Get the data.
    wind_data1, wind_data2 = datasets.split_list(datasets.get_column(data, 4))
    wind_data1 = datasets.none_to_zero(wind_data1)
    wind_data1 = datasets.convert_float(wind_data1)
    try:
        wind_low = min(wind_data1)
        wind_high = max(wind_data1)
        wind_avg = calculations.mean(wind_data1)
        wind_median = calculations.median(wind_data1)
        wind_range = calculations.range(wind_data1)
    except ZeroDivisionError:
        wind_low = "None"
        wind_high = "None"
        wind_avg = "None"
        wind_median = "None"
        wind_range = "None"
    wind_mode, wind_mode_count = calculations.mode(wind_data2)
    
    # Change any values, if needed.
    wind_low = "None" if wind_low == "None" else ("%.2f %s" % (wind_low, units["wind"]))
    wind_high = "None" if wind_high == "None" else ("%.2f %s" % (wind_high, units["wind"]))
    wind_avg = "None" if wind_avg == "None" else ("%.2f %s" % (wind_avg, units["wind"]))
    wind_median = "None" if wind_median == "None" else ("%.2f %s" % (wind_median, units["wind"]))
    wind_range = "None" if wind_range == "None" else ("%.2f %s" % (wind_range, units["wind"]))
    
    # Create the data list.
    data2 = [
        ["Lowest wind speed", wind_low],
        ["Highest wind speed", wind_high],
        ["Average wind speed", wind_avg],
        ["Median wind speed", wind_median],
        ["Range of wind speeds", wind_range],
        ["Most common wind direction", "%s (%d occurrences)" %
            (wind_mode if wind_mode != "" else "None", wind_mode_count)]
    ]
    
    return data2
Beispiel #8
0
def get_data(data):
    """Gets the graph data."""

    # Get the date data.
    date_data = datasets.get_column(data, 0)
    new_dates = dates.get_datetimes(date_data)

    # Get the data.
    temp_data = datasets.convert_float(datasets.get_column(data, 1))
    chil_data = datasets.convert_float(datasets.get_column(data, 2))
    prec_data1, prec_data2 = datasets.split_list(datasets.get_column(data, 3))
    prec_data = datasets.convert_float(datasets.none_to_zero(prec_data1))
    wind_data1, wind_data2 = datasets.split_list(datasets.get_column(data, 4))
    wind_data = datasets.convert_float(datasets.none_to_zero(wind_data1))
    humi_data = datasets.convert_float(datasets.get_column(data, 5))
    airp_data1, airp_data2 = datasets.split_list(datasets.get_column(data, 6))
    airp_data = datasets.convert_float(airp_data1)
    visi_data = datasets.convert_float(datasets.get_column(data, 7))
    clou_data1, clou_data2 = datasets.split_list3(datasets.get_column(data, 8))
    clou_data2 = datasets.strip_items(clou_data2, ["(", ")"])

    prec_split = datasets.split_list2(datasets.get_column(data, 3))
    prec_total = 0
    prec_total_rain = 0
    prec_total_snow = 0
    prec_total_hail = 0
    prec_total_sleet = 0
    prec_none = 0
    prec_rain = 0
    prec_snow = 0
    prec_hail = 0
    prec_sleet = 0
    for i in prec_split:
        if i[1] != "None":
            prec_total += float(i[0])
        if i[1] == "None":
            prec_none += 1
        elif i[1] == "Rain":
            prec_total_rain += float(i[0])
            prec_rain += 1
        elif i[1] == "Snow":
            prec_total_snow += float(i[0])
            prec_snow += 1
        elif i[1] == "Hail":
            prec_total_hail += float(i[0])
            prec_hail += 1
        elif i[1] == "Sleet":
            prec_total_sleet += float(i[0])
            prec_sleet += 1
    prec_amount = [
        prec_total_rain, prec_total_snow, prec_total_hail, prec_total_sleet
    ]
    prec_days = [prec_none, prec_rain, prec_snow, prec_hail, prec_sleet]

    airp_steady = 0
    airp_rising = 0
    airp_falling = 0
    for i in airp_data2:
        if i == "Steady":
            airp_steady += 1
        elif i == "Rising":
            airp_rising += 1
        elif i == "Falling":
            airp_falling += 1
    airp_change = [airp_steady, airp_rising, airp_falling]

    clou_sunny = 0
    clou_msunny = 0
    clou_pcloudy = 0
    clou_mcloudy = 0
    clou_cloudy = 0
    for i in clou_data1:
        if i == "Sunny":
            clou_sunny += 1
        elif i == "Mostly Sunny":
            clou_msunny += 1
        elif i == "Partly Cloudy":
            clou_pcloudy += 1
        elif i == "Mostly Cloudy":
            clou_mcloudy += 1
        elif i == "Cloudy":
            clou_cloudy += 1
    clou_days = [
        clou_sunny, clou_msunny, clou_pcloudy, clou_mcloudy, clou_cloudy
    ]

    clou_types = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    for i in clou_data2:
        if i == "None":
            clou_types[0] += 1
        elif i == "Unknown":
            clou_types[1] += 1
        elif i == "Cirrus":
            clou_types[2] += 1
        elif i == "Cirrocumulus":
            clou_types[3] += 1
        elif i == "Cirrostratus":
            clou_types[4] += 1
        elif i == "Cumulonimbus":
            clou_types[5] += 1
        elif i == "Altocumulus":
            clou_types[6] += 1
        elif i == "Altostratus":
            clou_types[7] += 1
        elif i == "Stratus":
            clou_types[8] += 1
        elif i == "Cumulus":
            clou_types[9] += 1
        elif i == "Stratocumulus":
            clou_types[10] += 1

    data = {
        "date_labels": date_data,
        "date_ticks": new_dates,
        "temp_data": temp_data,
        "prec_data": prec_data,
        "wind_data": wind_data,
        "humi_data": humi_data,
        "airp_data": airp_data,
        "prec_amount": prec_amount,
        "prec_days": prec_days,
        "airp_change": airp_change,
        "clou_days": clou_days,
        "clou_types": clou_types,
        "chil_data": chil_data,
        "visi_data": visi_data
    }

    return data
Beispiel #9
0
def prec_info(data, units):
    """"Gets the precipitation info."""

    # Get the data.
    num_days = len(data)
    prec_data1, prec_data2 = datasets.split_list(datasets.get_column(data, 3))
    prec_split = datasets.split_list2(datasets.get_column(data, 3))
    prec_data1 = datasets.none_to_zero(prec_data1)
    prec_data1 = datasets.convert_float(prec_data1)
    try:
        prec_low = min(prec_data1)
        prec_high = max(prec_data1)
        prec_avg = calculations.mean(prec_data1)
        prec_median = calculations.median(prec_data1)
        prec_range = calculations.range(prec_data1)
    except ZeroDivisionError:
        prec_low = "None"
        prec_high = "None"
        prec_avg = "None"
        prec_median = "None"
        prec_range = "None"
    prec_total = 0
    prec_total_rain = 0
    prec_total_snow = 0
    prec_total_hail = 0
    prec_total_sleet = 0
    prec_none = 0
    prec_rain = 0
    prec_snow = 0
    prec_hail = 0
    prec_sleet = 0
    for i in prec_split:
        if i[1] != "None":
            prec_total += float(i[0])
        if i[1] == "None":
            prec_none += 1
        elif i[1] == "Rain":
            prec_total_rain += float(i[0])
            prec_rain += 1
        elif i[1] == "Snow":
            prec_total_snow += float(i[0])
            prec_snow += 1
        elif i[1] == "Hail":
            prec_total_hail += float(i[0])
            prec_hail += 1
        elif i[1] == "Sleet":
            prec_total_sleet += float(i[0])
            prec_sleet += 1
    prec_mode, prec_mode_count = calculations.mode(prec_data2)
    if prec_total == 0:
        prec_per_rain = "0%"
        prec_per_snow = "0%"
        prec_per_hail = "0%"
        prec_per_sleet = "0%"
    else:
        prec_per_rain = "%.2f%%" % ((prec_total_rain / prec_total) * 100)
        prec_per_snow = "%.2f%%" % ((prec_total_snow / prec_total) * 100)
        prec_per_hail = "%.2f%%" % ((prec_total_hail / prec_total) * 100)
        prec_per_sleet = "%.2f%%" % ((prec_total_sleet / prec_total) * 100)

    # Change any values, if needed.
    prec_low = "None" if prec_low == "None" else ("%.2f %s" %
                                                  (prec_low, units["prec"]))
    prec_high = "None" if prec_high == "None" else ("%.2f %s" %
                                                    (prec_high, units["prec"]))
    prec_avg = "None" if prec_avg == "None" else ("%.2f %s" %
                                                  (prec_avg, units["prec"]))
    prec_median = "None" if prec_median == "None" else (
        "%.2f %s" % (prec_median, units["prec"]))
    prec_range = "None" if prec_range == "None" else (
        "%.2f %s" % (prec_range, units["prec"]))

    # Create the data list.
    data2 = [
        ["Lowest precipitation",
         prec_low], ["Highest precipitation", prec_high],
        ["Average precipitation", prec_avg],
        ["Median precipitation", prec_median],
        ["Range of precipitation", prec_range],
        ["Total precipitation",
         "%.2f %s" % (prec_total, units["prec"])],
        [
            "Total rain",
            "%.2f %s (%s)" % (prec_total_rain, units["prec"], prec_per_rain)
        ],
        [
            "Total snow",
            "%.2f %s (%s)" % (prec_total_snow, units["prec"], prec_per_snow)
        ],
        [
            "Total hail",
            "%.2f %s (%s)" % (prec_total_hail, units["prec"], prec_per_hail)
        ],
        [
            "Total sleet",
            "%.2f %s (%s)" % (prec_total_sleet, units["prec"], prec_per_sleet)
        ],
        [
            "Days with no precipitation",
            "%d day%s (%.2f%%)" % (prec_none, "" if prec_none == 1 else "s",
                                   (prec_none / num_days) * 100)
        ],
        [
            "Days with rain",
            "%d day%s (%.2f%%)" % (prec_rain, "" if prec_rain == 1 else "s",
                                   (prec_rain / num_days) * 100)
        ],
        [
            "Days with snow",
            "%d day%s (%.2f%%)" % (prec_snow, "" if prec_snow == 1 else "s",
                                   (prec_snow / num_days) * 100)
        ],
        [
            "Days with hail",
            "%d day%s (%.2f%%)" % (prec_hail, "" if prec_hail == 1 else "s",
                                   (prec_hail / num_days) * 100)
        ],
        [
            "Days with sleet",
            "%d day%s (%.2f%%)" % (prec_sleet, "" if prec_sleet == 1 else "s",
                                   (prec_sleet / num_days) * 100)
        ],
        [
            "Most common precipitation type",
            "%s (%d occurrences)" %
            (prec_mode if prec_mode != "" else "None", prec_mode_count)
        ]
    ]

    return data2
Beispiel #10
0
def general_info(data, units):
    """Gets the general info."""

    # Get the date data.
    date_data = datasets.get_column(data, 0)
    date_first = date_data[0]
    date_last = date_data[len(date_data) - 1]
    date_first2 = datetime.datetime.strptime(date_first, "%d/%m/%Y")
    date_last2 = datetime.datetime.strptime(date_last, "%d/%m/%Y")
    date_num = (date_last2 - date_first2).days + 1
    day_num = len(data)

    # Get the temperature data.
    temp_data = datasets.convert_float(datasets.get_column(data, 1))
    temp_low = min(temp_data)
    temp_high = max(temp_data)
    temp_avg = calculations.mean(temp_data)

    # Get the wind chill data.
    chil_data = datasets.convert_float(datasets.get_column(data, 2))
    chil_low = min(chil_data)
    chil_high = max(chil_data)
    chil_avg = calculations.mean(chil_data)

    # Get the precipitation data.
    prec_data1, prec_data2 = datasets.split_list(datasets.get_column(data, 3))
    prec_data1 = datasets.convert_float(datasets.none_to_zero(prec_data1))
    try:
        prec_low = min(prec_data1)
        prec_high = max(prec_data1)
        prec_avg = calculations.mean(prec_data1)
    except ZeroDivisionError:
        prec_low = "None"
        prec_high = "None"
        prec_avg = "None"

    # Get the wind data.
    wind_data1, wind_data2 = datasets.split_list(datasets.get_column(data, 4))
    wind_data1 = datasets.convert_float(datasets.none_to_zero(wind_data1))
    try:
        wind_low = min(wind_data1)
        wind_high = max(wind_data1)
        wind_avg = calculations.mean(wind_data1)
    except ZeroDivisionError:
        wind_low = "None"
        wind_high = "None"
        wind_avg = "None"

    # Get the humidity data.
    humi_data = datasets.convert_float(datasets.get_column(data, 5))
    humi_low = min(humi_data)
    humi_high = max(humi_data)
    humi_avg = calculations.mean(humi_data)

    # Get the air pressure data.
    airp_data1, airp_data2 = datasets.split_list(datasets.get_column(data, 6))
    airp_data1 = datasets.convert_float(airp_data1)
    airp_low = min(airp_data1)
    airp_high = max(airp_data1)
    airp_avg = calculations.mean(airp_data1)

    # Get the visibility data.
    visi_data = datasets.convert_float(datasets.get_column(data, 7))
    visi_low = min(visi_data)
    visi_high = max(visi_data)
    visi_avg = calculations.mean(visi_data)

    # Get the cloud cover data.
    clou_data = datasets.split_list3(datasets.get_column(data, 8))
    clou_data1 = Counter(clou_data[0])
    clou_data2 = Counter(datasets.strip_items(clou_data[1], ["(", ")"]))
    clou_data1_counter = clou_data1.most_common(1)[0]
    clou_data2_counter = clou_data2.most_common(1)[0]
    clou_mode1 = clou_data1_counter[0]
    clou_mode1_count = clou_data1_counter[1]
    clou_mode2 = clou_data2_counter[0]
    clou_mode2_count = clou_data2_counter[1]

    # Change any values, if needed.
    prec_low = "None" if prec_low == "None" else ("%.2f %s" %
                                                  (prec_low, units["prec"]))
    prec_high = "None" if prec_high == "None" else ("%.2f %s" %
                                                    (prec_high, units["prec"]))
    prec_avg = "None" if prec_avg == "None" else ("%.2f %s" %
                                                  (prec_avg, units["prec"]))
    wind_low = "None" if wind_low == "None" else ("%.2f %s" %
                                                  (wind_low, units["wind"]))
    wind_high = "None" if wind_high == "None" else ("%.2f %s" %
                                                    (wind_high, units["wind"]))
    wind_avg = "None" if wind_avg == "None" else ("%.2f %s" %
                                                  (wind_avg, units["wind"]))

    # Create the data list.
    data2 = [["First date", "%s" % date_first],
             ["Last date", "%s" % date_last],
             ["Number of days", "%d days" % day_num],
             ["Range of days", "%d days" % date_num],
             ["Lowest temperature",
              "%.2f %s" % (temp_low, units["temp"])],
             ["Highest temperature",
              "%.2f %s" % (temp_high, units["temp"])],
             ["Average temperature",
              "%.2f %s" % (temp_avg, units["temp"])],
             ["Lowest wind chill",
              "%.2f %s" % (chil_low, units["temp"])],
             ["Highest wind chill",
              "%.2f %s" % (chil_high, units["temp"])],
             ["Average wind chill",
              "%.2f %s" % (chil_avg, units["temp"])],
             ["Lowest precipitation", prec_low],
             ["Highest precipitation", prec_high],
             ["Average precipitation", prec_avg],
             ["Lowest wind speed",
              wind_low], ["Highest wind speed", wind_high],
             ["Average wind speed", wind_avg],
             ["Lowest humidity", "%.2f%%" % humi_low],
             ["Highest humidity", "%.2f%%" % humi_high],
             ["Average humidity", "%.2f%%" % humi_avg],
             ["Lowest air pressure",
              "%.2f %s" % (airp_low, units["airp"])],
             ["Highest air pressure",
              "%.2f %s" % (airp_high, units["airp"])],
             ["Average air pressure",
              "%.2f %s" % (airp_avg, units["airp"])],
             ["Lowest visibility",
              "%.2f %s" % (visi_low, units["visi"])],
             ["Highest visibility",
              "%.2f %s" % (visi_high, units["visi"])],
             ["Average visibility",
              "%.2f %s" % (visi_avg, units["visi"])],
             [
                 "Most common cloud cover",
                 "%s (%d occurrences)" % (clou_mode1, clou_mode1_count)
             ],
             [
                 "Most common cloud type",
                 "%s (%d occurrences)" % (clou_mode2, clou_mode2_count)
             ]]

    return data2
Beispiel #11
0
def filter_data(data, condition, insensitive):
    """Filters the data based on the user's conditions."""
    
    # Create the list for the filtered data.
    filtered = []
    
    # Get the column of the data that is being filtered.
    string_compare = False
    col = []
    field = condition[0].lower()
    if field == "date":
        col = datasets.get_column(data, 0)
        string_compare = True
    elif field == "temperature":
        col = datasets.convert_float(datasets.get_column(data, 1))
    elif field == "wind chill":
        col = datasets.convert_float(datasets.get_column(data, 2))
    elif field == "precipitation amount":
        col = datasets.get_column(data, 3)
        col = datasets.convert_float(datasets.none_to_zero(datasets.split_list(col)[0]))
    elif field == "precipitation type":
        string_compare = True
        ncol = datasets.get_column(data, 3)
        col = []
        for i in ncol:
            if i == "None":
                col.append(i)
            else:
                i_split = i.split(" ")
                col.append(i_split[1])
    elif field == "wind speed":
        col = datasets.get_column(data, 4)
        col = datasets.convert_float(datasets.none_to_zero(datasets.split_list(col)[0]))
    elif field == "wind direction":
        string_compare = True
        ncol = datasets.get_column(data, 4)
        col = []
        for i in ncol:
            if i == "None":
                col.append(i)
            else:
                i_split = i.split(" ")
                col.append(i_split[1])
    elif field == "humidity":
        col = datasets.convert_float(datasets.get_column(data, 5))
    elif field == "air pressure":
        col = datasets.convert_float(datasets.split_list(datasets.get_column(data, 6))[0])
    elif field == "air pressure change":
        string_compare = True
        col = datasets.split_list(datasets.get_column(data, 6))[1]
    elif field == "visibility":
        col = datasets.convert_float(datasets.get_column(data, 7))
    elif field == "cloud cover":
        string_compare = True
        col = datasets.split_list3(datasets.get_column(data, 8))[0]
    elif field == "cloud type":
        string_compare = True
        col = datasets.strip_items(datasets.split_list3(datasets.get_column(data, 8))[1], ["(", ")"])
    elif field == "notes":
        string_compare = True
        col = datasets.get_column(data, 9)
    
    # Loop through the data, and add it to the filtered list if it matches the condition.
    for i in range(0, len(data)):
        matches = filter_compare(col[i], condition[1].lower(), condition[2], string_compare, insensitive)
        if matches:
            filtered.append(data[i])
    
    return filtered
Beispiel #12
0
def filter_data(data, condition, insensitive):
    """Filters the data based on the user's conditions."""

    # Create the list for the filtered data.
    filtered = []

    # Get the column of the data that is being filtered.
    string_compare = False
    col = []
    field = condition[0].lower()
    if field == "date":
        col = datasets.get_column(data, 0)
        string_compare = True
    elif field == "temperature":
        col = datasets.convert_float(datasets.get_column(data, 1))
    elif field == "wind chill":
        col = datasets.convert_float(datasets.get_column(data, 2))
    elif field == "precipitation amount":
        col = datasets.get_column(data, 3)
        col = datasets.convert_float(
            datasets.none_to_zero(datasets.split_list(col)[0]))
    elif field == "precipitation type":
        string_compare = True
        ncol = datasets.get_column(data, 3)
        col = []
        for i in ncol:
            if i == "None":
                col.append(i)
            else:
                i_split = i.split(" ")
                col.append(i_split[1])
    elif field == "wind speed":
        col = datasets.get_column(data, 4)
        col = datasets.convert_float(
            datasets.none_to_zero(datasets.split_list(col)[0]))
    elif field == "wind direction":
        string_compare = True
        ncol = datasets.get_column(data, 4)
        col = []
        for i in ncol:
            if i == "None":
                col.append(i)
            else:
                i_split = i.split(" ")
                col.append(i_split[1])
    elif field == "humidity":
        col = datasets.convert_float(datasets.get_column(data, 5))
    elif field == "air pressure":
        col = datasets.convert_float(
            datasets.split_list(datasets.get_column(data, 6))[0])
    elif field == "air pressure change":
        string_compare = True
        col = datasets.split_list(datasets.get_column(data, 6))[1]
    elif field == "visibility":
        col = datasets.convert_float(datasets.get_column(data, 7))
    elif field == "cloud cover":
        string_compare = True
        col = datasets.split_list3(datasets.get_column(data, 8))[0]
    elif field == "cloud type":
        string_compare = True
        col = datasets.strip_items(
            datasets.split_list3(datasets.get_column(data, 8))[1], ["(", ")"])
    elif field == "notes":
        string_compare = True
        col = datasets.get_column(data, 9)

    # Loop through the data, and add it to the filtered list if it matches the condition.
    for i in range(0, len(data)):
        matches = filter_compare(col[i], condition[1].lower(), condition[2],
                                 string_compare, insensitive)
        if matches:
            filtered.append(data[i])

    return filtered
Beispiel #13
0
def get_data(data):
    """Gets the graph data."""
    
    # Get the date data.
    date_data = datasets.get_column(data, 0)
    new_dates = dates.get_datetimes(date_data)
    
    # Get the data.
    temp_data = datasets.convert_float(datasets.get_column(data, 1))
    chil_data = datasets.convert_float(datasets.get_column(data, 2))
    prec_data1, prec_data2 = datasets.split_list(datasets.get_column(data, 3))
    prec_data = datasets.convert_float(datasets.none_to_zero(prec_data1))
    wind_data1, wind_data2 = datasets.split_list(datasets.get_column(data, 4))
    wind_data = datasets.convert_float(datasets.none_to_zero(wind_data1))
    humi_data = datasets.convert_float(datasets.get_column(data, 5))
    airp_data1, airp_data2 = datasets.split_list(datasets.get_column(data, 6))
    airp_data = datasets.convert_float(airp_data1)
    visi_data = datasets.convert_float(datasets.get_column(data, 7))
    clou_data1, clou_data2 = datasets.split_list3(datasets.get_column(data, 8))
    clou_data2 = datasets.strip_items(clou_data2, ["(", ")"])
    
    prec_split = datasets.split_list2(datasets.get_column(data, 3))
    prec_total = 0
    prec_total_rain = 0
    prec_total_snow = 0
    prec_total_hail = 0
    prec_total_sleet = 0
    prec_none = 0
    prec_rain = 0
    prec_snow = 0
    prec_hail = 0
    prec_sleet = 0
    for i in prec_split:
        if i[1] != "None":
            prec_total += float(i[0])
        if i[1] == "None":
            prec_none += 1
        elif i[1] == "Rain":
            prec_total_rain += float(i[0])
            prec_rain += 1
        elif i[1] == "Snow":
            prec_total_snow += float(i[0])
            prec_snow += 1
        elif i[1] == "Hail":
            prec_total_hail += float(i[0])
            prec_hail += 1
        elif i[1] == "Sleet":
            prec_total_sleet += float(i[0])
            prec_sleet += 1
    prec_amount = [prec_total_rain, prec_total_snow, prec_total_hail, prec_total_sleet]
    prec_days = [prec_none, prec_rain, prec_snow, prec_hail, prec_sleet]
    
    airp_steady = 0
    airp_rising = 0
    airp_falling = 0
    for i in airp_data2:
        if i == "Steady":
            airp_steady += 1
        elif i == "Rising":
            airp_rising += 1
        elif i == "Falling":
            airp_falling += 1
    airp_change = [airp_steady, airp_rising, airp_falling]
    
    clou_sunny = 0
    clou_msunny = 0
    clou_pcloudy = 0
    clou_mcloudy = 0
    clou_cloudy = 0
    for i in clou_data1:
        if i == "Sunny":
            clou_sunny += 1
        elif i == "Mostly Sunny":
            clou_msunny += 1
        elif i == "Partly Cloudy":
            clou_pcloudy += 1
        elif i == "Mostly Cloudy":
            clou_mcloudy += 1
        elif i == "Cloudy":
            clou_cloudy += 1
    clou_days = [clou_sunny, clou_msunny, clou_pcloudy, clou_mcloudy, clou_cloudy]
    
    clou_types = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    for i in clou_data2:
        if i == "None":
            clou_types[0] += 1
        elif i == "Unknown":
            clou_types[1] += 1
        elif i == "Cirrus":
            clou_types[2] += 1
        elif i == "Cirrocumulus":
            clou_types[3] += 1
        elif i == "Cirrostratus":
            clou_types[4] += 1
        elif i == "Cumulonimbus":
            clou_types[5] += 1
        elif i == "Altocumulus":
            clou_types[6] += 1
        elif i == "Altostratus":
            clou_types[7] += 1
        elif i == "Stratus":
            clou_types[8] += 1
        elif i == "Cumulus":
            clou_types[9] += 1
        elif i == "Stratocumulus":
            clou_types[10] += 1
    
    data = {"date_labels": date_data,
            "date_ticks": new_dates,
            "temp_data": temp_data,
            "prec_data": prec_data,
            "wind_data": wind_data,
            "humi_data": humi_data, 
            "airp_data": airp_data,
            "prec_amount": prec_amount,
            "prec_days": prec_days,
            "airp_change": airp_change,
            "clou_days": clou_days,
            "clou_types": clou_types,
            "chil_data": chil_data,
            "visi_data": visi_data}
    
    return data
Beispiel #14
0
def general_info(data, units):
    """Gets the general info."""
    
    # Get the date data.
    date_data = datasets.get_column(data, 0)
    date_first = date_data[0]
    date_last = date_data[len(date_data) - 1]
    date_first2 = datetime.datetime.strptime(date_first, "%d/%m/%Y")
    date_last2 = datetime.datetime.strptime(date_last, "%d/%m/%Y")
    date_num = (date_last2 - date_first2).days + 1
    day_num = len(data)
    
    # Get the temperature data.
    temp_data = datasets.convert_float(datasets.get_column(data, 1))
    temp_low = min(temp_data)
    temp_high = max(temp_data)
    temp_avg = calculations.mean(temp_data)
    
    # Get the wind chill data.
    chil_data = datasets.convert_float(datasets.get_column(data, 2))
    chil_low = min(chil_data)
    chil_high = max(chil_data)
    chil_avg = calculations.mean(chil_data)
    
    # Get the precipitation data.
    prec_data1, prec_data2 = datasets.split_list(datasets.get_column(data, 3))
    prec_data1 = datasets.convert_float(datasets.none_to_zero(prec_data1))
    try:
        prec_low = min(prec_data1)
        prec_high = max(prec_data1)
        prec_avg = calculations.mean(prec_data1)
    except ZeroDivisionError:
        prec_low = "None"
        prec_high = "None"
        prec_avg = "None"
    
    # Get the wind data.
    wind_data1, wind_data2 = datasets.split_list(datasets.get_column(data, 4))
    wind_data1 = datasets.convert_float(datasets.none_to_zero(wind_data1))
    try:
        wind_low = min(wind_data1)
        wind_high = max(wind_data1)
        wind_avg = calculations.mean(wind_data1)
    except ZeroDivisionError:
        wind_low = "None"
        wind_high = "None"
        wind_avg = "None"
    
    # Get the humidity data.
    humi_data = datasets.convert_float(datasets.get_column(data, 5))
    humi_low = min(humi_data)
    humi_high = max(humi_data)
    humi_avg = calculations.mean(humi_data)
    
    # Get the air pressure data.
    airp_data1, airp_data2 = datasets.split_list(datasets.get_column(data, 6))
    airp_data1 = datasets.convert_float(airp_data1)
    airp_low = min(airp_data1)
    airp_high = max(airp_data1)
    airp_avg = calculations.mean(airp_data1)
    
    # Get the visibility data.
    visi_data = datasets.convert_float(datasets.get_column(data, 7))
    visi_low = min(visi_data)
    visi_high = max(visi_data)
    visi_avg = calculations.mean(visi_data)
    
    # Get the cloud cover data.
    clou_data = datasets.split_list3(datasets.get_column(data, 8))
    clou_data1 = Counter(clou_data[0])
    clou_data2 = Counter(datasets.strip_items(clou_data[1], ["(", ")"]))
    clou_data1_counter = clou_data1.most_common(1)[0]
    clou_data2_counter = clou_data2.most_common(1)[0]
    clou_mode1 = clou_data1_counter[0]
    clou_mode1_count = clou_data1_counter[1]
    clou_mode2 = clou_data2_counter[0]
    clou_mode2_count = clou_data2_counter[1]
    
    # Change any values, if needed.
    prec_low = "None" if prec_low == "None" else ("%.2f %s" % (prec_low, units["prec"]))
    prec_high = "None" if prec_high == "None" else ("%.2f %s" % (prec_high, units["prec"]))
    prec_avg = "None" if prec_avg == "None" else ("%.2f %s" % (prec_avg, units["prec"]))
    wind_low = "None" if wind_low == "None" else ("%.2f %s" % (wind_low, units["wind"]))
    wind_high = "None" if wind_high == "None" else ("%.2f %s" % (wind_high, units["wind"]))
    wind_avg = "None" if wind_avg == "None" else ("%.2f %s" % (wind_avg, units["wind"]))
    
    # Create the data list.
    data2 = [
        ["First date", "%s" % date_first],
        ["Last date", "%s" % date_last],
        ["Number of days", "%d days" % day_num],
        ["Range of days", "%d days" % date_num],
        ["Lowest temperature", "%.2f %s" % (temp_low, units["temp"])], 
        ["Highest temperature", "%.2f %s" % (temp_high, units["temp"])],
        ["Average temperature", "%.2f %s" % (temp_avg, units["temp"])],
        ["Lowest wind chill", "%.2f %s" % (chil_low, units["temp"])], 
        ["Highest wind chill", "%.2f %s" % (chil_high, units["temp"])],
        ["Average wind chill", "%.2f %s" % (chil_avg, units["temp"])],
        ["Lowest precipitation", prec_low],
        ["Highest precipitation", prec_high],
        ["Average precipitation", prec_avg],
        ["Lowest wind speed", wind_low],
        ["Highest wind speed", wind_high],
        ["Average wind speed", wind_avg],
        ["Lowest humidity", "%.2f%%" % humi_low], 
        ["Highest humidity", "%.2f%%" % humi_high],
        ["Average humidity", "%.2f%%" % humi_avg],
        ["Lowest air pressure", "%.2f %s" % (airp_low, units["airp"])],
        ["Highest air pressure", "%.2f %s" % (airp_high, units["airp"])],
        ["Average air pressure", "%.2f %s" % (airp_avg, units["airp"])],
        ["Lowest visibility", "%.2f %s" % (visi_low, units["visi"])], 
        ["Highest visibility", "%.2f %s" % (visi_high, units["visi"])],
        ["Average visibility", "%.2f %s" % (visi_avg, units["visi"])],
        ["Most common cloud cover", "%s (%d occurrences)" % (clou_mode1, clou_mode1_count)],
        ["Most common cloud type", "%s (%d occurrences)" % (clou_mode2, clou_mode2_count)]
    ]
    
    return data2
Beispiel #15
0
def prec_info(data, units):
    """"Gets the precipitation info."""
    
    # Get the data.
    num_days = len(data)
    prec_data1, prec_data2 = datasets.split_list(datasets.get_column(data, 3))
    prec_split = datasets.split_list2(datasets.get_column(data, 3))
    prec_data1 = datasets.none_to_zero(prec_data1)
    prec_data1 = datasets.convert_float(prec_data1)
    try:
        prec_low = min(prec_data1)
        prec_high = max(prec_data1)
        prec_avg = calculations.mean(prec_data1)
        prec_median = calculations.median(prec_data1)
        prec_range = calculations.range(prec_data1)
    except ZeroDivisionError:
        prec_low = "None"
        prec_high = "None"
        prec_avg = "None"
        prec_median = "None"
        prec_range = "None"
    prec_total = 0
    prec_total_rain = 0
    prec_total_snow = 0
    prec_total_hail = 0
    prec_total_sleet = 0
    prec_none = 0
    prec_rain = 0
    prec_snow = 0
    prec_hail = 0
    prec_sleet = 0
    for i in prec_split:
        if i[1] != "None":
            prec_total += float(i[0])
        if i[1] == "None":
            prec_none += 1
        elif i[1] == "Rain":
            prec_total_rain += float(i[0])
            prec_rain += 1
        elif i[1] == "Snow":
            prec_total_snow += float(i[0])
            prec_snow += 1
        elif i[1] == "Hail":
            prec_total_hail += float(i[0])
            prec_hail += 1
        elif i[1] == "Sleet":
            prec_total_sleet += float(i[0])
            prec_sleet += 1
    prec_mode, prec_mode_count = calculations.mode(prec_data2)
    if prec_total == 0:
        prec_per_rain = "0%"
        prec_per_snow = "0%"
        prec_per_hail = "0%"
        prec_per_sleet = "0%"
    else:
        prec_per_rain = "%.2f%%" % ((prec_total_rain / prec_total) * 100)
        prec_per_snow = "%.2f%%" % ((prec_total_snow / prec_total) * 100)
        prec_per_hail = "%.2f%%" % ((prec_total_hail / prec_total) * 100)
        prec_per_sleet = "%.2f%%" % ((prec_total_sleet / prec_total) * 100)
    
    # Change any values, if needed.
    prec_low = "None" if prec_low == "None" else ("%.2f %s" % (prec_low, units["prec"]))
    prec_high = "None" if prec_high == "None" else ("%.2f %s" % (prec_high, units["prec"]))
    prec_avg = "None" if prec_avg == "None" else ("%.2f %s" % (prec_avg, units["prec"]))
    prec_median = "None" if prec_median == "None" else ("%.2f %s" % (prec_median, units["prec"]))
    prec_range = "None" if prec_range == "None" else ("%.2f %s" % (prec_range, units["prec"]))
    
    # Create the data list.
    data2 = [
        ["Lowest precipitation", prec_low],
        ["Highest precipitation", prec_high],
        ["Average precipitation", prec_avg],
        ["Median precipitation", prec_median],
        ["Range of precipitation", prec_range],
        ["Total precipitation", "%.2f %s" % (prec_total, units["prec"])],
        ["Total rain", "%.2f %s (%s)" % (prec_total_rain, units["prec"], prec_per_rain)],
        ["Total snow", "%.2f %s (%s)" % (prec_total_snow, units["prec"], prec_per_snow)],
        ["Total hail", "%.2f %s (%s)" % (prec_total_hail, units["prec"], prec_per_hail)],
        ["Total sleet", "%.2f %s (%s)" % (prec_total_sleet, units["prec"], prec_per_sleet)],
        ["Days with no precipitation", "%d day%s (%.2f%%)" %
            (prec_none, "" if prec_none == 1 else "s", (prec_none / num_days) * 100)],
        ["Days with rain", "%d day%s (%.2f%%)" %
            (prec_rain, "" if prec_rain == 1 else "s", (prec_rain / num_days) * 100)],
        ["Days with snow", "%d day%s (%.2f%%)" %
            (prec_snow, "" if prec_snow == 1 else "s", (prec_snow / num_days) * 100)],
        ["Days with hail", "%d day%s (%.2f%%)" %
            (prec_hail, "" if prec_hail == 1 else "s", (prec_hail / num_days) * 100)],
        ["Days with sleet", "%d day%s (%.2f%%)" %
            (prec_sleet, "" if prec_sleet == 1 else "s", (prec_sleet / num_days) * 100)],
        ["Most common precipitation type", "%s (%d occurrences)" %
            (prec_mode if prec_mode != "" else "None", prec_mode_count)]
    ]
    
    return data2