Skip to content

Commit

Permalink
Replace flag exclude-transposition-errors with exclude-error-prone-se…
Browse files Browse the repository at this point in the history
…rial-numbers
  • Loading branch information
mrclmr committed Jan 9, 2024
1 parent 9dc0c93 commit 5c21145
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 65 deletions.
14 changes: 10 additions & 4 deletions cmd/icm/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newGenerateCmd(writer, writerErr io.Writer, config *configs.Config, ownerDe
endValue := serialNumValue{}
ownerValue := ownerValue{}
var excludeCheckDigit10 bool
var excludeTranspositionErr bool
var excludeErrorProneSerialNumbers bool

generateCmd := &cobra.Command{
Use: "generate",
Expand All @@ -112,7 +112,7 @@ icm generate --count 10
# Generate container numbers with custom format
icm generate --count 10 --sep-owner-equip '' --sep-serial-check '-'
# Generate container numbers without error-prone serial numbers
icm generate --count 10 --exclude-check-digit-10 --exclude-transposition-errors
icm generate --count 10 --exclude-check-digit-10 --exclude-error-prone-serial-numbers
# Generate container numbers within serial number range
icm generate --start 100500 --count 10
icm generate --start 100500 --end 100600
Expand All @@ -127,7 +127,7 @@ icm generate --count 1000000 | icm validate`,
builder := cont.NewUniqueGeneratorBuilder(r).
Count(count.value).
ExcludeCheckDigit10(excludeCheckDigit10).
ExcludeTranspositionErr(excludeTranspositionErr)
ExcludeErrorProneSerialNumbers(excludeErrorProneSerialNumbers)

if cmd.Flags().Changed("owner") {
builder.OwnerCodes([]string{ownerValue.value})
Expand Down Expand Up @@ -167,8 +167,14 @@ icm generate --count 1000000 | icm validate`,
generateCmd.Flags().VarP(&endValue, "end", "e", "end of serial number range")
generateCmd.Flags().Var(&ownerValue, "owner", "custom owner code")
generateCmd.Flags().BoolVar(&excludeCheckDigit10, "exclude-check-digit-10", false, "exclude check digit 10")
generateCmd.Flags().BoolVar(&excludeTranspositionErr, "exclude-transposition-errors", false,
generateCmd.Flags().BoolVar(&excludeErrorProneSerialNumbers, "exclude-transposition-errors", false,
"exclude possible transposition errors")
err := generateCmd.Flags().MarkDeprecated("exclude-transposition-errors", "use instead --exclude-error-prone-serial-numbers")
if err != nil {
return nil
}
generateCmd.Flags().BoolVar(&excludeErrorProneSerialNumbers, "exclude-error-prone-serial-numbers", false,
"exclude error-prone serial numbers. For example swapping the second 0 and first 1 of RCB U 001130 0 results in container number RCB U 010130 0 with a valid check digit 0")

generateCmd.Flags().String(configs.FlagNames.SepOE, configs.DefaultValues.SepOE,
"ABC(x)U1234560 (x) separates owner code and equipment category id")
Expand Down
24 changes: 12 additions & 12 deletions cmd/icm/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func newValidateCmd(stdin io.Reader, writer io.Writer, config *configs.Config, d
For single line input a human-readable output is used.
For multi line input CSV output is used. For example this is useful to scan
data sets for possible transposition errors. It is also possible to generate
data sets for error-prone serial numbers. It is also possible to generate
CSV data sets of random container numbers.
` + sepHelp,
Expand All @@ -192,7 +192,7 @@ icm generate --count 10 | icm validate
icm generate --count 10 | icm validate --output fancy
# Generate CSV data set
icm generate --count 1000000 | icm validate
# Validate a container number with 6 (!) possible transposition errors
# Validate a container number with 6 (!) error-prone serial numbers combinations
icm validate APL U 689473 0`,
Args: cobra.MaximumNArgs(6),
ValidArgsFunction: cobra.NoFileCompletions,
Expand Down Expand Up @@ -478,7 +478,7 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {
checkDigitDatum := input.NewDatum("check-digit").WithValue(value)
calcCheckDigitDatum := input.NewDatum("calculated-check-digit")
validCheckDigit := input.NewDatum("valid-check-digit")
possibleTranspositionError := input.NewDatum("possible-transposition-error")
errorProneSerialNumbers := input.NewDatum("possible-transposition-error")
if len(strings.Join(previousValues[0:3], "")) != 10 {
return newValidateError(fmt.Sprintf("%s is not calculable",
au.Underline("check digit"))),
Expand All @@ -487,7 +487,7 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {
checkDigitDatum,
calcCheckDigitDatum,
validCheckDigit.WithValue(fmt.Sprintf("%t", false)),
possibleTranspositionError,
errorProneSerialNumbers,
}
}

Expand All @@ -508,7 +508,7 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {
checkDigitDatum,
calcCheckDigitDatum.WithValue(strconv.Itoa(checkDigit)),
validCheckDigit.WithValue(fmt.Sprintf("%t", false)),
possibleTranspositionError,
errorProneSerialNumbers,
}
}

Expand All @@ -522,14 +522,14 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {
checkDigitDatum,
calcCheckDigitDatum.WithValue(strconv.Itoa(checkDigit)),
validCheckDigit.WithValue(fmt.Sprintf("%t", number == checkDigit%10)),
possibleTranspositionError,
errorProneSerialNumbers,
}
}

transposedContNums := cont.CheckTransposition(previousValues[2], equipCatID, serialNum, checkDigit)

if len(transposedContNums) != 0 {
infos = append(infos, input.Info{Text: "Possible transposition errors:"})
infos = append(infos, input.Info{Text: "Error-prone serial numbers:"})
builder := strings.Builder{}

for idx, tcn := range transposedContNums {
Expand All @@ -538,12 +538,12 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {
serialNumberFmt := ""
for i := 0; i < len(serialNumber); i++ {
if i == tcn.Pos {
serialNumberFmt += fmt.Sprintf("%c", au.Red(serialNumber[i]))
serialNumberFmt += fmt.Sprintf("%c", au.Magenta(serialNumber[i]))
// last serial number digit
if i == len(serialNumber)-1 {
continue
}
serialNumberFmt += fmt.Sprintf("%c", au.Red(serialNumber[i+1]))
serialNumberFmt += fmt.Sprintf("%c", au.Magenta(serialNumber[i+1]))
i++
} else {
serialNumberFmt += fmt.Sprintf("%c", serialNumber[i])
Expand All @@ -552,7 +552,7 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {

var digitFmt string
if tcn.Pos == 5 {
digitFmt = fmt.Sprintf("%d", au.Red(tcn.CheckDigit))
digitFmt = fmt.Sprintf("%d", au.Magenta(tcn.CheckDigit))
} else {
digitFmt = fmt.Sprintf("%d", tcn.CheckDigit)
}
Expand All @@ -574,7 +574,7 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {
checkDigitDatum,
calcCheckDigitDatum.WithValue(strconv.Itoa(checkDigit)),
validCheckDigit.WithValue(fmt.Sprintf("%t", number == checkDigit%10)),
possibleTranspositionError.WithValue(builder.String()),
errorProneSerialNumbers.WithValue(builder.String()),
}
}

Expand All @@ -584,7 +584,7 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {
checkDigitDatum,
calcCheckDigitDatum.WithValue(strconv.Itoa(checkDigit)),
validCheckDigit.WithValue(fmt.Sprintf("%t", number == checkDigit%10)),
possibleTranspositionError,
errorProneSerialNumbers,
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/icm/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func Test_validateCmd(t *testing.T) {
│ │ │ │
│ │ │ └─ length: some-length
│ │ │
│ │ └─ Possible transposition errors:
│ │ └─ Error-prone serial numbers:
│ │ ABC***U+++681034‧‧‧0
│ │ ABC***U+++681340‧‧‧0
│ │
Expand Down Expand Up @@ -313,7 +313,7 @@ func Test_validateCmd(t *testing.T) {
`
ABC U 681304 0 ✔
↑ ↑ ↑
│ │ └─ Possible transposition errors:
│ │ └─ Error-prone serial numbers:
│ │ ABC U 681034 0
│ │ ABC U 681340 0
│ │
Expand Down
52 changes: 26 additions & 26 deletions cont/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
// GeneratorBuilder is the struct for the builder.
// Use NewUniqueGeneratorBuilder to create a new one.
type GeneratorBuilder struct {
rand *rand.Rand
codes []string
count int
start int
end int
exclCheckDigit10 bool
exclTranspositionErr bool
rand *rand.Rand
codes []string
count int
start int
end int
exclCheckDigit10 bool
exclErrorProneSerialNumbers bool
}

// NewUniqueGeneratorBuilder returns a new random unique container number generator.
Expand Down Expand Up @@ -60,9 +60,9 @@ func (gb *GeneratorBuilder) ExcludeCheckDigit10(exclude bool) *GeneratorBuilder
return gb
}

// ExcludeTranspositionErr sets the exclusion of container numbers with possible transposition errors.
func (gb *GeneratorBuilder) ExcludeTranspositionErr(exclude bool) *GeneratorBuilder {
gb.exclTranspositionErr = exclude
// ExcludeErrorProneSerialNumbers sets the exclusion of container numbers with error-prone serial numbers.
func (gb *GeneratorBuilder) ExcludeErrorProneSerialNumbers(exclude bool) *GeneratorBuilder {
gb.exclErrorProneSerialNumbers = exclude
return gb
}

Expand Down Expand Up @@ -118,27 +118,27 @@ func (gb *GeneratorBuilder) Build() (*UniqueGenerator, error) {
})

return &UniqueGenerator{
codes: gb.codes,
lenCodes: lenCodes,
serialNumIt: sni,
count: count,
exclCheckDigit10: gb.exclCheckDigit10,
exclTranspositionErr: gb.exclTranspositionErr,
codes: gb.codes,
lenCodes: lenCodes,
serialNumIt: sni,
count: count,
exclCheckDigit10: gb.exclCheckDigit10,
exclErrorProneSerialNumbers: gb.exclErrorProneSerialNumbers,
}, nil
}

// UniqueGenerator holds state for generating random unique container numbers.
// Use NewUniqueGeneratorBuilder for initialization.
type UniqueGenerator struct {
codes []string
lenCodes int
ownerOffset int
serialNumIt serialNumIt
count int
contNum Number
generatedCount int
exclCheckDigit10 bool
exclTranspositionErr bool
codes []string
lenCodes int
ownerOffset int
serialNumIt serialNumIt
count int
contNum Number
generatedCount int
exclCheckDigit10 bool
exclErrorProneSerialNumbers bool
}

// Generate advances the serial number iterator to the next serial number,
Expand All @@ -161,7 +161,7 @@ func (g *UniqueGenerator) Generate() bool {
if g.exclCheckDigit10 && checkDigit == 10 {
return g.Generate()
}
if g.exclTranspositionErr && len(CheckTransposition(code, 'U', serialNum, checkDigit)) > 0 {
if g.exclErrorProneSerialNumbers && len(CheckTransposition(code, 'U', serialNum, checkDigit)) > 0 {
return g.Generate()
}
g.contNum = Number{code, 'U', serialNum, checkDigit % 10}
Expand Down
2 changes: 1 addition & 1 deletion cont/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestUniqueGenerator(t *testing.T) {
OwnerCodes([]string{"ABC"}).
Start(801743).
Count(1).
ExcludeTranspositionErr(true),
ExcludeErrorProneSerialNumbers(true),
false,
1,
},
Expand Down
12 changes: 9 additions & 3 deletions docs/gif/create-demo-gif.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
(cd ../.. && make install)
```

4. Run vhs command
4. Comment out temporarily `export PS1='\[\033[01;...`

```bash
vhs < demo.tape
```
#export PS1='...
```

5. Run vhs command

```bash
vhs demo.tape
```
Binary file modified docs/gif/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions docs/gif/demo.tape
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Output demo.gif
Require icm
Set Width 1200
Set Height 600
Set Shell bash
Set TypingSpeed 0.08

Hide
Type "rm -f ~/.icm/config.yml"
Expand All @@ -16,15 +18,15 @@ Type "icm generate"
Sleep 100ms
Enter

Sleep 4s
Sleep 3s

Type "icm generate --count 2"
Sleep 100ms
Enter

Sleep 4s
Sleep 3s

Type "icm generate --count 2 --exclude-transposition-errors"
Type "icm generate --count 2 --exclude-error-prone-serial-numbers"
Sleep 100ms
Enter

Expand All @@ -46,7 +48,7 @@ Type "icm validate btc_u123451-0"
Sleep 100ms
Enter

Sleep 4s
Sleep 8s

Type "icm validate 20R0"
Sleep 100ms
Expand Down
22 changes: 11 additions & 11 deletions docs/icm_generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ icm generate --count 10
# Generate container numbers with custom format
icm generate --count 10 --sep-owner-equip '' --sep-serial-check '-'
# Generate container numbers without error-prone serial numbers
icm generate --count 10 --exclude-check-digit-10 --exclude-transposition-errors
icm generate --count 10 --exclude-check-digit-10 --exclude-error-prone-serial-numbers
# Generate container numbers within serial number range
icm generate --start 100500 --count 10
icm generate --start 100500 --end 100600
Expand All @@ -49,16 +49,16 @@ icm generate --count 1000000 | icm validate
### Options

```
-c, --count int count of container numbers (default 1)
-s, --start int start of serial number range
-e, --end int end of serial number range
--owner string custom owner code
--exclude-check-digit-10 exclude check digit 10
--exclude-transposition-errors exclude possible transposition errors
--sep-owner-equip string ABC(x)U1234560 (x) separates owner code and equipment category id (default " ")
--sep-equip-serial string ABCU(x)1234560 (x) separates equipment category id and serial number (default " ")
--sep-serial-check string ABCU123456(x)0 (x) separates serial number and check digit (default " ")
-h, --help help for generate
-c, --count int count of container numbers (default 1)
-s, --start int start of serial number range
-e, --end int end of serial number range
--owner string custom owner code
--exclude-check-digit-10 exclude check digit 10
--exclude-error-prone-serial-numbers exclude error-prone serial numbers. For example swapping the second 0 and first 1 of RCB U 001130 0 results in container number RCB U 010130 0 with a valid check digit 0
--sep-owner-equip string ABC(x)U1234560 (x) separates owner code and equipment category id (default " ")
--sep-equip-serial string ABCU(x)1234560 (x) separates equipment category id and serial number (default " ")
--sep-serial-check string ABCU123456(x)0 (x) separates serial number and check digit (default " ")
-h, --help help for generate
```

### SEE ALSO
Expand Down
4 changes: 2 additions & 2 deletions docs/icm_validate.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Validate intermodal container markings with single or multi line input.
For single line input a human-readable output is used.

For multi line input CSV output is used. For example this is useful to scan
data sets for possible transposition errors. It is also possible to generate
data sets for error-prone serial numbers. It is also possible to generate
CSV data sets of random container numbers.

Configuration for separators is generated first time you
Expand Down Expand Up @@ -43,7 +43,7 @@ icm generate --count 10 | icm validate
icm generate --count 10 | icm validate --output fancy
# Generate CSV data set
icm generate --count 1000000 | icm validate
# Validate a container number with 6 (!) possible transposition errors
# Validate a container number with 6 (!) possible error-prone serial number
icm validate APL U 689473 0
```

Expand Down

0 comments on commit 5c21145

Please sign in to comment.