Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refine wrapped stats copy

laurenspriem12eba26a3dbf
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/stats_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/stats_candidate_builder.dart
index 51a701daf3..5d25078987 100644
--- a/mobile/apps/photos/lib/services/wrapped/builders/stats_candidate_builder.dart
+++ b/mobile/apps/photos/lib/services/wrapped/builders/stats_candidate_builder.dart
@@ -124,32 +124,42 @@ class StatsCandidateBuilder extends WrappedCandidateBuilder {
final DateFormat monthFormat = DateFormat("MMMM");
final String baseSentence =
- "You averaged ${averageFormat.format(snapshot.averagePerDay)} memories a day.";
+ "You averaged ${averageFormat.format(snapshot.averagePerDay)} memories a day";
String? busiestMonthName;
- String? secondSentence;
if (snapshot.busiestMonth != null && snapshot.busiestMonthCount > 0) {
busiestMonthName = monthFormat
.format(DateTime(snapshot.year, snapshot.busiestMonth!, 1));
}
- if (busiestMonthName != null && snapshot.longestStreakDays >= 1) {
- secondSentence =
- "$busiestMonthName peaked at ${numberFormat.format(snapshot.busiestMonthCount)} memories, and your longest streak ran ${numberFormat.format(snapshot.longestStreakDays)} days.";
- } else if (busiestMonthName != null) {
- secondSentence =
- "$busiestMonthName peaked at ${numberFormat.format(snapshot.busiestMonthCount)} memories.";
- } else if (snapshot.longestStreakDays >= 1) {
- secondSentence =
- "Your longest streak ran ${numberFormat.format(snapshot.longestStreakDays)} days.";
+ String? topFormatLabel;
+ int topFormatCount = 0;
+ snapshot.formatCounts.forEach((String format, int count) {
+ if (count > topFormatCount ||
+ (count == topFormatCount &&
+ topFormatLabel != null &&
+ format.compareTo(topFormatLabel!) < 0)) {
+ topFormatLabel = format;
+ topFormatCount = count;
+ }
+ });
+ if (topFormatLabel != null && topFormatCount <= 0) {
+ topFormatLabel = null;
}
final List<String> chips = _cleanChips(<String>[
- "Active days: ${numberFormat.format(snapshot.daysWithCaptures)}",
+ if (busiestMonthName != null && snapshot.busiestMonthCount > 0)
+ "$busiestMonthName: ${numberFormat.format(snapshot.busiestMonthCount)}",
if (snapshot.longestGapDays >= 2)
"Longest breather: ${numberFormat.format(snapshot.longestGapDays)} days",
+ if (topFormatLabel != null)
+ "$topFormatLabel: ${numberFormat.format(topFormatCount)}",
]);
const List<MediaRef> media = <MediaRef>[];
+ final String subtitle = topFormatLabel != null
+ ? "$baseSentence, and $topFormatLabel was your format of choice."
+ : "$baseSentence.";
+
final Map<String, Object?> meta = <String, Object?>{
"year": snapshot.year,
"averagePerDay": snapshot.averagePerDay,
@@ -181,9 +191,7 @@ class StatsCandidateBuilder extends WrappedCandidateBuilder {
return WrappedCard(
type: WrappedCardType.statsVelocity,
title: "Daily groove",
- subtitle: secondSentence != null
- ? "$baseSentence $secondSentence"
- : baseSentence,
+ subtitle: subtitle,
media: media,
meta: meta
..addAll(
@@ -255,22 +263,66 @@ class StatsCandidateBuilder extends WrappedCandidateBuilder {
}
final NumberFormat numberFormat = NumberFormat.decimalPattern();
+ final DateFormat weekStartFormat = DateFormat("MMM d");
+ DateTime? peakWeekStart;
+ int peakWeekCount = 0;
+ for (int index = 0;
+ index < snapshot.heatmapRows.length &&
+ index < snapshot.heatmapWeekStartDates.length;
+ index += 1) {
+ final List<int> week = snapshot.heatmapRows[index];
+ final int weekTotal =
+ week.fold<int>(0, (int sum, int value) => sum + math.max(0, value));
+ final DateTime weekStart = snapshot.heatmapWeekStartDates[index];
+ if (weekTotal > peakWeekCount ||
+ (weekTotal == peakWeekCount &&
+ (peakWeekStart == null || weekStart.isBefore(peakWeekStart)))) {
+ peakWeekCount = weekTotal;
+ peakWeekStart = weekStart;
+ }
+ }
+ DateTime? displayWeekStart;
+ if (peakWeekStart != null) {
+ final DateTime yearStart = DateTime(snapshot.year, 1, 1);
+ final DateTime yearEnd = DateTime(snapshot.year, 12, 31);
+ final DateTime weekBase = peakWeekStart;
+ displayWeekStart = weekBase;
+ if (displayWeekStart.isBefore(yearStart) ||
+ displayWeekStart.isAfter(yearEnd)) {
+ for (int offset = 0; offset < 7; offset += 1) {
+ final DateTime candidate =
+ _atLocalMidnight(weekBase.add(Duration(days: offset)));
+ if (!candidate.isBefore(yearStart) && !candidate.isAfter(yearEnd)) {
+ displayWeekStart = candidate;
+ break;
+ }
+ }
+ }
+ }
+ String formatDayCount(int value) {
+ final String formatted = numberFormat.format(value);
+ return value == 1 ? "$formatted day" : "$formatted days";
+ }
+
+ final List<String> detailChips = _cleanChips(<String>[
+ if (displayWeekStart != null)
+ "Peak week: ${weekStartFormat.format(displayWeekStart)} Β· ${numberFormat.format(peakWeekCount)}",
+ "Longest streak: ${formatDayCount(snapshot.longestStreakDays)}",
+ "Longest pause: ${formatDayCount(snapshot.longestGapDays)}",
+ "Active days: ${numberFormat.format(snapshot.daysWithCaptures)}",
+ ]);
final Map<String, Object?> meta = <String, Object?>{
"weekdayLabels": snapshot.heatmapWeekdayLabels,
"quarters": quarterBlocks,
"maxCount": snapshot.heatmapMaxCount,
- "detailChips": <String>[
- if (snapshot.busiestMonthName != null)
- "Peak month: ${snapshot.busiestMonthName}",
- "Total captures: ${numberFormat.format(snapshot.totalCount)}",
- ],
+ "detailChips": detailChips,
};
return <WrappedCard>[
WrappedCard(
type: WrappedCardType.statsHeatmap,
title: "Season rhythm",
- subtitle: "Quarter by quarter, here's how the year flowed.",
+ subtitle: "Week by week, here's how the year flowed.",
meta: meta,
),
];
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/shared_widgets.dart b/mobile/apps/photos/lib/ui/wrapped/cards/shared_widgets.dart
index 79e06635c8..6bff8e905e 100644
--- a/mobile/apps/photos/lib/ui/wrapped/cards/shared_widgets.dart
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/shared_widgets.dart
@@ -183,46 +183,6 @@ class _HeroMediaCollage extends StatelessWidget {
}
}
-class _MediaRow extends StatelessWidget {
- const _MediaRow({
- required this.media,
- required this.colorScheme,
- });
-
- final List<MediaRef> media;
- final EnteColorScheme colorScheme;
-
- @override
- Widget build(BuildContext context) {
- return SizedBox(
- height: 96,
- child: Row(
- children: [
- for (final (int index, MediaRef ref) in media.indexed) ...[
- Expanded(
- child: Padding(
- padding:
- EdgeInsets.only(right: index == media.length - 1 ? 0 : 12),
- child: _MediaTile(
- mediaRef: ref,
- borderRadius: 18,
- ),
- ),
- ),
- ],
- if (media.isEmpty)
- Expanded(
- child: _MediaPlaceholder(
- colorScheme: colorScheme,
- borderRadius: 18,
- ),
- ),
- ],
- ),
- );
- }
-}
-
class _MediaGrid extends StatelessWidget {
const _MediaGrid({
required this.media,
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/stats_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/stats_card_content.dart
index 5c3ad193cd..343783138d 100644
--- a/mobile/apps/photos/lib/ui/wrapped/cards/stats_card_content.dart
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/stats_card_content.dart
@@ -738,32 +738,33 @@ class _FormatDistributionChart extends StatelessWidget {
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.all(16),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- SizedBox(
- height: 140,
- width: 140,
- child: CustomPaint(
- painter: _FormatPieChartPainter(
- values: entries
- .map(
- (MapEntry<String, int> entry) => entry.value.toDouble(),
- )
- .toList(growable: false),
- colors: colors,
- totalLabel: numberFormat.format(totalCount),
- totalCaption: "files",
- totalStyle: textTheme.largeBold,
- captionStyle: textTheme.tinyMuted,
- ringBackgroundColor:
- colorScheme.fillMuted.withValues(alpha: 0.18),
+ child: Center(
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ SizedBox(
+ height: 140,
+ width: 140,
+ child: CustomPaint(
+ painter: _FormatPieChartPainter(
+ values: entries
+ .map(
+ (MapEntry<String, int> entry) => entry.value.toDouble(),
+ )
+ .toList(growable: false),
+ colors: colors,
+ totalLabel: numberFormat.format(totalCount),
+ totalCaption: "files",
+ totalStyle: textTheme.largeBold,
+ captionStyle: textTheme.tinyMuted,
+ ringBackgroundColor:
+ colorScheme.fillMuted.withValues(alpha: 0.18),
+ ),
),
),
- ),
- const SizedBox(width: 20),
- Expanded(
- child: Column(
+ const SizedBox(width: 20),
+ Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
@@ -774,15 +775,14 @@ class _FormatDistributionChart extends StatelessWidget {
),
child: _FormatLegendEntry(
color: colors[index],
- label:
- "${entries[index].key} ${numberFormat.format(entries[index].value)}",
+ label: entries[index].key,
textTheme: textTheme,
),
),
],
),
- ),
- ],
+ ],
+ ),
),
);
}