Skip to content

Commit

Permalink
Manager: Add historical (un)availability to weekly clears
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel committed Mar 12, 2024
1 parent 1c6627a commit c8ebbaa
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 181 deletions.
8 changes: 8 additions & 0 deletions ArcdpsLogManager/Sections/Clears/EncounterAvailability.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace GW2Scratch.ArcdpsLogManager.Sections.Clears;

public enum EncounterAvailability
{
Available,
DoesNotExist,
NotLogged,
}
67 changes: 2 additions & 65 deletions ArcdpsLogManager/Sections/Clears/IFinishableEncounter.cs
Original file line number Diff line number Diff line change
@@ -1,77 +1,14 @@
using GW2Scratch.ArcdpsLogManager.Logs;
using GW2Scratch.EVTCAnalytics.GameData.Encounters;
using GW2Scratch.EVTCAnalytics.Processing.Encounters.Modes;
using GW2Scratch.EVTCAnalytics.Processing.Encounters.Results;
using System;
using System.Collections.Generic;
using System.Linq;

namespace GW2Scratch.ArcdpsLogManager.Sections.Clears;

public interface IFinishableEncounter
{
bool IsSatisfiedBy(IEnumerable<LogData> logs);
bool IsChallengeModeSatisfiedBy(IEnumerable<LogData> logs);
bool HasNormalMode { get; }
bool HasChallengeMode { get; }
EncounterAvailability GetNormalModeAvailability(DateOnly resetDate);
EncounterAvailability GetChallengeModeAvailability(DateOnly resetDate);
Category Category { get; }
}

public class NormalEncounter(Encounter encounter, bool hasChallengeMode, Category category) : IFinishableEncounter
{
public Encounter Encounter { get; } = encounter;
public bool HasNormalMode => true;
public bool HasChallengeMode { get; } = hasChallengeMode;
public Category Category { get; } = category;

public bool IsSatisfiedBy(IEnumerable<LogData> logs)
{
return logs.Any(log => log.ParsingStatus == ParsingStatus.Parsed && log.EncounterResult == EncounterResult.Success && log.Encounter == Encounter);
}

public bool IsChallengeModeSatisfiedBy(IEnumerable<LogData> logs)
{
return logs.Any(log => log.ParsingStatus == ParsingStatus.Parsed && log.EncounterResult == EncounterResult.Success && log.Encounter == Encounter &&
log.EncounterMode == EncounterMode.Challenge);
}
}

public class UnsupportedEncounter(string name, Category category) : IFinishableEncounter
{
public string Name { get; } = name;
public bool HasNormalMode => false;
public bool HasChallengeMode => false;
public Category Category { get; } = category;

public bool IsSatisfiedBy(IEnumerable<LogData> logs)
{
throw new NotSupportedException();
}

public bool IsChallengeModeSatisfiedBy(IEnumerable<LogData> logs)
{
throw new NotSupportedException();
}
}

public class MultipartEncounter(string name, IEnumerable<Encounter> encounters, bool hasChallengeMode, Category category) : IFinishableEncounter
{
public string Name { get; } = name;
private IEnumerable<Encounter> Encounters { get; } = encounters;
public bool HasNormalMode => true;
public bool HasChallengeMode { get; } = hasChallengeMode;
public Category Category { get; } = category;

public bool IsSatisfiedBy(IEnumerable<LogData> logs)
{
return Encounters.All(encounter => logs.Any(log =>
log.ParsingStatus == ParsingStatus.Parsed && log.EncounterResult == EncounterResult.Success && log.Encounter == encounter));
}

public bool IsChallengeModeSatisfiedBy(IEnumerable<LogData> logs)
{
return Encounters.All(encounter => logs.Any(log =>
log.ParsingStatus == ParsingStatus.Parsed && log.EncounterResult == EncounterResult.Success && log.Encounter == encounter &&
log.EncounterMode == EncounterMode.Challenge));
}
}
63 changes: 63 additions & 0 deletions ArcdpsLogManager/Sections/Clears/MultipartEncounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using GW2Scratch.ArcdpsLogManager.Logs;
using GW2Scratch.EVTCAnalytics.GameData.Encounters;
using GW2Scratch.EVTCAnalytics.Processing.Encounters.Modes;
using GW2Scratch.EVTCAnalytics.Processing.Encounters.Results;
using System;
using System.Collections.Generic;
using System.Linq;

namespace GW2Scratch.ArcdpsLogManager.Sections.Clears;

