forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team_match_log.go
53 lines (43 loc) · 1.52 KB
/
team_match_log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
//
// Utilities for logging packets received from team driver stations during a match.
package main
import (
"fmt"
"log"
"os"
"time"
)
const logsDir = "static/logs"
type TeamMatchLog struct {
logger *log.Logger
logFile *os.File
}
// Creates a file to log to for the given match and team.
func NewTeamMatchLog(teamId int, match *Match) (*TeamMatchLog, error) {
err := os.MkdirAll(logsDir, 0755)
if err != nil {
return nil, err
}
filename := fmt.Sprintf("%s/%s_%s_Match_%s_%d.csv", logsDir, time.Now().Format("20060102150405"),
match.CapitalizedType(), match.DisplayName, teamId)
logFile, err := os.Create(filename)
if err != nil {
return nil, err
}
log := TeamMatchLog{log.New(logFile, "", 0), logFile}
log.logger.Println("matchTimeSec,teamId,allianceStation,robotLinked,auto,enabled,emergencyStop," +
"batteryVoltage,dsVersion,packetCount,missedPacketCount,dsRobotTripTimeMs")
return &log, nil
}
// Adds a line to the log when a packet is received.
func (log *TeamMatchLog) LogDsStatus(matchTimeSec float64, dsStatus *DriverStationStatus) {
log.logger.Printf("%f,%d,%s,%v,%v,%v,%v,%f,%s,%d,%d,%d", matchTimeSec, dsStatus.TeamId,
dsStatus.AllianceStation, dsStatus.RobotLinked, dsStatus.Auto, dsStatus.Enabled,
dsStatus.EmergencyStop, dsStatus.BatteryVoltage, dsStatus.DsVersion, dsStatus.PacketCount,
dsStatus.MissedPacketCount, dsStatus.DsRobotTripTimeMs)
}
func (log *TeamMatchLog) Close() {
log.logFile.Close()
}