Ejemplo n.º 1
0
    def draw(self, screen, weather, updated):
        if weather is None or not updated:
            return

        current = weather["current"]
        daily = weather["daily"][0]

        short_summary = _(current["weather"][0]["main"])
        icon = current["weather"][0]["icon"]
        temperature = current["temp"]
        humidity = current["humidity"]
        feels_like = current["feels_like"]
        pressure = current["pressure"]
        uv_index = int(current["uvi"])
        long_summary = daily["weather"][0]["description"]
        temperature_high = daily["temp"]["max"]
        temperature_low = daily["temp"]["min"]

        heat_color = Utils.heat_color(temperature, humidity, self.units)
        uv_color = Utils.uv_color(uv_index)
        weather_icon = Utils.weather_icon(icon, self.icon_size)

        temperature = Utils.temperature_text(int(temperature), self.units)
        feels_like = Utils.temperature_text(int(feels_like), self.units)
        temperature_low = Utils.temperature_text(int(temperature_low),
                                                 self.units)
        temperature_high = Utils.temperature_text(int(temperature_high),
                                                  self.units)
        humidity = Utils.percentage_text(humidity)
        uv_index = str(uv_index)
        pressure = Utils.pressure_text(int(pressure))

        text_x = weather_icon.get_size()[0]
        text_width = self.rect.width - text_x

        message1 = self.text_warp("{} {}".format(temperature, short_summary),
                                  text_width,
                                  "medium",
                                  bold=True,
                                  max_lines=1)[0]
        message2 = "{} {}   {} {} {} {}".format(_("Feels Like"), feels_like,
                                                _("Low"), temperature_low,
                                                _("High"), temperature_high)
        if self.text_size(message2, "small")[0] > text_width:
            message2 = "Feel {}  {} - {}".format(feels_like, temperature_low,
                                                 temperature_high)
        message3 = "{} {}  {} {}  {} {}".format(_("Humidity"), humidity,
                                                _("Pressure"), pressure,
                                                _("UVindex"), uv_index)
        if self.text_size(message3, "small")[0] > text_width:
            message3 = "{}  {}  UV {}".format(humidity, pressure, uv_index)
        max_lines = int((self.rect.height - 55) / 15)
        message4s = self.text_warp(long_summary,
                                   text_width,
                                   "small",
                                   bold=True,
                                   max_lines=max_lines)

        self.clear_surface()
        self.draw_image(weather_icon, (0, 0))
        self.draw_text(message1, (text_x, 0), "medium", heat_color, bold=True)
        self.draw_text(message2, (text_x, 25), "small", "white")
        i = message3.index("UV")
        (right, _bottom) = self.draw_text(message3[:i], (text_x, 40), "small",
                                          "white")
        self.draw_text(message3[i:], (right, 40), "small", uv_color, bold=True)
        height = 55 + (15 * (max_lines - len(message4s))) / 2
        for message in message4s:
            self.draw_text(message, (text_x, height),
                           "small",
                           "white",
                           bold=True)
            height += 15
        self.update_screen(screen)