public class MultipartEncounter : IFinishableEncounter
{
private readonly DateOnly? normalModeSince;
private readonly DateOnly? challengeModeSince;

public MultipartEncounter(string name, IEnumerable<Encounter> encounters, Category category, DateOnly? normalModeSince, DateOnly? challengeModeSince)
{
if (normalModeSince.HasValue && normalModeSince.Value.DayOfWeek != DayOfWeek.Monday)
{
throw new ArgumentException("Normal mode reset date must be a Monday.", nameof(normalModeSince));
}

if (challengeModeSince.HasValue && challengeModeSince.Value.DayOfWeek != DayOfWeek.Monday)
{
throw new ArgumentException("Challenge mode reset date must be a Monday.", nameof(challengeModeSince));
}

this.normalModeSince = normalModeSince;
this.challengeModeSince = challengeModeSince;
Name = name;
Encounters = encounters;
Category = category;
}

public string Name { get; }
private IEnumerable<Encounter> Encounters { get; }
public Category Category { get; }

public EncounterAvailability GetNormalModeAvailability(DateOnly resetDate)
{
if (normalModeSince == null) return EncounterAvailability.NotLogged;
return resetDate < normalModeSince ? EncounterAvailability.DoesNotExist : EncounterAvailability.Available;
}

public EncounterAvailability GetChallengeModeAvailability(DateOnly resetDate)
{
if (challengeModeSince == null) return EncounterAvailability.NotLogged;
return resetDate < challengeModeSince ? EncounterAvailability.DoesNotExist : EncounterAvailability.Available;
}

public bool IsSatisfiedBy(IEnumerable<LogData> logs)
{
return Encounters.All(encounter => logs.Any(log =>
log.ParsingStatus == ParsingStatus.Parsed && log.EncounterResult == EncounterResult.Success && log.Encounter == encounter));
}

public bool IsChallengeModeSatisfiedBy(IEnumerable<LogData> logs)
{
return Encounters.All(encounter => logs.Any(log =>
log.ParsingStatus == ParsingStatus.Parsed && log.EncounterResult == EncounterResult.Success && log.Encounter == encounter &&
log.EncounterMode == EncounterMode.Challenge));
}
}
76 changes: 76 additions & 0 deletions ArcdpsLogManager/Sections/Clears/NormalEncounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using GW2Scratch.ArcdpsLogManager.Logs;
using GW2Scratch.EVTCAnalytics.GameData.Encounters;
using GW2Scratch.EVTCAnalytics.Processing.Encounters.Modes;
using GW2Scratch.EVTCAnalytics.Processing.Encounters.Results;
using System;
using System.Collections.Generic;
using System.Linq;

namespace GW2Scratch.ArcdpsLogManager.Sections.Clears;

public class NormalEncounter : IFinishableEncounter
{
private readonly DateOnly? normalModeSince;
private readonly DateOnly? challengeModeSince;
private readonly DateOnly? logsSince;

public NormalEncounter(Encounter encounter, Category category, DateOnly? normalModeSince, DateOnly? challengeModeSince, DateOnly? logsSince = null)
{
if (normalModeSince.HasValue && normalModeSince.Value.DayOfWeek != DayOfWeek.Monday)
{
throw new ArgumentException("Normal mode reset date must be a Monday.", nameof(normalModeSince));
}

if (challengeModeSince.HasValue && challengeModeSince.Value.DayOfWeek != DayOfWeek.Monday)
{
throw new ArgumentException("Challenge mode reset date must be a Monday.", nameof(challengeModeSince));
}

if (logsSince.HasValue && logsSince.Value.DayOfWeek != DayOfWeek.Monday)
{
throw new ArgumentException("Logs since date must be a Monday.", nameof(logsSince));
}

this.normalModeSince = normalModeSince;
this.challengeModeSince = challengeModeSince;
this.logsSince = logsSince;
Encounter = encounter;
Category = category;
}

public Encounter Encounter { get; }

public EncounterAvailability GetNormalModeAvailability(DateOnly resetDate)
{
if (normalModeSince == null) return EncounterAvailability.DoesNotExist;
if (resetDate < normalModeSince)
{
return EncounterAvailability.DoesNotExist;
}

return resetDate < logsSince ? EncounterAvailability.NotLogged : EncounterAvailability.Available;
}

public EncounterAvailability GetChallengeModeAvailability(DateOnly resetDate)
{
if (challengeModeSince == null) return EncounterAvailability.DoesNotExist;
if (resetDate < challengeModeSince)
{
return EncounterAvailability.DoesNotExist;
}
return resetDate < logsSince ? EncounterAvailability.NotLogged : EncounterAvailability.Available;
}

public Category Category { get; }

public bool IsSatisfiedBy(IEnumerable<LogData> logs)
{
return logs.Any(log => log.ParsingStatus == ParsingStatus.Parsed && log.EncounterResult == EncounterResult.Success && log.Encounter == Encounter);
}

public bool IsChallengeModeSatisfiedBy(IEnumerable<LogData> logs)
{
return logs.Any(log => log.ParsingStatus == ParsingStatus.Parsed && log.EncounterResult == EncounterResult.Success && log.Encounter == Encounter &&
log.EncounterMode == EncounterMode.Challenge);
}
}
17 changes: 17 additions & 0 deletions ArcdpsLogManager/Sections/Clears/UnsupportedEncounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using GW2Scratch.ArcdpsLogManager.Logs;
using System;
using System.Collections.Generic;

namespace GW2Scratch.ArcdpsLogManager.Sections.Clears;

public class UnsupportedEncounter(string name, Category category) : IFinishableEncounter
{
public EncounterAvailability GetNormalModeAvailability(DateOnly resetDate) => EncounterAvailability.NotLogged;
public EncounterAvailability GetChallengeModeAvailability(DateOnly resetDate) => EncounterAvailability.NotLogged;

public string Name { get; } = name;
public Category Category { get; } = category;

public bool IsSatisfiedBy(IEnumerable<LogData> logs) => false;
public bool IsChallengeModeSatisfiedBy(IEnumerable<LogData> logs) => false;
}
Loading

0 comments on commit c8ebbaa

Please sign in to comment.