mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
Added artist rank.
This commit is contained in:
parent
c50fb30eb3
commit
3ddbdd8a82
9 changed files with 87 additions and 4 deletions
|
@ -62,6 +62,9 @@ namespace Roadie.Library.Data
|
|||
[Column("rating")]
|
||||
public short? Rating { get; set; }
|
||||
|
||||
[Column("rank")]
|
||||
public decimal? Rank { get; set; }
|
||||
|
||||
[Column("realName")]
|
||||
[MaxLength(500)]
|
||||
public string RealName { get; set; }
|
||||
|
|
|
@ -87,6 +87,8 @@ namespace Roadie.Library.Models
|
|||
|
||||
public short? Rating { get; set; }
|
||||
|
||||
public decimal? Rank { get; set; }
|
||||
|
||||
[MaxLength(500)]
|
||||
public string RealName { get; set; }
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Roadie.Library.Models
|
|||
{
|
||||
public DataToken Artist { get; set; }
|
||||
public short? Rating { get; set; }
|
||||
public decimal? Rank { get; set; }
|
||||
public UserArtist UserRating { get; set; }
|
||||
public int? ReleaseCount { get; set; }
|
||||
public int? TrackCount { get; set; }
|
||||
|
@ -30,6 +31,7 @@ namespace Roadie.Library.Models
|
|||
},
|
||||
Thumbnail = thumbnail,
|
||||
Rating = artist.Rating,
|
||||
Rank = artist.Rank,
|
||||
CreatedDate = artist.CreatedDate,
|
||||
LastUpdated = artist.LastUpdated,
|
||||
LastPlayed = artist.LastPlayed,
|
||||
|
|
|
@ -284,6 +284,7 @@ namespace Roadie.Api.Services
|
|||
TimeSpanInSeconds = (int)sw.Elapsed.TotalSeconds
|
||||
});
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
await this.UpdateArtistRank(artist.Id, true);
|
||||
await this.LogAndPublish($"ScanArtist `{artist}`, By User `{user}`", LogLevel.Information);
|
||||
return new OperationResult<bool>
|
||||
{
|
||||
|
|
|
@ -202,6 +202,7 @@ namespace Roadie.Api.Services
|
|||
},
|
||||
Thumbnail = this.MakeArtistThumbnailImage(a.RoadieId),
|
||||
Rating = a.Rating,
|
||||
Rank = a.Rank,
|
||||
CreatedDate = a.CreatedDate,
|
||||
LastUpdated = a.LastUpdated,
|
||||
LastPlayed = a.LastPlayed,
|
||||
|
@ -735,6 +736,7 @@ namespace Roadie.Api.Services
|
|||
},
|
||||
Thumbnail = this.MakeArtistThumbnailImage(a.RoadieId),
|
||||
Rating = a.Rating,
|
||||
Rank = a.Rank,
|
||||
CreatedDate = a.CreatedDate,
|
||||
LastUpdated = a.LastUpdated,
|
||||
LastPlayed = a.LastPlayed,
|
||||
|
@ -758,6 +760,7 @@ namespace Roadie.Api.Services
|
|||
},
|
||||
Thumbnail = this.MakeArtistThumbnailImage(a.RoadieId),
|
||||
Rating = a.Rating,
|
||||
Rank = a.Rank,
|
||||
CreatedDate = a.CreatedDate,
|
||||
LastUpdated = a.LastUpdated,
|
||||
LastPlayed = a.LastPlayed,
|
||||
|
|
|
@ -363,7 +363,7 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
artist.LastUpdated = now;
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
|
||||
await this.UpdateArtistRank(artist.Id);
|
||||
this.CacheManager.ClearRegion(user.CacheRegion);
|
||||
this.CacheManager.ClearRegion(artist.CacheRegion);
|
||||
|
||||
|
@ -826,11 +826,76 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all artists involved with release and update their rank
|
||||
/// </summary>
|
||||
protected async Task UpdateArtistsRankForRelease(data.Release release)
|
||||
{
|
||||
if(release != null)
|
||||
{
|
||||
var artistsForRelease = new List<int>
|
||||
{
|
||||
release.ArtistId
|
||||
};
|
||||
var trackArtistsForRelease = (from t in this.DbContext.Tracks
|
||||
join rm in this.DbContext.ReleaseMedias on t.ReleaseMediaId equals rm.Id
|
||||
where rm.ReleaseId == release.Id
|
||||
where t.ArtistId.HasValue
|
||||
select t.ArtistId.Value).ToArray();
|
||||
artistsForRelease.AddRange(trackArtistsForRelease);
|
||||
foreach(var artistId in artistsForRelease.Distinct())
|
||||
{
|
||||
await this.UpdateArtistRank(artistId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Artist Rank
|
||||
/// Artist Rank is a sum of the artists release ranks + artist tracks rating + artist user rating
|
||||
/// </summary>
|
||||
protected async Task UpdateArtistRank(int artistId, bool updateReleaseRanks = false)
|
||||
{
|
||||
var artist = this.DbContext.Artists.FirstOrDefault(x => x.Id == artistId);
|
||||
if (artist != null)
|
||||
{
|
||||
if(updateReleaseRanks)
|
||||
{
|
||||
var artistReleaseIds = this.DbContext.Releases.Where(x => x.ArtistId == artistId).Select(x => x.Id).ToArray();
|
||||
foreach(var artistReleaseId in artistReleaseIds)
|
||||
{
|
||||
await this.UpdateReleaseRank(artistReleaseId, false);
|
||||
}
|
||||
}
|
||||
|
||||
var artistTrackAverage = (from t in this.DbContext.Tracks
|
||||
join rm in this.DbContext.ReleaseMedias on t.ReleaseMediaId equals rm.Id
|
||||
join ut in this.DbContext.UserTracks on t.Id equals ut.TrackId
|
||||
where t.ArtistId == artist.Id
|
||||
select (double?)ut.Rating).ToArray().Average(x => x) ?? 0;
|
||||
|
||||
var artistReleaseRatingSum = (from r in this.DbContext.Releases
|
||||
join ur in this.DbContext.UserReleases on r.Id equals ur.ReleaseId
|
||||
where r.ArtistId == artist.Id
|
||||
select (double?)ur.Rating).ToArray().Average(x => x) ?? 0;
|
||||
|
||||
var artistReleaseRankSum = (from r in this.DbContext.Releases
|
||||
where r.ArtistId == artist.Id
|
||||
select r.Rank).ToArray().Average(x => x) ?? 0;
|
||||
|
||||
artist.Rank = SafeParser.ToNumber<decimal>(artistTrackAverage + artistReleaseRatingSum) + artistReleaseRankSum + artist.Rating;
|
||||
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
this.CacheManager.ClearRegion(artist.CacheRegion);
|
||||
this.Logger.LogInformation("UpdatedArtistRank For Artist `{0}`", artist);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Relase Rank
|
||||
/// Release Rank Calculation = Average of Track User Ratings + (User Rating of Release / Release Track Count) + Collection Rank Value
|
||||
/// </summary>
|
||||
protected async Task UpdateReleaseRank(int releaseId)
|
||||
protected async Task UpdateReleaseRank(int releaseId, bool updateArtistRank = true)
|
||||
{
|
||||
var release = this.DbContext.Releases.FirstOrDefault(x => x.Id == releaseId);
|
||||
if (release != null)
|
||||
|
@ -863,6 +928,11 @@ namespace Roadie.Api.Services
|
|||
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
this.CacheManager.ClearRegion(release.CacheRegion);
|
||||
this.Logger.LogInformation("UpdateReleaseRank For Release `{0}`", release);
|
||||
if (updateArtistRank)
|
||||
{
|
||||
await this.UpdateArtistsRankForRelease(release);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -338,6 +338,7 @@ namespace Roadie.Api.Services
|
|||
Id = trackArtist.RoadieId,
|
||||
Artist = new DataToken { Text = trackArtist.Name, Value = trackArtist.RoadieId.ToString() },
|
||||
Rating = trackArtist.Rating,
|
||||
Rank = trackArtist.Rank,
|
||||
CreatedDate = trackArtist.CreatedDate,
|
||||
LastUpdated = trackArtist.LastUpdated,
|
||||
LastPlayed = trackArtist.LastPlayed,
|
||||
|
@ -353,6 +354,7 @@ namespace Roadie.Api.Services
|
|||
Id = releaseArtist.RoadieId,
|
||||
Artist = new DataToken { Text = releaseArtist.Name, Value = releaseArtist.RoadieId.ToString() },
|
||||
Rating = releaseArtist.Rating,
|
||||
Rank = releaseArtist.Rank,
|
||||
CreatedDate = releaseArtist.CreatedDate,
|
||||
LastUpdated = releaseArtist.LastUpdated,
|
||||
LastPlayed = releaseArtist.LastPlayed,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"Roadie.Api": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Production"
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:5123/"
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"Override": {
|
||||
"System": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Information"
|
||||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
|
|
Loading…
Reference in a new issue