Public Access
Implement meeting assistant v1
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
namespace MeetingAssistant.MeetingNotes;
|
||||
|
||||
internal static class OutlookMeetingCandidateSelector
|
||||
{
|
||||
private static readonly TimeSpan MinimumRemainingOverlap = TimeSpan.FromMinutes(5);
|
||||
private static readonly TimeSpan UpcomingStartWindow = TimeSpan.FromMinutes(5);
|
||||
|
||||
public static T? Select<T>(
|
||||
IReadOnlyList<T> candidates,
|
||||
DateTime startedAt,
|
||||
Func<T, DateTime> getStart,
|
||||
Func<T, DateTime> getEnd)
|
||||
where T : class
|
||||
{
|
||||
var goodOverlaps = candidates
|
||||
.Where(candidate =>
|
||||
getStart(candidate) <= startedAt &&
|
||||
getEnd(candidate) >= startedAt.Add(MinimumRemainingOverlap))
|
||||
.ToList();
|
||||
if (goodOverlaps.Count == 1)
|
||||
{
|
||||
return goodOverlaps[0];
|
||||
}
|
||||
|
||||
if (goodOverlaps.Count > 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var upcoming = candidates
|
||||
.Where(candidate =>
|
||||
getStart(candidate) > startedAt &&
|
||||
getStart(candidate) <= startedAt.Add(UpcomingStartWindow))
|
||||
.OrderBy(getStart)
|
||||
.ToList();
|
||||
return upcoming.Count == 1 ? upcoming[0] : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user