예제 #1
0
def temp_info(data, units):
    """"Gets the temperature info."""

    # Get the 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)
    temp_median = calculations.median(temp_data)
    temp_range = calculations.range(temp_data)
    temp_mode, temp_mode_count = calculations.mode(temp_data)

    # Create the data list.
    data2 = [["Lowest temperature",
              "%.2f %s" % (temp_low, units["temp"])],
             ["Highest temperature",
              "%.2f %s" % (temp_high, units["temp"])],
             ["Average temperature",
              "%.2f %s" % (temp_avg, units["temp"])],
             ["Median temperature",
              "%.2f %s" % (temp_median, units["temp"])],
             [
                 "Range of temperatures",
                 "%.2f %s" % (temp_range, units["temp"])
             ],
             [
                 "Most common temperature",
                 "%.2f %s (%d occurrences)" %
                 (temp_mode, units["temp"], temp_mode_count)
             ]]

    return data2
예제 #2
0
def chil_info(data, units):
    """"Gets the wind chill info."""

    # Get the 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)
    chil_median = calculations.median(chil_data)
    chil_range = calculations.range(chil_data)
    chil_mode, chil_mode_count = calculations.mode(chil_data)

    # Create the data list.
    data2 = [["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"])],
             ["Median wind chill",
              "%.2f %s" % (chil_median, units["temp"])],
             ["Range of wind chills",
              "%.2f %s" % (chil_range, units["temp"])],
             [
                 "Most common wind chill",
                 "%.2f %s (%d occurrences)" %
                 (chil_mode, units["temp"], chil_mode_count)
             ]]

    return data2
예제 #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
예제 #4
0
def visi_info(data, units):
    """"Gets the visibility info."""

    # Get the data.
    visi_data = datasets.convert_float(datasets.get_column(data, 2))
    visi_low = min(visi_data)
    visi_high = max(visi_data)
    visi_avg = calculations.mean(visi_data)
    visi_median = calculations.median(visi_data)
    visi_range = calculations.range(visi_data)
    visi_mode, visi_mode_count = calculations.mode(visi_data)

    # Create the data list.
    data2 = [["Lowest visibility",
              "%.2f %s" % (visi_low, units["visi"])],
             ["Highest visibility",
              "%.2f %s" % (visi_high, units["visi"])],
             ["Average visibility",
              "%.2f %s" % (visi_avg, units["visi"])],
             ["Median visibility",
              "%.2f %s" % (visi_median, units["visi"])],
             ["Range of visibility",
              "%.2f %s" % (visi_range, units["visi"])],
             [
                 "Most common visibility",
                 "%.2f %s (%d occurrences)" %
                 (visi_mode, units["visi"], visi_mode_count)
             ]]

    return data2
예제 #5
0
def filter_and(set1, set2):
    """Returns a list of the items that are in both set1 and set2."""

    # Get the date column of the second list for the comparison.
    filtered = []
    date_list = datasets.get_column(set2, 0)

    # Loop through the first set, and only add the item to the filtered list if it's also in the second set.
    for i in set1:
        if i[0] in date_list:
            filtered.append(i)

    return filtered
예제 #6
0
def filter_and(set1, set2):
    """Returns a list of the items that are in both set1 and set2."""
    
    # Get the date column of the second list for the comparison.
    filtered = []
    date_list = datasets.get_column(set2, 0)
    
    # Loop through the first set, and only add the item to the filtered list if it's also in the second set.
    for i in set1:
        if i[0] in date_list:
            filtered.append(i)
    
    return filtered
예제 #7
0
def filter_not(set1, data):
    """Returns a list of the items in data that are not in set1."""

    # Get the date column of the set for the comparison.
    filtered = []
    date_list = datasets.get_column(set1, 0)

    # Loop through the data list, and only add the item to the filtered list if it's not in the other set.
    for i in data:
        if i[0] not in date_list:
            filtered.append(i)

    return filtered
예제 #8
0
def filter_not(set1, data):
    """Returns a list of the items in data that are not in set1."""
    
    # Get the date column of the set for the comparison.
    filtered = []
    date_list = datasets.get_column(set1, 0)
    
    # Loop through the data list, and only add the item to the filtered list if it's not in the other set.
    for i in data:
        if i[0] not in date_list:
            filtered.append(i)
    
    return filtered
