| | | 1 | | using System.ComponentModel; |
| | | 2 | | using Spectre.Console; |
| | | 3 | | using Spectre.Console.Cli; |
| | | 4 | | |
| | | 5 | | namespace Orchestrator.Commands.Observability.PrepareSlice; |
| | | 6 | | |
| | | 7 | | public sealed class PrepareSliceSettings : CommandSettings |
| | | 8 | | { |
| | | 9 | | [CommandOption("--community-context")] |
| | | 10 | | [Description("Community context used to scope persisted historical match outcomes")] |
| | 1 | 11 | | public string CommunityContext { get; set; } = string.Empty; |
| | | 12 | | |
| | | 13 | | [CommandOption("--matchdays")] |
| | | 14 | | [Description("Optional comma-separated list of matchdays to sample from. Defaults to all Bundesliga matchdays.")] |
| | | 15 | | public string? Matchdays { get; set; } |
| | | 16 | | |
| | | 17 | | [CommandOption("--sample-size")] |
| | | 18 | | [Description("Number of dataset items to sample")] |
| | | 19 | | [DefaultValue(10)] |
| | 1 | 20 | | public int SampleSize { get; set; } = 10; |
| | | 21 | | |
| | | 22 | | [CommandOption("--sample-seed")] |
| | | 23 | | [Description("Optional deterministic seed for random slice selection. Defaults to the current UTC date in yyyyMMdd f |
| | | 24 | | public int? SampleSeed { get; set; } |
| | | 25 | | |
| | | 26 | | [CommandOption("--starts-after")] |
| | | 27 | | [Description("Optional match start cutoff in NodaTime invariant ZonedDateTime 'G' format. Only matches strictly afte |
| | | 28 | | public string? StartsAfter { get; set; } |
| | | 29 | | |
| | | 30 | | [CommandOption("--slice-key")] |
| | | 31 | | [Description("Optional slice key override. Defaults to random-<sample-size>-seed-<sample-seed>")] |
| | | 32 | | public string? SliceKey { get; set; } |
| | | 33 | | |
| | | 34 | | [CommandOption("--slice-kind")] |
| | | 35 | | [Description("Logical slice kind metadata tag")] |
| | | 36 | | [DefaultValue("random-sample")] |
| | 1 | 37 | | public string SliceKind { get; set; } = "random-sample"; |
| | | 38 | | |
| | | 39 | | [CommandOption("--sample-method")] |
| | | 40 | | [Description("Logical sample selection method metadata tag")] |
| | | 41 | | [DefaultValue("random-sample")] |
| | 1 | 42 | | public string SampleMethod { get; set; } = "random-sample"; |
| | | 43 | | |
| | | 44 | | [CommandOption("--source-pool-key")] |
| | | 45 | | [Description("Optional source pool identifier used in dataset names and output paths. Defaults to all-matchdays")] |
| | | 46 | | public string? SourcePoolKey { get; set; } |
| | | 47 | | |
| | | 48 | | [CommandOption("--dataset-name")] |
| | | 49 | | [Description("Optional hosted dataset name override for the prepared slice")] |
| | | 50 | | public string? DatasetName { get; set; } |
| | | 51 | | |
| | | 52 | | [CommandOption("--output-directory")] |
| | | 53 | | [Description("Optional output directory override. Defaults to artifacts/langfuse-experiments/slices/<community>/<sou |
| | | 54 | | public string? OutputDirectory { get; set; } |
| | | 55 | | |
| | | 56 | | public override ValidationResult Validate() |
| | | 57 | | { |
| | 1 | 58 | | if (string.IsNullOrWhiteSpace(CommunityContext)) |
| | | 59 | | { |
| | 0 | 60 | | return ValidationResult.Error("--community-context is required"); |
| | | 61 | | } |
| | | 62 | | |
| | 1 | 63 | | if (SampleSize < 1) |
| | | 64 | | { |
| | 0 | 65 | | return ValidationResult.Error("--sample-size must be at least 1"); |
| | | 66 | | } |
| | | 67 | | |
| | 1 | 68 | | if (string.IsNullOrWhiteSpace(SliceKind)) |
| | | 69 | | { |
| | 0 | 70 | | return ValidationResult.Error("--slice-kind must be a non-empty string"); |
| | | 71 | | } |
| | | 72 | | |
| | 1 | 73 | | if (string.IsNullOrWhiteSpace(SampleMethod)) |
| | | 74 | | { |
| | 0 | 75 | | return ValidationResult.Error("--sample-method must be a non-empty string"); |
| | | 76 | | } |
| | | 77 | | |
| | 1 | 78 | | if (!string.IsNullOrWhiteSpace(StartsAfter)) |
| | | 79 | | { |
| | | 80 | | try |
| | | 81 | | { |
| | 1 | 82 | | _ = EvaluationTimeParser.Parse(StartsAfter); |
| | 1 | 83 | | } |
| | | 84 | | catch (ArgumentException ex) |
| | | 85 | | { |
| | 1 | 86 | | return ValidationResult.Error(ex.Message); |
| | | 87 | | } |
| | | 88 | | } |
| | | 89 | | |
| | 1 | 90 | | if (string.IsNullOrWhiteSpace(Matchdays)) |
| | | 91 | | { |
| | 0 | 92 | | return ValidationResult.Success(); |
| | | 93 | | } |
| | | 94 | | |
| | 1 | 95 | | var segments = Matchdays.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); |
| | 1 | 96 | | if (segments.Length == 0) |
| | | 97 | | { |
| | 0 | 98 | | return ValidationResult.Error("--matchdays must contain at least one matchday number when provided"); |
| | | 99 | | } |
| | | 100 | | |
| | 1 | 101 | | foreach (var segment in segments) |
| | | 102 | | { |
| | 1 | 103 | | if (!int.TryParse(segment, out var matchday) || matchday is < 1 or > 34) |
| | | 104 | | { |
| | 0 | 105 | | return ValidationResult.Error($"Invalid matchday '{segment}'. Expected an integer between 1 and 34."); |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | |
| | 1 | 109 | | return ValidationResult.Success(); |
| | 1 | 110 | | } |
| | | 111 | | } |