Layout and Push Fix
This commit is contained in:
@@ -107,10 +107,10 @@ public sealed class PdfExportService : IPdfExportService
|
||||
var currentDay = weekStart.AddDays(i).Date;
|
||||
var dayEntries = entries.Where(x => x.EntryDate.Date == currentDay).OrderBy(x => x.Timestamp).ToList();
|
||||
|
||||
var averageState = CalculateAverageState(dayEntries);
|
||||
var worstState = CalculateWorstState(dayEntries);
|
||||
var statusText = dayEntries.Count == 0
|
||||
? "—"
|
||||
: $"{GetStateText(averageState!.Value)} ({dayEntries.Count})";
|
||||
: $"{GetStateText(worstState!.Value)} ({dayEntries.Count})";
|
||||
|
||||
var activities = dayEntries
|
||||
.Where(x => x.ActivityId.HasValue)
|
||||
@@ -128,8 +128,8 @@ public sealed class PdfExportService : IPdfExportService
|
||||
sb.AppendLine("<tr>");
|
||||
sb.AppendLine($"<td>{Encode(currentDay.ToString("ddd, dd.MM.yyyy"))}</td>");
|
||||
sb.AppendLine($"<td>{dayEntries.Count}</td>");
|
||||
sb.AppendLine(averageState.HasValue
|
||||
? StateCell(averageState.Value, statusText)
|
||||
sb.AppendLine(worstState.HasValue
|
||||
? StateCell(worstState.Value, statusText)
|
||||
: "<td>—</td>");
|
||||
sb.AppendLine($"<td>{Encode(activities.Count > 0 ? string.Join(", ", activities) : "—")}</td>");
|
||||
sb.AppendLine($"<td>{Encode(symptoms.Count > 0 ? string.Join(", ", symptoms) : "—")}</td>");
|
||||
@@ -175,10 +175,10 @@ public sealed class PdfExportService : IPdfExportService
|
||||
var currentDay = new DateTime(year, month, day);
|
||||
var dayEntries = entries.Where(x => x.EntryDate.Date == currentDay.Date).OrderBy(x => x.Timestamp).ToList();
|
||||
|
||||
var averageState = CalculateAverageState(dayEntries);
|
||||
var worstState = CalculateWorstState(dayEntries);
|
||||
var statusText = dayEntries.Count == 0
|
||||
? "—"
|
||||
: GetStateText(averageState!.Value);
|
||||
: GetStateText(worstState!.Value);
|
||||
|
||||
var activities = dayEntries
|
||||
.Where(x => x.ActivityId.HasValue)
|
||||
@@ -196,8 +196,8 @@ public sealed class PdfExportService : IPdfExportService
|
||||
sb.AppendLine("<tr>");
|
||||
sb.AppendLine($"<td class=\"compact-day\">{Encode(currentDay.ToString("dd.MM."))}</td>");
|
||||
sb.AppendLine($"<td class=\"compact-count\">{dayEntries.Count}</td>");
|
||||
sb.AppendLine(averageState.HasValue
|
||||
? StateCellCompact(averageState.Value, statusText)
|
||||
sb.AppendLine(worstState.HasValue
|
||||
? StateCellCompact(worstState.Value, statusText)
|
||||
: "<td>—</td>");
|
||||
sb.AppendLine($"<td class=\"compact-activity\">{Encode(activities.Count > 0 ? string.Join(", ", activities) : "—")}</td>");
|
||||
sb.AppendLine($"<td class=\"compact-symptoms\">{Encode(symptoms.Count > 0 ? string.Join(", ", symptoms) : "—")}</td>");
|
||||
@@ -236,11 +236,11 @@ public sealed class PdfExportService : IPdfExportService
|
||||
.ToList();
|
||||
|
||||
var monthDate = new DateTime(year, month, 1);
|
||||
var averageState = CalculateAverageState(monthEntries);
|
||||
var worstState = CalculateWorstState(monthEntries);
|
||||
|
||||
var statusText = monthEntries.Count == 0
|
||||
? "—"
|
||||
: $"{GetStateText(averageState!.Value)} ({monthEntries.Count})";
|
||||
: $"{GetStateText(worstState!.Value)} ({monthEntries.Count})";
|
||||
|
||||
var activities = monthEntries
|
||||
.Where(x => x.ActivityId.HasValue)
|
||||
@@ -258,8 +258,8 @@ public sealed class PdfExportService : IPdfExportService
|
||||
sb.AppendLine("<tr>");
|
||||
sb.AppendLine($"<td>{Encode(monthDate.ToString("MMMM"))}</td>");
|
||||
sb.AppendLine($"<td>{monthEntries.Count}</td>");
|
||||
sb.AppendLine(averageState.HasValue
|
||||
? StateCell(averageState.Value, statusText)
|
||||
sb.AppendLine(worstState.HasValue
|
||||
? StateCell(worstState.Value, statusText)
|
||||
: "<td>—</td>");
|
||||
sb.AppendLine($"<td>{Encode(activities.Count > 0 ? string.Join(", ", activities) : "—")}</td>");
|
||||
sb.AppendLine($"<td>{Encode(symptoms.Count > 0 ? string.Join(", ", symptoms) : "—")}</td>");
|
||||
@@ -384,32 +384,23 @@ public sealed class PdfExportService : IPdfExportService
|
||||
return date.Date.AddDays(-diff);
|
||||
}
|
||||
|
||||
private static HealthState? CalculateAverageState(IReadOnlyCollection<HealthEntry> entries)
|
||||
private static HealthState? CalculateWorstState(IReadOnlyCollection<HealthEntry> entries)
|
||||
{
|
||||
if (entries.Count == 0)
|
||||
return null;
|
||||
|
||||
var average = entries.Average(x => StateToNumber(x.State));
|
||||
var rounded = (int)Math.Round(average, MidpointRounding.AwayFromZero);
|
||||
if (entries.Any(x => x.State == HealthState.Gray))
|
||||
return HealthState.Gray;
|
||||
|
||||
return rounded switch
|
||||
{
|
||||
<= 0 => HealthState.Green,
|
||||
1 => HealthState.Yellow,
|
||||
2 => HealthState.Red,
|
||||
_ => HealthState.Gray
|
||||
};
|
||||
if (entries.Any(x => x.State == HealthState.Red))
|
||||
return HealthState.Red;
|
||||
|
||||
if (entries.Any(x => x.State == HealthState.Yellow))
|
||||
return HealthState.Yellow;
|
||||
|
||||
return HealthState.Green;
|
||||
}
|
||||
|
||||
private static int StateToNumber(HealthState state) => state switch
|
||||
{
|
||||
HealthState.Green => 0,
|
||||
HealthState.Yellow => 1,
|
||||
HealthState.Red => 2,
|
||||
HealthState.Gray => 3,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
private static string ToCssHex(Color color)
|
||||
{
|
||||
var r = (int)Math.Round(color.Red * 255);
|
||||
|
||||
Reference in New Issue
Block a user