Пример #1
0
def clou_info(data, units):
    """Gets the cloud cover info."""

    # Get the data.
    num_days = len(data)
    clou_data1, clou_data2 = datasets.split_list3(datasets.get_column(data, 8))
    # Get the number of days of each cloud cover.
    clou_cover = Counter(clou_data1)
    m_list1 = clou_cover.most_common()
    m_dict1 = {}
    for i in m_list1:
        m_dict1[i[0]] = i[1]
    # Get the number of days of each cloud type.
    clou_type = Counter(datasets.strip_items(clou_data2, ["(", ")"]))
    m_list2 = clou_type.most_common()
    m_dict2 = {}
    for i in m_list2:
        m_dict2[i[0]] = i[1]

    # If any of the items don't appear, add dict items for them, with the values set to 0.
    if "Sunny" not in m_dict1:
        m_dict1["Sunny"] = 0
    if "Mostly Sunny" not in m_dict1:
        m_dict1["Mostly Sunny"] = 0
    if "Partly Cloudy" not in m_dict1:
        m_dict1["Partly Cloudy"] = 0
    if "Mostly Cloudy" not in m_dict1:
        m_dict1["Mostly Cloudy"] = 0
    if "Cloudy" not in m_dict1:
        m_dict1["Cloudy"] = 0
    if "None" not in m_dict2:
        m_dict2["None"] = 0
    if "Unknown" not in m_dict2:
        m_dict2["Unknown"] = 0
    if "Cirrus" not in m_dict2:
        m_dict2["Cirrus"] = 0
    if "Cirrocumulus" not in m_dict2:
        m_dict2["Cirrocumulus"] = 0
    if "Cirrostratus" not in m_dict2:
        m_dict2["Cirrostratus"] = 0
    if "Cumulonimbus" not in m_dict2:
        m_dict2["Cumulonimbus"] = 0
    if "Altocumulus" not in m_dict2:
        m_dict2["Altocumulus"] = 0
    if "Altostratus" not in m_dict2:
        m_dict2["Altostratus"] = 0
    if "Stratus" not in m_dict2:
        m_dict2["Stratus"] = 0
    if "Cumulus" not in m_dict2:
        m_dict2["Cumulus"] = 0
    if "Stratocumulus" not in m_dict2:
        m_dict2["Stratocumulus"] = 0

    # Create the data list.
    data2 = [
        [
            "Most common cloud cover",
            "%s (%s occurrences)" % (m_list1[0][0], m_list1[0][1])
        ],
        [
            "Most common cloud type",
            "%s (%s occurrences)" % (m_list2[0][0], m_list2[0][1])
        ],
        [
            "Days sunny",
            "%s day%s (%d%%)" %
            (m_dict1["Sunny"], "" if m_dict1["Sunny"] == 1 else "s",
             (m_dict1["Sunny"] / num_days) * 100)
        ],
        [
            "Days mostly sunny",
            "%s day%s (%d%%)" % (m_dict1["Mostly Sunny"],
                                 "" if m_dict1["Mostly Sunny"] == 1 else "s",
                                 (m_dict1["Mostly Sunny"] / num_days) * 100)
        ],
        [
            "Days partly cloudy",
            "%s day%s (%d%%)" % (m_dict1["Partly Cloudy"],
                                 "" if m_dict1["Partly Cloudy"] == 1 else "s",
                                 (m_dict1["Partly Cloudy"] / num_days) * 100)
        ],
        [
            "Days mostly cloudy",
            "%s day%s (%d%%)" % (m_dict1["Mostly Cloudy"],
                                 "" if m_dict1["Mostly Cloudy"] == 1 else "s",
                                 (m_dict1["Mostly Cloudy"] / num_days) * 100)
        ],
        [
            "Days cloudy",
            "%s day%s (%d%%)" %
            (m_dict1["Cloudy"], "" if m_dict1["Cloudy"] == 1 else "s",
             (m_dict1["Cloudy"] / num_days) * 100)
        ],
        [
            "Days with no clouds",
            "%s day%s (%d%%)" %
            (m_dict2["None"], "" if m_dict2["None"] == 1 else "s",
             (m_dict2["None"] / num_days) * 100)
        ],
        [
            "Days with unknown clouds",
            "%s day%s (%d%%)" %
            (m_dict2["Unknown"], "" if m_dict2["Unknown"] == 1 else "s",
             (m_dict2["Unknown"] / num_days) * 100)
        ],
        [
            "Days with cirrus",
            "%s day%s (%d%%)" %
            (m_dict2["Cirrus"], "" if m_dict2["Cirrus"] == 1 else "s",
             (m_dict2["Unknown"] / num_days) * 100)
        ],
        [
            "Days with cirrocumulus",
            "%s day%s (%d%%)" % (m_dict2["Cirrocumulus"],
                                 "" if m_dict2["Cirrocumulus"] == 1 else "s",
                                 (m_dict2["Cirrocumulus"] / num_days) * 100)
        ],
        [
            "Days with cirrostratos",
            "%s day%s (%d%%)" % (m_dict2["Cirrostratus"],
                                 "" if m_dict2["Cirrostratus"] == 1 else "s",
                                 (m_dict2["Cirrostratus"] / num_days) * 100)
        ],
        [
            "Days with cumulonimbus",
            "%s day%s (%d%%)" % (m_dict2["Cumulonimbus"],
                                 "" if m_dict2["Cumulonimbus"] == 1 else "s",
                                 (m_dict2["Cumulonimbus"] / num_days) * 100)
        ],
        [
            "Days with altocumulus",
            "%s day%s (%d%%)" % (m_dict2["Altocumulus"],
                                 "" if m_dict2["Altocumulus"] == 1 else "s",
                                 (m_dict2["Altocumulus"] / num_days) * 100)
        ],
        [
            "Days with altostratus",
            "%s day%s (%d%%)" % (m_dict2["Altostratus"],
                                 "" if m_dict2["Altostratus"] == 1 else "s",
                                 (m_dict2["Altostratus"] / num_days) * 100)
        ],
        [
            "Days with stratus",
            "%s day%s (%d%%)" %
            (m_dict2["Stratus"], "" if m_dict2["Stratus"] == 1 else "s",
             (m_dict2["Stratus"] / num_days) * 100)
        ],
        [
            "Days with cumulus",
            "%s day%s (%d%%)" %
            (m_dict2["Cumulus"], "" if m_dict2["Cumulus"] == 1 else "s",
             (m_dict2["Cumulus"] / num_days) * 100)
        ],
        [
            "Days with stratocumulus",
            "%s day%s (%d%%)" % (m_dict2["Stratocumulus"],
                                 "" if m_dict2["Stratocumulus"] == 1 else "s",
                                 (m_dict2["Stratocumulus"] / num_days) * 100)
        ]
    ]

    return data2
