Merge branch 'fix/imaging-metadata': decode tiers, preview-only and undecodable frames, GPR companions, MakerNote fields
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
70 files changed
+2201
-124
No files matched your search
@@ -19,6 +19,9 @@ public sealed record DuplicateFrame(string Sha256, Guid FrameId, Guid SequenceId
|
||||
/// <summary>Light statistics of one frame, written by the analysis job.</summary>
|
||||
public readonly record struct FrameLightStats(Guid FrameId, double? MeanLogLuminance, double? ClipLow, double? ClipHigh);
|
||||
|
||||
/// <summary>Decode-tier fields of one frame (BRIEF §8.2): its flags and the stored size of its largest embedded preview.</summary>
|
||||
public readonly record struct FrameTierFields(Guid FrameId, FrameFlags Flags, int PreviewWidth, int PreviewHeight);
|
||||
|
||||
/// <summary>Per-format totals and flagged-frame counts of one sequence.</summary>
|
||||
public sealed record SequenceFrameStats(IReadOnlyList<FormatBucket> ByFormat, long Missing, long Corrupt, long Duplicate, long Excluded);
|
||||
|
||||
@@ -30,7 +33,7 @@ public sealed class FrameRepository
|
||||
"id", "sequence_id", "idx", "relative_path", "file_name", "original_file_name", "size", "sha256", "captured_at",
|
||||
"utc_offset_minutes", "timestamp_source", "exposure_time", "f_number", "iso", "focal_length", "exposure_bias",
|
||||
"white_balance", "orientation", "width", "height", "format", "preview_offset", "preview_length",
|
||||
"mean_log_luminance", "clip_low", "clip_high", "flags",
|
||||
"mean_log_luminance", "clip_low", "clip_high", "flags", "preview_width", "preview_height",
|
||||
];
|
||||
|
||||
private static readonly string Columns = string.Join(", ", ColumnNames);
|
||||
@@ -40,7 +43,7 @@ public sealed class FrameRepository
|
||||
/// <summary>Rows per statement of the batched PostgreSQL updates (4 or fewer parameters per row).</summary>
|
||||
private const int Batch = 1000;
|
||||
|
||||
/// <summary>Rows per multi-row upsert: 30 x 27 parameters stays below SQLite's historical 999-variable limit.</summary>
|
||||
/// <summary>Rows per multi-row upsert: 30 x 29 parameters stays below SQLite's historical 999-variable limit.</summary>
|
||||
private const int UpsertRows = 30;
|
||||
|
||||
/// <summary>Light statistics belong to the analysis job; a sync from the sidecar never clears them.</summary>
|
||||
@@ -138,6 +141,44 @@ public sealed class FrameRepository
|
||||
return updated;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>Writes the decode-tier fields of many frames in one transaction; returns the number of frames updated.</summary>
|
||||
public Task<int> UpdateTiersAsync(IReadOnlyList<FrameTierFields> frames, CancellationToken cancellationToken = default) =>
|
||||
_db.InTransactionAsync(async session =>
|
||||
{
|
||||
var updated = 0;
|
||||
if (_db.Sql.IsPostgres)
|
||||
{
|
||||
// One UPDATE … FROM (VALUES …) per batch instead of a round trip per frame (a first analysis of a RAW sequence).
|
||||
for (var start = 0; start < frames.Count; start += Batch)
|
||||
{
|
||||
var count = Math.Min(Batch, frames.Count - start);
|
||||
var sql = new StringBuilder("UPDATE frames AS f SET flags = v.fl, preview_width = v.w, preview_height = v.h FROM (VALUES ");
|
||||
var args = new DbParam[count * 4];
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var f = frames[start + i];
|
||||
sql.Append(i > 0 ? ", (" : "(").Append('$').Append(4 * i + 1).Append(", $").Append(4 * i + 2)
|
||||
.Append(", $").Append(4 * i + 3).Append(", $").Append(4 * i + 4).Append(')');
|
||||
args[4 * i] = f.FrameId;
|
||||
args[4 * i + 1] = (int)f.Flags;
|
||||
args[4 * i + 2] = f.PreviewWidth;
|
||||
args[4 * i + 3] = f.PreviewHeight;
|
||||
}
|
||||
sql.Append(") AS v(id, fl, w, h) WHERE f.id = v.id");
|
||||
updated += await session.ExecuteAsync(sql.ToString(), args, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var f in frames)
|
||||
{
|
||||
updated += await session.ExecuteAsync("UPDATE frames SET flags = $2, preview_width = $3, preview_height = $4 WHERE id = $1",
|
||||
[f.FrameId, (int)f.Flags, f.PreviewWidth, f.PreviewHeight], cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Makes the frames of a sequence exactly <paramref name="frames"/> (from its sidecar): rows are upserted by id,
|
||||
/// rows not listed are deleted, light statistics of kept rows survive. Indexes may be renumbered freely.
|
||||
@@ -181,6 +222,15 @@ public sealed class FrameRepository
|
||||
"WHERE s.archive_id = $1 AND f.size = $2 AND f.captured_at = $3",
|
||||
[archiveId, size, SequenceRepository.Wall(capturedAt)], Map, cancellationToken);
|
||||
|
||||
/// <summary>Frames of an archive in this format captured from <paramref name="from"/> to <paramref name="to"/> (inclusive),
|
||||
/// by capture time (a GoPro GPR's JPEG in another sequence).</summary>
|
||||
public Task<IReadOnlyList<Frame>> ListByCaptureRangeAsync(Guid archiveId, ImageFileFormat format, DateTime from, DateTime to,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
_db.ListAsync(
|
||||
$"SELECT {string.Join(", ", ColumnNames.Select(c => "f." + c))} FROM frames f JOIN sequences s ON s.id = f.sequence_id " +
|
||||
"WHERE s.archive_id = $1 AND f.format = $2 AND f.captured_at >= $3 AND f.captured_at <= $4 ORDER BY f.captured_at, f.id",
|
||||
[archiveId, (int)format, SequenceRepository.Wall(from), SequenceRepository.Wall(to)], Map, cancellationToken);
|
||||
|
||||
/// <summary>Every frame of an archive whose SHA-256 occurs more than once, grouped by hash then sequence and index.</summary>
|
||||
public Task<IReadOnlyList<DuplicateFrame>> ListDuplicatesAsync(Guid archiveId, CancellationToken cancellationToken = default) =>
|
||||
_db.ListAsync(
|
||||
@@ -247,7 +297,7 @@ public sealed class FrameRepository
|
||||
f.Id, f.SequenceId, f.Index, f.RelativePath, f.FileName, f.OriginalFileName, f.Size, f.Sha256?.ToLowerInvariant(),
|
||||
SequenceRepository.Wall(f.CapturedAt), f.UtcOffsetMinutes, (int)f.TimestampSource, f.ExposureTime, f.FNumber, f.Iso,
|
||||
f.FocalLength, f.ExposureBias, f.WhiteBalance, f.Orientation, f.Width, f.Height, (int)f.Format, f.PreviewOffset,
|
||||
f.PreviewLength, f.MeanLogLuminance, f.ClipLow, f.ClipHigh, (int)f.Flags,
|
||||
f.PreviewLength, f.MeanLogLuminance, f.ClipLow, f.ClipHigh, (int)f.Flags, f.PreviewWidth, f.PreviewHeight,
|
||||
];
|
||||
|
||||
private static Frame Map(DbRow r) => new()
|
||||
@@ -279,5 +329,7 @@ public sealed class FrameRepository
|
||||
ClipLow = r.GetDoubleOrNull(24),
|
||||
ClipHigh = r.GetDoubleOrNull(25),
|
||||
Flags = (FrameFlags)r.GetInt32(26),
|
||||
PreviewWidth = r.GetInt32(27),
|
||||
PreviewHeight = r.GetInt32(28),
|
||||
};
|
||||
}
|
||||
@@ -122,7 +122,8 @@ public sealed class SequenceRepository
|
||||
private const string Columns =
|
||||
"s.id, s.archive_id, s.title, s.folder, s.camera_make, s.camera_model, s.camera_serial, s.lens, s.first_capture, s.last_capture, " +
|
||||
"s.frame_count, s.median_interval, s.total_bytes, s.status, s.rendered_count, s.verified_at, s.hero_frame_id, s.rating, s.notes, " +
|
||||
"s.settings_json, s.analysis_json, s.origin, s.sync_state, s.settings_version, s.frames_version, s.owner_user_id, s.warning_count, s.updated_at";
|
||||
"s.settings_json, s.analysis_json, s.origin, s.sync_state, s.settings_version, s.frames_version, s.owner_user_id, s.warning_count, s.updated_at, " +
|
||||
"s.preview_only_count";
|
||||
|
||||
/// <summary>rendered_count is owned by <see cref="RenderRepository"/> once the row exists.</summary>
|
||||
private static readonly string UpsertSql = SqlDialect.Upsert("sequences",
|
||||
@@ -130,12 +131,12 @@ public sealed class SequenceRepository
|
||||
"id", "archive_id", "title", "title_key", "search_text", "folder", "camera_make", "camera_model", "camera_serial", "lens",
|
||||
"first_capture", "last_capture", "frame_count", "median_interval", "total_bytes", "status", "rendered_count", "verified_at",
|
||||
"hero_frame_id", "rating", "notes", "settings_json", "analysis_json", "origin", "sync_state", "settings_version",
|
||||
"frames_version", "owner_user_id", "warning_count", "updated_at",
|
||||
"frames_version", "owner_user_id", "warning_count", "updated_at", "preview_only_count",
|
||||
], 1, ["rendered_count"]);
|
||||
|
||||
/// <summary>Ordinal of the tag list after <see cref="Columns"/>, and of the sort key a listing appends after it.</summary>
|
||||
private const int TagsOrdinal = 28;
|
||||
private const int SortKeyOrdinal = 29;
|
||||
private const int TagsOrdinal = 29;
|
||||
private const int SortKeyOrdinal = 30;
|
||||
|
||||
private readonly DbAccess _db;
|
||||
private readonly string _select;
|
||||
@@ -445,7 +446,7 @@ public sealed class SequenceRepository
|
||||
s.Id, s.ArchiveId, s.Title, s.DisplayTitle.ToLowerInvariant(), search, s.Folder, s.CameraMake, s.CameraModel, s.CameraSerial, s.Lens,
|
||||
Wall(s.FirstCapture), Wall(s.LastCapture), s.FrameCount, s.MedianInterval, s.TotalBytes, (int)s.Status, s.RenderedCount, s.VerifiedAt,
|
||||
s.HeroFrameId, s.Rating, s.Notes, DbParam.Json(s.SettingsJson), DbParam.Json(s.AnalysisJson), (int)s.Origin, (int)s.SyncState,
|
||||
s.SettingsVersion, s.FramesVersion, s.OwnerUserId, s.WarningCount, s.UpdatedAt,
|
||||
s.SettingsVersion, s.FramesVersion, s.OwnerUserId, s.WarningCount, s.UpdatedAt, s.PreviewOnlyCount,
|
||||
], cancellationToken);
|
||||
}
|
||||
|
||||
@@ -523,6 +524,7 @@ public sealed class SequenceRepository
|
||||
OwnerUserId = r.GetGuidOrNull(25),
|
||||
WarningCount = r.GetInt32(26),
|
||||
UpdatedAt = r.GetDateTimeOffset(27),
|
||||
PreviewOnlyCount = r.GetInt32(28),
|
||||
Tags = tags,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user