func UpdateTotalBeats() {
	heartbeatStats.TotalBeats += 1
	heartbeatStats.TotalBeatsFormatted = FormattedNum(heartbeatStats.TotalBeats)
}
UpdateTotalBeats will update the formatted total beats statistic
package main
import (
	"encoding/json"
	"github.com/go-redis/redis/v8"
	"github.com/nitishm/go-rejson/v4"
	"log"
	"time"
)
var (
	rdb *redis.Client    
	rjh *rejson.Handler  
	redisAddr = "database:6379"  
	redisPass = ""               
	heartbeatStats   *HeartbeatStats    = nil
	heartbeatDevices *[]HeartbeatDevice = nil
)
func SetupDatabase() (*redis.Client, *rejson.Handler) {
	rh := rejson.NewReJSONHandler()
	client := redis.NewClient(&redis.Options{
		Addr:     redisAddr,
		Password: redisPass,
	})
	rh.SetGoRedisClient(client)
	return client, rh
}
func SetupDatabaseSaving() {
	ticker := time.NewTicker(5 * time.Minute)
	go func() {
		for {
			select {
			case <-ticker.C:
				SaveLocalInDatabase()
			}
		}
	}()
}
func SetupLocalValues() {
	if res, err := rjh.JSONGet("stats", "."); err != nil {
		heartbeatStats = defaultHeartbeatStats
	} else {
		var stats HeartbeatStats
		if err = json.Unmarshal(res.([]byte), &stats); err != nil {
			panic(err)
		}
		heartbeatStats = &stats
	}
	if res, err := rjh.JSONGet("devices", "."); err != nil {
		heartbeatDevices = defaultHeartbeatDevices
	} else {
		var devices []HeartbeatDevice
		if err = json.Unmarshal(res.([]byte), &devices); err != nil {
			panic(err)
		}
		heartbeatDevices = &devices
	}
}
func SaveLocalInDatabase() {
	UpdateUptime()
	log.Printf("- Autosaving database, uptime is %v\n", heartbeatStats.TotalUptime)
	if _, err := rjh.JSONSet("stats", ".", heartbeatStats); err != nil {
		log.Fatalf("Error saving stats: %v", err)
	}
	if _, err := rjh.JSONSet("devices", ".", heartbeatDevices); err != nil {
		log.Fatalf("Error saving devices: %v", err)
	}
}
func LastSeen() string {
	lastBeat := GetLastBeat()
	if lastBeat == nil {
		return "Never"
	}
	return time.Unix(lastBeat.Timestamp, 0).Format(timeFormat)
}
func LongestAbsence() string {
	lastBeat := GetLastBeat()
	for _, device := range *heartbeatDevices {
		if lastBeat == nil {
			lastBeat = &device.LastBeat
		}
		if device.LastBeat.Timestamp > lastBeat.Timestamp {
			lastBeat = &device.LastBeat
		}
	}
	if lastBeat == nil {
		heartbeatStats.LastBeatFormatted = "Never"
		return "Never"
	}
	diff := time.Now().Unix() - lastBeat.Timestamp
	if diff > heartbeatStats.LongestMissingBeat {
		heartbeatStats.LongestMissingBeat = diff
		return FormattedTime(diff)
	} else {
		return FormattedTime(heartbeatStats.LongestMissingBeat)
	}
}
func UpdateUptime() {
	now := time.Now().Unix()
	diff := now - uptimeTimer
	uptimeTimer = now - 1
	heartbeatStats.TotalUptime += diff
}
func UpdateLastBeatFmt() {
	currentTime := time.Now()
	lastBeat := GetLastBeat()
	if lastBeat != nil {
		heartbeatStats.LastBeatFormatted = TimeDifference(lastBeat.Timestamp, currentTime)
	}
}
func UpdateLastBeatFmtV(lastBeat *HeartbeatBeat, currentTime time.Time) {
	if lastBeat != nil {
		heartbeatStats.LastBeatFormatted = TimeDifference(lastBeat.Timestamp, currentTime)
	}
}