module RaspbergUptimeStore
RaspbergUptimeStore — RabbotDb uptime stats with VB record.rut reboot logic.
Constants
- DEFAULT_STATS
- KEY
- PLUGIN
Public Instance Methods
Source
# File lib/raspberg_uptime_store.rb, line 21 def load(store:) stats = store.get_plugin_json(plugin: PLUGIN, key: KEY, default: nil) return DEFAULT_STATS.dup if stats.nil? DEFAULT_STATS.merge(stats) end
Source
# File lib/raspberg_uptime_store.rb, line 28 def save(stats, store:) store.set_plugin_json(plugin: PLUGIN, key: KEY, value: stats) end
Source
# File lib/raspberg_uptime_store.rb, line 32 def tick(uptime_sec:, store:, at: Time.now) stats = load(store: store) rebooted = false last_uptime = stats["last_uptime_sec"].to_f current_minutes = (uptime_sec.to_f / 60.0).floor if last_uptime.positive? && uptime_sec.to_f < last_uptime ended_minutes = (last_uptime / 60.0).floor stats["last_session_minutes"] = ended_minutes stats["total_minutes"] = stats["total_minutes"].to_i + ended_minutes stats["reboot_count"] = stats["reboot_count"].to_i + 1 RaspbergBootlog.record_boot(at: at, store: store) rebooted = true elsif last_uptime.zero? && RaspbergBootlogStore.load(store: store).empty? RaspbergBootlog.record_boot(at: at, store: store) end if current_minutes > stats["highest_minutes"].to_i stats["highest_minutes"] = current_minutes end stats["last_uptime_sec"] = uptime_sec.to_f save(stats, store: store) { stats: stats, rebooted: rebooted } end