func CheckRecent(db *sql.DB, plate string, timestamp *time.Time) (bool, error) {
	upsertQuery := "INSERT INTO last_seen (plate, time) VALUES (($1), ($2)) ON CONFLICT (plate) DO UPDATE SET time = ($2)"
	var last_seen time.Time

	err := db.QueryRow("SELECT time FROM last_seen WHERE plate = $1", plate).Scan(&last_seen)
	switch {
	case err == sql.ErrNoRows:
		log.Println("Plate:", plate, "not seen recently (no rows), inserting timestamp:", timestamp)
		_, err = db.Exec(upsertQuery, plate, timestamp)
		if err != nil {
			return false, err
		}
		return false, nil

	case err != nil:
		return false, err

	default:
		timeago := Round(time.Since(last_seen), time.Millisecond)
		if timeago > config.Opts.EventIntervalTime {
			log.Println("Plate:", plate, "not seen recently, marker set at", timeago, "ago, over", config.Opts.EventIntervalTime, "ago, updating timestamp:", timestamp)
			_, err = db.Exec(upsertQuery, plate, timestamp)
			if err != nil {
				return false, err
			}
			return false, nil
		} else {
			log.Println("Plate:", plate, "seen recently", timeago, "ago, updating timestamp:", timestamp)
			_, err = db.Exec(upsertQuery, plate, timestamp)
			if err != nil {
				return true, err
			}
			return true, nil
		}
	}
}
// CheckRecent checks whether we've seen this plate recently
CheckRecent checks whether we've seen this plate recently
// CheckRecent checks whether we ' ve seen this plate recently
func CheckRecent(db *sql.DB, plate string, timestamp *time.Time) (bool, error) {
	upsertQuery := "INSERT INTO last_seen (plate, time) VALUES (($1), ($2)) ON CONFLICT (plate) DO UPDATE SET time = ($2)"
	var last_seen time.Time
	err := db.QueryRow("SELECT time FROM last_seen WHERE plate = $1", plate).Scan(&last_seen)
	switch {
	case err == sql.ErrNoRows:
		log.Println("Plate:", plate, "not seen recently (no rows), inserting timestamp:", timestamp)
		_, err = db.Exec(upsertQuery, plate, timestamp)
		if err != nil {
			return false, err
		}
		return false, nil
	case err != nil:
		return false, err
	default:
		timeago := Round(time.Since(last_seen), time.Millisecond)
		if timeago > config.Opts.EventIntervalTime {
			log.Println("Plate:", plate, "not seen recently, marker set at", timeago, "ago, over", config.Opts.EventIntervalTime, "ago, updating timestamp:", timestamp)
			_, err = db.Exec(upsertQuery, plate, timestamp)
			if err != nil {
				return false, err
			}
			return false, nil
		} else {
			log.Println("Plate:", plate, "seen recently", timeago, "ago, updating timestamp:", timestamp)
			_, err = db.Exec(upsertQuery, plate, timestamp)
			if err != nil {
				return true, err
			}
			return true, nil
		}
	}
}
func CheckRecent ( db * sql . DB , plate string , timestamp * time . Time ) ( bool , error ) { upsertQuery := " " var last_seen time . Time err := db . QueryRow ( " " , plate ) . Scan ( & last_seen ) switch { case err == sql . ErrNoRows : log . Println ( " " , plate , " " , timestamp ) _ , err = db . Exec ( upsertQuery , plate , timestamp ) if err != nil { return false , err } return false , nil case err != nil : return false , err default : timeago := Round ( time . Since ( last_seen ) , time . Millisecond ) if timeago > config . Opts . EventIntervalTime { log . Println ( " " , plate , " " , timeago , " " , config . Opts . EventIntervalTime , " " , timestamp ) _ , err = db . Exec ( upsertQuery , plate , timestamp ) if err != nil { return false , err } return false , nil } else { log . Println ( " " , plate , " " , timeago , " " , timestamp ) _ , err = db . Exec ( upsertQuery , plate , timestamp ) if err != nil { return true , err } return true , nil } } }
CheckRecent checks whether we've seen this plate recently
CheckRecent checks whether we ' ve seen this plate recently