E5: dimostrazione, prove dell'interfaccia e schermate delle copie automatiche
La dimostrazione mostra le copie automatiche senza avviare il lavoratore: «Studio Lumen» è automatica con «Solo i nuovi» dall'inizio dei suoi file più recenti non copiati; un lavoro automatico del motore vero (su un orologio spostato indietro) ne ha copiati alcuni e un lavoro automatico interrotto tiene esattamente il resto. «Riconosci le copie già presenti» gira davvero in «Studio Lumen» (una copia riconosciuta, un file diverso): in «Disco USB» avrebbe allungato ogni avvio della dimostrazione di 47 s. Le prove della dimostrazione controllano questi dati e che un lavoratore di prova riprenda solo il lavoro interrotto. Le prove dell'interfaccia (nella CI) coprono la domanda «Solo i nuovi», la nota allo spegnimento, l'etichetta «Automatica dal …», «Riconosci» con il suo lavoro nella Dashboard, la pausa con i file che aspettano e la conferma di «Usa la cartella generale». Schermata nuova 32, rifatte 15, 16, 17 e 21, con le differenze dai mockup in differenze.md e una riga in decisioni.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f8491529ca
commit
94f6b316f6
14 files changed
+754
-16
No files matched your search
+216
-10
@@ -14,8 +14,13 @@ namespace Febe.Web.Demo;
|
||||
/// «Studio Lumen» for @studio.lumen.demo, @il.porto.demo not exported, and for @marta.demo about two thirds of its
|
||||
/// photos copied by the real engine (a completed job with its report), one «Tolto», one «Superato» and one «Errore»,
|
||||
/// and a job left «interrotto» for the Dashboard; tappa E3 adds a copy converted to PNG, a frame of a video and two
|
||||
/// conversions of the library («Convertito», «Non si converte»). Everything lives in the demo's temporary folder, whose «esporta» is
|
||||
/// the demo's <c>/esporta</c>: the counts, the marks and the «Copie» filter come from the same rows the engine wrote.
|
||||
/// conversions of the library («Convertito», «Non si converte»). Tappa E5: «Studio Lumen» is «Automatica» since a past
|
||||
/// instant, with an automatic job that copied part of its new files (by the real engine) and one left «interrotto» with
|
||||
/// the rest, and a «Riconosci le copie già presenti» (by the real engine) that recognised one copy and found one
|
||||
/// different file. The demo never runs the automatic worker (decision of 4 December 2026, as for the conversion
|
||||
/// of the library): what the automatic copies would do next is only the interrupted job. Everything lives in the demo's
|
||||
/// temporary folder, whose «esporta» is the demo's <c>/esporta</c>: the counts, the marks and the «Copie» filter come
|
||||
/// from the same rows the engine wrote.
|
||||
/// </summary>
|
||||
public static class DemoExport
|
||||
{
|
||||
@@ -59,19 +64,26 @@ public static class DemoExport
|
||||
}
|
||||
|
||||
var files = new DemoFileResolver(world);
|
||||
await using var service = new ExportService(new ExportEnvironment
|
||||
var gate = new LongWorkGate();
|
||||
|
||||
// The jobs of the past (tappa E5) are run by a service whose clock is moved back: their times, copies and events
|
||||
// are those of the engine at that instant. A private signal: nothing listens to it in the demo.
|
||||
ExportService NewService(IClock at) => new(new ExportEnvironment
|
||||
{
|
||||
Storage = database,
|
||||
Layout = () => layout,
|
||||
DataFolder = data.Root,
|
||||
Clock = clock,
|
||||
Clock = at,
|
||||
Root = options,
|
||||
ResolveSource = files.Resolve,
|
||||
Disk = new DemoExportDisk(),
|
||||
Session = NoEngineSession.Instance,
|
||||
Gate = new LongWorkGate(),
|
||||
Gate = gate,
|
||||
AutoSignal = new AutoExportSignal(),
|
||||
});
|
||||
|
||||
await using var service = NewService(clock);
|
||||
|
||||
var accounts = await database.Accounts.ListAsync(ct).ConfigureAwait(false);
|
||||
var marta = accounts.FirstOrDefault(a => a.Username == CopiedAccount);
|
||||
var studio = accounts.FirstOrDefault(a => a.Username == OwnFolderAccount);
|
||||
@@ -79,11 +91,12 @@ public static class DemoExport
|
||||
var general = (await service.Destinations.CreateAsync(
|
||||
new DestinationSpec(ExportScope.General, null, GeneralFolder, GeneralFolder, ContentTypes.All, null, null, null),
|
||||
ct).ConfigureAwait(false)).Destination;
|
||||
ExportDestination? own = null;
|
||||
if (studio is not null)
|
||||
{
|
||||
await service.Destinations.CreateAsync(
|
||||
own = (await service.Destinations.CreateAsync(
|
||||
new DestinationSpec(ExportScope.Account, studio.Id, OwnFolder, OwnFolder, ContentTypes.PostPhotos | ContentTypes.PostVideos, null, null, null),
|
||||
ct).ConfigureAwait(false);
|
||||
ct).ConfigureAwait(false)).Destination;
|
||||
}
|
||||
|
||||
if (porto is not null)
|
||||
@@ -111,10 +124,10 @@ public static class DemoExport
|
||||
|
||||
if (studio is not null)
|
||||
{
|
||||
var own = await PhotosAsync(database, studio, world, ct).ConfigureAwait(false);
|
||||
if (own.Count > 0)
|
||||
var ownPhotos = await PhotosAsync(database, studio, world, ct).ConfigureAwait(false);
|
||||
if (ownPhotos.Count > 0)
|
||||
{
|
||||
await service.StartAsync(new ExportJobRequest(new ExportSelection.Media([.. own.Take(Math.Max(1, own.Count / 2)).Select(p => p.Media.Id)])), ct).ConfigureAwait(false);
|
||||
await service.StartAsync(new ExportJobRequest(new ExportSelection.Media([.. ownPhotos.Take(Math.Max(1, ownPhotos.Count / 2)).Select(p => p.Media.Id)])), ct).ConfigureAwait(false);
|
||||
await service.WaitAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -132,6 +145,189 @@ public static class DemoExport
|
||||
|
||||
await FrameAsync(database, world, general, marta, clock, ct).ConfigureAwait(false);
|
||||
await ConversionsAsync(root, database, world, [.. rest.Skip(FormatsFrom + 1).Take(2)], clock, ct).ConfigureAwait(false);
|
||||
|
||||
// Tappa E5: the automatic copies of «Studio Lumen», and «Riconosci le copie già presenti» there.
|
||||
if (own is not null && studio is not null)
|
||||
{
|
||||
await AutomaticAsync(database, own, NewService, clock, ct).ConfigureAwait(false);
|
||||
await RecognizeAsync(database, world, own, studio, NewService, clock, ct).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>How many files of «Studio Lumen» are «new» for its automatic copies: the newest ones not copied yet.</summary>
|
||||
private const int AutomaticFiles = 24;
|
||||
|
||||
/// <summary>
|
||||
/// «Studio Lumen» becomes «Automatica» with «Solo i nuovi» at the instant its newest files not copied yet start
|
||||
/// (about <see cref="AutomaticFiles"/> of them). An automatic job of the real engine, at a past instant, copies the
|
||||
/// older part (only photos: the demo's videos are one shared file that is not the one recorded, and would fail); a
|
||||
/// job left «interrotto» by the last stop holds the rest, so what the automatic copies would do next is exactly that
|
||||
/// job (the worker never runs in the demo).
|
||||
/// </summary>
|
||||
private static async Task AutomaticAsync(FebeDatabase database, ExportDestination own, Func<IClock, ExportService> newService, IClock clock, CancellationToken ct)
|
||||
{
|
||||
var exports = database.Exports;
|
||||
var now = clock.Now;
|
||||
|
||||
// The files of the folder not copied yet, newest first.
|
||||
var all = await AutomaticFilesAsync(database, new ExportSelection.Automatic([new(own.Id, null)], [], Round: true), ct).ConfigureAwait(false);
|
||||
if (all.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// The «new» files: the newest ones, until there are enough of them and at least two entries made only of photos.
|
||||
var count = 0;
|
||||
var photoEntries = 0;
|
||||
DateTimeOffset since = default;
|
||||
foreach (var entry in all.GroupBy(f => f.Candidate.EntryId).OrderByDescending(g => g.Max(f => f.SavedAt)))
|
||||
{
|
||||
count += entry.Count();
|
||||
photoEntries += entry.All(f => f.Candidate.MediaKind == MediaKind.Photo) ? 1 : 0;
|
||||
since = entry.Min(f => f.SavedAt);
|
||||
if (count >= AutomaticFiles && photoEntries >= 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await exports.UpdateDestinationAsync(own with { Automatic = true, AutomaticSince = since }, ct).ConfigureAwait(false);
|
||||
own = (await exports.GetDestinationAsync(own.Id, ct).ConfigureAwait(false))!;
|
||||
var scope = new ExportSelection.AutomaticScope(own.Id, own.AutomaticSince);
|
||||
var fresh = await AutomaticFilesAsync(database, new ExportSelection.Automatic([scope], [], Round: true), ct).ConfigureAwait(false);
|
||||
|
||||
// The older half of the entries made only of photos went with an automatic job; the others are held back from it.
|
||||
var byEntry = fresh.GroupBy(f => f.Candidate.EntryId).ToList();
|
||||
var copied = byEntry.Where(g => g.All(f => f.Candidate.MediaKind == MediaKind.Photo))
|
||||
.OrderBy(g => g.Max(f => f.SavedAt))
|
||||
.Take(Math.Max(1, byEntry.Count(g => g.All(f => f.Candidate.MediaKind == MediaKind.Photo)) / 2))
|
||||
.ToList();
|
||||
var copiedIds = copied.Select(g => g.Key).ToHashSet();
|
||||
if (copied.Count > 0)
|
||||
{
|
||||
var newest = copied.Max(g => g.Max(f => f.SavedAt));
|
||||
var at = newest + TimeSpan.FromMinutes(5) < now - TimeSpan.FromMinutes(30) ? newest + TimeSpan.FromMinutes(5) : now - TimeSpan.FromMinutes(30);
|
||||
if (at < newest)
|
||||
{
|
||||
at = newest + TimeSpan.FromSeconds(1) < now ? newest + TimeSpan.FromSeconds(1) : now - TimeSpan.FromMinutes(2);
|
||||
}
|
||||
|
||||
await using var past = newService(new ShiftedClock(clock, at - now));
|
||||
var held = byEntry.Select(g => g.Key).Where(id => !copiedIds.Contains(id)).ToList();
|
||||
var start = await past.TryStartAutomaticAsync(new ExportSelection.Automatic([scope], held, Round: true), ct).ConfigureAwait(false);
|
||||
if (start.Outcome == AutoExportStartOutcome.Started)
|
||||
{
|
||||
await past.WaitAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
// What is left is the job «interrotto»: one item per file to write (the first file of each picture, as planned).
|
||||
var left = await AutomaticFilesAsync(database, new ExportSelection.Automatic([scope], [], Round: true), ct).ConfigureAwait(false);
|
||||
var items = left.Select(f => f.Candidate).Where(c => c.Sha256 is not null)
|
||||
.GroupBy(c => c.Sha256!, StringComparer.Ordinal)
|
||||
.Select(g => g.OrderBy(c => c.MediaId).First())
|
||||
.OrderBy(c => c.MediaId)
|
||||
.ToList();
|
||||
if (items.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lastRun = (await exports.ListRunsAsync(ct).ConfigureAwait(false)).Where(r => r.DestinationId == own.Id).Select(r => r.StartedAt).DefaultIfEmpty(now - TimeSpan.FromHours(2)).Max();
|
||||
var started = left.Max(f => f.SavedAt) + TimeSpan.FromMinutes(2);
|
||||
started = started < lastRun + TimeSpan.FromMinutes(10) ? lastRun + TimeSpan.FromMinutes(10) : started;
|
||||
started = started > now - TimeSpan.FromMinutes(1) ? now - TimeSpan.FromMinutes(1) : started;
|
||||
var run = await exports.CreateRunAsync(
|
||||
new ExportRun { DestinationId = own.Id, Origin = ExportRunOrigin.Automatic, State = ExportRunState.Interrupted, StartedAt = started, CompletedAt = null },
|
||||
ct).ConfigureAwait(false);
|
||||
await exports.AddItemsAsync(
|
||||
[.. items.Select(c => new ExportItem { RunId = run.Id, MediaId = c.MediaId, AccountId = c.AccountId, SourceSha256 = c.Sha256 })],
|
||||
ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>The files an automatic selection gives, with the instant each was saved in the library.</summary>
|
||||
private static async Task<List<(ExportCandidate Candidate, DateTimeOffset SavedAt)>> AutomaticFilesAsync(FebeDatabase database, ExportSelection.Automatic selection, CancellationToken ct)
|
||||
{
|
||||
var files = new List<(ExportCandidate, DateTimeOffset)>();
|
||||
long after = 0;
|
||||
while (true)
|
||||
{
|
||||
var page = await database.Exports.ListCandidatesAsync(selection, after, 1000, ct).ConfigureAwait(false);
|
||||
foreach (var candidate in page)
|
||||
{
|
||||
if (await database.Media.GetAsync(candidate.MediaId, ct).ConfigureAwait(false) is { DownloadedAt: { } saved })
|
||||
{
|
||||
files.Add((candidate, saved));
|
||||
}
|
||||
}
|
||||
|
||||
if (page.Count < 1000)
|
||||
{
|
||||
return files;
|
||||
}
|
||||
|
||||
after = page[^1].MediaId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// «Riconosci le copie già presenti» in «Studio Lumen», three hours ago, by the real engine: a byte copy of an older
|
||||
/// photo of @studio.lumen.demo at the path its copy would take is recognised («già presente, riconosciuto»), the path
|
||||
/// of another one holds a different picture («diverso»), and every other file not copied yet is «non trovato». It
|
||||
/// writes nothing. In the own folder, not in «Disco USB»: there it would look for some 28.000 files at every start of
|
||||
/// the demo. The two photos are not «new» for the automatic copies, which keep their interrupted job as it is.
|
||||
/// </summary>
|
||||
private static async Task RecognizeAsync(
|
||||
FebeDatabase database,
|
||||
DemoWorld world,
|
||||
ExportDestination own,
|
||||
Account studio,
|
||||
Func<IClock, ExportService> newService,
|
||||
IClock clock,
|
||||
CancellationToken ct)
|
||||
{
|
||||
own = (await database.Exports.GetDestinationAsync(own.Id, ct).ConfigureAwait(false))!;
|
||||
var fresh = (await AutomaticFilesAsync(database, new ExportSelection.Automatic([new(own.Id, own.AutomaticSince)], [], Round: true), ct).ConfigureAwait(false))
|
||||
.Select(f => f.Candidate.Sha256).ToHashSet(StringComparer.Ordinal);
|
||||
var older = (await AutomaticFilesAsync(database, new ExportSelection.Automatic([new(own.Id, null)], [], Round: true), ct).ConfigureAwait(false))
|
||||
.Where(f => f.Candidate.MediaKind == MediaKind.Photo && !fresh.Contains(f.Candidate.Sha256))
|
||||
.OrderBy(f => f.SavedAt);
|
||||
|
||||
// Two posts (the path of a post needs no highlight) of two pictures, whose paths are free.
|
||||
var placed = new List<(Media Media, string Path)>();
|
||||
foreach (var (candidate, _) in older)
|
||||
{
|
||||
if (placed.Count == 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (candidate.Sha256 is { } sha && placed.All(p => p.Media.Sha256 != sha) && world.Pictures.TryGetValue(sha, out var source) && File.Exists(source)
|
||||
&& await database.Media.GetAsync(candidate.MediaId, ct).ConfigureAwait(false) is { } photo
|
||||
&& await database.Entries.GetAsync(photo.EntryId, ct).ConfigureAwait(false) is { Kind: EntryKind.Post } entry)
|
||||
{
|
||||
var relative = ExportPaths.RelativePathFor(own, ExportPaths.Segments(own, LibraryNaming.Default, studio, entry, photo, null, false, world.Zone));
|
||||
var target = Path.Combine(own.RootPath, LibraryLayout.ToPlatform(relative));
|
||||
if (!File.Exists(target))
|
||||
{
|
||||
placed.Add((photo, target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (placed.Count == 2)
|
||||
{
|
||||
// The first: the very bytes of the library. The second: another picture of the demo, with the same name.
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(placed[0].Path)!);
|
||||
File.Copy(world.Pictures[placed[0].Media.Sha256!], placed[0].Path, overwrite: false);
|
||||
var other = world.Pictures.First(p => p.Key != placed[1].Media.Sha256 && p.Key != placed[0].Media.Sha256 && File.Exists(p.Value)).Value;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(placed[1].Path)!);
|
||||
File.Copy(other, placed[1].Path, overwrite: false);
|
||||
}
|
||||
|
||||
await using var past = newService(new ShiftedClock(clock, -TimeSpan.FromHours(3)));
|
||||
await past.RecognizeAsync(own.Id, ct).ConfigureAwait(false);
|
||||
await past.WaitAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>The instant the demo's frame copy was asked at; the demo video shows its 10th picture then (1.125 s).</summary>
|
||||
@@ -445,6 +641,16 @@ public sealed class DemoExportMounts(string root) : IExportMounts
|
||||
public IReadOnlyList<ExportMount> All() => [_mount];
|
||||
}
|
||||
|
||||
/// <summary>The demo's clock moved by a fixed time: the jobs of the past the demo seeds (tappa E5) run on it.</summary>
|
||||
internal sealed class ShiftedClock(IClock inner, TimeSpan shift) : IClock
|
||||
{
|
||||
public DateTimeOffset Now => inner.Now + shift;
|
||||
|
||||
public TimeZoneInfo LocalZone => inner.LocalZone;
|
||||
|
||||
public Task Delay(TimeSpan time, CancellationToken ct) => inner.Delay(time, ct);
|
||||
}
|
||||
|
||||
/// <summary>The demo's disks: 1,8 TB free, no file size limit.</summary>
|
||||
public sealed class DemoExportDisk : IExportDisk
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user