#202 : Optimisation du Dashboard.
This commit is contained in:
@@ -2,7 +2,6 @@ namespace Webzine.Business;
|
|||||||
|
|
||||||
using Webzine.Business.Contracts;
|
using Webzine.Business.Contracts;
|
||||||
using Webzine.Business.Contracts.Dto;
|
using Webzine.Business.Contracts.Dto;
|
||||||
using Webzine.Entity;
|
|
||||||
using Webzine.Repository.Contracts;
|
using Webzine.Repository.Contracts;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -34,37 +33,22 @@ public class DashboardService : IDashboardService
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public DashboardDTO GetDashboardData()
|
public DashboardDTO GetDashboardData()
|
||||||
{
|
{
|
||||||
IEnumerable<Titre> titres = this.titreRepository.FindAll();
|
string artisteLePlusChronique = this.titreRepository.FindMostReviewedArtistName() ?? string.Empty;
|
||||||
|
string albumLePlusChronique = this.titreRepository.FindArtistNameWithMostReviewedAlbums() ?? string.Empty;
|
||||||
Artiste? artisteLePlusChronique = titres
|
var musiqueLaPlusJouee = this.titreRepository.FindMostPlayedTitle();
|
||||||
.GroupBy(t => t.Artiste)
|
|
||||||
.OrderByDescending(g => g.Count())
|
|
||||||
.FirstOrDefault()
|
|
||||||
?.Key;
|
|
||||||
|
|
||||||
Artiste? albumLePlusChronique = titres
|
|
||||||
.GroupBy(t => (t.Artiste, t.Album))
|
|
||||||
.GroupBy(g => g.Key.Artiste)
|
|
||||||
.OrderByDescending(g => g.Count())
|
|
||||||
.FirstOrDefault()
|
|
||||||
?.Key;
|
|
||||||
|
|
||||||
Titre? musiqueLaPlusJouee = titres
|
|
||||||
.OrderByDescending(t => t.NbLectures)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
return new DashboardDTO
|
return new DashboardDTO
|
||||||
{
|
{
|
||||||
NombreArtistes = this.artisteRepository.Count(),
|
NombreArtistes = this.artisteRepository.Count(),
|
||||||
ArtisteLePlusChronique = artisteLePlusChronique.Nom,
|
ArtisteLePlusChronique = artisteLePlusChronique,
|
||||||
AlbumLePlusChronique = albumLePlusChronique.Nom,
|
AlbumLePlusChronique = albumLePlusChronique,
|
||||||
NombreBiographies = this.artisteRepository.Count(a => !string.IsNullOrEmpty(a.Biographie)),
|
NombreBiographies = this.artisteRepository.CountWithBiography(),
|
||||||
IdMusiqueLaPlusJouee = musiqueLaPlusJouee.IdTitre,
|
IdMusiqueLaPlusJouee = musiqueLaPlusJouee?.IdTitre ?? 0,
|
||||||
MusiqueLaPlusJouee = musiqueLaPlusJouee.Libelle,
|
MusiqueLaPlusJouee = musiqueLaPlusJouee?.Libelle ?? string.Empty,
|
||||||
NombreTitres = this.titreRepository.Count(),
|
NombreTitres = this.titreRepository.Count(),
|
||||||
NombreGenres = this.styleRepository.Count(),
|
NombreGenres = this.styleRepository.Count(),
|
||||||
NombreLectures = titres.Sum(t => t.NbLectures),
|
NombreLectures = this.titreRepository.CountLecture(),
|
||||||
NombreLikes = titres.Sum(t => t.NbLikes),
|
NombreLikes = this.titreRepository.CountLike(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,5 +72,11 @@ namespace Webzine.Repository.Contracts
|
|||||||
/// <param name="predicate">Le prédicat de filtrage.</param>
|
/// <param name="predicate">Le prédicat de filtrage.</param>
|
||||||
/// <returns>Le nombre d'artistes correspondants.</returns>
|
/// <returns>Le nombre d'artistes correspondants.</returns>
|
||||||
int Count(Func<Artiste, bool> predicate);
|
int Count(Func<Artiste, bool> predicate);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Récupère le nombre d'artistes ayant une biographie renseignée.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Le nombre d'artistes avec biographie.</returns>
|
||||||
|
int CountWithBiography();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,5 +77,35 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="titre">L'objet titre à mettre à jour.</param>
|
/// <param name="titre">L'objet titre à mettre à jour.</param>
|
||||||
void Update(Titre titre);
|
void Update(Titre titre);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retourne le nombre total de likes.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Integer.</returns>
|
||||||
|
int CountLike();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retourne le nombre total de lecture.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Integer.</returns>
|
||||||
|
int CountLecture();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retourne le nom de l'artiste ayant le plus de titres chroniqués.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Le nom de l'artiste le plus chroniqué, ou null si aucun titre n'existe.</returns>
|
||||||
|
string? FindMostReviewedArtistName();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retourne le nom de l'artiste ayant le plus d'albums chroniqués.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Le nom de l'artiste concerné, ou null si aucun titre n'existe.</returns>
|
||||||
|
string? FindArtistNameWithMostReviewedAlbums();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retourne l'identifiant et le libellé du titre le plus joué.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Un tuple contenant l'identifiant et le libellé du titre le plus joué, ou null si aucun titre n'existe.</returns>
|
||||||
|
(int IdTitre, string Libelle)? FindMostPlayedTitle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,6 +208,22 @@ namespace Webzine.Repository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public int CountWithBiography()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int count = this.context.Artistes.Count(a => !string.IsNullOrEmpty(a.Biographie));
|
||||||
|
this.logger.LogDebug("Nombre d'artistes avec biographie: {Count}", count);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogError(ex, "Erreur lors du comptage des artistes avec biographie.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IEnumerable<Artiste> FindArtistes(int offset, int limit)
|
public IEnumerable<Artiste> FindArtistes(int offset, int limit)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -325,4 +325,100 @@ public class DbTitreRepository : ITitreRepository
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public int CountLike()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var likes = this.context.Titres.Sum(t => t.NbLikes);
|
||||||
|
return likes;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogError(ex, "Erreur lors de la récupération des likes.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public int CountLecture()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var lectures = this.context.Titres.Sum(t => t.NbLectures);
|
||||||
|
return lectures;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogError(ex, "Erreur lors de la récupération des lectures.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string? FindMostReviewedArtistName()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return this.context.Titres
|
||||||
|
.AsNoTracking()
|
||||||
|
.GroupBy(t => new { t.IdArtiste, t.Artiste.Nom })
|
||||||
|
.OrderByDescending(g => g.Count())
|
||||||
|
.ThenBy(g => g.Key.Nom)
|
||||||
|
.Select(g => g.Key.Nom)
|
||||||
|
.FirstOrDefault();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste le plus chroniqué.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string? FindArtistNameWithMostReviewedAlbums()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return this.context.Titres
|
||||||
|
.AsNoTracking()
|
||||||
|
.GroupBy(t => new { t.IdArtiste, t.Artiste.Nom })
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
g.Key.Nom,
|
||||||
|
AlbumCount = g.Select(t => t.Album).Distinct().Count(),
|
||||||
|
})
|
||||||
|
.OrderByDescending(x => x.AlbumCount)
|
||||||
|
.ThenBy(x => x.Nom)
|
||||||
|
.Select(x => x.Nom)
|
||||||
|
.FirstOrDefault();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le plus d'albums chroniqués.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public (int IdTitre, string Libelle)? FindMostPlayedTitle()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = this.context.Titres
|
||||||
|
.AsNoTracking()
|
||||||
|
.OrderByDescending(t => t.NbLectures)
|
||||||
|
.ThenBy(t => t.Libelle)
|
||||||
|
.Select(t => new { t.IdTitre, t.Libelle })
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
return result == null ? null : (result.IdTitre, result.Libelle);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogError(ex, "Erreur lors de la recherche du titre le plus joué.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -107,6 +107,12 @@ namespace Webzine.Repository
|
|||||||
return this.dataStore.Artistes.Count(predicate);
|
return this.dataStore.Artistes.Count(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public int CountWithBiography()
|
||||||
|
{
|
||||||
|
return this.dataStore.Artistes.Count(a => !string.IsNullOrEmpty(a.Biographie));
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IEnumerable<Artiste> FindArtistes(int offset, int limit)
|
public IEnumerable<Artiste> FindArtistes(int offset, int limit)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -131,4 +131,54 @@ public class LocalTitreRepository : ITitreRepository
|
|||||||
existingTitre.IdArtiste = titre.IdArtiste;
|
existingTitre.IdArtiste = titre.IdArtiste;
|
||||||
existingTitre.Styles = titre.Styles;
|
existingTitre.Styles = titre.Styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public int CountLike()
|
||||||
|
{
|
||||||
|
return this.dataStore.Titres.Sum(t => t.NbLikes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public int CountLecture()
|
||||||
|
{
|
||||||
|
return this.dataStore.Titres.Sum(t => t.NbLectures);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string? FindMostReviewedArtistName()
|
||||||
|
{
|
||||||
|
return this.dataStore.Titres
|
||||||
|
.GroupBy(t => t.Artiste)
|
||||||
|
.OrderByDescending(g => g.Count())
|
||||||
|
.ThenBy(g => g.Key?.Nom)
|
||||||
|
.Select(g => g.Key?.Nom)
|
||||||
|
.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string? FindArtistNameWithMostReviewedAlbums()
|
||||||
|
{
|
||||||
|
return this.dataStore.Titres
|
||||||
|
.GroupBy(t => t.Artiste)
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
ArtistName = g.Key?.Nom,
|
||||||
|
AlbumCount = g.Select(t => t.Album).Distinct().Count(),
|
||||||
|
})
|
||||||
|
.OrderByDescending(x => x.AlbumCount)
|
||||||
|
.ThenBy(x => x.ArtistName)
|
||||||
|
.Select(x => x.ArtistName)
|
||||||
|
.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public (int IdTitre, string Libelle)? FindMostPlayedTitle()
|
||||||
|
{
|
||||||
|
Titre? titre = this.dataStore.Titres
|
||||||
|
.OrderByDescending(t => t.NbLectures)
|
||||||
|
.ThenBy(t => t.Libelle)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
return titre == null ? null : (titre.IdTitre, titre.Libelle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ try
|
|||||||
|
|
||||||
if (seederType == SeederType.Local)
|
if (seederType == SeederType.Local)
|
||||||
{
|
{
|
||||||
repo.SeedBaseDeDonnees();
|
repo.SeedBaseDeDonnees(nbArtistes: 1000, nbTitres: 50000, maxStyles: 50);
|
||||||
}
|
}
|
||||||
else if (seederType == SeederType.Spotify)
|
else if (seederType == SeederType.Spotify)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"Seeder": "Spotify",
|
"Seeder": "Local",
|
||||||
"Repository": "Db",
|
"Repository": "Db",
|
||||||
"SpotifySeeder": {
|
"SpotifySeeder": {
|
||||||
"ClientId": "",
|
"ClientId": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user