Skip to content

Commit b425bcd

Browse files
committed
fix telemetryPoints for FE
1 parent 0cf757a commit b425bcd

11 files changed

Lines changed: 99 additions & 57 deletions

File tree

docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ services:
4848
JAVA_OPTS: "-Xmx2g -Xms1g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:G1ReservePercent=20"
4949
QDB_SHARED_WORKER_COUNT: "5"
5050
QDB_HTTP_ENABLED: "true"
51-
QDB_PG_ENABLED: "false"
51+
QDB_PG_ENABLED: "true"
5252
QDB_LINE_TCP_ENABLED: "true"
5353
QDB_METRICS_ENABLED: "true"
5454
QDB_CAIRO_WAL_ENABLED_DEFAULT: "true"

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ services:
6565
JAVA_OPTS: "-Xmx2g -Xms1g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:G1ReservePercent=20"
6666
QDB_SHARED_WORKER_COUNT: "2"
6767
QDB_HTTP_ENABLED: "true"
68-
QDB_PG_ENABLED: "false"
68+
QDB_PG_ENABLED: "true"
6969
QDB_METRICS_ENABLED: "true"
7070
QDB_LINE_TCP_ENABLED: "true"
7171
QDB_CAIRO_WAL_ENABLED_DEFAULT: "true"

