refactor(dotnet): centralize runtime audit trail
Validators (Pushes and Pull Requests) / validate-ui-and-storage (push) Successful in 16s
Validators (Pushes and Pull Requests) / validate-core (push) Has been cancelled

This commit is contained in:
2026-07-13 00:52:32 +09:00
parent aa61465ce0
commit 99377e9ca9
7 changed files with 68 additions and 89 deletions
@@ -1,6 +1,7 @@
using System.Text.Json;
using QuantEngine.Core.Domain;
using QuantEngine.Core.Interfaces;
using QuantEngine.Application.Interfaces;
namespace QuantEngine.Application.Services;
@@ -15,34 +16,12 @@ public sealed record FactorComputationAudit(
public sealed class FactorComputationService
{
private readonly HistoryIngestionService _history;
private readonly string _auditRoot;
private readonly IRuntimeAuditTrailService _auditTrail;
public FactorComputationService(HistoryIngestionService history)
public FactorComputationService(HistoryIngestionService history, IRuntimeAuditTrailService auditTrail)
{
_history = history;
_auditRoot = FindRepoTempRoot();
}
private static string FindRepoTempRoot()
{
var current = new DirectoryInfo(AppContext.BaseDirectory);
while (current != null)
{
if (Directory.Exists(Path.Combine(current.FullName, ".git")))
{
return Path.Combine(current.FullName, "Temp", "factor_audit");
}
current = current.Parent;
}
return Path.Combine(Directory.GetCurrentDirectory(), "Temp", "factor_audit");
}
private void AppendAudit(FactorComputationAudit audit)
{
Directory.CreateDirectory(_auditRoot);
var path = Path.Combine(_auditRoot, $"{audit.Ticker}.jsonl");
File.AppendAllText(path, JsonSerializer.Serialize(audit, new JsonSerializerOptions { WriteIndented = false }) + Environment.NewLine);
_auditTrail = auditTrail;
}
public FactorOutputs Compute(
@@ -53,7 +32,7 @@ public sealed class FactorComputationService
{
var computedAt = DateTimeOffset.UtcNow;
var outputs = FactorCalculator.CalculateFactors(stockBars, indexBars);
AppendAudit(new FactorComputationAudit(ticker, stockBars.Count, indexBars.Count, "SUCCEEDED", computedAt, sourceVersion));
_auditTrail.Append("factor_audit", ticker, new FactorComputationAudit(ticker, stockBars.Count, indexBars.Count, "SUCCEEDED", computedAt, sourceVersion));
return outputs;
}
@@ -71,6 +50,6 @@ public sealed class FactorComputationService
await _history.AppendFactorOutputAsync("stdev_20d", sourceVersion, outputs.StDev20D, "PASS", sourceVersion, when);
await _history.AppendFactorOutputAsync("beta_60d", sourceVersion, outputs.Beta60D, "PASS", sourceVersion, when);
await _history.AppendFactorOutputAsync("rs_20d", sourceVersion, outputs.Rs20D, "PASS", sourceVersion, when);
AppendAudit(new FactorComputationAudit(ticker, 0, 0, "PERSISTED", when, sourceVersion));
_auditTrail.Append("factor_audit", ticker, new FactorComputationAudit(ticker, 0, 0, "PERSISTED", when, sourceVersion));
}
}