✨ Improvements, new data in rewind point
🐛 Fix most called rewind point unable to get real data
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
using NodaTime.TimeZones;
|
||||
|
||||
namespace DysonNetwork.Pass.Rewind;
|
||||
|
||||
@@ -15,6 +17,32 @@ public class PassRewindService(AppDatabase db)
|
||||
var startDate = new LocalDate(year - 1, 12, 26).AtMidnight().InUtc().ToInstant();
|
||||
var endDate = new LocalDate(year, 12, 26).AtMidnight().InUtc().ToInstant();
|
||||
|
||||
var timeZone = (await db.AccountProfiles
|
||||
.Where(p => p.AccountId == accountId)
|
||||
.FirstOrDefaultAsync())?.TimeZone;
|
||||
|
||||
var zone = TimeZoneInfo.Utc;
|
||||
if (!string.IsNullOrEmpty(timeZone))
|
||||
try
|
||||
{
|
||||
zone = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
|
||||
}
|
||||
catch (DateTimeZoneNotFoundException)
|
||||
{
|
||||
// use UTC
|
||||
}
|
||||
|
||||
var newFriendsCount = await db.AccountRelationships
|
||||
.Where(r => r.CreatedAt >= startDate && r.CreatedAt < endDate)
|
||||
.Where(r => r.AccountId == accountId)
|
||||
.Where(r => r.Status == RelationshipStatus.Friends)
|
||||
.CountAsync();
|
||||
var newBlockedCount = await db.AccountRelationships
|
||||
.Where(r => r.CreatedAt >= startDate && r.CreatedAt < endDate)
|
||||
.Where(r => r.AccountId == accountId)
|
||||
.Where(r => r.Status == RelationshipStatus.Blocked)
|
||||
.CountAsync();
|
||||
|
||||
var checkInDates = await db.AccountCheckInResults
|
||||
.Where(a => a.CreatedAt >= startDate && a.CreatedAt < endDate)
|
||||
.Where(a => a.AccountId == accountId)
|
||||
@@ -53,13 +81,28 @@ public class PassRewindService(AppDatabase db)
|
||||
.OrderByDescending(g => g.Count)
|
||||
.FirstOrDefault();
|
||||
|
||||
var actionTimes = await db.ActionLogs
|
||||
.Where(a => a.CreatedAt >= startDate && a.CreatedAt < endDate)
|
||||
.Where(a => a.AccountId == accountId)
|
||||
.Select(a => a.CreatedAt.ToDateTimeUtc())
|
||||
.ToListAsync();
|
||||
var actionTimes = actionDates
|
||||
.Select(a => TimeZoneInfo.ConvertTimeFromUtc(a, zone).TimeOfDay)
|
||||
.ToList();
|
||||
|
||||
TimeSpan? latestActiveTime = actionTimes.Any() ? actionTimes.Max(dt => dt.TimeOfDay) : null;
|
||||
TimeSpan? latestActiveTime = null;
|
||||
if (actionTimes.Count != 0)
|
||||
{
|
||||
var timesBefore6Am = actionTimes.Where(t => t < TimeSpan.FromHours(6)).ToList();
|
||||
latestActiveTime = timesBefore6Am.Count != 0 ? timesBefore6Am.Max() : actionTimes.Max();
|
||||
}
|
||||
|
||||
var lotteriesQuery = db.Lotteries
|
||||
.Where(l => l.CreatedAt >= startDate && l.CreatedAt < endDate)
|
||||
.Where(l => l.AccountId == accountId)
|
||||
.AsQueryable();
|
||||
var lotteriesWins = await lotteriesQuery
|
||||
.Where(l => l.MatchedRegionOneNumbers != null && l.MatchedRegionOneNumbers.Count > 0)
|
||||
.CountAsync();
|
||||
var lotteriesLosses = await lotteriesQuery
|
||||
.Where(l => l.MatchedRegionOneNumbers == null || l.MatchedRegionOneNumbers.Count == 0)
|
||||
.CountAsync();
|
||||
var lotteriesWinRate = lotteriesWins / (double)(lotteriesWins + lotteriesLosses);
|
||||
|
||||
var data = new Dictionary<string, object?>
|
||||
{
|
||||
@@ -68,8 +111,13 @@ public class PassRewindService(AppDatabase db)
|
||||
["most_active_day"] = mostActiveDay?.Date.ToString("yyyy-MM-dd"),
|
||||
["most_active_weekday"] = mostActiveWeekday?.Day.ToString(),
|
||||
["latest_active_time"] = latestActiveTime?.ToString(@"hh\:mm"),
|
||||
["new_friends_count"] = newFriendsCount,
|
||||
["new_blocked_count"] = newBlockedCount,
|
||||
["lotteries_wins"] = lotteriesWins,
|
||||
["lotteries_losses"] = lotteriesLosses,
|
||||
["lotteries_win_rate"] = lotteriesWinRate,
|
||||
};
|
||||
|
||||
|
||||
return new RewindEvent
|
||||
{
|
||||
ServiceId = "pass",
|
||||
|
||||
Reference in New Issue
Block a user