M3 Motore: Governatore con tetti da action_log, interruttore con fermi 1/6/24 ore e ripresa manuale, fascia giornaliera spostata a caso e salvata, sessioni con pause log-normali e pavimento, composizione delle sessioni sulla coda persistente, «Controlla ora» con conferma fuori fascia, cruscotto per l'interfaccia e calcolatore «Con queste impostazioni», simulazione con orologio virtuale e comando --simula; prove del motore e dell'interruttore

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 17:33:28 +00:00
1 parent e2c987873b
commit 346d5ca075
38 files changed
+9308

No files matched your search

+237
View File
@@ -0,0 +1,237 @@
using System.Globalization;
using System.Text;
using Febe.Core.Abstractions;
using Febe.Core.Domain;
namespace Febe.Core.Engine;
/// <summary>
/// Italian wording used by the engine for events, denials and the monitor (spec §10.4): dot for thousands, comma for
/// decimals, «verso le» for future engine times. Independent of the process culture, so it reads the same in Docker
/// (invariant globalization) and on Windows.
/// </summary>
public static class ItalianText
{
private static readonly string[] Months =
[
"gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno",
"luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre",
];
private static readonly string[] Weekdays = ["domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato"];
/// <summary>Whole number with dots for thousands: 7.682.</summary>
public static string Number(long value)
{
var digits = Math.Abs(value).ToString(CultureInfo.InvariantCulture);
var builder = new StringBuilder();
if (value < 0)
{
builder.Append('-');
}
for (var i = 0; i < digits.Length; i++)
{
if (i > 0 && (digits.Length - i) % 3 == 0)
{
builder.Append('.');
}
builder.Append(digits[i]);
}
return builder.ToString();
}
/// <summary>Decimal number with a comma: 1,3. Trailing zeros of the decimals are kept only when asked.</summary>
public static string Decimal(double value, int decimals = 1, bool keepZeros = false)
{
var rounded = Math.Round(value, decimals, MidpointRounding.AwayFromZero);
var whole = (long)Math.Truncate(rounded);
var fraction = Math.Abs(rounded - whole);
var text = Number(whole);
if (whole == 0 && rounded < 0)
{
text = "-0";
}
if (decimals <= 0)
{
return text;
}
var fractionDigits = ((long)Math.Round(fraction * Math.Pow(10, decimals))).ToString(CultureInfo.InvariantCulture).PadLeft(decimals, '0');
if (!keepZeros)
{
fractionDigits = fractionDigits.TrimEnd('0');
}
return fractionDigits.Length == 0 ? text : text + "," + fractionDigits;
}
/// <summary>Byte amount: «850 MB», «1,3 GB».</summary>
public static string Bytes(long bytes)
{
const double KB = 1024;
const double MB = KB * 1024;
const double GB = MB * 1024;
return bytes switch
{
>= (long)GB => Decimal(bytes / GB, 1) + " GB",
>= (long)MB => Decimal(bytes / MB, bytes >= 100 * MB ? 0 : 1) + " MB",
>= (long)KB => Decimal(bytes / KB, 0) + " kB",
_ => Number(bytes) + " byte",
};
}
/// <summary>Local clock time without a leading zero on the hour: «7:42», «15:30».</summary>
public static string Clock(DateTimeOffset instant, TimeZoneInfo zone)
{
var local = LocalCalendar.ToLocal(instant, zone);
return local.Hour.ToString(CultureInfo.InvariantCulture) + ":" + local.Minute.ToString("00", CultureInfo.InvariantCulture);
}
/// <summary>«alle 17:32», «all'1:05».</summary>
public static string At(DateTimeOffset instant, TimeZoneInfo zone) =>
(LocalCalendar.ToLocal(instant, zone).Hour == 1 ? "all'" : "alle ") + Clock(instant, zone);
/// <summary>«dalle 16:32», «dall'1:05».</summary>
public static string Since(DateTimeOffset instant, TimeZoneInfo zone) =>
(LocalCalendar.ToLocal(instant, zone).Hour == 1 ? "dall'" : "dalle ") + Clock(instant, zone);
/// <summary>
/// A future engine time, always indicative (spec §7.9): «verso le 15:30», «domani verso le 7:42»,
/// «giovedì verso le 7:42», «il 21 ottobre verso le 7:42».
/// </summary>
public static string Around(DateTimeOffset instant, DateTimeOffset now, TimeZoneInfo zone)
{
var hour = LocalCalendar.ToLocal(instant, zone).Hour;
var time = (hour == 1 ? "verso l'" : "verso le ") + Clock(instant, zone);
var prefix = DayPrefix(instant, now, zone);
return prefix.Length == 0 ? time : prefix + " " + time;
}
/// <summary>«alle 17:32», «domani alle 7:42»: a fixed future time (e.g. the end of a throttle stop).</summary>
public static string AtDay(DateTimeOffset instant, DateTimeOffset now, TimeZoneInfo zone)
{
var prefix = DayPrefix(instant, now, zone);
var at = At(instant, zone);
return prefix.Length == 0 ? at : prefix + " " + at;
}
/// <summary>«13 ottobre».</summary>
public static string Day(DateOnly day) => day.Day.ToString(CultureInfo.InvariantCulture) + " " + Months[day.Month - 1];
/// <summary>«lunedì 13 ottobre».</summary>
public static string DayWithWeekday(DateOnly day) => Weekdays[(int)day.DayOfWeek] + " " + Day(day);
/// <summary>A duration in words: «45 minuti», «1 ora e 20 minuti», «2 giorni e 3 ore», «30 secondi».</summary>
public static string Duration(TimeSpan span)
{
if (span < TimeSpan.Zero)
{
span = TimeSpan.Zero;
}
if (span < TimeSpan.FromMinutes(1))
{
var seconds = (long)Math.Round(span.TotalSeconds);
return seconds == 1 ? "1 secondo" : Number(seconds) + " secondi";
}
if (span < TimeSpan.FromHours(1))
{
return Minutes((long)Math.Round(span.TotalMinutes));
}
if (span < TimeSpan.FromDays(2))
{
var totalMinutes = (long)Math.Round(span.TotalMinutes);
var hours = totalMinutes / 60;
var minutes = totalMinutes % 60;
var text = hours == 1 ? "1 ora" : Number(hours) + " ore";
return minutes == 0 ? text : text + " e " + Minutes(minutes);
}
var totalHours = (long)Math.Round(span.TotalHours);
var days = totalHours / 24;
var restHours = totalHours % 24;
var dayText = days == 1 ? "1 giorno" : Number(days) + " giorni";
return restHours == 0 ? dayText : dayText + " e " + (restHours == 1 ? "1 ora" : Number(restHours) + " ore");
}
/// <summary>An interval of a check («ogni 3 ore», «ogni 75 minuti», «ogni giorno»).</summary>
public static string Every(TimeSpan interval)
{
if (interval >= TimeSpan.FromHours(23.5) && interval <= TimeSpan.FromHours(24.5))
{
return "ogni giorno";
}
if (interval < TimeSpan.FromHours(2) && interval.TotalMinutes % 60 != 0)
{
return "ogni " + Minutes((long)Math.Round(interval.TotalMinutes));
}
var hours = interval.TotalHours;
if (Math.Abs(hours - Math.Round(hours)) < 0.05)
{
var whole = (long)Math.Round(hours);
return whole == 1 ? "ogni ora" : "ogni " + Number(whole) + " ore";
}
return "ogni " + Decimal(hours, 1) + " ore";
}
/// <summary>Italian name of a budget category, as in the table of spec §7.5.</summary>
public static string Category(ActionKind kind) => kind switch
{
ActionKind.Home => "aperture della home",
ActionKind.ProfileOpen => "profili aperti",
ActionKind.StoryView => "storie viste",
ActionKind.BackfillPage => "pagine di storico",
ActionKind.SinglePost => "post singoli",
ActionKind.FollowingListPage => "pagine dell'elenco dei seguiti",
ActionKind.DataDownload => "dati scaricati",
_ => kind.ToString(),
};
/// <summary>Category name with a capital initial, for labels: «Profili aperti».</summary>
public static string CategoryLabel(ActionKind kind) => Capitalize(Category(kind));
/// <summary>Italian name of a caution profile: «Prudente».</summary>
public static string Profile(CautionProfileKind kind) => kind switch
{
CautionProfileKind.Prudent => "Prudente",
CautionProfileKind.Balanced => "Equilibrato",
CautionProfileKind.Fast => "Rapido",
CautionProfileKind.Custom => "Su misura",
_ => kind.ToString(),
};
/// <summary>«@marta.demo».</summary>
public static string Handle(string? username) => string.IsNullOrWhiteSpace(username) ? "un account" : "@" + username.TrimStart('@');
/// <summary>Count with its noun: «1 storia nuova», «3 storie nuove».</summary>
public static string Count(long count, string singular, string plural) =>
count == 1 ? "1 " + singular : Number(count) + " " + plural;
public static string Capitalize(string text) =>
string.IsNullOrEmpty(text) ? text : char.ToUpperInvariant(text[0]) + text[1..];
private static string Minutes(long minutes) => minutes == 1 ? "1 minuto" : Number(minutes) + " minuti";
private static string DayPrefix(DateTimeOffset instant, DateTimeOffset now, TimeZoneInfo zone)
{
var day = LocalCalendar.Today(instant, zone);
var today = LocalCalendar.Today(now, zone);
var difference = day.DayNumber - today.DayNumber;
return difference switch
{
<= 0 => string.Empty,
1 => "domani",
< 7 => Weekdays[(int)day.DayOfWeek],
_ => "il " + Day(day),
};
}
}