telemetryService/golang/cmd/telemetry-service/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func main() {
2121

2222
cfg := config.NewConfig()
2323

24-
schema := questdb.NewRepository(cfg.QuestDbHost, cfg.QuestDBPort)
24+
schema := questdb.NewSchema(cfg.QuestDbHost, cfg.QuestDBPort)
2525
if err := schema.CreateTableHTTP(); err != nil {
2626
log.Printf("Failed to create table: %v", err)
2727
log.Println("Exiting due to database initialization failure")
@@ -38,7 +38,7 @@ func main() {
3838
}
3939
log.Println("Sender pool created successfully")
4040

41-
pgxPool, err := pgxpool.New(context.Background(), fmt.Sprintf("postgres://%s:%d/questdb?sslmode=disable", cfg.QuestDbHost,
41+
pgxPool, err := pgxpool.New(context.Background(), fmt.Sprintf("postgres://admin:quest@%s:%d/questdb?sslmode=disable", cfg.QuestDbHost,
4242
8812))
4343
if err != nil {
4444
log.Fatalf("pgx pool: %v", err)

telemetryService/golang/internal/adapter/questdb/reader.go

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,65 @@ package questdb
33
import (
44
"context"
55
"fmt"
6+
"strconv"
7+
"time"
68

9+
"github.com/jackc/pgx/v5/pgtype"
710
"github.com/ojparkinson/telemetryService/internal/db/generated"
811
"github.com/ojparkinson/telemetryService/internal/domain"
912
)
1013

1114
func (r *Repository) ListSessions(ctx context.Context) ([]domain.Session, error) {
1215
rows, err := r.queries.ListSessions(ctx)
1316
if err != nil {
14-
return nil, fmt.Errorf("list sessions: %W", err)
17+
return nil, fmt.Errorf("list sessions: %w", err)
1518
}
1619

1720
sessions := make([]domain.Session, len(rows))
1821
for i, row := range rows {
22+
var maxLapID string
23+
if v, ok := row.MaxLapID.(string); ok {
24+
maxLapID = v
25+
} else if v, ok := row.MaxLapID.(pgtype.Text); ok {
26+
maxLapID = v.String
27+
}
28+
29+
var lastUpdated time.Time
30+
if v, ok := row.LastUpdated.(time.Time); ok {
31+
lastUpdated = v
32+
} else if v, ok := row.LastUpdated.(pgtype.Timestamp); ok && v.Valid {
33+
lastUpdated = v.Time
34+
}
35+
1936
sessions[i] = domain.Session{
20-
SessionID: row.SessionID,
21-
TrackName: row.TrackName,
22-
SessionName: row.SessionName,
23-
MaxLapID: row.MaxLapID,
24-
LastUpdated: row.LastUpdated,
37+
SessionID: row.SessionID.String,
38+
TrackName: row.TrackName.String,
39+
SessionName: row.SessionName.String,
40+
MaxLapID: maxLapID,
41+
LastUpdated: lastUpdated,
2542
}
2643
}
2744
return sessions, nil
2845
}
2946

3047
func (r *Repository) ListLaps(ctx context.Context, sessionsID string) ([]domain.Lap, error) {
31-
rows, err := r.queries.ListLaps(ctx, sessionsID)
48+
rows, err := r.queries.ListLaps(ctx, pgtype.Text{String: sessionsID, Valid: true})
3249
if err != nil {
3350
return nil, fmt.Errorf("list laps: %w", err)
3451
}
3552

3653
laps := make([]domain.Lap, len(rows))
3754
for i, row := range rows {
38-
laps[i] = domain.Lap{LapID: row.LapID}
55+
lapID, _ := strconv.Atoi(row.String)
56+
laps[i] = domain.Lap{LapID: lapID}
3957
}
4058
return laps, nil
4159
}
4260

4361
func (r *Repository) GetLapTelemetry(ctx context.Context, sessionID, lapID string) ([]domain.TelemetryPoint, error) {
4462
rows, err := r.queries.GetLapTelemetry(ctx, generated.GetLapTelemetryParams{
45-
SessionID: sessionID,
46-
LapID: lapID,
63+
SessionID: pgtype.Text{String: sessionID, Valid: true},
64+
LapID: pgtype.Text{String: lapID, Valid: true},
4765
})
4866
if err != nil {
4967
return nil, fmt.Errorf("get lap telemetry: %w", err)
@@ -58,11 +76,31 @@ func (r *Repository) GetLapTelemetry(ctx context.Context, sessionID, lapID strin
5876

5977
func telemetryPointFromRow(row generated.Telemetrytick) domain.TelemetryPoint {
6078
return domain.TelemetryPoint{
61-
Speed: row.Speed,
62-
Throttle: row.Throttle,
63-
Brake: row.Brake,
64-
RPM: row.Rpm,
65-
Gear: row.Gear,
66-
// ... all fields, but now it's typed — no getString/getFloat64 helpers
79+
Speed: row.Speed.Float64,
80+
Throttle: row.Throttle.Float64,
81+
Brake: row.Brake.Float64,
82+
RPM: row.Rpm.Float64,
83+
Gear: uint32(row.Gear.Int32),
84+
LapDistPct: row.LapDistPct.Float64,
85+
SteeringWheelAngle: row.SteeringWheelAngle.Float64,
86+
Lat: row.Lat.Float64,
87+
Lon: row.Lon.Float64,
88+
Alt: row.Alt.Float64,
89+
VelocityX: row.VelocityX.Float64,
90+
VelocityY: row.VelocityY.Float64,
91+
VelocityZ: row.VelocityZ.Float64,
92+
LatAccel: row.LatAccel.Float64,
93+
LongAccel: row.LongAccel.Float64,
94+
VertAccel: row.VertAccel.Float64,
95+
Pitch: row.Pitch.Float64,
96+
Roll: row.Roll.Float64,
97+
Yaw: row.Yaw.Float64,
98+
YawNorth: row.YawNorth.Float64,
99+
FuelLevel: row.FuelLevel.Float64,
100+
LapCurrentLapTime: row.LapCurrentLapTime.Float64,
101+
PlayerCarPosition: uint32(row.PlayerCarPosition.Int32),
102+
TrackName: row.TrackName.String,
103+
SessionNum: row.SessionNum.String,
104+
SessionTime: row.SessionTime.Float64,
67105
}
68106
}

telemetryService/golang/internal/adapter/questdb/schema.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import (
99

1010
type Schema struct {
1111
host string
12-
port string
12+
port int
13+
}
14+
15+
func NewSchema(host string, port int) *Schema {
16+
return &Schema{host: host, port: port}
1317
}
1418

1519
func (s *Schema) CreateTableHTTP() error {

telemetryService/golang/internal/api/handlers.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ func (s *Server) handleGetLaps(w http.ResponseWriter, r *http.Request) {
4343
return
4444
}
4545

46-
respondJSON(w, 200, rows)
46+
lapIDs := make([]int, len(rows))
47+
48+
for i, row := range rows {
49+
lapIDs[i] = row.LapID
50+
}
51+
52+
respondJSON(w, 200, lapIDs)
4753

4854
}
4955

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
package db
2-
3-
4-
type database struct {
5-
conn sql.
6-
}

telemetryService/golang/internal/db/generated/laps.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-- name: ListLaps :many
22
SELECT DISTINCT lap_id FROM TelemetryTicks
3-
WHERE session_id = @session_id ORDER BY lap_id ASC;
3+
WHERE session_id = $1 ORDER BY CAST(lap_id as int) ASC;

telemetryService/golang/internal/domain/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ type SessionRepository interface {
1313
}
1414

1515
type TelemetryWriter interface {
16-
WriteBatch(ctx context.Context, records []*messaging.Telemetry)
16+
WriteBatch(ctx context.Context, records []*messaging.Telemetry) error
1717
}

0 commit comments

Comments
 (0)