Skip to content

Commit a4af796

Browse files
committed
Use consistent filename for ssl-log-cutter and ssl-auto-recorder
1 parent b1180a2 commit a4af796

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

cmd/ssl-log-cutter/ssl-log-cutter.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"flag"
55
"fmt"
66
"github.com/RoboCup-SSL/ssl-go-tools/internal/referee"
7+
"github.com/RoboCup-SSL/ssl-go-tools/pkg/auto"
78
"github.com/RoboCup-SSL/ssl-go-tools/pkg/persistence"
89
"github.com/pkg/errors"
910
"google.golang.org/protobuf/proto"
1011
"log"
1112
"os"
1213
"path/filepath"
13-
"strings"
1414
"time"
1515
)
1616

@@ -263,18 +263,11 @@ func getRefereeMsg(logMessage *persistence.Message) (*referee.Referee, error) {
263263
}
264264

265265
func logFileName(firstRefereeMsg *referee.Referee) string {
266-
teamNameYellow := strings.Replace(*firstRefereeMsg.Yellow.Name, " ", "_", -1)
267-
teamNameBlue := strings.Replace(*firstRefereeMsg.Blue.Name, " ", "_", -1)
268-
date := time.Unix(0, int64(*firstRefereeMsg.PacketTimestamp*1000)).In(loadLocation()).Format("2006-01-02_15-04")
269-
name := fmt.Sprintf("%s_%s-vs-%s%s", date, teamNameYellow, teamNameBlue, logFileExtension())
270-
return filepath.Join(*outputFolder, name)
271-
}
272-
273-
func logFileExtension() string {
266+
name := auto.LogFileName(firstRefereeMsg, loadLocation())
274267
if *compress {
275-
return ".log.gz"
268+
name = name + ".gz"
276269
}
277-
return ".log"
270+
return filepath.Join(*outputFolder, name)
278271
}
279272

280273
func loadLocation() *time.Location {

pkg/auto/auto-recorder.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package auto
22

33
import (
4-
"fmt"
54
"github.com/RoboCup-SSL/ssl-go-tools/internal/referee"
65
"github.com/RoboCup-SSL/ssl-go-tools/pkg/index"
76
"github.com/RoboCup-SSL/ssl-go-tools/pkg/persistence"
87
"google.golang.org/protobuf/proto"
98
"log"
109
"os"
1110
"path/filepath"
12-
"strings"
1311
"time"
1412
)
1513

@@ -65,7 +63,7 @@ func (r *Recorder) consumeMessage(message *persistence.Message) {
6563
}
6664

6765
if !r.Recorder.IsRecording() && isTeamSet(&refMsg) && (isGameStage(&refMsg) || isPreGameStage(&refMsg)) {
68-
logFileName := logFileName(&refMsg)
66+
logFileName := LogFileName(&refMsg, time.UTC)
6967
r.logFilePath = filepath.Join(r.logFileDir, logFileName)
7068
log.Println("Start recording ", r.logFilePath)
7169
if err := r.Recorder.StartRecording(r.logFilePath); err != nil {
@@ -84,14 +82,6 @@ func (r *Recorder) consumeMessage(message *persistence.Message) {
8482
}
8583
}
8684

87-
func logFileName(refMsg *referee.Referee) string {
88-
teamNameYellow := strings.Replace(*refMsg.Yellow.Name, " ", "_", -1)
89-
teamNameBlue := strings.Replace(*refMsg.Blue.Name, " ", "_", -1)
90-
date := time.Unix(0, int64(*refMsg.PacketTimestamp*1000)).Format("2006-01-02_15-04")
91-
matchType := refMsg.GetMatchType().String()
92-
return fmt.Sprintf("%s_%s_%s-vs-%s.log", date, matchType, teamNameYellow, teamNameBlue)
93-
}
94-
9585
func isGameStage(message *referee.Referee) bool {
9686
switch *message.Stage {
9787
case referee.Referee_NORMAL_FIRST_HALF,

pkg/auto/filename.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package auto
2+
3+
import (
4+
"fmt"
5+
"github.com/RoboCup-SSL/ssl-go-tools/internal/referee"
6+
"strings"
7+
"time"
8+
)
9+
10+
func LogFileName(refMsg *referee.Referee, location *time.Location) string {
11+
teamNameYellow := strings.Replace(*refMsg.Yellow.Name, " ", "_", -1)
12+
teamNameBlue := strings.Replace(*refMsg.Blue.Name, " ", "_", -1)
13+
date := time.Unix(0, int64(*refMsg.PacketTimestamp*1000)).In(location).Format("2006-01-02_15-04")
14+
matchType := refMsg.GetMatchType().String()
15+
return fmt.Sprintf("%s_%s_%s-vs-%s.log", date, matchType, teamNameYellow, teamNameBlue)
16+
}

0 commit comments

Comments
 (0)