Skip to content

Commit

Permalink
Merge pull request #177 from DennisvHest/development
Browse files Browse the repository at this point in the history
1.5.0
  • Loading branch information
DennisvHest committed Jun 22, 2024
2 parents 9b28ff2 + bbbfa5a commit ea894be
Show file tree
Hide file tree
Showing 43 changed files with 1,553 additions and 293 deletions.
14 changes: 7 additions & 7 deletions MapMaven.Core.Tests/MapMaven.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MockQueryable.Moq" Version="7.0.1" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="20.0.34" />
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="20.0.34" />
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="20.0.34" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Xunit.Microsoft.DependencyInjection" Version="8.0.12" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="21.0.2" />
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="21.0.2" />
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="21.0.2" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="Xunit.Microsoft.DependencyInjection" Version="8.1.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
12 changes: 6 additions & 6 deletions MapMaven.Core/MapMaven.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<PackageReference Include="BeatSaverSharper" Version="3.4.5" />
<PackageReference Include="FastDeepCloner" Version="1.3.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.DataAnnotations.Validation" Version="3.2.0-rc1.20223.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="8.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="8.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -35,7 +35,7 @@
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NSwag.ApiDescription.Client" Version="14.0.3">
<PackageReference Include="NSwag.ApiDescription.Client" Version="14.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -44,10 +44,10 @@
<PackageReference Include="RateLimiter" Version="2.2.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
<PackageReference Include="System.Drawing.Common" Version="8.0.3" />
<PackageReference Include="System.Drawing.Common" Version="8.0.5" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="20.0.34" />
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="20.0.34" />
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="21.0.2" />
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="21.0.2" />
</ItemGroup>
<ItemGroup Label="ScoreSaberScoreEstimateMLModel">
<None Include="ScoreEstimation\ScoreSaberScoreEstimateMLModel.consumption.cs">
Expand Down
14 changes: 0 additions & 14 deletions MapMaven.Core/Models/Data/Leaderboards/ScoreSaber/RankedMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,5 @@ public class RankedMap
[JsonPropertyName("njs")]
public double NoteJumpSpeed { get; set; }
public int RecentScores { get; set; }

