Skip to content

Commit

Permalink
Use consistent filename for ssl-log-cutter and ssl-auto-recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Dec 29, 2024
1 parent b1180a2 commit a4af796
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
15 changes: 4 additions & 11 deletions cmd/ssl-log-cutter/ssl-log-cutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"flag"
"fmt"
"github.com/RoboCup-SSL/ssl-go-tools/internal/referee"
"github.com/RoboCup-SSL/ssl-go-tools/pkg/auto"
"github.com/RoboCup-SSL/ssl-go-tools/pkg/persistence"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"log"
"os"
"path/filepath"
"strings"
"time"
)

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

func logFileName(firstRefereeMsg *referee.Referee) string {
teamNameYellow := strings.Replace(*firstRefereeMsg.Yellow.Name, " ", "_", -1)
teamNameBlue := strings.Replace(*firstRefereeMsg.Blue.Name, " ", "_", -1)
date := time.Unix(0, int64(*firstRefereeMsg.PacketTimestamp*1000)).In(loadLocation()).Format("2006-01-02_15-04")
name := fmt.Sprintf("%s_%s-vs-%s%s", date, teamNameYellow, teamNameBlue, logFileExtension())
return filepath.Join(*outputFolder, name)
}

func logFileExtension() string {
name := auto.LogFileName(firstRefereeMsg, loadLocation())
if *compress {
return ".log.gz"
name = name + ".gz"
}
return ".log"
return filepath.Join(*outputFolder, name)
}

func loadLocation() *time.Location {
Expand Down
12 changes: 1 addition & 11 deletions pkg/auto/auto-recorder.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package auto

import (
"fmt"
"github.com/RoboCup-SSL/ssl-go-tools/internal/referee"
"github.com/RoboCup-SSL/ssl-go-tools/pkg/index"
"github.com/RoboCup-SSL/ssl-go-tools/pkg/persistence"
"google.golang.org/protobuf/proto"
"log"
"os"
"path/filepath"
"strings"
"time"
)

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

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

func logFileName(refMsg *referee.Referee) string {
teamNameYellow := strings.Replace(*refMsg.Yellow.Name, " ", "_", -1)
teamNameBlue := strings.Replace(*refMsg.Blue.Name, " ", "_", -1)
date := time.Unix(0, int64(*refMsg.PacketTimestamp*1000)).Format("2006-01-02_15-04")
matchType := refMsg.GetMatchType().String()
return fmt.Sprintf("%s_%s_%s-vs-%s.log", date, matchType, teamNameYellow, teamNameBlue)
}

func isGameStage(message *referee.Referee) bool {
switch *message.Stage {
case referee.Referee_NORMAL_FIRST_HALF,
Expand Down
16 changes: 16 additions & 0 deletions pkg/auto/filename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package auto

import (
"fmt"
"github.com/RoboCup-SSL/ssl-go-tools/internal/referee"
"strings"
"time"
)

func LogFileName(refMsg *referee.Referee, location *time.Location) string {
teamNameYellow := strings.Replace(*refMsg.Yellow.Name, " ", "_", -1)
teamNameBlue := strings.Replace(*refMsg.Blue.Name, " ", "_", -1)
date := time.Unix(0, int64(*refMsg.PacketTimestamp*1000)).In(location).Format("2006-01-02_15-04")
matchType := refMsg.GetMatchType().String()
return fmt.Sprintf("%s_%s_%s-vs-%s.log", date, matchType, teamNameYellow, teamNameBlue)
}

0 comments on commit a4af796

Please sign in to comment.