Infrastruttura: nome «Rail Enterprise», CI e rilasci su Gitea, documentazione
Il progetto adotta il nome «Rail Enterprise» ovunque (codice RailEnterprise.*, variabili RE_*, intestazioni RESV/RECL, immagine rail-enterprise-server) per allinearsi al repository Gitea. Aggiunge Gitea Actions sul modello di Chronos: CI su PR e main, rilascio da tag con gioco Windows (client Godot + server in server/), server Windows/Linux e immagine Docker nel registro Gitea, nightly. Aggiunge i riferimenti visivi 06–09, i modelli di PR e issue, l'ADR 0014 e aggiorna README (comandi locali), STATE e CLAUDE.md. 120 test verdi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f6c2a17b4d
commit
c1a0049bcf
300 files changed
+1602
-1045
No files matched your search
@@ -0,0 +1,78 @@
|
||||
namespace RailEnterprise.Core.Economy;
|
||||
|
||||
/// <summary>
|
||||
/// Somma mobile su una finestra fissa di N campioni giornalieri (per esempio domanda e offerta
|
||||
/// degli ultimi 30 giorni). La somma è ricalcolata dal buffer a ogni giro completo per non
|
||||
/// accumulare errori di arrotondamento.
|
||||
/// </summary>
|
||||
public sealed class RollingWindow
|
||||
{
|
||||
private readonly double[] _values;
|
||||
private int _next;
|
||||
private int _count;
|
||||
private double _sum;
|
||||
|
||||
public RollingWindow(int length)
|
||||
{
|
||||
if (length <= 0) throw new ArgumentOutOfRangeException(nameof(length));
|
||||
_values = new double[length];
|
||||
}
|
||||
|
||||
public int Length => _values.Length;
|
||||
public int Count => _count;
|
||||
public double Sum => _sum;
|
||||
public double Average => _count == 0 ? 0 : _sum / _count;
|
||||
|
||||
public void Add(double value)
|
||||
{
|
||||
_sum -= _values[_next];
|
||||
_values[_next] = value;
|
||||
_sum += value;
|
||||
_next++;
|
||||
if (_next == _values.Length)
|
||||
{
|
||||
_next = 0;
|
||||
double s = 0;
|
||||
foreach (double v in _values) s += v;
|
||||
_sum = s;
|
||||
}
|
||||
if (_count < _values.Length) _count++;
|
||||
}
|
||||
|
||||
/// <summary>Valore aggiunto k giorni fa (0 = l'ultimo).</summary>
|
||||
public double Ago(int k)
|
||||
{
|
||||
if (k < 0 || k >= _count) return 0;
|
||||
int i = (_next - 1 - k) % _values.Length;
|
||||
if (i < 0) i += _values.Length;
|
||||
return _values[i];
|
||||
}
|
||||
|
||||
internal void Save(Persistence.SaveWriter w)
|
||||
{
|
||||
w.Write(_values.Length);
|
||||
foreach (double v in _values) w.Write(v);
|
||||
w.Write(_next);
|
||||
w.Write(_count);
|
||||
w.Write(_sum);
|
||||
}
|
||||
|
||||
internal static RollingWindow Load(Persistence.SaveReader r)
|
||||
{
|
||||
int length = r.ReadInt32();
|
||||
var window = new RollingWindow(length);
|
||||
for (int i = 0; i < length; i++) window._values[i] = r.ReadDouble();
|
||||
window._next = r.ReadInt32();
|
||||
window._count = r.ReadInt32();
|
||||
window._sum = r.ReadDouble();
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Media mobile esponenziale con costante pari a una finestra di N giorni (α = 2/(N+1)).</summary>
|
||||
public static class Ema
|
||||
{
|
||||
public static double Alpha(int windowDays) => 2.0 / (windowDays + 1);
|
||||
|
||||
public static double Step(double current, double sample, int windowDays) => current + Alpha(windowDays) * (sample - current);
|
||||
}
|
||||
Reference in new issue
Block a user