No magic here. The division doesn’t give you 5224903, it gives you 5224903.21667 or so. The “int()” knocks off the decimals. It does NOT round up. As such, you are getting the LAST 5 minute period, that is the number of 5 minute periods that have already passed since the epoch.
If you had no remainder, you would be getting the 5 minute period that *just* passed—as in, right now. But we don’t want the last 5 minute period, we want the next. You say that the 1 just adds a second to the time stamp. Actually, the one adds one more five minute period — that is, the NEXT 5 minute period. So, now we have the correct 5 minute period, but we need to convert that to seconds since the epoch. That’s easy enough to do. Just multiply by 300 (there are 300 seconds in a give minute period). > On Sep 2, 2019, at 5:42 PM, Pat <p...@obrienphoto.net> wrote: > > I don't know why, but I'm fascinated with this small bit of code. I always > wondered how the archive interval runs on the 5th minute reliably (on a > vanilla install). It doesn't matter when you start weewx, it'll run on that > 5th minute interval. If I start weewx at 8:31, I'll get an archive (most > times) at 8:35. That got me thinking it's not a sleep, but something else. > > So I dug and I found the magic timer a few months ago, but I've been stuck on > trying to understand the math behind it. Is someone able to explain this in > laymans terms? > > Let's say these are the variables: > > int(self.engine._get_console_time() = 1567470965 > self.archive_interval = 300 > > If I take a the console time (1567470965), divide it by 300, I get 5224903 > Then adding 1 is easy, I get 5224904 > Then multiplying this by 300 gives me the time ahead on the 5th minute, or > 1567471200 > > I have no idea how or why that +1 alters the end result. It's just adding a > second to the timestamp. > > (int( 1567470965 / 300) + 1) * 300 = 1567471200 > > I think it's pretty cool how this works! > > -- > You received this message because you are subscribed to the Google Groups > "weewx-development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to weewx-development+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/weewx-development/9c929337-f1ae-4034-a18f-c7191472fb13%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "weewx-development" group. To unsubscribe from this group and stop receiving emails from it, send an email to weewx-development+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/32724FEC-2AE6-42BB-829B-022096CB3BCE%40johnkline.com.