예제 #9
0
def get_restore_data(main_dir, conf_dir, config, default_width, default_height, default_dataset="Main Dataset"):
    """Gets the last window size."""

    try:
        rest_file = open("%s/application_restore.json" % conf_dir, "r")
        rest_data = json.load(rest_file)
        rest_file.close()
        last_width = rest_data["window_width"]
        last_height = rest_data["window_height"]
        last_dataset = rest_data["last_dataset"]

    except IOError as e:
        print("get_window_size(): Error reading restore file (IOError):\n%s" % e,
              "Continuing with default...")
        last_width = default_width
        last_height = default_height
        last_dataset = default_dataset
    
    except (TypeError, ValueError) as e:
        print("get_window_size(): Error reading restore file (TypeError or ValueError):\n%s" % e,
              "Continuing with default...")
        last_width = default_width
        last_height = default_height
        last_dataset = default_dataset
    
    # Check if the dataset exists. 
    dataset_list = datasets.get_column(io.get_dataset_list(main_dir, "", False), 0)
    if last_dataset in dataset_list:
        dataset_exists = True
        original_dataset = ""
    else:
        dataset_exists = False
        original_dataset = last_dataset
    
    # If the dataset doesn't exist, switch or make one that does:
    if not dataset_exists:

        # If the default dataset exists, switch to that.
        if "Main Dataset" in dataset_list:
            last_dataset = "Main Dataset"

        # Otherwise, create the default dataset.
        else:
            ensure_files_exist(main_dir, conf_dir)
    
    # If the user doesn't want to restore the window size, set the size to the defaults.
    if not config["restore"]:
        return last_dataset, original_dataset, dataset_exists, default_width, default_height

    return last_dataset, original_dataset, dataset_exists, last_width, last_height
예제 #10
0
def filter_or(set1, set2):
    """Returns a list of the items that are in either set1 or set2."""
    
    # Get the date column of the first set for the comparison.
    date_list = datasets.get_column(set1, 0)
    
    # Loop through the second list, and add the item if it isn't already in the first list.
    filtered = set1[:]
    for i in set2:
        if i[0] not in date_list:
            filtered.append(i)
    
    filtered = sorted(filtered, key=lambda x: datetime.datetime.strptime(x[0], "%d/%m/%Y"))
    return filtered
예제 #11
0
def filter_or(set1, set2):
    """Returns a list of the items that are in either set1 or set2."""

    # Get the date column of the first set for the comparison.
    date_list = datasets.get_column(set1, 0)

    # Loop through the second list, and add the item if it isn't already in the first list.
    filtered = set1[:]
    for i in set2:
        if i[0] not in date_list:
            filtered.append(i)

    filtered = sorted(
        filtered, key=lambda x: datetime.datetime.strptime(x[0], "%d/%m/%Y"))
    return filtered
예제 #12
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
예제 #13
0
def chil_table(data, units):
    """"Gets the wind chill table data."""
    
    # Get the 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)
    chil_median = calculations.median(chil_data)
    
    # Calculate and add the data.
    data2 = []
    for i in range(0, len(data)):
        
        chil = [data[i][0], "%.2f %s" % (chil_data[i], units["temp"])]
        chil += build_table(chil_data[i], chil_low, chil_high, chil_avg, chil_median, units["temp"])
        data2.append(chil)
    
    return data2
예제 #14
0
def temp_table(data, units):
    """"Gets the temperature table data."""
    
    # Get the 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)
    temp_median = calculations.median(temp_data)
    
    # Calculate and add the data.
    data2 = []
    for i in range(0, len(data)):
        
        temp = [data[i][0], "%.2f %s" % (temp_data[i], units["temp"])]
        temp += build_table(temp_data[i], temp_low, temp_high, temp_avg, temp_median, units["temp"])
        data2.append(temp)
    
    return data2
예제 #15
0
def visi_table(data, units):
    """"Gets the visibility table data."""
    
    # Get the 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)
    visi_median = calculations.median(visi_data)
    
    # Calculate and add the data.
    data2 = []
    for i in range(0, len(data)):
        
        visi = [data[i][0], "%.2f %s" % (visi_data[i], units["visi"])]
        visi += build_table(visi_data[i], visi_low, visi_high, visi_avg, visi_median, units["visi"])
        data2.append(visi)
    
    return data2
예제 #16
0
def humi_table(data, units):
    """"Gets the humidity table data."""
    
    # Get the 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)
    humi_median = calculations.median(humi_data)
    
    # Calculate and add the data.
    data2 = []
    for i in range(0, len(data)):
        
        humi = [data[i][0], "%.2f%%" % (humi_data[i])]
        humi += build_table(humi_data[i], humi_low, humi_high, humi_avg, humi_median, "%", unit_space=False)
        data2.append(humi)
    
    return data2
예제 #17
0
파일: info.py 프로젝트: achesak/weatherlog
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
예제 #18
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
예제 #19
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
    def remove_condition(self, widget):
        """Removes the selected condition."""

        # Get the selected conditions.
        model, treeiter = self.treeview.get_selection().get_selected_rows()
        conds = []
        for i in treeiter:
            conds.append(model[i][0])

        # Don't continue if nothing was selected.
        if len(conds) == 0:
            return

        # Remove the conditions and update the UI.
        for i in conds:
            index = datasets.get_column(self.conditions, 0).index(i)
            del self.conditions[index]

        self.liststore.clear()
        for i in self.conditions:
            self.liststore.append(i)
예제 #21
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
    def remove_condition(self, widget):
        """Removes the selected condition."""

        # Get the selected conditions.
        model, treeiter = self.treeview.get_selection().get_selected_rows()
        conds = []
        for i in treeiter:
            conds.append(model[i][0])

        # Don't continue if nothing was selected.
        if len(conds) == 0:
            return

        # Remove the conditions and update the UI.
        for i in conds:
            index = datasets.get_column(self.conditions, 0).index(i)
            del self.conditions[index]

        self.liststore.clear()
        for i in self.conditions:
            self.liststore.append(i)
