refactor(dotnet): normalize learning dataset export inputs
This commit is contained in:
@@ -11,7 +11,9 @@ public sealed class LearningDatasetService
|
||||
|
||||
public async Task<string> ExportJsonAsync(string outputPath, int limit = 1000)
|
||||
{
|
||||
var rows = await _reader.ReadTrainingExamplesAsync(limit);
|
||||
var normalizedOutputPath = RequireValue(outputPath, nameof(outputPath));
|
||||
var normalizedLimit = Math.Clamp(limit, 1, 10000);
|
||||
var rows = await _reader.ReadTrainingExamplesAsync(normalizedLimit);
|
||||
var payload = new
|
||||
{
|
||||
formula_id = "ENGINE_HISTORY_TRAINING_DATASET_V1",
|
||||
@@ -21,9 +23,19 @@ public sealed class LearningDatasetService
|
||||
source = "engine_history.training_example_v1",
|
||||
rows
|
||||
};
|
||||
var path = Path.GetFullPath(outputPath);
|
||||
var path = Path.GetFullPath(normalizedOutputPath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
await File.WriteAllTextAsync(path, JsonSerializer.Serialize(payload, new JsonSerializerOptions { WriteIndented = true }));
|
||||
return path;
|
||||
}
|
||||
|
||||
private static string RequireValue(string value, string parameterName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new ArgumentException("Value is required.", parameterName);
|
||||
}
|
||||
|
||||
return value.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user