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
def humi_chart(data, units): """"Gets the humidity chart 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_chart(humi_data[i], humi_low, humi_high, humi_avg, humi_median, "%", unit_space=False) data2.append(humi) return data2
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
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
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
def prec_chart(data, units): """"Gets the precipitation chart data.""" # Get the 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) 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"])] if prec_avg == prec_data1[i]: average = "Average Value" else: average = prec_avg - prec_data1[i] average = "%.2f %s %s" % (abs(average), units["prec"], "above" if prec_avg < prec_data1[i] else "below") prec.append(average) if prec_low == prec_data1[i]: low = "Lowest Value" else: low = prec_low - prec_data1[i] low = "%.2f %s %s" % (abs(low), units["prec"], "above" if prec_low < prec_data1[i] else "below") prec.append(low) if prec_high == prec_data1[i]: high = "Highest Value" else: high = prec_high - prec_data1[i] high = "%.2f %s %s" % (abs(high), units["prec"], "above" if prec_high < prec_data1[i] else "below") prec.append(high) if prec_median == prec_data1[i]: median = "Median Value" else: median = prec_median - prec_data1[i] median = "%.2f %s %s" % (abs(median), units["prec"], "above" if prec_median < prec_data1[i] else "below") prec.append(median) data2.append(prec) return data2
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
def wind_chart(data, units): """"Gets the wind chart 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"])] if wind_avg == wind_data1[i]: average = "Average Value" else: average = wind_avg - wind_data1[i] average = "%.2f %s %s" % (abs(average), units["wind"], "above" if wind_avg < wind_data1[i] else "below") wind.append(average) if wind_low == wind_data1[i]: low = "Lowest Value" else: low = wind_low - wind_data1[i] low = "%.2f %s %s" % (abs(low), units["wind"], "above" if wind_low < wind_data1[i] else "below") wind.append(low) if wind_high == wind_data1[i]: high = "Highest Value" else: high = wind_high - wind_data1[i] high = "%.2f %s %s" % (abs(high), units["wind"], "above" if wind_high < wind_data1[i] else "below") wind.append(high) if wind_median == wind_data1[i]: median = "Median Value" else: median = wind_median - wind_data1[i] median = "%.2f %s %s" % (abs(median), units["wind"], "above" if wind_median < wind_data1[i] else "below") wind.append(median) data2.append(wind) return data2
def airp_chart(data, units): """"Gets the air pressure chart 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"])] if airp_avg == airp_data1[i]: average = "Average Value" else: average = airp_avg - airp_data1[i] average = "%.2f %s %s" % (abs(average), units["airp"], "above" if airp_avg < airp_data1[i] else "below") airp.append(average) if airp_low == airp_data1[i]: low = "Lowest Value" else: low = airp_low - airp_data1[i] low = "%.2f %s %s" % (abs(low), units["airp"], "above" if airp_low < airp_data1[i] else "below") airp.append(low) if airp_high == airp_data1[i]: high = "Highest Value" else: high = airp_high - airp_data1[i] high = "%.2f %s %s" % (abs(high), units["airp"], "above" if airp_high < airp_data1[i] else "below") airp.append(high) if airp_median == airp_data1[i]: median = "Median Value" else: median = airp_median - airp_data1[i] median = "%.2f %s %s" % (abs(median), units["airp"], "above" if airp_median < airp_data1[i] else "below") airp.append(median) data2.append(airp) return data2
def humi_chart(data, units): """"Gets the humidity chart 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])] if humi_avg == humi_data[i]: average = "Average Value" else: average = humi_avg - humi_data[i] average = "%.2f%% %s" % (abs(average), "above" if humi_avg < humi_data[i] else "below") humi.append(average) if humi_low == humi_data[i]: low = "Lowest Value" else: low = humi_low - humi_data[i] low = "%.2f%% %s" % (abs(low), "above" if humi_low < humi_data[i] else "below") humi.append(low) if humi_high == humi_data[i]: high = "Highest Value" else: high = humi_high - humi_data[i] high = "%.2f%% %s" % (abs(high), "above" if humi_high < humi_data[i] else "below") humi.append(high) if humi_median == humi_data[i]: median = "Median Value" else: median = humi_median - humi_data[i] median = "%.2f%% %s" % (abs(median), "above" if humi_median < humi_data[i] else "below") humi.append(median) data2.append(humi) return data2
def temp_chart(data, units): """"Gets the temperature chart 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"])] if temp_avg == temp_data[i]: average = "Average Value" else: average = temp_avg - temp_data[i] average = "%.2f %s %s" % (abs(average), units["temp"], "above" if temp_avg < temp_data[i] else "below") temp.append(average) if temp_low == temp_data[i]: low = "Lowest Value" else: low = temp_low - temp_data[i] low = "%.2f %s %s" % (abs(low), units["temp"], "above" if temp_low < temp_data[i] else "below") temp.append(low) if temp_high == temp_data[i]: high = "Highest Value" else: high = temp_high - temp_data[i] high = "%.2f %s %s" % (abs(high), units["temp"], "above" if temp_high < temp_data[i] else "below") temp.append(high) if temp_median == temp_data[i]: median = "Median Value" else: median = temp_median - temp_data[i] median = "%.2f %s %s" % (abs(median), units["temp"], "above" if temp_median < temp_data[i] else "below") temp.append(median) data2.append(temp) return data2
def visi_chart(data, units): """"Gets the visibility chart 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"])] if visi_avg == visi_data[i]: average = "Average Value" else: average = visi_avg - visi_data[i] average = "%.2f %s %s" % (abs(average), units["visi"], "above" if visi_avg < visi_data[i] else "below") visi.append(average) if visi_low == visi_data[i]: low = "Lowest Value" else: low = visi_low - visi_data[i] low = "%.2f %s %s" % (abs(low), units["visi"], "above" if visi_low < visi_data[i] else "below") visi.append(low) if visi_high == visi_data[i]: high = "Highest Value" else: high = visi_high - visi_data[i] high = "%.2f %s %s" % (abs(high), units["visi"], "above" if visi_high < visi_data[i] else "below") visi.append(high) if visi_median == visi_data[i]: median = "Median Value" else: median = visi_median - visi_data[i] median = "%.2f %s %s" % (abs(median), units["visi"], "above" if visi_median < visi_data[i] else "below") visi.append(median) data2.append(visi) return data2
def chil_chart(data, units): """"Gets the wind chill chart 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"])] if chil_avg == chil_data[i]: average = "Average Value" else: average = chil_avg - chil_data[i] average = "%.2f %s %s" % (abs(average), units["temp"], "above" if chil_avg < chil_data[i] else "below") chil.append(average) if chil_low == chil_data[i]: low = "Lowest Value" else: low = chil_low - chil_data[i] low = "%.2f %s %s" % (abs(low), units["temp"], "above" if chil_low < chil_data[i] else "below") chil.append(low) if chil_high == chil_data[i]: high = "Highest Value" else: high = chil_high - chil_data[i] high = "%.2f %s %s" % (abs(high), units["temp"], "above" if chil_high < chil_data[i] else "below") chil.append(high) if chil_median == chil_data[i]: median = "Median Value" else: median = chil_median - chil_data[i] median = "%.2f %s %s" % (abs(median), units["temp"], "above" if chil_median < chil_data[i] else "below") chil.append(median) data2.append(chil) return data2
def chil_chart(data, units): """"Gets the wind chill chart 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_chart(chil_data[i], chil_low, chil_high, chil_avg, chil_median, units["temp"]) data2.append(chil) return data2
def temp_chart(data, units): """"Gets the temperature chart 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_chart(temp_data[i], temp_low, temp_high, temp_avg, temp_median, units["temp"]) data2.append(temp) return data2
def visi_chart(data, units): """"Gets the visibility chart 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_chart(visi_data[i], visi_low, visi_high, visi_avg, visi_median, units["visi"]) data2.append(visi) return data2
def airp_chart(data, units): """"Gets the air pressure chart 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_chart(airp_data1[i], airp_low, airp_high, airp_avg, airp_median, units["airp"]) data2.append(airp) return data2
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: 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
def prec_chart(data, units): """"Gets the precipitation chart 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_chart(prec_data1[i], prec_low, prec_high, prec_avg, prec_median, units["prec"]) data2.append(prec) return data2
def wind_chart(data, units): """"Gets the wind chart 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_chart(wind_data1[i], wind_low, wind_high, wind_avg, wind_median, units["wind"]) data2.append(wind) return data2
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
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
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
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
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
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
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
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: 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
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
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