public WorkTimeAnalyzerTest() { workTimeAnalyzer = new WorkTimeAnalyzer((eventToJudge, date) => { return(eventToJudge.DateTimeInstant < date.AddDays(1).AddHours(4)); }); foreach (var workEvent in workEvents) { workTimeAnalyzer.AddWorkEvent(workEvent); } }
//todo REFACTOR public async Task <Result <ShortWorkSummary> > Handle(GetShortWorkSummaryOfEmployeeQuery request, CancellationToken cancellationToken) { DateTime fromInclusiveUtc = request.FromInclusive.ToUniversalTime(); DateTime toInclusiveUtc = request.ToInclusive.ToUniversalTime(); var result = await persistWorkEventPort.GetWorkEventsOfEmployeeBetweenAsync( request.EmployeeId, fromInclusiveUtc, toInclusiveUtc); if (result.IsFailed) { return(result.ToResult <ShortWorkSummary>()); } var workEvents = result.Value; WorkTimeAnalyzer workTimeAnalyzer = new WorkTimeAnalyzer(workDayEndsAt_3am); foreach (var workEvent in workEvents) { workTimeAnalyzer.AddWorkEvent(workEvent); } var workDurations = workTimeAnalyzer.GetWorkDurations(); ShortWorkSummary shortWorkSummary = new ShortWorkSummary(fromInclusiveUtc, toInclusiveUtc); TimeSpan workDurationSum = TimeSpan.Zero; foreach (var workDuration in workDurations) { shortWorkSummary.SetStatusOfDay(workDuration.StartDateTimeInstant.Value.ToUniversalTime(), workDuration.Completed ? ShortWorkSummary.DayStatus.PRESENCE : ShortWorkSummary.DayStatus.PROBLEM); TimeSpan?timeSpan = workDuration.AsTimeSpan(); if (timeSpan.HasValue) { workDurationSum = workDurationSum.Add(timeSpan.Value); } } shortWorkSummary.MinutesOfWork = (uint)workDurationSum.TotalMinutes; return(Result.Ok(shortWorkSummary)); }
public async Task <Result <DetailedWorkSummary> > Handle(GetDetailedWorkSummaryOfEmployeeQuery request, CancellationToken cancellationToken) { DateTime fromInclusiveUtc = request.FromInclusive.ToUniversalTime(); DateTime toInclusiveUtc = request.ToInclusive.ToUniversalTime(); var result = await persistWorkEventPort.GetWorkEventsOfEmployeeBetweenAsync( request.EmployeeId, fromInclusiveUtc, toInclusiveUtc); if (result.IsFailed) { return(result.ToResult <DetailedWorkSummary>()); } var workEvents = result.Value; WorkTimeAnalyzer workTimeAnalyzer = new WorkTimeAnalyzer(workDayEndsAt_3am); foreach (var workEvent in workEvents) { workTimeAnalyzer.AddWorkEvent(workEvent); } var workDurations = workTimeAnalyzer.GetWorkDurations(); DetailedWorkSummary detailedWorkSummary = new DetailedWorkSummary( fromInclusiveUtc, toInclusiveUtc, workDurations); TimeSpan workDurationSum = TimeSpan.Zero; foreach (var workDuration in workDurations) { TimeSpan?timeSpan = workDuration.AsTimeSpan(); if (timeSpan.HasValue) { workDurationSum = workDurationSum.Add(timeSpan.Value); } } detailedWorkSummary.MinutesOfWork = (uint)workDurationSum.TotalMinutes; return(Result.Ok(detailedWorkSummary)); }