Ejemplo n.º 2
0
    def draw(self, screen, weather, updated):
        if weather is None or not updated:
            return

        current = weather["current"]
        daily = weather["daily"][0]

        short_summary = _(current["weather"][0]["main"])
        icon = current["weather"][0]["icon"]
        temperature = current["temp"]
        humidity = current["humidity"]
        feels_like = current["feels_like"]
        pressure = current["pressure"]
        uv_index = int(current["uvi"])
        try:
            rain_1h = current["rain"]["1h"]
        except KeyError:
            rain_1h = '0'
        windspeed = current["wind_speed"]
        try:
            windgust = current["wind_gust"]
        except KeyError:
            windgust = 'nan'
        print(windgust)
        long_summary = daily["weather"][0]["description"]
        temperature_high = daily["temp"]["max"]
        temperature_low = daily["temp"]["min"]
        heat_color = Utils.heat_color(temperature, humidity, self.units)
        uv_color = Utils.uv_color(uv_index)
        weather_icon = Utils.weather_icon(icon, self.icon_size)

        #temperature = Utils.temperature_text(int(temperature), self.units)
        temperature = Utils.temperature_text(round(temperature, 1), self.units)
        feels_like = Utils.temperature_text(int(feels_like), self.units)
        temperature_low = Utils.temperature_text(int(temperature_low),
                                                 self.units)
        temperature_high = Utils.temperature_text(int(temperature_high),
                                                  self.units)
        humidity = Utils.percentage_text(humidity)
        uv_index = str(uv_index)
        pressure = Utils.pressure_text(int(pressure))

        """
        HistoryGraphLog - log data to GraphDatalog.txt
        """
        # TODO: Add maintenance of GraphDataLog.txt for removing old data to keep file small.
        xtemperature = temperature
        xtemperature = xtemperature[:-2]
        xpressure = pressure
        xpressure = xpressure[:-2]
        xtimestamp = time.strftime('%m-%d-%Y %H:%M:%S')

        graph = "GraphDataLog.txt"
        file = open(graph, "a", newline='')

        with file:
            myfields = ['xdate', 'temp', 'press', 'rain_1h', 'windspeed', 'windgust']
            writer = csv.DictWriter(file, fieldnames=myfields)
            #writer.writeheader()
            writer.writerow({'xdate': xtimestamp, 'temp': xtemperature, 'press': xpressure, 'rain_1h': rain_1h, 'windspeed': windspeed, 'windgust': windgust})
        #file.close()
        df = pandas.read_csv(graph)

        # convert to datetime
        df['xdate'] = pandas.to_datetime(df['xdate'])
        # calculate mask
        m1 = df['xdate'] >= (pandas.to_datetime('now') - pandas.DateOffset(days=1))
        m2 = df['xdate'] <= pandas.to_datetime('now')
        #mask = m1 & m2
        mask = m1
        # output masked dataframes
        # df[~mask].to_csv('out1.csv', index=False)
        #Remove time from datetime
        #df['xdate'] = pandas.to_datetime(df['xdate']).dt.date
        df[mask].to_csv('GraphData.csv', index=False)
        """
        END GraphLog
        """


        text_x = weather_icon.get_size()[0]
        text_width = self.rect.width - text_x

        message1 = self.text_warp("{} {}".format(temperature, short_summary),
                                  text_width,
                                  "medium",
                                  bold=True,
                                  max_lines=1)[0]
        message2 = "{} {}   {} {} {} {}".format(_("Feels Like"), feels_like,
                                                _("Low"), temperature_low,
                                                _("High"), temperature_high)
        if self.text_size(message2, "small")[0] > text_width:
            message2 = "Feel {}  {} - {}".format(feels_like, temperature_low,
                                                 temperature_high)
        message3 = "{} {}  {} {}  {} {}".format(_("Humidity"), humidity,
                                                _("Pressure"), pressure,
                                                _("UVindex"), uv_index)
        if self.text_size(message3, "small")[0] > text_width:
            message3 = "{}  {}  UV {}".format(humidity, pressure, uv_index)
        max_lines = int((self.rect.height - 55) / 15)
        message4s = self.text_warp(long_summary,
                                   text_width,
                                   "small",
                                   bold=True,
                                   max_lines=max_lines)

        self.clear_surface()
        self.draw_image(weather_icon, (0, 0))
        self.draw_text(message1, (text_x, 15), "large", heat_color, bold=True)
        self.draw_text(message2, (text_x, 52), "small", "white")
        i = message3.index("UV")
        (right, _bottom) = self.draw_text(message3[:i], (text_x, 70), "small",
                                          "white")
        self.draw_text(message3[i:], (right, 70), "small", uv_color, bold=True)
        height = 70 + (15 * (max_lines - len(message4s))) / 2
        for message in message4s:
            self.draw_text(message, (text_x, height),
                           "small",
                           "blue",
                           bold=True)
            height += 15
        self.update_screen(screen)