Fixed date time assignments when testing ingestions. Added more ingestion tests. Fixed voice work updater bugs.
This commit is contained in:
@@ -161,12 +161,15 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
private void UpsertVoiceWork(VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
{
|
||||
VoiceWork voiceWork = GetOrAddVoiceWork(ingest, upsertContext);
|
||||
VoiceWorkUpsertState state = ComputeVoiceWorkUpsertState(voiceWork, ingest, upsertContext);
|
||||
|
||||
bool isAdded = dbContext.Entry(voiceWork).State == EntityState.Added;
|
||||
bool isWithinCurrentScanAnchor = voiceWork.LastScannedDate == upsertContext.CurrentScanAnchor;
|
||||
bool isNewOnSale = voiceWork.SalesDate is null && ingest.SalesDate is not null;
|
||||
//bool isAdded = dbContext.Entry(voiceWork).State == EntityState.Added;
|
||||
//bool isWithinCurrentScanAnchor = voiceWork.LastScannedDate == upsertContext.CurrentScanAnchor.DateTime;
|
||||
//bool isWithinPreviousScanAnchor = voiceWork.LastScannedDate == upsertContext.PreviousScanAnchor.DateTime;
|
||||
//bool hasGoneOnSale = voiceWork.SalesDate is null && ingest.SalesDate is not null;
|
||||
|
||||
bool isNew = isAdded || isWithinCurrentScanAnchor || isNewOnSale;
|
||||
//bool isNewUpcoming = ingest.SalesDate is null && (isAdded || isWithinCurrentScanAnchor || (isWithinPreviousScanAnchor && upsertContext.PreviousScanAnchor.DateTime.Hour == 16));
|
||||
//bool isNewOnSale = ingest.SalesDate is not null && (isAdded || hasGoneOnSale || isWithinCurrentScanAnchor);
|
||||
|
||||
voiceWork.Circle = upsertContext.Circles[ingest.MakerId];
|
||||
voiceWork.ProductName = ingest.Title;
|
||||
@@ -180,20 +183,21 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
voiceWork.StarRating = ingest.StarRating;
|
||||
voiceWork.Votes = ingest.Votes;
|
||||
voiceWork.IsValid = true;
|
||||
voiceWork.LastScannedDate = ComputeLastScannedDate(voiceWork.LastScannedDate, state, upsertContext);
|
||||
|
||||
if (ingest.SalesDate.HasValue)
|
||||
{
|
||||
voiceWork.SalesDate = ingest.SalesDate.Value.ToDateTime(new TimeOnly(0, 0));
|
||||
voiceWork.ExpectedDate = null;
|
||||
voiceWork.PlannedReleaseDate = null;
|
||||
voiceWork.Status = isNew ? (byte)VoiceWorkStatus.NewRelease : (byte)VoiceWorkStatus.Available;
|
||||
voiceWork.Status = state.IsNewOnSale ? (byte)VoiceWorkStatus.NewRelease : (byte)VoiceWorkStatus.Available;
|
||||
}
|
||||
else
|
||||
{
|
||||
voiceWork.SalesDate = null;
|
||||
voiceWork.ExpectedDate = ingest.ExpectedDate?.ToDateTime(new TimeOnly(0, 0));
|
||||
voiceWork.PlannedReleaseDate = ingest.RegistrationDate > upsertContext.CurrentScanAnchor ? ingest.RegistrationDate : null;
|
||||
voiceWork.Status = isNew ? (byte)VoiceWorkStatus.NewAndUpcoming : (byte)VoiceWorkStatus.Upcoming;
|
||||
voiceWork.Status = state.IsNewUpcoming ? (byte)VoiceWorkStatus.NewAndUpcoming : (byte)VoiceWorkStatus.Upcoming;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +217,52 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
return voiceWork;
|
||||
}
|
||||
|
||||
private sealed record VoiceWorkUpsertState(
|
||||
bool IsAdded,
|
||||
bool ScannedThisAnchor,
|
||||
bool ScannedPrevAt4pm,
|
||||
bool WentOnSale,
|
||||
bool HasSalesDate,
|
||||
bool IsNewUpcoming,
|
||||
bool IsNewOnSale
|
||||
);
|
||||
|
||||
private VoiceWorkUpsertState ComputeVoiceWorkUpsertState(VoiceWork voiceWork, VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
{
|
||||
bool isAdded = dbContext.Entry(voiceWork).State == EntityState.Added;
|
||||
|
||||
DateTime currentScanAnchor = upsertContext.CurrentScanAnchor.DateTime;
|
||||
DateTime previousScanAnchor = upsertContext.PreviousScanAnchor.DateTime;
|
||||
|
||||
bool scannedThis = voiceWork.LastScannedDate == currentScanAnchor;
|
||||
bool scannedPrevAt4pm = voiceWork.LastScannedDate == previousScanAnchor && previousScanAnchor.Hour == 16;
|
||||
bool hasSales = ingest.SalesDate is not null;
|
||||
bool wentOnSale = voiceWork.SalesDate is null && hasSales;
|
||||
|
||||
bool isNewUpcoming = !hasSales && (isAdded || scannedThis || scannedPrevAt4pm);
|
||||
bool isNewOnSale = hasSales && (isAdded || wentOnSale || scannedThis);
|
||||
|
||||
return new VoiceWorkUpsertState(
|
||||
IsAdded: isAdded,
|
||||
ScannedThisAnchor: scannedThis,
|
||||
ScannedPrevAt4pm: scannedPrevAt4pm,
|
||||
WentOnSale: wentOnSale,
|
||||
HasSalesDate: hasSales,
|
||||
IsNewUpcoming: isNewUpcoming,
|
||||
IsNewOnSale: isNewOnSale
|
||||
);
|
||||
}
|
||||
|
||||
private static DateTime? ComputeLastScannedDate(DateTime? existing, VoiceWorkUpsertState state, VoiceWorkUpsertContext upsertContext)
|
||||
{
|
||||
if ((state.IsNewUpcoming || state.IsNewOnSale) == false)
|
||||
return null;
|
||||
|
||||
var current = upsertContext.CurrentScanAnchor.DateTime;
|
||||
|
||||
return state.WentOnSale ? current : existing ?? current;
|
||||
}
|
||||
|
||||
private void UpsertTags(VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
{
|
||||
foreach (string tagName in ingest.Tags)
|
||||
|
||||
Reference in New Issue
Block a user