forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam_match_log.go
52 lines (42 loc) · 1.48 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
// 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,packetType,teamId,allianceStation,robotLinked,auto,enabled," +
"emergencyStop,batteryVoltage,missedPacketCount,dsRobotTripTimeMs")
return &log, nil
}
// Adds a line to the log when a packet is received.
func (log *TeamMatchLog) LogDsPacket(matchTimeSec float64, packetType int, dsConn *DriverStationConnection) {
log.logger.Printf("%f,%d,%d,%s,%v,%v,%v,%v,%f,%d,%d", matchTimeSec, packetType, dsConn.TeamId,
dsConn.AllianceStation, dsConn.RobotLinked, dsConn.Auto, dsConn.Enabled, dsConn.EmergencyStop,
dsConn.BatteryVoltage, dsConn.MissedPacketCount, dsConn.DsRobotTripTimeMs)
}
func (log *TeamMatchLog) Close() {
log.logFile.Close()
}