From 3f3b5d84676e0be14d133cf4887bf4b1431b5437 Mon Sep 17 00:00:00 2001 From: Pavel Zhur Date: Mon, 5 Aug 2024 07:32:40 +0300 Subject: [PATCH 1/2] ItemsPerPage --- .../VExternal1/Main/SongsByChordsRequest.cs | 2 -- .../VExternal1/Main/SongsByHeaderRequest.cs | 2 -- .../VExternal1/PagedRequestBase.cs | 1 + .../VExternal1/Tonalities/LoopsRequest.cs | 2 -- .../VExternal1/Tonalities/SongsRequest.cs | 2 -- .../Functions/VExternal1/SongsByChords.cs | 4 ++-- .../Functions/VExternal1/SongsByHeader.cs | 6 +++--- .../Functions/VExternal1/TonalitiesLoops.cs | 4 ++-- .../Functions/VExternal1/TonalitiesSongs.cs | 4 ++-- .../HarmonyDB.Playground.Web/Views/Home/Loops.cshtml | 2 +- .../Views/Home/SongsByChords.cshtml | 2 +- .../Views/Home/SongsByHeader.cshtml | 2 +- .../HarmonyDB.Playground.Web/Views/Tonalities/Loops.cshtml | 2 +- .../HarmonyDB.Playground.Web/Views/Tonalities/Songs.cshtml | 2 +- 14 files changed, 15 insertions(+), 22 deletions(-) diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Main/SongsByChordsRequest.cs b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Main/SongsByChordsRequest.cs index 63713cec..6a3bad0d 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Main/SongsByChordsRequest.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Main/SongsByChordsRequest.cs @@ -10,8 +10,6 @@ public record SongsByChordsRequest : PagedRequestBase public int MinRating { get; init; } = 70; - public int SongsPerPage { get; init; } = 100; - [JsonConverter(typeof(JsonStringEnumConverter))] public SongsByChordsRequestOrdering Ordering { get; init; } = SongsByChordsRequestOrdering.ByRating; } \ No newline at end of file diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Main/SongsByHeaderRequest.cs b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Main/SongsByHeaderRequest.cs index fc5714d8..61955023 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Main/SongsByHeaderRequest.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Main/SongsByHeaderRequest.cs @@ -5,6 +5,4 @@ public record SongsByHeaderRequest : PagedRequestBase public required string Query { get; init; } public int MinRating { get; init; } = 70; - - public int SongsPerPage { get; init; } = 100; } \ No newline at end of file diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/PagedRequestBase.cs b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/PagedRequestBase.cs index 044a481d..4e46fd71 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/PagedRequestBase.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/PagedRequestBase.cs @@ -3,4 +3,5 @@ namespace HarmonyDB.Index.Api.Model.VExternal1; public record PagedRequestBase { public int PageNumber { get; init; } = 1; + public int ItemsPerPage { get; init; } = 100; } \ No newline at end of file diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Tonalities/LoopsRequest.cs b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Tonalities/LoopsRequest.cs index d52f9968..147e2ca2 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Tonalities/LoopsRequest.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Tonalities/LoopsRequest.cs @@ -30,8 +30,6 @@ public record LoopsRequest : PagedRequestBase public RequestScaleFilter DetectedScaleFilter { get; init; } = RequestScaleFilter.Any; - public int LoopsPerPage { get; init; } = 100; - [JsonConverter(typeof(JsonStringEnumConverter))] public LoopsRequestOrdering Ordering { get; init; } = LoopsRequestOrdering.SuccessionsDesc; } \ No newline at end of file diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Tonalities/SongsRequest.cs b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Tonalities/SongsRequest.cs index fcee8029..28b31ee8 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Tonalities/SongsRequest.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api.Model/VExternal1/Tonalities/SongsRequest.cs @@ -31,8 +31,6 @@ public record SongsRequest : PagedRequestBase public SongsRequestCorrectDetectionFilter CorrectDetectionFilter { get; init; } = SongsRequestCorrectDetectionFilter.Any; public SongsRequestKnownTonalityFilter KnownTonalityFilter { get; init; } = SongsRequestKnownTonalityFilter.Any; - - public int SongsPerPage { get; init; } = 100; [JsonConverter(typeof(JsonStringEnumConverter))] public SongsRequestOrdering Ordering { get; init; } = SongsRequestOrdering.TonalityConfidenceDesc; diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/SongsByChords.cs b/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/SongsByChords.cs index 5db30112..2b820e77 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/SongsByChords.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/SongsByChords.cs @@ -90,14 +90,14 @@ protected override async Task Execute(SongsByChordsReques return new() { - Songs = results.Skip((request.PageNumber - 1) * request.SongsPerPage).Take(request.SongsPerPage).Select(x => new SongsByChordsResponseSong + Songs = results.Skip((request.PageNumber - 1) * request.ItemsPerPage).Take(request.ItemsPerPage).Select(x => new SongsByChordsResponseSong { Header = x.h, Coverage = x.coverage, PredictedTonalityIndex = tonalitiesCache.Songs.GetValueOrDefault(x.h.ExternalId)?.TonalityProbabilities.ToLinear().GetPredictedTonality().ToIndex(), }).ToList(), Total = results.Count, - TotalPages = results.Count / request.SongsPerPage + (results.Count % request.SongsPerPage == 0 ? 0 : 1), + TotalPages = results.Count / request.ItemsPerPage + (results.Count % request.ItemsPerPage == 0 ? 0 : 1), CurrentPageNumber = request.PageNumber, }; } diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/SongsByHeader.cs b/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/SongsByHeader.cs index 450dfaf7..ace684f6 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/SongsByHeader.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/SongsByHeader.cs @@ -63,12 +63,12 @@ protected override async Task Execute(SongsByHeaderReques return new() { Songs = results - .Skip((request.PageNumber - 1) * request.SongsPerPage) - .Take(request.SongsPerPage) + .Skip((request.PageNumber - 1) * request.ItemsPerPage) + .Take(request.ItemsPerPage) .Select(x => new SongsByHeaderResponseSong(x, tonalitiesCache.Songs.GetValueOrDefault(x.ExternalId)?.TonalityProbabilities.ToLinear().GetPredictedTonality().ToIndex())) .ToList(), Total = results.Count, - TotalPages = results.Count / request.SongsPerPage + (results.Count % request.SongsPerPage == 0 ? 0 : 1), + TotalPages = results.Count / request.ItemsPerPage + (results.Count % request.ItemsPerPage == 0 ? 0 : 1), CurrentPageNumber = request.PageNumber, }; } diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/TonalitiesLoops.cs b/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/TonalitiesLoops.cs index 5af78053..6ce1a893 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/TonalitiesLoops.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/TonalitiesLoops.cs @@ -129,9 +129,9 @@ protected override async Task Execute(LoopsRequest request) return new() { Total = loops.Count, - TotalPages = loops.Count / request.LoopsPerPage + (loops.Count % request.LoopsPerPage == 0 ? 0 : 1), + TotalPages = loops.Count / request.ItemsPerPage + (loops.Count % request.ItemsPerPage == 0 ? 0 : 1), CurrentPageNumber = request.PageNumber, - Loops = orderedLoops.Skip((request.PageNumber - 1) * request.LoopsPerPage).Take(request.LoopsPerPage).ToList(), + Loops = orderedLoops.Skip((request.PageNumber - 1) * request.ItemsPerPage).Take(request.ItemsPerPage).ToList(), Distributions = new() { TotalSongs = loops.GetPercentiles(x => x.TotalSongs), diff --git a/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/TonalitiesSongs.cs b/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/TonalitiesSongs.cs index 35238479..82da9959 100644 --- a/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/TonalitiesSongs.cs +++ b/HarmonyDB.Index/HarmonyDB.Index.Api/Functions/VExternal1/TonalitiesSongs.cs @@ -156,9 +156,9 @@ protected override async Task Execute(SongsRequest request) return new() { Total = songs.Count, - TotalPages = songs.Count / request.SongsPerPage + (songs.Count % request.SongsPerPage == 0 ? 0 : 1), + TotalPages = songs.Count / request.ItemsPerPage + (songs.Count % request.ItemsPerPage == 0 ? 0 : 1), CurrentPageNumber = request.PageNumber, - Songs = orderedSongs.Skip((request.PageNumber - 1) * request.SongsPerPage).Take(request.SongsPerPage).ToList(), + Songs = orderedSongs.Skip((request.PageNumber - 1) * request.ItemsPerPage).Take(request.ItemsPerPage).ToList(), Distributions = new() { Rating = songs.GetPercentiles(x => x.IndexHeader.Rating), diff --git a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Home/Loops.cshtml b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Home/Loops.cshtml index c7efa164..4b6ebf2f 100644 --- a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Home/Loops.cshtml +++ b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Home/Loops.cshtml @@ -42,7 +42,7 @@ @ViewLocalizer["Min total successions"]: @Html.TextBoxFor(x => x.MinTotalSuccessions)

- @ViewLocalizer["Loops Per Page"]: @Html.TextBoxFor(x => x.LoopsPerPage) + @ViewLocalizer["Loops Per Page"]: @Html.TextBoxFor(x => x.ItemsPerPage)

@ViewLocalizer["Scale"]: diff --git a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Home/SongsByChords.cshtml b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Home/SongsByChords.cshtml index 405356eb..2a758f09 100644 --- a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Home/SongsByChords.cshtml +++ b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Home/SongsByChords.cshtml @@ -47,7 +47,7 @@ @ViewLocalizer["Min rating (whole, 0–100)"]: @Html.TextBoxFor(x => x.MinRating)

- @ViewLocalizer["Songs Per Page"]: @Html.TextBoxFor(x => x.SongsPerPage) + @ViewLocalizer["Songs Per Page"]: @Html.TextBoxFor(x => x.ItemsPerPage)

- @ViewLocalizer["Songs Per Page"]: @Html.TextBoxFor(x => x.SongsPerPage) + @ViewLocalizer["Songs Per Page"]: @Html.TextBoxFor(x => x.ItemsPerPage)

- @ViewLocalizer["Loops Per Page"]: @Html.TextBoxFor(x => x.LoopsPerPage) + @ViewLocalizer["Loops Per Page"]: @Html.TextBoxFor(x => x.ItemsPerPage)

- @ViewLocalizer["Songs Per Page"]: @Html.TextBoxFor(x => x.SongsPerPage) + @ViewLocalizer["Songs Per Page"]: @Html.TextBoxFor(x => x.ItemsPerPage)

\ No newline at end of file diff --git a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Shared/Limit.ru.resx b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Shared/Limit.ru.resx new file mode 100644 index 00000000..5afc782e --- /dev/null +++ b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Shared/Limit.ru.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Только первые и последние {0} результатов доступны в песочнице. Чтобы получить доступ к остальным, пожалуйста, свяжитесь с разработчиками. + + \ No newline at end of file diff --git a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Shared/Trace.cshtml b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Shared/Trace.cshtml index fdcc1250..8084dad4 100644 --- a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Shared/Trace.cshtml +++ b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Shared/Trace.cshtml @@ -6,7 +6,7 @@ ApiTraceBag? trace = ViewBag.Trace; } -@if (trace != null) +@if (trace != null && ViewBag.Limit == null) {

@ViewLocalizer["Trace"]

@foreach (var request in trace.Requests) diff --git a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Tonalities/Loops.cshtml b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Tonalities/Loops.cshtml index 8d5d2762..110334ac 100644 --- a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Tonalities/Loops.cshtml +++ b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Tonalities/Loops.cshtml @@ -108,8 +108,14 @@ @await Html.PartialAsync("Paging", Model) - - + @if (ViewBag.Limit != null) + { + @await Html.PartialAsync("Limit", (int)ViewBag.Limit) + } + else + { +
+ @if (Model.ViewMode == StructureViewMode.Interpreted) @@ -128,52 +134,53 @@ - - @foreach (var loop in response.Loops) - { - - @{ - var predicted = loop.Probabilities.GetPredictedTonality(); - var secondPredicted = loop.Probabilities.GetSecondPredictedTonality(out var secondConfidence); - var relativeToPredicted = predicted.GetRelativeScale(false); - var predictedViewMode = Model.ViewMode == StructureViewMode.Interpreted ? predicted.OnceAsNullable() : null; - } - - - @if (Model.ViewMode == StructureViewMode.Interpreted) - { - - } - - - - - @if (Model.ViewMode == StructureViewMode.Interpreted) - { - - - } - @if (secondPredicted != relativeToPredicted) - { - - - } - else - { - - - } - - - - - - - - - - } -
@ViewLocalizer["Progression"]@ViewLocalizer["Tonic Score"] @ViewLocalizer["Scale Score"]
@Html.ActionLink(loop.Normalized.GetTitle(predictedViewMode), "Loop", new StructureLoopModel { Normalized = loop.Normalized })@loop.Normalized.GetFunctionsTitle(predicted)@predicted.ToLoopTonalityTitle(predictedViewMode)@loop.Probabilities.TonalityConfidence().ToString("P0")@secondPredicted.ToLoopTonalityTitle(predictedViewMode)@secondConfidence.ToString("P0")@loop.Normalized.GetTitle(secondPredicted)@loop.Normalized.GetFunctionsTitle(secondPredicted)@relativeToPredicted.ToLoopTonalityTitle(predictedViewMode)@loop.Probabilities[relativeToPredicted.ToIndex()].ToString("P0")@loop.TonicScore.ToString("P0")@loop.Length@loop.TotalSongs.ToString("N0")@loop.TotalOccurrences.ToString("N0")@loop.TotalSuccessions.ToString("N0")@loop.AverageCoverage.ToString("P0")@loop.Probabilities.TonicConfidence(false).ToString("P0")@loop.ScaleScore.ToString("P0")
+ + @foreach (var loop in response.Loops) + { + + @{ + var predicted = loop.Probabilities.GetPredictedTonality(); + var secondPredicted = loop.Probabilities.GetSecondPredictedTonality(out var secondConfidence); + var relativeToPredicted = predicted.GetRelativeScale(false); + var predictedViewMode = Model.ViewMode == StructureViewMode.Interpreted ? predicted.OnceAsNullable() : null; + } + + @Html.ActionLink(loop.Normalized.GetTitle(predictedViewMode), "Loop", new StructureLoopModel { Normalized = loop.Normalized }) + @if (Model.ViewMode == StructureViewMode.Interpreted) + { + @loop.Normalized.GetFunctionsTitle(predicted) + } + @predicted.ToLoopTonalityTitle(predictedViewMode) + @loop.Probabilities.TonalityConfidence().ToString("P0") + @secondPredicted.ToLoopTonalityTitle(predictedViewMode) + @secondConfidence.ToString("P0") + @if (Model.ViewMode == StructureViewMode.Interpreted) + { + @loop.Normalized.GetTitle(secondPredicted) + @loop.Normalized.GetFunctionsTitle(secondPredicted) + } + @if (secondPredicted != relativeToPredicted) + { + @relativeToPredicted.ToLoopTonalityTitle(predictedViewMode) + @loop.Probabilities[relativeToPredicted.ToIndex()].ToString("P0") + } + else + { + + + } + @loop.TonicScore.ToString("P0") + @loop.Length + @loop.TotalSongs.ToString("N0") + @loop.TotalOccurrences.ToString("N0") + @loop.TotalSuccessions.ToString("N0") + @loop.AverageCoverage.ToString("P0") + @loop.Probabilities.TonicConfidence(false).ToString("P0") + @loop.ScaleScore.ToString("P0") + + } + + } @await Html.PartialAsync("Paging", Model) } diff --git a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Tonalities/Songs.cshtml b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Tonalities/Songs.cshtml index 9498000b..65c17437 100644 --- a/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Tonalities/Songs.cshtml +++ b/HarmonyDB.Playground/HarmonyDB.Playground.Web/Views/Tonalities/Songs.cshtml @@ -166,9 +166,15 @@ @await Html.PartialAsync("Paging", Model) - - - + + @if (ViewBag.Limit != null) + { + @await Html.PartialAsync("Limit", (int)ViewBag.Limit) + } + else + { +
+ @@ -183,48 +189,49 @@ - - @foreach (var song in response.Songs) - { - - - - - - - - @{ - var predicted = song.Probabilities.GetPredictedTonality(); - var secondPredicted = song.Probabilities.GetSecondPredictedTonality(out var secondConfidence); - var relativeToPredicted = predicted.GetRelativeScale(true); - } - - - - - @if (secondPredicted != relativeToPredicted) - { - - - } - else - { - - - } - - - - - } -
@ViewLocalizer["Song"] @ViewLocalizer["Source"]@ViewLocalizer["Tonic Score"] @ViewLocalizer["Scale Score"]
- @string.Join(", ", song.IndexHeader.Artists ?? Enumerable.Empty()) – @Html.ActionLink(song.IndexHeader.Title, "Song", new StructureSongModel - { - ExternalId = song.IndexHeader.ExternalId - }) - @song.IndexHeader.Source - @song.KnownTonalityIndex?.ToSongTonalityTitle() - @song.IndexHeader.BestTonality?.IsReliable@((int)(song.IndexHeader.Rating ?? 0))%@song.TotalLoops.ToString("N0")@predicted.ToSongTonalityTitle()@song.Probabilities.TonalityConfidence().ToString("P0")@secondPredicted.ToSongTonalityTitle()@secondConfidence.ToString("P0")@relativeToPredicted.ToSongTonalityTitle()@song.Probabilities[relativeToPredicted.ToIndex()].ToString("P0")@song.Probabilities.TonicConfidence(true).ToString("P0")@song.ScaleScore.ToString("P0")@song.TonicScore.ToString("P0")
+ + @foreach (var song in response.Songs) + { + + + @string.Join(", ", song.IndexHeader.Artists ?? Enumerable.Empty()) – @Html.ActionLink(song.IndexHeader.Title, "Song", new StructureSongModel + { + ExternalId = song.IndexHeader.ExternalId + }) + + @song.IndexHeader.Source + + @song.KnownTonalityIndex?.ToSongTonalityTitle() + + @song.IndexHeader.BestTonality?.IsReliable + @((int)(song.IndexHeader.Rating ?? 0))% + @song.TotalLoops.ToString("N0") + @{ + var predicted = song.Probabilities.GetPredictedTonality(); + var secondPredicted = song.Probabilities.GetSecondPredictedTonality(out var secondConfidence); + var relativeToPredicted = predicted.GetRelativeScale(true); + } + @predicted.ToSongTonalityTitle() + @song.Probabilities.TonalityConfidence().ToString("P0") + @secondPredicted.ToSongTonalityTitle() + @secondConfidence.ToString("P0") + @if (secondPredicted != relativeToPredicted) + { + @relativeToPredicted.ToSongTonalityTitle() + @song.Probabilities[relativeToPredicted.ToIndex()].ToString("P0") + } + else + { + + + } + @song.Probabilities.TonicConfidence(true).ToString("P0") + @song.ScaleScore.ToString("P0") + @song.TonicScore.ToString("P0") + + } + + } @await Html.PartialAsync("Paging", Model) }