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)