d85f2e0fb3
Bootstraper läd jetzt die farbeinstellung sofort und nicht nachträglich cleanup and rework PDF switch to HTML export fix Colorsystem Farben für knöpfe hinzugefügt als anpassung button color button color primary and secondary change
87 lines
2.6 KiB
C#
87 lines
2.6 KiB
C#
using cfs_tracker.Helpers;
|
|
using cfs_tracker.Models;
|
|
|
|
namespace cfs_tracker.Services;
|
|
|
|
public class AggregationService
|
|
{
|
|
public AverageStateResult CalculateAverage(IEnumerable<HealthEntry> entries)
|
|
{
|
|
var list = entries?.ToList() ?? new List<HealthEntry>();
|
|
if (list.Count == 0)
|
|
{
|
|
return new AverageStateResult
|
|
{
|
|
HasValue = false,
|
|
AverageScore = 0,
|
|
State = HealthState.Gray
|
|
};
|
|
}
|
|
|
|
var average = list.Average(x => x.State.ToScore());
|
|
|
|
return new AverageStateResult
|
|
{
|
|
HasValue = true,
|
|
AverageScore = average,
|
|
State = average switch
|
|
{
|
|
>= 2.5 => HealthState.Green,
|
|
>= 1.5 => HealthState.Yellow,
|
|
>= 0.5 => HealthState.Red,
|
|
_ => HealthState.Gray
|
|
}
|
|
};
|
|
}
|
|
|
|
public IEnumerable<HealthEntry> FilterForDayPart(IEnumerable<HealthEntry> entries, DayPart part)
|
|
{
|
|
return entries.Where(x =>
|
|
{
|
|
if (x.DayPart.HasValue)
|
|
return x.DayPart == part;
|
|
|
|
return part == DayPart.Morning
|
|
? x.Timestamp.Hour < 12
|
|
: x.Timestamp.Hour >= 12;
|
|
});
|
|
}
|
|
|
|
public string BuildDistinctActivityText(IEnumerable<HealthEntry> entries, IReadOnlyDictionary<int, string> activityMap)
|
|
{
|
|
var names = entries
|
|
.Where(x => x.ActivityId.HasValue)
|
|
.Select(x => x.ActivityId!.Value)
|
|
.Where(activityMap.ContainsKey)
|
|
.Select(x => activityMap[x])
|
|
.Where(x => !string.Equals(x, "Keine Tätigkeit", StringComparison.OrdinalIgnoreCase))
|
|
.Distinct()
|
|
.OrderBy(x => x)
|
|
.ToList();
|
|
|
|
return names.Count == 0 ? string.Empty : string.Join(", ", names);
|
|
}
|
|
|
|
public string BuildDistinctSymptomText(IEnumerable<HealthEntry> entries, IReadOnlyDictionary<int, List<string>> symptomsByEntryId)
|
|
{
|
|
var names = entries
|
|
.Where(x => symptomsByEntryId.ContainsKey(x.Id))
|
|
.SelectMany(x => symptomsByEntryId[x.Id])
|
|
.Distinct()
|
|
.OrderBy(x => x)
|
|
.ToList();
|
|
|
|
return names.Count == 0 ? string.Empty : string.Join(", ", names);
|
|
}
|
|
|
|
public string ToDisplayText(AverageStateResult averageResult, AppearanceService appearanceService)
|
|
{
|
|
if (!averageResult.HasValue)
|
|
return "-";
|
|
|
|
return appearanceService.GetText(
|
|
averageResult.State.ToAppearanceTextKey(),
|
|
averageResult.State.ToFallbackText());
|
|
}
|
|
}
|