public Map ToMap()
{
return new Map
{
Id = Key,
Hash = Id,
Name = Name,
SongAuthorName = Artist,
MapAuthorName = Mapper,
SongDuration = TimeSpan.FromSeconds((double)(DurationSeconds ?? Duration / Bpm)),
CoverImageUrl = $"https://cdn.scoresaber.com/covers/{Id}.png"
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AdvancedSearchMap
public string MapAuthorName { get; set; }

[DisplayName("Date added")]
public DateTime AddedDateTime { get; set; }
public DateTime? AddedDateTime { get; set; }

[ApplicableForMapPool(MapPool.Improvement)]
public bool Hidden { get; set; }
Expand Down
17 changes: 16 additions & 1 deletion MapMaven.Core/Models/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Map
public string? Description { get; set; }
public string SongAuthorName { get; set; }
public string MapAuthorName { get; set; }
public DateTime AddedDateTime { get; set; }
public DateTime? AddedDateTime { get; set; }
public TimeSpan SongDuration { get; set; }
public TimeSpan PreviewStartTime { get; set; }
public TimeSpan PreviewDuration { get; set; }
Expand All @@ -34,6 +34,21 @@ public class Map
public IEnumerable<ScoreEstimate> ScoreEstimates { get; set; } = Enumerable.Empty<ScoreEstimate>();
public ScoreEstimate? ScoreEstimate => ScoreEstimates.FirstOrDefault();

public Map() { }

public Map(Beatmap beatmap)
{
Id = beatmap.ID;
Hash = beatmap.LatestVersion.Hash;
Name = beatmap.Name;
SongAuthorName = beatmap.Metadata.SongAuthorName;
MapAuthorName = beatmap.Metadata.LevelAuthorName;
SongDuration = TimeSpan.FromSeconds(beatmap.Metadata.Duration);
CoverImageUrl = beatmap.LatestVersion.CoverURL;

SetMapDetails(beatmap);
}

public void SetRankedMapDetails(RankedMapInfoItem rankedMap)
{
if (rankedMap == null)
Expand Down
22 changes: 21 additions & 1 deletion MapMaven.Core/Models/PlayerProfile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MapMaven.Core.Models
using System.Linq;

namespace MapMaven.Core.Models
{
public class PlayerProfile
{
Expand All @@ -10,6 +12,7 @@ public class PlayerProfile
public int CountryRank { get; set; }
public double Pp { get; set; }
public LeaderboardProvider LeaderboardProvider { get; set; }
public IEnumerable<RankHistoryRecord> RankHistory { get; set; } = [];

public PlayerProfile() {}

Expand All @@ -23,6 +26,22 @@ public PlayerProfile(ApiClients.ScoreSaber.Player player)
CountryRank = Convert.ToInt32(player.CountryRank);
Pp = player.Pp;
LeaderboardProvider = LeaderboardProvider.ScoreSaber;

var playerRankHistory = player.Histories
?.Split(',')
.Select(int.Parse)
.Cast<int?>()
.ToArray() ?? [];

RankHistory = [new RankHistoryRecord() { Date = DateOnly.FromDateTime(DateTime.Today), Rank = Rank }];

RankHistory = RankHistory.Concat(Enumerable.Range(1, 49).Select(dateOffset => new RankHistoryRecord
{
Rank = playerRankHistory.ElementAtOrDefault(playerRankHistory.Length - dateOffset),
Date = DateOnly.FromDateTime(DateTime.Today.AddDays(-dateOffset))
}));

RankHistory = RankHistory.OrderBy(x => x.Date);
}

public PlayerProfile(ApiClients.BeatLeader.PlayerResponseFull playerProfile)
Expand All @@ -35,6 +54,7 @@ public PlayerProfile(ApiClients.BeatLeader.PlayerResponseFull playerProfile)
CountryRank = Convert.ToInt32(playerProfile.CountryRank);
Pp = playerProfile.Pp;
LeaderboardProvider = LeaderboardProvider.BeatLeader;
RankHistory = [];
}
}
}
22 changes: 22 additions & 0 deletions MapMaven.Core/Models/RankHistoryRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using MapMaven.Core.ApiClients.BeatLeader;

namespace MapMaven.Core.Models
{
public class RankHistoryRecord
{
public int? Rank { get; set; }
public int? CountryRank { get; set; }
public double? Pp { get; set; }
public DateOnly Date { get; set; }

public RankHistoryRecord() { }

public RankHistoryRecord(PlayerScoreStatsHistory history)
{
Rank = history.Rank;
CountryRank = history.CountryRank;
Pp = history.Pp;
Date = DateOnly.FromDateTime(DateTimeOffset.FromUnixTimeSeconds(history.Timestamp).DateTime);
}
}
}
1 change: 1 addition & 0 deletions MapMaven.Core/Models/Score.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Score
public IEnumerable<string> Modifiers { get; set; } = Enumerable.Empty<string>();
public double Pp { get; set; }
public double Weight { get; set; }
public double WeightedPp => Pp * Weight;
public double BadCuts { get; set; }
public double MissedNotes { get; set; }
public double MaxCombo { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions MapMaven.Core/Services/Interfaces/IMapService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ public interface IMapService
void AddMapFilters(IEnumerable<MapFilter> filters);
void RemoveMapFilters(IEnumerable<MapFilter> filters);
void SetMapSort(MapSort? sort);
Map? GetMapById(string mapId);
Task<Map?> GetMapDetails(string mapHash);
}
}
1 change: 1 addition & 0 deletions MapMaven.Core/Services/Interfaces/IPlaylistService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface IPlaylistService
Task AddMapToPlaylist(Map map, Playlist playlist, bool loadPlaylists = true);
Task<Playlist> AddPlaylist(EditPlaylistModel editPlaylistModel, IEnumerable<Map>? playlistMaps = null, bool loadPlaylists = true);
Task<Playlist?> AddPlaylistAndDownloadMaps(EditPlaylistModel editPlaylistModel, IEnumerable<Map> playlistMaps, bool loadPlaylists = true, IProgress<ItemProgress<Map>>? progress = null, CancellationToken cancellationToken = default);
Task<Playlist?> AddPlaylistAndDownloadMaps(Playlist playlist, IEnumerable<Map> playlistMaps, bool loadPlaylists = true, IProgress<ItemProgress<Map>>? progress = null, CancellationToken cancellationToken = default);
Task DeletePlaylist(Playlist playlist, bool deleteMaps = false);
Task<IEnumerable<Map>> DownloadPlaylistMapsIfNotExist(IEnumerable<Map> playlistMaps, IProgress<ItemProgress<Map>>? progress = null, bool loadMapInfo = true, CancellationToken cancellationToken = default);
Task<Playlist> EditDynamicPlaylist(EditDynamicPlaylistModel editPlaylistModel);
Expand Down
47 changes: 46 additions & 1 deletion MapMaven.Core/Services/Leaderboards/BeatLeaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public class BeatLeaderService : ILeaderboardProviderService

