Fix what the independent review of Phase 12 found, and close the phase
ci / test (postgres) (push) Successful in 7m31s
ci / test (sqlite) (push) Successful in 6m0s
ci / test (postgres) (pull_request) Successful in 7m15s
ci / test (sqlite) (pull_request) Successful in 6m8s
ci / image (push) Successful in 1m45s
ci / image (pull_request) Successful in 1m6s

- A flat window has no z-score even when its mean misses the common value by
  one rounding step (it gave a meaningless z of about 0.995).
- A broken ECB history (a maintenance page, a cut download, a damaged cached
  copy) is refused in Italian instead of crashing `data ecb`, and a download
  is checked and moved into place in one step, so it never replaces the good
  copy.
- A fixed time zone with 60 or more minutes is refused instead of being read
  as the next hour.
- `data fx` says why when every bar of the file falls outside the market week.

ADR 0028 records the choices of the phase; ROADMAP and STATE mark it done.

refs #118, refs #119, refs #120, refs #121

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-04 10:51:03 +01:00
1 parent 2a96e08d5a
commit 8d02d02876
10 files changed
+209 -21

No files matched your search

+3
View File
@@ -54,6 +54,9 @@ public sealed class BasketSignalTests
// Fewer than W values, a flat window or a missing value: no z.
Assert.IsNull(BasketIndex.ZScore(index, 3, window: 5));
Assert.IsNull(BasketIndex.ZScore([5, 5, 5, 5, 5], 4, window: 5));
// A flat window of a value with no exact binary form: its mean misses by one rounding step, still no z.
Assert.IsNull(BasketIndex.ZScore(Enumerable.Repeat(10856.1, 100).ToArray(), 99));
Assert.IsNull(BasketIndex.ZScore(Enumerable.Repeat(0.1, 100).ToArray(), 99));
Assert.IsNull(BasketIndex.ZScore([1, 2, double.NaN, 4, 5], 4, window: 5));
Assert.AreEqual(100, BasketIndex.DefaultWindow);
}
+67
View File
@@ -559,6 +559,71 @@ public sealed class ResearchBarsTests
}
}
[TestMethod]
[TestCategory(Category.Integration)]
public async Task DataFxSaysWhyWhenEveryBarFallsOutsideTheMarketWeek()
{
var data = TempFolder.Create("data-fx-weekend");
try
{
var env = ServerHarness.DockerSqlite();
const string NL = "\n";
var saturday = Path.Combine(data, "EURUSD_Candlestick_1_M_BID_06.01.2024-06.01.2024.csv");
await File.WriteAllTextAsync(saturday, "Gmt time,Open,High,Low,Close,Volume" + NL + "06.01.2024 08:00:00.000,1.0945,1.0945,1.0945,1.0945,0" + NL
+ "06.01.2024 08:01:00.000,1.0945,1.0945,1.0945,1.0945,0" + NL + "06.01.2024 08:02:00.000,1.0945,1.0945,1.0945,1.0945,0" + NL).ConfigureAwait(false);
using var output = new StringWriter();
Assert.AreEqual(1, await DataCommand.RunAsync(["fx", saturday, "--platform", "docker", "--data-dir", data], output, env).ConfigureAwait(false), output.ToString());
StringAssert.StartsWith(output.ToString(), "Non riuscito: ");
StringAssert.Contains(output.ToString(), "tutte le 3 barre lette cadono fuori dall'orario del mercato");
Assert.AreEqual(0, new ResearchStore(Path.Combine(data, "research")).Series().Count, "nothing written");
}
finally
{
TempFolder.Delete(data);
}
}
[TestMethod]
[TestCategory(Category.Integration)]
public async Task ABrokenEcbHistoryNeverReplacesTheGoodOneAndIsRefusedInItalian()
{
var data = TempFolder.Create("data-ecb-broken");
try
{
var env = ServerHarness.DockerSqlite();
using (var first = new StringWriter())
{
Assert.AreEqual(0, await DataCommand.RunAsync(["ecb", "--platform", "docker", "--data-dir", data], first, env, new FakeHttp().OnBytes("eurofxref-hist.zip", EcbZip())).ConfigureAwait(false), first.ToString());
}
var cached = Path.Combine(data, "research", Ecb.HistoryFile);
var good = await File.ReadAllBytesAsync(cached).ConfigureAwait(false);
// The ECB answers with a page that is not the history: the command stops in Italian and the good copy stays.
var page = new FakeHttp().OnBytes("eurofxref-hist.zip", System.Text.Encoding.UTF8.GetBytes("<html>Manutenzione</html>"));
using (var output = new StringWriter())
{
Assert.AreEqual(1, await DataCommand.RunAsync(["ecb", "--platform", "docker", "--data-dir", data], output, env, page).ConfigureAwait(false), output.ToString());
StringAssert.StartsWith(output.ToString(), "Non riuscito: BCE: il file scaricato non è lo storico dei cambi");
}
CollectionAssert.AreEqual(good, await File.ReadAllBytesAsync(cached).ConfigureAwait(false), "the good history is untouched");
Assert.IsFalse(File.Exists(cached + ".tmp"));
// A cached copy cut short (an old interrupted write): offline, the command says so instead of crashing.
await File.WriteAllBytesAsync(cached, good.AsSpan(0, good.Length / 2).ToArray()).ConfigureAwait(false);
using (var output = new StringWriter())
{
Assert.AreEqual(1, await DataCommand.RunAsync(["ecb", "--offline", "--platform", "docker", "--data-dir", data], output, env, new FakeHttp()).ConfigureAwait(false), output.ToString());
StringAssert.StartsWith(output.ToString(), "Non riuscito: BCE: il file già scaricato non è lo storico dei cambi");
}
}
finally
{
TempFolder.Delete(data);
}
}
[TestMethod]
[TestCategory(Category.Unit)]
public async Task DataUsageListsTheNewCommandsAndTimeframes()
@@ -589,6 +654,8 @@ public sealed class ResearchBarsTests
Assert.AreEqual(TimeSpan.FromHours(5.5), CsvImporter.ZoneOf("UTC+05:30").BaseUtcOffset);
Assert.AreEqual(TimeSpan.Zero, CsvImporter.ZoneOf("UTC").BaseUtcOffset);
Assert.ThrowsExactly<TimeZoneNotFoundException>(() => CsvImporter.ZoneOf("Nowhere/Atlantis"));
Assert.ThrowsExactly<TimeZoneNotFoundException>(() => CsvImporter.ZoneOf("UTC-05:60"), "a typo in the minutes is refused, not read as UTC-06:00");
Assert.ThrowsExactly<TimeZoneNotFoundException>(() => CsvImporter.ZoneOf("UTC+00:90"));
}
[TestMethod]