def update_archive(self): #Now get all the Current Data now = Now.get(1) #Get the amount of rain in the last period rain_amount = 0.0 rains = database.Table_Rain.select() for rain in rains: if (datetime.datetime.now() - rain.time) > datetime.timedelta( seconds=settings.how_often_to_archive_data): rain_amount = rain_amount + rain.quantity #Insert all values into the archive table. new_archive = database.Table_Archive(date=datetime.datetime.now(), In_Temp=now.In_Temp, Out_Temp=now.Out_Temp, Attic_Temp=now.Attic_Temp, In_Humid=now.In_Humid, Out_Humid=now.Out_Humid, Attic_Humid=now.Attic_Humid, Out_Wind_Avg=now.Out_Wind_Avg, Out_Wind_Max=now.Out_Wind_Max, Out_Rain_Minute=rain_amount, System_CPU=now.System_CPU, System_RAM=now.System_RAM, Now_Feel=now.Now_Feel) logging.getLogger("thread-archive").info(" Sensor data archived.")
def update_archive(self): #Now get all the Current Data now = Now.get(1) #Get the amount of rain in the last period rain_amount = 0.0 rains = database.Table_Rain.select() for rain in rains: if (datetime.datetime.now() - rain.time) > datetime.timedelta(seconds = settings.how_often_to_archive_data): rain_amount = rain_amount + rain.quantity #Insert all values into the archive table. new_archive = database.Table_Archive(date=datetime.datetime.now(), In_Temp=now.In_Temp, Out_Temp=now.Out_Temp, Attic_Temp=now.Attic_Temp, In_Humid=now.In_Humid, Out_Humid=now.Out_Humid, Attic_Humid=now.Attic_Humid, Out_Wind_Avg=now.Out_Wind_Avg, Out_Wind_Max=now.Out_Wind_Max, Out_Rain_Minute=rain_amount, System_CPU=now.System_CPU, System_RAM=now.System_RAM, Now_Feel=now.Now_Feel) logging.getLogger("thread-archive").info(" Sensor data archived.")
def echo_client(self, conn): try: while True: msg = conn.recv() now = Now.get() #Do we just need to reset the current rainfall? if msg == "reset_rain": now.Out_Rain_Since_Reset = 0 conn.send(now) except EOFError: logging.getLogger("thread-listener").debug("Connection closed")
def update_feels_like(self): parsed_json = weather.fetchWeather('conditions') weather.closeURL() NOW_URL = "https://icons.wxug.com/i/c/v4/" + parsed_json['current_observation']['icon'] + ".svg" NOW_Feel = float(parsed_json['current_observation']['feelslike_f']) now = Now.get() now.Now_URL = NOW_URL now.Now_Feel = NOW_Feel logging.getLogger("thread-feels").info(" Updated feels like info.")
def update_feels_forecast(self): parsed_json = weather.fetchWeather('forecast') weather.closeURL() NOW_Feel_High = float(parsed_json['forecast']['simpleforecast']['forecastday'][0]['high']["fahrenheit"]) NOW_Feel_Low = float(parsed_json['forecast']['simpleforecast']['forecastday'][0]['low']["fahrenheit"]) now = Now.get() now.Now_Feel_High = NOW_Feel_High now.NOW_Feel_Low = NOW_Feel_Low logging.getLogger("thread-feels").info(" Updated high-low data.")
def update_feels_like(self): parsed_json = weather.fetchWeather('conditions') weather.closeURL() NOW_URL = "https://icons.wxug.com/i/c/v4/" + parsed_json[ 'current_observation']['icon'] + ".svg" NOW_Feel = float(parsed_json['current_observation']['feelslike_f']) now = Now.get() now.Now_URL = NOW_URL now.Now_Feel = NOW_Feel logging.getLogger("thread-feels").info(" Updated feels like info.")
def update_feels_forecast(self): parsed_json = weather.fetchWeather('forecast') weather.closeURL() NOW_Feel_High = float(parsed_json['forecast']['simpleforecast'] ['forecastday'][0]['high']["fahrenheit"]) NOW_Feel_Low = float(parsed_json['forecast']['simpleforecast'] ['forecastday'][0]['low']["fahrenheit"]) now = Now.get() now.Now_Feel_High = NOW_Feel_High now.NOW_Feel_Low = NOW_Feel_Low logging.getLogger("thread-feels").info(" Updated high-low data.")
def strftime(format, tt=None): # pylint: disable=missing-docstring,redefined-builtin t = Unix(int(mktime(tt)), 0) if tt else Now() ret = [] prev, n = 0, format.find('%', 0, -1) while n != -1: ret.append(format[prev:n]) next_ch = format[n + 1] c = _strftime_directive_map.get(next_ch) if c is NotImplemented: raise NotImplementedError('Code: %' + next_ch + ' not yet supported') if c: ret.append(t.Format(c)) else: ret.append(format[n:n+2]) n += 2 prev, n = n, format.find('%', n, -1) ret.append(format[prev:]) return ''.join(ret)
def update_rain_compile(self): rain_24h = 0.0 rain_today = 0.0 now = datetime.datetime.now() midnight = now.replace(tzinfo=pytz.UTC).astimezone(pytz.timezone(settings.my_timezone)).replace(hour=0,minute=0,second=0,microsecond=0).astimezone(pytz.UTC).replace(tzinfo=None) rains = database.Table_Rain.select() for rain in rains: if (now - rain.time) < datetime.timedelta(hours = 24): rain_24h = rain_24h + rain.quantity if (rain.time > midnight): rain_today = rain_today + rain.quantity now = Now.get(1) now.Out_Rain_Last_24h = rain_24h now.Out_Rain_Today = rain_today logging.getLogger("thread-rain_compile").info(" Compiled rain pulse data.")
def seed(self, a=None): """Seed the golang.math.rand generator.""" if a is None: a = Now().UnixNano() Seed(a)
def time(): return float(Now().UnixNano()) / Second
def localtime(seconds=None): t = (Unix(seconds, 0) if seconds else Now()).Local() return struct_time((t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), (t.Weekday() + 6) % 7, t.YearDay(), 0))
def time(): return float(Now().UnixNano()) / Second def strftime(format, tt=None): # pylint: disable=missing-docstring,redefined-builtin t = Unix(int(mktime(tt)), 0) if tt else Now() ret = [] prev, n = 0, format.find('%', 0, -1) while n != -1: ret.append(format[prev:n]) next_ch = format[n + 1] c = _strftime_directive_map.get(next_ch) if c is NotImplemented: raise NotImplementedError('Code: %' + next_ch + ' not yet supported') if c: ret.append(t.Format(c)) else: ret.append(format[n:n+2]) n += 2 prev, n = n, format.find('%', n, -1) ret.append(format[prev:]) return ''.join(ret) # TODO: Calculate real value for daylight saving. daylight = 0 # TODO: Use local DST instead of ''. tzname = (Now().Zone()[0], '')