PlayerScores = playerScores;

PlayerProfile = _playerId
var playerProfile = _playerId
.Select(playerId =>
{
if (string.IsNullOrEmpty(playerId))
Expand All @@ -137,6 +137,7 @@ public class BeatLeaderService : ILeaderboardProviderService
keepOriginalId: false,
leaderboardContext: (ApiClients.BeatLeader.LeaderboardContexts)Models.Data.Leaderboards.BeatLeader.LeaderboardContexts.General
);
return new PlayerProfile(playerProfile);
})
.Catch((Exception exception) =>
Expand All @@ -152,6 +153,50 @@ public class BeatLeaderService : ILeaderboardProviderService
})
.Concat();

var playerHistory = _playerId
.Select(playerId =>
{
if (string.IsNullOrEmpty(playerId))
return Observable.Return(Enumerable.Empty<RankHistoryRecord>());
return Observable.FromAsync(async () =>
{
await _beatLeaderApiLimit;
var history = await _beatLeader.HistoryAsync(
id: playerId,
leaderboardContext: (ApiClients.BeatLeader.LeaderboardContexts)Models.Data.Leaderboards.BeatLeader.LeaderboardContexts.General,
count: 50
);
return history
?.Select(h => new RankHistoryRecord(h))
.OrderBy(h => h.Date) ?? Enumerable.Empty<RankHistoryRecord>();
})
.Catch((Exception exception) =>
{
_applicationEventService.RaiseError(new ErrorEvent
{
Exception = exception,
Message = "Failed to load player history from BeatLeader."
});
return Observable.Return(Enumerable.Empty<RankHistoryRecord>());
});
}).Concat().Replay(1);

playerHistory.Connect();

PlayerProfile = Observable.CombineLatest(playerProfile, playerHistory, (profile, history) =>
{
if (profile is null)
return null;
profile.RankHistory = history ?? Enumerable.Empty<RankHistoryRecord>();
return profile;
});

_rankedMaps = new(GetRankedMaps, TimeSpan.FromHours(6), []);

var playerId = _applicationSettingService.ApplicationSettings
Expand Down
2 changes: 1 addition & 1 deletion MapMaven.Core/Services/Leaderboards/LeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class LeaderboardService : ILeaderboardService
public IObservable<LeaderboardProvider?> ActiveLeaderboardProviderName => _activeLeaderboardProviderName;
public IObservable<IEnumerable<ILeaderboardProviderService>> AvailableLeaderboardProviderServices { get; private set; }

