mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-23 08:57:40 -05:00
fix(names): drop S from generated nest names
S reads too much like 5 on labels and screens, so the sequence alphabet is now base-29. Already-issued names keep their numbers: the server's stored counter stays authoritative and a base-29 name can never equal an earlier base-30 one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5e2c268b8
commit
86b0370a8f
3 files changed
+19
-17
No files matched your search
+11
-10
@@ -2,12 +2,13 @@ namespace OpenNest.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Generated nest names: "N" + two-digit year + "-" + the year's sequence number in an
|
||||
/// unambiguous base-30 alphabet, padded to three digits with its zero digit ('2').
|
||||
/// The sequence runs for the whole year; three digits cover 27,000 nests before a fourth appears.
|
||||
/// unambiguous base-29 alphabet, padded to three digits with its zero digit ('2').
|
||||
/// No S (it reads as 5). The sequence runs for the whole year; three digits cover 24,389 nests
|
||||
/// before a fourth appears.
|
||||
/// </summary>
|
||||
public static class NestNames
|
||||
{
|
||||
private const string Base30Digits = "2345679ACDEFGHJKLMNPQRSTUVWXYZ";
|
||||
private const string Base29Digits = "2345679ACDEFGHJKLMNPQRTUVWXYZ";
|
||||
|
||||
/// <summary>Earliest and latest years a sequence may be allocated for.</summary>
|
||||
public const int MinYear = 2000, MaxYear = 2099;
|
||||
@@ -15,7 +16,7 @@ public static class NestNames
|
||||
public static string Format(int year, int number)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(number);
|
||||
var seq = ToBase30(number).PadLeft(3, Base30Digits[0]);
|
||||
var seq = ToBase29(number).PadLeft(3, Base29Digits[0]);
|
||||
return $"N{year % 100:D2}-{seq}";
|
||||
}
|
||||
|
||||
@@ -33,10 +34,10 @@ public static class NestNames
|
||||
long value = 0;
|
||||
foreach (var c in name.AsSpan(prefix.Length))
|
||||
{
|
||||
var digit = Base30Digits.IndexOf(c);
|
||||
var digit = Base29Digits.IndexOf(c);
|
||||
if (digit < 0)
|
||||
return false;
|
||||
value = value * Base30Digits.Length + digit;
|
||||
value = value * Base29Digits.Length + digit;
|
||||
if (value > int.MaxValue)
|
||||
return false;
|
||||
}
|
||||
@@ -45,16 +46,16 @@ public static class NestNames
|
||||
return Format(year, number) == name;
|
||||
}
|
||||
|
||||
private static string ToBase30(int value)
|
||||
private static string ToBase29(int value)
|
||||
{
|
||||
if (value == 0)
|
||||
return Base30Digits[0].ToString();
|
||||
return Base29Digits[0].ToString();
|
||||
|
||||
var result = "";
|
||||
while (value > 0)
|
||||
{
|
||||
result = Base30Digits[value % Base30Digits.Length] + result;
|
||||
value /= Base30Digits.Length;
|
||||
result = Base29Digits[value % Base29Digits.Length] + result;
|
||||
value /= Base29Digits.Length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ public class NestNamesTests
|
||||
[Theory]
|
||||
[InlineData(0, "N26-222")]
|
||||
[InlineData(1, "N26-223")]
|
||||
[InlineData(29, "N26-22Z")]
|
||||
[InlineData(30, "N26-232")]
|
||||
[InlineData(900, "N26-322")]
|
||||
[InlineData(27000, "N26-3222")]
|
||||
public void NamesUseTwoDigitYearAndPaddedBase30Sequence(int number, string expected)
|
||||
[InlineData(28, "N26-22Z")]
|
||||
[InlineData(29, "N26-232")]
|
||||
[InlineData(841, "N26-322")]
|
||||
[InlineData(24389, "N26-3222")]
|
||||
public void NamesUseTwoDigitYearAndPaddedBase29Sequence(int number, string expected)
|
||||
{
|
||||
Assert.Equal(expected, NestNames.Format(2026, number));
|
||||
Assert.True(NestNames.TryParse(expected, 2026, out var parsed));
|
||||
@@ -25,6 +25,7 @@ public class NestNamesTests
|
||||
[InlineData("N26-23")]
|
||||
[InlineData("N26-2223")]
|
||||
[InlineData("N26-22B")]
|
||||
[InlineData("N26-22S")]
|
||||
[InlineData("n26-223")]
|
||||
[InlineData("N26-223 copy")]
|
||||
[InlineData("N26-ZZZZZZZZZ")]
|
||||
|
||||
@@ -198,8 +198,8 @@ The note never blocks the dialog, save or post, and posting is not gated on hold
|
||||
### Generated nest names
|
||||
|
||||
**File > New** names a nest `N<yy>-<seq>` (`OpenNest.Data.NestNames`): the
|
||||
two-digit year and the year's sequence number in a base-30 alphabet without
|
||||
look-alike characters, padded to three digits (27,000 a year before a fourth
|
||||
two-digit year and the year's sequence number in a base-29 alphabet without
|
||||
look-alike characters (no S, which reads as 5), padded to three digits (24,389 a year before a fourth
|
||||
appears). The sequence runs for the whole year. In Database mode the desktop
|
||||
asks `POST /api/nest-names/next` for the number, so every PC shares one
|
||||
counter per year (`nest_sequences`, schema version 6). The server also keeps
|
||||
|
||||
Reference in new issue
Block a user