Skip to content

Commit

Permalink
remove temperature tracking feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-m committed Dec 27, 2023
1 parent 562ee64 commit 8e3ac49
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 140 deletions.
24 changes: 1 addition & 23 deletions cmd/trainbot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/jo-m/trainbot/internal/pkg/stitch"
"github.com/jo-m/trainbot/internal/pkg/upload"
"github.com/jo-m/trainbot/pkg/imutil"
"github.com/jo-m/trainbot/pkg/thermal"
"github.com/jo-m/trainbot/pkg/vid"
"github.com/nfnt/resize"
"github.com/rs/zerolog/log"
Expand All @@ -51,8 +50,7 @@ type config struct {
CPUProfile bool `arg:"--cpu-profile,env:CPU_PROFILE" help:"Write CPU profile"`
HeapProfile bool `arg:"--heap-profile,env:HEAP_PROFILE" help:"Write memory heap profiles"`

EnableUpload bool `arg:"--enable-upload,env:ENABLE_UPLOAD" help:"Enable uploading of data."`
EnableTempMeasurement bool `arg:"--enable-temperature-measurement,env:ENABLE_TEMPERATURE_MEASUREMENT" help:"Enable periodic onboard temperature (thermal sensor) measurements to the database."`
EnableUpload bool `arg:"--enable-upload,env:ENABLE_UPLOAD" help:"Enable uploading of data."`

upload.FTPConfig
upload.DataStore
Expand Down Expand Up @@ -369,23 +367,6 @@ func deleteOldLocalBlobsForever(store upload.DataStore, dbx *sqlx.DB) {
}
}

func measureTempForever(dbx *sqlx.DB) {
for ; true; <-time.Tick(time.Minute * 15) {
temp, err := thermal.MeasureDegC()
if err != nil {
log.Err(err).Msg("failed to read temperature")
continue
}

log.Info().Float64("tempDegC", temp).Msg("current temperature")

_, err = db.InsertTemp(dbx, time.Now(), temp)
if err != nil {
log.Err(err).Msg("failed to write temperature to database")
}
}
}

func main() {
c := parseCheckArgs()

Expand Down Expand Up @@ -431,9 +412,6 @@ func main() {
go deleteOldLocalBlobsForever(c.DataStore, dbx)
go cleanupOrphanedRemoteBlobsForever(dbx, c.FTPConfig)
}
if c.EnableTempMeasurement {
go measureTempForever(dbx)
}

detectTrainsForever(c, trains)

Expand Down
1 change: 0 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ UPLOAD_FTP_USER="ftpuser"
UPLOAD_FTP_PASSWORD="ftp-password"
UPLOAD_FTP_PWD="wwwroot/trains/data"

ENABLE_TEMPERATURE_MEASUREMENT=true
PROMETHEUS=false
PROMETHEUS_LISTEN=:18963
20 changes: 0 additions & 20 deletions frontend/src/components/TemperatureDisplay.vue

This file was deleted.

17 changes: 0 additions & 17 deletions frontend/src/lib/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,3 @@ export const histSpeedKPH = (db: SqlJs.Database, binSz: number = 10): number[][]
FROM speed_rounded
GROUP BY speed_rounded
ORDER BY speed_rounded;`)[0].values as number[][]

export const tempDegCPast24hAvg = (db: SqlJs.Database): number[][] => {
const res = db.exec(`
SELECT
CAST(strftime('%H', timestamp) AS INT) AS hod,
ROUND(AVG(temp_deg_c))
FROM temperatures
WHERE timestamp >= DATETIME('now','-24 hours')
GROUP BY hod
ORDER BY hod ASC`)

if (res.length == 0) {
return []
}

return res[0].values as number[][]
}
18 changes: 1 addition & 17 deletions frontend/src/views/TrainStatsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
histCountPerDayOfWeek,
dayOfWeekLabels,
histHourOfDay,
histSpeedKPH,
tempDegCPast24hAvg
histSpeedKPH
} from '@/lib/stats'
import VerticalHist from '@/components/VerticalHist.vue'
Expand Down Expand Up @@ -72,21 +71,6 @@ const widthPx = 200
></VerticalHist>
</td>
</tr>
<tr>
<td>Avg core temperature 24h [°C]</td>
<td>
<VerticalHist
:data="tempDegCPast24hAvg(db)"
:width-px="widthPx"
:labels="
Object.fromEntries(
Array.from({ length: 24 }, (x, i) => [i, `00${i}:00`.slice(-5)])
)
"
color="#cc0000"
></VerticalHist>
</td>
</tr>
</tbody>
</v-table>
</v-card-text>
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/views/TrainsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import TrainList from '@/components/TrainList.vue'
import TrainGrid from '@/components/TrainGrid.vue'
import FilterDialog, { type updateFilterArgs } from '@/components/FilterDialog.vue'
import StaleDataWarningDialog from '@/components/StaleDataWarningDialog.vue'
import TemperatureDisplay from '@/components/TemperatureDisplay.vue'
import FavoritesDialog from '@/components/FavoritesDialog.vue'
import { ref, onMounted, onUnmounted, inject, watch } from 'vue'
import { dbKey, getTrains, type Train as TrainType, type Filter } from '@/lib/db'
Expand Down Expand Up @@ -112,7 +111,6 @@ function scrollUp() {
<template>
<!-- App bar -->
<Teleport to="#app-bar-teleport">
<TemperatureDisplay />
<StaleDataWarningDialog />

<v-btn
Expand Down
20 changes: 0 additions & 20 deletions internal/pkg/db/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,6 @@ func SetCleanedUp(db *sqlx.DB, id int64) error {
return err
}

// InsertTemp inserts a new temperature measurement.
// Returns the db id of the new row.
func InsertTemp(db *sqlx.DB, ts time.Time, tempDegC float64) (int64, error) {
var id int64
const q = `
INSERT INTO temperatures (
timestamp,
temp_deg_c
)
VALUES (?, ?)
RETURNING id;`
err := db.Get(&id, q,
ts.Format(dbTSFormat), tempDegC)
if err != nil {
return 0, err
}

return id, nil
}

// GetAllBlobs lists all blobs which the database knows about.
// Does not include thumbnails.
func GetAllBlobs(db *sqlx.DB) (map[string]struct{}, error) {
Expand Down
14 changes: 0 additions & 14 deletions internal/pkg/db/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,3 @@ func Test_Train_TimesstampDBSerialization(t *testing.T) {
assert.Len(t, results, 2)
assert.Equal(t, "2023-11-10T12:57:45.897+01:00", results[0].StartTS)
}

func Test_Temperature_Queries(t *testing.T) {
tmp := t.TempDir()
dbpath := filepath.Join(tmp, "test.db")
db, err := Open(dbpath)
assert.NoError(t, err)
assert.NotNil(t, db)
defer db.Close()

// Insert.
id, err := InsertTemp(db, time.Now(), 123.456)
assert.NoError(t, err)
assert.Greater(t, id, int64(0))
}
1 change: 1 addition & 0 deletions internal/pkg/db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ ORDER BY id ASC;
-- Truncate old tables.
DELETE FROM trains_blob_cleanups;
DELETE FROM trains;
DELETE FROM temperatures;

COMMIT;

Expand Down
26 changes: 0 additions & 26 deletions pkg/thermal/thermal.go

This file was deleted.

0 comments on commit 8e3ac49

Please sign in to comment.