Пример #2
0
def filter_data(data, condition):
    """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 == "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)
        if matches:
            filtered.append(data[i])
    
    return filtered
Пример #3
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
Пример #4
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:
        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:
        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
Пример #5
0
def clou_info(data, units):
    """Gets the cloud cover info."""
    
    # Get the data.
    num_days = len(data)
    clou_data1, clou_data2 = datasets.split_list3(datasets.get_column(data, 8))
    # Get the number of days of each cloud cover.
    clou_cover = Counter(clou_data1)
    m_list1 = clou_cover.most_common()
    m_dict1 = {}
    for i in m_list1:
        m_dict1[i[0]] = i[1]
    # Get the number of days of each cloud type.
    clou_type = Counter(datasets.strip_items(clou_data2, ["(", ")"]))
    m_list2 = clou_type.most_common()
    m_dict2 = {}
    for i in m_list2:
        m_dict2[i[0]] = i[1]
    
    # If any of the items don't appear, add dict items for them, with the values set to 0.
    if not "Sunny" in m_dict1:
        m_dict1["Sunny"] = 0
    if not "Mostly Sunny" in m_dict1:
        m_dict1["Mostly Sunny"] = 0
    if not "Partly Cloudy" in m_dict1:
        m_dict1["Partly Cloudy"] = 0
    if not "Mostly Cloudy" in m_dict1:
        m_dict1["Mostly Cloudy"] = 0
    if not "Cloudy" in m_dict1:
        m_dict1["Cloudy"] = 0
    if not "None" in m_dict2:
        m_dict2["None"] = 0
    if not "Unknown" in m_dict2:
        m_dict2["Unknown"] = 0
    if not "Cirrus" in m_dict2:
        m_dict2["Cirrus"] = 0
    if not "Cirrocumulus" in m_dict2:
        m_dict2["Cirrocumulus"] = 0
    if not "Cirrostratus" in m_dict2:
        m_dict2["Cirrostratus"] = 0
    if not "Cumulonimbus" in m_dict2:
        m_dict2["Cumulonimbus"] = 0
    if not "Altocumulus" in m_dict2:
        m_dict2["Altocumulus"] = 0
    if not "Altostratus" in m_dict2:
        m_dict2["Altostratus"] = 0
    if not "Stratus" in m_dict2:
        m_dict2["Stratus"] = 0
    if not "Cumulus" in m_dict2:
        m_dict2["Cumulus"] = 0
    if not "Stratocumulus" in m_dict2:
        m_dict2["Stratocumulus"] = 0
    
    # Create the data list.
    data2 = [
        ["Most common cloud cover", "%s (%s occurrences)" % (m_list1[0][0], m_list1[0][1])],
        ["Most common cloud type", "%s (%s occurrences)" % (m_list2[0][0], m_list2[0][1])],
        ["Days sunny", "%s day%s (%d%%)" % (m_dict1["Sunny"], "" if m_dict1["Sunny"] == 1 else "s", (m_dict1["Sunny"] / num_days) * 100)],
        ["Days mostly sunny", "%s day%s (%d%%)" % (m_dict1["Mostly Sunny"], "" if m_dict1["Mostly Sunny"] == 1 else "s", (m_dict1["Mostly Sunny"] / num_days) * 100)],
        ["Days partly cloudy", "%s day%s (%d%%)" % (m_dict1["Partly Cloudy"], "" if m_dict1["Partly Cloudy"] == 1 else "s", (m_dict1["Partly Cloudy"] / num_days) * 100)],
        ["Days mostly cloudy", "%s day%s (%d%%)" % (m_dict1["Mostly Cloudy"], "" if m_dict1["Mostly Cloudy"] == 1 else "s", (m_dict1["Mostly Cloudy"] / num_days) * 100)],
        ["Days cloudy", "%s day%s (%d%%)" % (m_dict1["Cloudy"], "" if m_dict1["Cloudy"] == 1 else "s", (m_dict1["Cloudy"] / num_days) * 100)],
        ["Days with no clouds", "%s day%s (%d%%)" % (m_dict2["None"], "" if m_dict2["None"] == 1 else "s", (m_dict2["None"] / num_days) * 100)],
        ["Days with unknown clouds", "%s day%s (%d%%)" % (m_dict2["Unknown"], "" if m_dict2["Unknown"] == 1 else "s", (m_dict2["Unknown"] / num_days) * 100)],
        ["Days with cirrus", "%s day%s (%d%%)" % (m_dict2["Cirrus"], "" if m_dict2["Cirrus"] == 1 else "s", (m_dict2["Unknown"] / num_days) * 100)],
        ["Days with cirrocumulus", "%s day%s (%d%%)" % (m_dict2["Cirrocumulus"], "" if m_dict2["Cirrocumulus"] == 1 else "s", (m_dict2["Cirrocumulus"] / num_days) * 100)],
        ["Days with cirrostratos", "%s day%s (%d%%)" % (m_dict2["Cirrostratus"], "" if m_dict2["Cirrostratus"] == 1 else "s", (m_dict2["Cirrostratus"] / num_days) * 100)],
        ["Days with cumulonimbus", "%s day%s (%d%%)" % (m_dict2["Cumulonimbus"], "" if m_dict2["Cumulonimbus"] == 1 else "s", (m_dict2["Cumulonimbus"] / num_days) * 100)],
        ["Days with altocumulus", "%s day%s (%d%%)" % (m_dict2["Altocumulus"], "" if m_dict2["Altocumulus"] == 1 else "s", (m_dict2["Altocumulus"] / num_days) * 100)],
        ["Days with altostratus", "%s day%s (%d%%)" % (m_dict2["Altostratus"], "" if m_dict2["Altostratus"] == 1 else "s", (m_dict2["Altostratus"] / num_days) * 100)],
        ["Days with stratus", "%s day%s (%d%%)" % (m_dict2["Stratus"], "" if m_dict2["Stratus"] == 1 else "s", (m_dict2["Stratus"] / num_days) * 100)],
        ["Days with cumulus", "%s day%s (%d%%)" % (m_dict2["Cumulus"], "" if m_dict2["Cumulus"] == 1 else "s", (m_dict2["Cumulus"] / num_days) * 100)],
        ["Days with stratocumulus", "%s day%s (%d%%)" % (m_dict2["Stratocumulus"], "" if m_dict2["Stratocumulus"] == 1 else "s", (m_dict2["Stratocumulus"] / num_days) * 100)]
    ]
    
    return data2
Пример #6
0
 def __init__(self, parent, profile, data, date, units):
     """Create the dialog."""
     
     # Determine the default units.
     unit = 0
     if units["prec"] == "in":
         unit = 1
     
     # Create the dialog
     Gtk.Dialog.__init__(self, "Edit %s - %s" % (date, profile), parent, Gtk.DialogFlags.MODAL)
     self.set_size_request(500, 600)
     self.set_resizable(False)
     self.add_button("Cancel", Gtk.ResponseType.CANCEL)
     self.add_button("OK", Gtk.ResponseType.OK)
     
     # Create the grids.
     new_box = self.get_content_area()
     new_grid = Gtk.Grid()
     new_grid.set_column_spacing(3)
     new_grid.set_row_spacing(3)
     new_box.add(new_grid)
     
     # Temperature entry
     temp_lbl = Gtk.Label("Temperature: ")
     temp_lbl.set_alignment(0, 0.5)
     new_grid.add(temp_lbl)
     if units["temp"] == "°C":
         temp_adj = Gtk.Adjustment(lower = -100, upper = 100, step_increment = 1)
     else:
         temp_adj = Gtk.Adjustment(lower = -150, upper = 150, step_increment = 1)
     self.temp_sbtn = Gtk.SpinButton(digits = 2, adjustment = temp_adj)
     self.temp_sbtn.set_numeric(False)
     self.temp_sbtn.set_value(0)
     new_grid.attach_next_to(self.temp_sbtn, temp_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.temp_unit = Gtk.ComboBoxText()
     for i in ["°C", "°F"]:
         self.temp_unit.append_text(i)
     self.temp_unit.set_active(unit)
     new_grid.attach_next_to(self.temp_unit, self.temp_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Wind Chill entry
     chil_lbl = Gtk.Label("Wind Chill: ")
     chil_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(chil_lbl, temp_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     if units["temp"] == "°C":
         chil_adj = Gtk.Adjustment(lower = -100, upper = 100, step_increment = 1)
     else:
         chil_adj = Gtk.Adjustment(lower = -150, upper = 150, step_increment = 1)
     self.chil_sbtn = Gtk.SpinButton(digits = 2, adjustment = chil_adj)
     self.chil_sbtn.set_numeric(False)
     self.chil_sbtn.set_value(0)
     new_grid.attach_next_to(self.chil_sbtn, chil_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.chil_unit = Gtk.ComboBoxText()
     for i in ["°C", "°F"]:
         self.chil_unit.append_text(i)
     self.chil_unit.set_active(unit)
     new_grid.attach_next_to(self.chil_unit, self.chil_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Precipitation entry
     prec_lbl = Gtk.Label("Precipitation: ")
     prec_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(prec_lbl, chil_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     prec_adj = Gtk.Adjustment(lower = 0, upper = 100, step_increment = 1)
     self.prec_sbtn = Gtk.SpinButton(digits = 2, adjustment = prec_adj)
     self.prec_sbtn.set_numeric(False)
     self.prec_sbtn.set_value(0)
     new_grid.attach_next_to(self.prec_sbtn, prec_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.prec_unit = Gtk.ComboBoxText()
     for i in ["cm", "in"]:
         self.prec_unit.append_text(i)
     self.prec_unit.set_active(unit)
     new_grid.attach_next_to(self.prec_unit, self.prec_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Precipitation Type entry
     prec_lbl2 = Gtk.Label("Precipitation Type: ")
     prec_lbl2.set_alignment(0, 0.5)
     new_grid.attach_next_to(prec_lbl2, prec_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.prec_com = Gtk.ComboBoxText()
     for i in ["None", "Rain", "Snow", "Hail", "Sleet"]:
         self.prec_com.append_text(i)
     self.prec_com.set_active(0)
     new_grid.attach_next_to(self.prec_com, prec_lbl2, Gtk.PositionType.RIGHT, 2, 1)
     
     # Wind Speed entry
     wind_lbl = Gtk.Label("Wind Speed: ")
     wind_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(wind_lbl, prec_lbl2, Gtk.PositionType.BOTTOM, 1, 1)
     wind_adj = Gtk.Adjustment(lower = 0, upper = 500, step_increment = 1)
     self.wind_sbtn = Gtk.SpinButton(digits = 2, adjustment = wind_adj)
     self.wind_sbtn.set_numeric(False)
     self.wind_sbtn.set_value(0)
     new_grid.attach_next_to(self.wind_sbtn, wind_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.wind_unit = Gtk.ComboBoxText()
     for i in ["kph", "mph"]:
         self.wind_unit.append_text(i)
     self.wind_unit.set_active(unit)
     new_grid.attach_next_to(self.wind_unit, self.wind_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Wind Direction entry
     wind_lbl2 = Gtk.Label("Wind Direction: ")
     wind_lbl2.set_alignment(0, 0.5)
     new_grid.attach_next_to(wind_lbl2, wind_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.wind_com = Gtk.ComboBoxText()
     for i in ["None", "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]:
         self.wind_com.append_text(i)
     self.wind_com.set_active(0)
     new_grid.attach_next_to(self.wind_com, wind_lbl2, Gtk.PositionType.RIGHT, 2, 1)
     
     # Humidity entry
     humi_lbl = Gtk.Label("Humidity %: ")
     humi_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(humi_lbl, wind_lbl2, Gtk.PositionType.BOTTOM, 1, 1)
     humi_adj = Gtk.Adjustment(lower = 0, upper = 100, step_increment = 1)
     self.humi_sbtn = Gtk.SpinButton(digits = 2, adjustment = humi_adj)
     self.humi_sbtn.set_numeric(False)
     self.humi_sbtn.set_value(0)
     new_grid.attach_next_to(self.humi_sbtn, humi_lbl, Gtk.PositionType.RIGHT, 2, 1)
     
     # Air Pressure entry
     airp_lbl = Gtk.Label("Air Pressure: ")
     airp_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(airp_lbl, humi_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     airp_adj = Gtk.Adjustment(lower = 0, upper = 2000, step_increment = 1)
     self.airp_sbtn = Gtk.SpinButton(digits = 2, adjustment = airp_adj)
     self.airp_sbtn.set_numeric(False)
     self.airp_sbtn.set_value(0)
     new_grid.attach_next_to(self.airp_sbtn, airp_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.airp_unit = Gtk.ComboBoxText()
     for i in ["hPa", "mbar"]:
         self.airp_unit.append_text(i)
     self.airp_unit.set_active(unit)
     new_grid.attach_next_to(self.airp_unit, self.airp_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Air Pressure Change entry
     airp_lbl2 = Gtk.Label("Air Pressure Change: ")
     airp_lbl2.set_alignment(0, 0.5)
     new_grid.attach_next_to(airp_lbl2, airp_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.airp_com = Gtk.ComboBoxText()
     for i in ["Steady", "Rising", "Falling"]:
         self.airp_com.append_text(i)
     self.airp_com.set_active(0)
     new_grid.attach_next_to(self.airp_com, airp_lbl2, Gtk.PositionType.RIGHT, 2, 1)
     
     # Visibility entry
     visi_lbl = Gtk.Label("Visibility: ")
     visi_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(visi_lbl, airp_lbl2, Gtk.PositionType.BOTTOM, 1, 1)
     visi_adj = Gtk.Adjustment(lower = 0, upper = 1000, step_increment = 1)
     self.visi_sbtn = Gtk.SpinButton(digits = 2, adjustment = visi_adj)
     self.visi_sbtn.set_numeric(False)
     self.visi_sbtn.set_value(0)
     new_grid.attach_next_to(self.visi_sbtn, visi_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.visi_unit = Gtk.ComboBoxText()
     for i in ["km", "mi"]:
         self.visi_unit.append_text(i)
     self.visi_unit.set_active(unit)
     new_grid.attach_next_to(self.visi_unit, self.visi_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Cloud Cover entry
     clou_lbl = Gtk.Label("Cloud Cover: ")
     clou_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(clou_lbl, visi_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.clou_com = Gtk.ComboBoxText()
     for i in ["Sunny", "Mostly Sunny", "Partly Cloudy", "Mostly Cloudy", "Cloudy"]:
         self.clou_com.append_text(i)
     self.clou_com.set_active(0)
     new_grid.attach_next_to(self.clou_com, clou_lbl, Gtk.PositionType.RIGHT, 2, 1)
     
     # Cloud Type entry
     clou_lbl2 = Gtk.Label("Cloud Type: ")
     clou_lbl2.set_alignment(0, 0.5)
     new_grid.attach_next_to(clou_lbl2, clou_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.clou_com2 = Gtk.ComboBoxText()
     for i in ["None", "Unknown", "Cirrus", "Cirrocumulus", "Cirrostratus", "Cumulonimbus", "Altocumulus", "Altostratus",
               "Stratus", "Cumulus", "Stratocumulus"]:
         self.clou_com2.append_text(i)
     self.clou_com2.set_active(0)
     new_grid.attach_next_to(self.clou_com2, clou_lbl2, Gtk.PositionType.RIGHT, 2, 1)
     
     # Notes entry
     note_lbl = Gtk.Label("Notes: ", valign = Gtk.Align.START)
     note_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(note_lbl, clou_lbl2, Gtk.PositionType.BOTTOM, 1, 1)
     self.note_view = Gtk.TextView()
     self.note_view.set_wrap_mode(Gtk.WrapMode.WORD)
     self.note_buffer = self.note_view.get_buffer()
     note_win = Gtk.ScrolledWindow()
     note_win.set_hexpand(True)
     note_win.set_vexpand(True)
     note_win.set_size_request(100, 100)
     note_win.add(self.note_view)
     new_grid.attach_next_to(note_win, note_lbl, Gtk.PositionType.RIGHT, 2, 1)
     
     # Set the values.
     self.temp_sbtn.set_value(float(data[1]))
     self.chil_sbtn.set_value(float(data[2]))
     if data[3] != "None":
         d2 = data[3].split(" ")
         prec_list = ["None", "Rain", "Snow", "Hail", "Sleet"]
         for i in range(0, len(prec_list)):
             if d2[1] == prec_list[i]:
                 self.prec_com.set_active(i)
                 break
         self.prec_sbtn.set_value(float(d2[0]))
     if data[4] != "None":
         d3 = data[4].split(" ")
         wind_list = ["None", "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]
         for i in range(0, len(wind_list)):
             if d3[1] == wind_list[i]:
                 self.wind_com.set_active(i)
                 break
         self.wind_sbtn.set_value(float(d3[0]))
     self.humi_sbtn.set_value(float(data[5]))
     d5 = data[6].split(" ")
     airp_list = ["Steady", "Rising", "Falling"]
     for i in range(0, len(airp_list)):
         if d5[1] == airp_list[i]:
             self.airp_com.set_active(i)
             break
     self.airp_sbtn.set_value(float(d5[0]))
     self.visi_sbtn.set_value(float(data[7]))
     clou_list1 = ["Sunny", "Mostly Sunny", "Partly Cloudy", "Mostly Cloudy", "Cloudy"]
     clou_list2 = ["None", "Unknown", "Cirrus", "Cirrocumulus", "Cirrostratus", "Cumulonimbus", "Altocumulus", "Altostratus", 
                   "Stratus", "Cumulus", "Stratocumulus"]
     d81, d82 = datasets.split_list3([data[8]])
     d82 = datasets.strip_items(d82, ["(", ")"])
     for i in range(0, len(clou_list1)):
         if d81[0] == clou_list1[i]:
             self.clou_com.set_active(i)
             break
     for i in range(0, len(clou_list2)):
         if d82[0] == clou_list2[i]:
             self.clou_com2.set_active(i)
             break
     self.note_buffer.set_text(data[9])
     
     # Connect 'Enter' key to the OK button.
     ok_btn = self.get_widget_for_response(response_id = Gtk.ResponseType.OK)
     ok_btn.set_can_default(True)
     ok_btn.grab_default()
     
     # Show the dialog.
     self.show_all()
Пример #7
0
def get_data(data):
    """Gets the graph data."""
    
    # Get the date data.
    date_data = datasets.get_column(data, 0)
    new_dates = get_dates(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_data, new_dates, temp_data, prec_data, wind_data, humi_data, airp_data, prec_amount,
            prec_days, airp_change, clou_days, clou_types, chil_data, visi_data]
    
    return data
Пример #8
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 == "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
Пример #9
0
 def __init__(self, parent, dataset, data, date, units):
     """Create the dialog."""
     
     # Determine the default units.
     unit = 0
     if config["units"] == "imperial":
         unit = 1
     
     Gtk.Dialog.__init__(self, "Edit %s - %s" % (date, dataset), parent, Gtk.DialogFlags.MODAL)
     self.set_size_request(500, 600)
     self.add_button("Cancel", Gtk.ResponseType.CANCEL)
     self.add_button("OK", Gtk.ResponseType.OK)
     
     # Create the grids.
     new_box = self.get_content_area()
     new_grid = Gtk.Grid()
     new_grid.set_column_spacing(3)
     new_grid.set_row_spacing(3)
     new_box.add(new_grid)
     
     # Temperature entry
     temp_lbl = Gtk.Label("Temperature: ")
     temp_lbl.set_alignment(0, 0.5)
     new_grid.add(temp_lbl)
     if units["temp"].encode("utf-8") == "°C":
         temp_adj = Gtk.Adjustment(lower = -100, upper = 100, step_increment = 1)
     else:
         temp_adj = Gtk.Adjustment(lower = -150, upper = 150, step_increment = 1)
     self.temp_sbtn = Gtk.SpinButton(digits = 2, adjustment = temp_adj)
     self.temp_sbtn.set_numeric(False)
     self.temp_sbtn.set_value(0)
     new_grid.attach_next_to(self.temp_sbtn, temp_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.temp_unit = Gtk.ComboBoxText()
     for i in ["°C", "°F"]:
         self.temp_unit.append_text(i)
     self.temp_unit.set_active(unit)
     new_grid.attach_next_to(self.temp_unit, self.temp_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Wind Chill entry
     chil_lbl = Gtk.Label("Wind Chill: ")
     chil_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(chil_lbl, temp_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     if units["temp"].encode("utf-8") == "°C":
         chil_adj = Gtk.Adjustment(lower = -100, upper = 100, step_increment = 1)
     else:
         chil_adj = Gtk.Adjustment(lower = -150, upper = 150, step_increment = 1)
     self.chil_sbtn = Gtk.SpinButton(digits = 2, adjustment = chil_adj)
     self.chil_sbtn.set_numeric(False)
     self.chil_sbtn.set_value(0)
     new_grid.attach_next_to(self.chil_sbtn, chil_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.chil_unit = Gtk.ComboBoxText()
     for i in ["°C", "°F"]:
         self.chil_unit.append_text(i)
     self.chil_unit.set_active(unit)
     new_grid.attach_next_to(self.chil_unit, self.chil_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Precipitation entry
     prec_lbl = Gtk.Label("Precipitation: ")
     prec_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(prec_lbl, chil_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     prec_adj = Gtk.Adjustment(lower = 0, upper = 100, step_increment = 1)
     self.prec_sbtn = Gtk.SpinButton(digits = 2, adjustment = prec_adj)
     self.prec_sbtn.set_numeric(False)
     self.prec_sbtn.set_value(0)
     new_grid.attach_next_to(self.prec_sbtn, prec_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.prec_unit = Gtk.ComboBoxText()
     for i in ["cm", "in"]:
         self.prec_unit.append_text(i)
     self.prec_unit.set_active(unit)
     new_grid.attach_next_to(self.prec_unit, self.prec_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Precipitation Type entry
     prec_lbl2 = Gtk.Label("Precipitation Type: ")
     prec_lbl2.set_alignment(0, 0.5)
     new_grid.attach_next_to(prec_lbl2, prec_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.prec_com = Gtk.ComboBoxText()
     for i in ["None", "Rain", "Snow", "Hail", "Sleet"]:
         self.prec_com.append_text(i)
     self.prec_com.set_active(0)
     new_grid.attach_next_to(self.prec_com, prec_lbl2, Gtk.PositionType.RIGHT, 2, 1)
     
     # Wind Speed entry
     wind_lbl = Gtk.Label("Wind Speed: ")
     wind_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(wind_lbl, prec_lbl2, Gtk.PositionType.BOTTOM, 1, 1)
     wind_adj = Gtk.Adjustment(lower = 0, upper = 500, step_increment = 1)
     self.wind_sbtn = Gtk.SpinButton(digits = 2, adjustment = wind_adj)
     self.wind_sbtn.set_numeric(False)
     self.wind_sbtn.set_value(0)
     new_grid.attach_next_to(self.wind_sbtn, wind_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.wind_unit = Gtk.ComboBoxText()
     for i in ["kph", "mph"]:
         self.wind_unit.append_text(i)
     self.wind_unit.set_active(unit)
     new_grid.attach_next_to(self.wind_unit, self.wind_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Wind Direction entry
     wind_lbl2 = Gtk.Label("Wind Direction: ")
     wind_lbl2.set_alignment(0, 0.5)
     new_grid.attach_next_to(wind_lbl2, wind_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.wind_com = Gtk.ComboBoxText()
     for i in ["None", "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]:
         self.wind_com.append_text(i)
     self.wind_com.set_active(0)
     new_grid.attach_next_to(self.wind_com, wind_lbl2, Gtk.PositionType.RIGHT, 2, 1)
     
     # Humidity entry
     humi_lbl = Gtk.Label("Humidity %: ")
     humi_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(humi_lbl, wind_lbl2, Gtk.PositionType.BOTTOM, 1, 1)
     humi_adj = Gtk.Adjustment(lower = 0, upper = 100, step_increment = 1)
     self.humi_sbtn = Gtk.SpinButton(digits = 2, adjustment = humi_adj)
     self.humi_sbtn.set_numeric(False)
     self.humi_sbtn.set_value(0)
     new_grid.attach_next_to(self.humi_sbtn, humi_lbl, Gtk.PositionType.RIGHT, 2, 1)
     
     # Air Pressure entry
     airp_lbl = Gtk.Label("Air Pressure: ")
     airp_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(airp_lbl, humi_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     airp_adj = Gtk.Adjustment(lower = 0, upper = 2000, step_increment = 1)
     self.airp_sbtn = Gtk.SpinButton(digits = 2, adjustment = airp_adj)
     self.airp_sbtn.set_numeric(False)
     self.airp_sbtn.set_value(0)
     new_grid.attach_next_to(self.airp_sbtn, airp_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.airp_unit = Gtk.ComboBoxText()
     for i in ["hPa", "mbar"]:
         self.airp_unit.append_text(i)
     self.airp_unit.set_active(unit)
     new_grid.attach_next_to(self.airp_unit, self.airp_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Air Pressure Change entry
     airp_lbl2 = Gtk.Label("Air Pressure Change: ")
     airp_lbl2.set_alignment(0, 0.5)
     new_grid.attach_next_to(airp_lbl2, airp_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.airp_com = Gtk.ComboBoxText()
     for i in ["Steady", "Rising", "Falling"]:
         self.airp_com.append_text(i)
     self.airp_com.set_active(0)
     new_grid.attach_next_to(self.airp_com, airp_lbl2, Gtk.PositionType.RIGHT, 2, 1)
     
     # Visibility entry
     visi_lbl = Gtk.Label("Visibility: ")
     visi_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(visi_lbl, airp_lbl2, Gtk.PositionType.BOTTOM, 1, 1)
     visi_adj = Gtk.Adjustment(lower = 0, upper = 1000, step_increment = 1)
     self.visi_sbtn = Gtk.SpinButton(digits = 2, adjustment = visi_adj)
     self.visi_sbtn.set_numeric(False)
     self.visi_sbtn.set_value(0)
     new_grid.attach_next_to(self.visi_sbtn, visi_lbl, Gtk.PositionType.RIGHT, 1, 1)
     self.visi_unit = Gtk.ComboBoxText()
     for i in ["km", "mi"]:
         self.visi_unit.append_text(i)
     self.visi_unit.set_active(unit)
     new_grid.attach_next_to(self.visi_unit, self.visi_sbtn, Gtk.PositionType.RIGHT, 1, 1)
     
     # Cloud Cover entry
     clou_lbl = Gtk.Label("Cloud Cover: ")
     clou_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(clou_lbl, visi_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.clou_com = Gtk.ComboBoxText()
     for i in ["Sunny", "Mostly Sunny", "Partly Cloudy", "Mostly Cloudy", "Cloudy"]:
         self.clou_com.append_text(i)
     self.clou_com.set_active(0)
     new_grid.attach_next_to(self.clou_com, clou_lbl, Gtk.PositionType.RIGHT, 2, 1)
     
     # Cloud Type entry
     clou_lbl2 = Gtk.Label("Cloud Type: ")
     clou_lbl2.set_alignment(0, 0.5)
     new_grid.attach_next_to(clou_lbl2, clou_lbl, Gtk.PositionType.BOTTOM, 1, 1)
     self.clou_com2 = Gtk.ComboBoxText()
     for i in ["None", "Unknown", "Cirrus", "Cirrocumulus", "Cirrostratus", "Cumulonimbus", "Altocumulus", "Altostratus",
               "Stratus", "Cumulus", "Stratocumulus"]:
         self.clou_com2.append_text(i)
     self.clou_com2.set_active(0)
     new_grid.attach_next_to(self.clou_com2, clou_lbl2, Gtk.PositionType.RIGHT, 2, 1)
     
     # Notes entry
     note_lbl = Gtk.Label("Notes: ", valign = Gtk.Align.START)
     note_lbl.set_alignment(0, 0.5)
     new_grid.attach_next_to(note_lbl, clou_lbl2, Gtk.PositionType.BOTTOM, 1, 1)
     self.note_view = Gtk.TextView()
     self.note_view.set_wrap_mode(Gtk.WrapMode.WORD)
     self.note_buffer = self.note_view.get_buffer()
     note_win = Gtk.ScrolledWindow()
     note_win.set_hexpand(True)
     note_win.set_vexpand(True)
     note_win.set_size_request(100, 100)
     note_win.add(self.note_view)
     new_grid.attach_next_to(note_win, note_lbl, Gtk.PositionType.RIGHT, 2, 1)
     
     # Set the values.
     self.temp_sbtn.set_value(float(data[1]))
     self.chil_sbtn.set_value(float(data[2]))
     if data[3] != "None":
         d2 = data[3].split(" ")
         prec_list = ["None", "Rain", "Snow", "Hail", "Sleet"]
         for i in range(0, len(prec_list)):
             if d2[1] == prec_list[i]:
                 self.prec_com.set_active(i)
                 break
         self.prec_sbtn.set_value(float(d2[0]))
     if data[4] != "None":
         d3 = data[4].split(" ")
         wind_list = ["None", "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]
         for i in range(0, len(wind_list)):
             if d3[1] == wind_list[i]:
                 self.wind_com.set_active(i)
                 break
         self.wind_sbtn.set_value(float(d3[0]))
     self.humi_sbtn.set_value(float(data[5]))
     d5 = data[6].split(" ")
     airp_list = ["Steady", "Rising", "Falling"]
     for i in range(0, len(airp_list)):
         if d5[1] == airp_list[i]:
             self.airp_com.set_active(i)
             break
     self.airp_sbtn.set_value(float(d5[0]))
     self.visi_sbtn.set_value(float(data[7]))
     clou_list1 = ["Sunny", "Mostly Sunny", "Partly Cloudy", "Mostly Cloudy", "Cloudy"]
     clou_list2 = ["None", "Unknown", "Cirrus", "Cirrocumulus", "Cirrostratus", "Cumulonimbus", "Altocumulus", "Altostratus", 
                   "Stratus", "Cumulus", "Stratocumulus"]
     d81, d82 = datasets.split_list3([data[8]])
     d82 = datasets.strip_items(d82, ["(", ")"])
     for i in range(0, len(clou_list1)):
         if d81[0] == clou_list1[i]:
             self.clou_com.set_active(i)
             break
     for i in range(0, len(clou_list2)):
         if d82[0] == clou_list2[i]:
             self.clou_com2.set_active(i)
             break
     self.note_buffer.set_text(data[9])
     
     # Connect 'Enter' key to the OK button.
     ok_btn = self.get_widget_for_response(response_id = Gtk.ResponseType.OK)
     ok_btn.set_can_default(True)
     ok_btn.grab_default()
     
     # Show the dialog.
     self.show_all()
Пример #10
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