public string? PlayerId => LeaderboardProviders[_activeLeaderboardProviderName.Value].PlayerId;
public string? PlayerId => _activeLeaderboardProviderName.Value is not null ? LeaderboardProviders[_activeLeaderboardProviderName.Value].PlayerId : null;
public LeaderboardProvider? ActiveLeaderboardProviderNameValue => _activeLeaderboardProviderName.Value;

public const string ReplayBaseUrl = "https://replay.beatleader.xyz";
Expand Down
15 changes: 15 additions & 0 deletions MapMaven.Core/Services/MapService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class MapService : IMapService
private readonly BehaviorSubject<IEnumerable<HiddenMap>> _hiddenMaps = new(Enumerable.Empty<HiddenMap>());

public IObservable<IEnumerable<Map>> Maps { get; private set; }
private IEnumerable<Map> _maps { get; set; } = Enumerable.Empty<Map>();
public IObservable<IEnumerable<Map>> RankedMaps { get; private set; }
public IObservable<IEnumerable<Map>> CompleteMapData { get; private set; }
public IObservable<IEnumerable<Map>> CompleteRankedMapData { get; private set; }
Expand Down Expand Up @@ -83,6 +84,8 @@ public class MapService : IMapService
_leaderBoardService.RankedMapScoreEstimates.StartWith(Enumerable.Empty<ScoreEstimate>()),
CombineMapData);

Maps.Subscribe(maps => _maps = maps);

HiddenMaps = Observable.CombineLatest(_hiddenMaps, _leaderBoardService.PlayerProfile, (hiddenMaps, player) =>
{
if (hiddenMaps == null || player == null)
Expand Down Expand Up @@ -287,6 +290,18 @@ public async Task<Map> GetMapDetails(Map map)
return map;
}

public async Task<Map?> GetMapDetails(string mapHash)
{
var beatMap = await _beatSaver.BeatmapByHash(mapHash);

if (beatMap is null)
return null;

return new Map(beatMap);
}

public Map? GetMapById(string mapId) => _maps.FirstOrDefault(m => m.Id == mapId);

public async Task DownloadMap(Map map, bool force = false, IProgress<double>? progress = null, bool loadMapInfo = true, CancellationToken cancellationToken = default)
{
if (!force && MapIsInstalled(map))
Expand Down
5 changes: 5 additions & 0 deletions MapMaven.Core/Services/PlaylistService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ private IPlaylist CreateIPlaylist(EditPlaylistModel editPlaylistModel, IEnumerab
return addedPlaylist;
}

public async Task<Playlist?> AddPlaylistAndDownloadMaps(Playlist playlist, IEnumerable<Map> playlistMaps, bool loadPlaylists = true, IProgress<ItemProgress<Map>>? progress = null, CancellationToken cancellationToken = default)
{
return await AddPlaylistAndDownloadMaps(new EditPlaylistModel(playlist), playlistMaps, loadPlaylists, progress, cancellationToken);
}

public async Task<Playlist?> AddPlaylistAndDownloadMaps(EditPlaylistModel editPlaylistModel, IEnumerable<Map> playlistMaps, bool loadPlaylists = true, IProgress<ItemProgress<Map>>? progress = null, CancellationToken cancellationToken = default)
{
_creatingPlaylist.OnNext(true);
Expand Down
9 changes: 9 additions & 0 deletions MapMaven.Core/Utilities/BeatSaver/MapTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MapMaven.Core.Utilities.BeatSaver
{
public static class MapTag
{
private static readonly string[] DisciplineTags = [ "accuracy", "balanced", "challenge", "dance", "fitness", "speed", "tech" ];

public static bool IsDisciplineTag(string tag) => DisciplineTags.Contains(tag);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RateLimiter" Version="2.2.0" />
</ItemGroup>
Expand Down
Loading

0 comments on commit ea894be

Please sign in to comment.