-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_units.go
99 lines (95 loc) · 3.11 KB
/
parse_units.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
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2024 Michael D Henderson. All rights reserved.
package main
import (
"github.com/spf13/cobra"
"log"
)
var cmdParseUnits = &cobra.Command{
Use: "units",
Short: "Parse all unit files in the input path",
Long: `Read all unit input files, parse them for locations, status, and movement data. Write the combined results into the output path.`,
Run: func(cmd *cobra.Command, args []string) {
log.Printf("parse: units: index %s\n", argsParse.index)
log.Printf("parse: units: output %s\n", argsParse.output)
//// unit files have names like YEAR-MONTH.CLAN.UNIT.input.txt
//pattern := `^(\d{3})-(\d{2})\.(0\d{3})\.(\d{4}([cefg][1-9])?)\.input\.txt$`
//re, err := regexp.Compile(pattern)
//if err != nil {
// log.Fatal(err)
//}
//
//// find all unit input files in the input directory.
//var inputFiles []units.InputFile
//entries, err := os.ReadDir(argsParse.input)
//if err != nil {
// log.Fatal(err)
//}
//for _, entry := range entries {
// if entry.IsDir() {
// continue
// }
// fileName := entry.Name()
// matches := re.FindStringSubmatch(fileName)
// //log.Printf("matches %2d %v\n", len(matches), matches)
// // check for 6 because there are actually 6 captures in the pattern
// if len(matches) != 6 {
// continue
// }
// inputFiles = append(inputFiles, units.InputFile{
// Year: matches[1],
// Month: matches[2],
// Clan: matches[3],
// Unit: matches[4],
// File: filepath.Join(argsParse.input, fileName),
// })
//}
//
//clans := map[string]*units.Clan{}
//
//for _, inputFile := range inputFiles {
// clan, ok := clans[inputFile.Clan]
// if !ok {
// clan = &units.Clan{Id: inputFile.Clan}
// clans[clan.Id] = clan
// }
// //log.Printf("parse: units: input %+v\n", inputFile)
// unit, parseErr := units.Parse(inputFile)
// if parseErr != nil {
// log.Printf("unit %s: error: %v\n", inputFile.File, parseErr)
// err = cerrs.ErrParseFailed
// continue
// }
// clan.Units = append(clan.Units, unit)
// log.Printf("clan %s: unit %6s: %-7s => %-7s\n", clan.Id, unit.Id, unit.Started, unit.Finished)
// if unit.Movement == nil {
// log.Printf("clan %s: unit %s: missing movement\n", clan.Id, unit.Id)
// } else {
// var raw, buf string
// for n, step := range unit.Movement.Steps {
// if n != 0 {
// raw += ", "
// buf += ", "
// }
// raw += fmt.Sprintf("{%s}", step.RawText)
// buf += fmt.Sprintf("%v", *step)
// }
// log.Printf("clan %s: unit %s: steps %d => %s\n", clan.Id, unit.Id, len(unit.Movement.Steps), raw)
// log.Printf("clan %s: unit %s: steps %d => %s\n", clan.Id, unit.Id, len(unit.Movement.Steps), buf)
// }
// if unit.Movement.Failed.Direction != "" {
// log.Printf("clan %s: unit %s: failed %+v\n", clan.Id, unit.Id, unit.Movement.Failed)
// }
//}
//
//if err != nil {
// log.Printf("error parsing input: %v\n", err)
//}
//
//// write out our debug log
//if b := movements.DebugBuffer.Bytes(); len(b) > 0 {
// if err := os.WriteFile(filepath.Join(argsParse.output, "debug_movements.txt"), b, 0644); err != nil {
// log.Fatal(err)
// }
//}
},
}