-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·89 lines (74 loc) · 2.7 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Package main is the entry point for the Albatross application.
// It processes shot data from various launch monitors and calculates targets.
package main
import (
"flag"
"os"
"strings"
"albatross/internal/calculators"
"albatross/internal/logging"
"albatross/internal/parsers"
"albatross/internal/writer"
"albatross/utils"
)
// main is the entry point of the application. It handles command-line arguments,
// processes shot data, calculates targets, and writes the results to a file.
func main() {
// Initialize the logger
logging.InitLogger()
// Define command-line flags
launchMonitorType := flag.String("type", "", "Launch monitor type (e.g., mlm2pro)")
inputFile := flag.String("input", "", "Input CSV file path")
flag.Parse()
// Validate command-line arguments
if *launchMonitorType == "" || *inputFile == "" {
logging.Fatal("Usage: go run main.go -type <launch_monitor_type> -input <input_csv_file>", nil)
}
normalizedType := normalizeLaunchMonitorType(*launchMonitorType)
// Validate launch monitor type
if !isValidLaunchMonitorType(normalizedType) {
logging.Fatal("Error: Invalid launch monitor type. Supported type is mlm2pro.", logging.Fields{
"providedType": normalizedType,
})
}
// Process shot data from the input file
shotData, err := parsers.ProcessShotData(*inputFile, normalizedType)
if err != nil {
logging.Error("Error processing shot data", err, logging.Fields{
"inputFile": *inputFile,
"launchMonitorType": normalizedType,
})
os.Exit(1)
}
logging.Info("Processed shot data", logging.Fields{
"count": len(shotData),
})
// Calculate targets based on the processed shot data
calculators.CalculateTargets(&shotData)
logging.Debug("Calculated targets", logging.Fields{
"shotData": shotData,
})
// Write processed data to an output file
outputFile := utils.ReplaceFileExtension(*inputFile, "_processed.csv")
writer := writer.ShotPatternWriter{}
if err := writer.Write(outputFile, shotData); err != nil {
logging.Error("Error writing output file", err, logging.Fields{
"outputFile": outputFile,
})
os.Exit(1)
}
logging.Info("Successfully processed shots and saved results", logging.Fields{
"shotsProcessed": len(shotData),
"outputFile": outputFile,
})
}
// normalizeLaunchMonitorType converts the launch monitor type to lowercase for consistency.
// This ensures that the type check is case-insensitive.
func normalizeLaunchMonitorType(launchMonitorType string) string {
return strings.ToLower(launchMonitorType)
}
// isValidLaunchMonitorType checks if the provided launch monitor type is supported.
// Currently, only "mlm2pro" is supported.
func isValidLaunchMonitorType(launchMonitorType string) bool {
return launchMonitorType == "mlm2pro"
}