예제 #23
0
파일: info.py 프로젝트: achesak/weatherlog
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
예제 #24
0
파일: info.py 프로젝트: achesak/weatherlog
def humi_info(data, units):
    """Gets the humidity info."""
    
    # Get the 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)
    humi_median = calculations.median(humi_data)
    humi_range = calculations.range(humi_data)
    humi_mode, humi_mode_count = calculations.mode(humi_data)
    
    # Create the data list.
    data2 = [
        ["Lowest humidity", "%.2f%%" % humi_low],
        ["Highest humidity", "%.2f%%" % humi_high],
        ["Average humidity", "%.2f%%" % humi_avg],
        ["Median humidity", "%.2f%%" % humi_median],
        ["Range of humidity", "%.2f%%" % humi_range],
        ["Most common humidity", "%.2f%% (%d occurrences)" % (humi_mode, humi_mode_count)]
    ]
    
    return data2
예제 #25
0
파일: info.py 프로젝트: achesak/weatherlog
def visi_info(data, units):
    """"Gets the visibility info."""
    
    # Get the data.
    visi_data = datasets.convert_float(datasets.get_column(data, 2))
    visi_low = min(visi_data)
    visi_high = max(visi_data)
    visi_avg = calculations.mean(visi_data)
    visi_median = calculations.median(visi_data)
    visi_range = calculations.range(visi_data)
    visi_mode, visi_mode_count = calculations.mode(visi_data)
    
    # Create the data list.
    data2 = [
        ["Lowest visibility", "%.2f %s" % (visi_low, units["visi"])],
        ["Highest visibility", "%.2f %s" % (visi_high, units["visi"])],
        ["Average visibility", "%.2f %s" % (visi_avg, units["visi"])],
        ["Median visibility", "%.2f %s" % (visi_median, units["visi"])],
        ["Range of visibility", "%.2f %s" % (visi_range, units["visi"])],
        ["Most common visibility", "%.2f %s (%d occurrences)" % (visi_mode, units["visi"], visi_mode_count)]
    ]
    
    return data2
예제 #26
0
파일: info.py 프로젝트: achesak/weatherlog
def chil_info(data, units):
    """"Gets the wind chill info."""
    
    # Get the 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)
    chil_median = calculations.median(chil_data)
    chil_range = calculations.range(chil_data)
    chil_mode, chil_mode_count = calculations.mode(chil_data)
    
    # Create the data list.
    data2 = [
        ["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"])],
        ["Median wind chill", "%.2f %s" % (chil_median, units["temp"])],
        ["Range of wind chills", "%.2f %s" % (chil_range, units["temp"])],
        ["Most common wind chill", "%.2f %s (%d occurrences)" % (chil_mode, units["temp"], chil_mode_count)]
    ]
    
    return data2
예제 #27
0
파일: info.py 프로젝트: achesak/weatherlog
def temp_info(data, units):
    """"Gets the temperature info."""
    
    # Get the 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)
    temp_median = calculations.median(temp_data)
    temp_range = calculations.range(temp_data)
    temp_mode, temp_mode_count = calculations.mode(temp_data)
    
    # Create the data list.
    data2 = [
        ["Lowest temperature", "%.2f %s" % (temp_low, units["temp"])],
        ["Highest temperature", "%.2f %s" % (temp_high, units["temp"])],
        ["Average temperature", "%.2f %s" % (temp_avg, units["temp"])],
        ["Median temperature", "%.2f %s" % (temp_median, units["temp"])],
        ["Range of temperatures", "%.2f %s" % (temp_range, units["temp"])],
        ["Most common temperature", "%.2f %s (%d occurrences)" % (temp_mode, units["temp"], temp_mode_count)]
    ]
    
    return data2
예제 #28
0
def humi_info(data, units):
    """Gets the humidity info."""

    # Get the 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)
    humi_median = calculations.median(humi_data)
    humi_range = calculations.range(humi_data)
    humi_mode, humi_mode_count = calculations.mode(humi_data)

    # Create the data list.
    data2 = [["Lowest humidity", "%.2f%%" % humi_low],
             ["Highest humidity", "%.2f%%" % humi_high],
             ["Average humidity", "%.2f%%" % humi_avg],
             ["Median humidity", "%.2f%%" % humi_median],
             ["Range of humidity", "%.2f%%" % humi_range],
             [
                 "Most common humidity",
                 "%.2f%% (%d occurrences)" % (humi_mode, humi_mode_count)
             ]]

    return data2
예제 #29
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
예제 #30
0
파일: info.py 프로젝트: achesak/weatherlog
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
예제 #31
0
파일: info.py 프로젝트: achesak/weatherlog
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
예제 #32
0
파일: info.py 프로젝트: achesak/weatherlog
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
예제 #33
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
예제 #34
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
예제 #35
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
예제 #36
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
예제 #37
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
예제 #38
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