Skip to content

Commit

Permalink
fix(server/cli): rearchitect analyze-log function
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Mar 25, 2024
1 parent e970fd7 commit cc6942c
Showing 1 changed file with 64 additions and 44 deletions.
108 changes: 64 additions & 44 deletions server/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,16 @@ var analyzeLogCmd = &cobra.Command{
log.Fatalln("only .db files are supported")
}

realPath, err := filepath.Abs(match)
if err != nil {
log.Fatalln(err)
}

loggerLoaders = append(loggerLoaders, func() (*logger.Logger, error) {
return logger.NewLoggerFromPath(match)
return logger.NewLoggerFromPath(realPath)
})

log.Println("loaded", match)
log.Println("loaded", realPath)
}
}

Expand All @@ -252,66 +257,81 @@ var analyzeLogCmd = &cobra.Command{
// map[analyzer]map[participantId]map[filePath]struct{FilePath string, ErrorQuotient float64, RepeatedErrorDensity float64, TimeToSolve time.Duration}
results := map[string]map[string]*analyzeResults{}

for _, analyzer := range analyzers {
switch analyzer {
case "eq":
eqa := log_analyzer.New[errorquotient.Analyzer](loggerLoaders...)
if err := eqa.Analyze(); err != nil {
log.Fatalln(err)
}
for _, lgLoader := range loggerLoaders {
lg, err := lgLoader()
if err != nil {
log.Fatalln(err)
}

loader := func() (*logger.Logger, error) {
return lg, nil
}

for participantId, filePaths := range eqa.ResultsByParticipant {
if _, ok := results[participantId]; !ok {
results[participantId] = map[string]*analyzeResults{}
for _, analyzer := range analyzers {
switch analyzer {
case "eq":
eqa := log_analyzer.New[errorquotient.Analyzer](loader)
if err := eqa.Analyze(); err != nil {
log.Fatalln(err)
}

for filePath, eq := range filePaths {
if _, ok := results[participantId][filePath]; !ok {
results[participantId][filePath] = &analyzeResults{FilePath: filePath}
for participantId, filePaths := range eqa.ResultsByParticipant {
if _, ok := results[participantId]; !ok {
results[participantId] = map[string]*analyzeResults{}
}

results[participantId][filePath].ErrorQuotient = eq
}
}
case "red":
red := log_analyzer.New[red.Analyzer](loggerLoaders...)
if err := red.Analyze(); err != nil {
log.Fatalln(err)
}
for filePath, eq := range filePaths {
if _, ok := results[participantId][filePath]; !ok {
results[participantId][filePath] = &analyzeResults{FilePath: filePath}
}

for participantId, filePaths := range red.ResultsByParticipant {
if _, ok := results[participantId]; !ok {
results[participantId] = map[string]*analyzeResults{}
results[participantId][filePath].ErrorQuotient = eq
}
}
case "red":
red := log_analyzer.New[red.Analyzer](loader)
if err := red.Analyze(); err != nil {
log.Fatalln(err)
}

for filePath, red := range filePaths {
if _, ok := results[participantId][filePath]; !ok {
results[participantId][filePath] = &analyzeResults{FilePath: filePath}
for participantId, filePaths := range red.ResultsByParticipant {
if _, ok := results[participantId]; !ok {
results[participantId] = map[string]*analyzeResults{}
}

results[participantId][filePath].RepeatedErrorDensity = red
}
}
case "tts":
tts := log_analyzer.New[timetosolve.Analyzer](loggerLoaders...)
if err := tts.Analyze(); err != nil {
log.Fatalln(err)
}
for filePath, red := range filePaths {
if _, ok := results[participantId][filePath]; !ok {
results[participantId][filePath] = &analyzeResults{FilePath: filePath}
}

for participantId, filePaths := range tts.ResultsByParticipant {
if _, ok := results[participantId]; !ok {
results[participantId] = map[string]*analyzeResults{}
results[participantId][filePath].RepeatedErrorDensity = red
}
}
case "tts":
tts := log_analyzer.New[timetosolve.Analyzer](loader)
if err := tts.Analyze(); err != nil {
log.Fatalln(err)
}

for filePath, tts := range filePaths {
if _, ok := results[participantId][filePath]; !ok {
results[participantId][filePath] = &analyzeResults{FilePath: filePath}
for participantId, filePaths := range tts.ResultsByParticipant {
if _, ok := results[participantId]; !ok {
results[participantId] = map[string]*analyzeResults{}
}

results[participantId][filePath].TimeToSolve = tts
for filePath, tts := range filePaths {
if _, ok := results[participantId][filePath]; !ok {
results[participantId][filePath] = &analyzeResults{FilePath: filePath}
}

results[participantId][filePath].TimeToSolve = tts
}
}
}
}

if err := lg.Close(); err != nil {
log.Fatalln(err)
}
}

// save the results to an excel file
Expand Down

0 comments on commit cc6942c

Please sign in to comment.