From 65fc7fa21e70c1142a0bf16bf467534949a42978 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Thu, 12 Jan 2023 15:54:52 +0200 Subject: [PATCH 1/6] Load weekly data for Views&Visitors, Total Likes, and Total Comments Insights excluding today --- .../Stats/Insights/SiteStatsInsightsViewModel.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsViewModel.swift b/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsViewModel.swift index 1fdd6e86d07c..8efa2cb6075c 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsViewModel.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsViewModel.swift @@ -61,7 +61,9 @@ class SiteStatsInsightsViewModel: Observable { self.periodStore = periodStore let viewsCount = insightsStore.getAllTimeStats()?.viewsCount ?? 0 self.itemToDisplay = pinnedItemStore?.itemToDisplay(for: viewsCount) - self.lastRequestedDate = StatsDataHelper.currentDateForSite() + + // Exclude today's data for weekly insights + self.lastRequestedDate = StatsDataHelper.yesterdayDateForSite() self.lastRequestedPeriod = StatsPeriodUnit.day insightsChangeReceipt = self.insightsStore.onChange { [weak self] in From a0f6176fdd6921fc83bda3deed34fa2c57b942d7 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Thu, 12 Jan 2023 16:51:49 +0200 Subject: [PATCH 2/6] Update Views & Visitors labels from "week" to "7-days" --- .../Stats/Charts/InsightsLineChart.swift | 4 ++-- .../Helpers/SiteStatsImmuTableRows.swift | 24 ++++++++++++++----- .../ViewsVisitorsLineChartCell.swift | 11 ++------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/InsightsLineChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/InsightsLineChart.swift index 2c2497f70a27..c0fbc3219a64 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/InsightsLineChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/InsightsLineChart.swift @@ -83,9 +83,9 @@ class InsightsLineChart { var chartData = [LineChartData]() let thisWeekDataSet = LineChartDataSet(entries: thisWeekEntries, - label: NSLocalizedString("This Week", comment: "Accessibility label used for distinguishing Views and Visitors in the Stats → Insights Views Visitors Line chart.")) + label: NSLocalizedString("stats.insights.accessibility.label.viewsVisitorsLastDays", value: "Last 7-days", comment: "Accessibility label used for distinguishing Views and Visitors in the Stats → Insights Views Visitors Line chart.")) let prevWeekDataSet = LineChartDataSet(entries: prevWeekEntries, - label: NSLocalizedString("Previous Week", comment: "Accessibility label used for distinguishing Views and Visitors in the Stats → Insights Views Visitors Line chart.")) + label: NSLocalizedString("stats.insights.accessibility.label.viewsVisitorsPreviousDays", value: "Previous 7-days", comment: "Accessibility label used for distinguishing Views and Visitors in the Stats → Insights Views Visitors Line chart.")) let viewsDataSets = [ thisWeekDataSet, prevWeekDataSet ] let viewsChartData = LineChartData(dataSets: viewsDataSets) chartData.append(viewsChartData) diff --git a/WordPress/Classes/ViewRelated/Stats/Helpers/SiteStatsImmuTableRows.swift b/WordPress/Classes/ViewRelated/Stats/Helpers/SiteStatsImmuTableRows.swift index b6c981b99c8a..bfb7c8295c5a 100644 --- a/WordPress/Classes/ViewRelated/Stats/Helpers/SiteStatsImmuTableRows.swift +++ b/WordPress/Classes/ViewRelated/Stats/Helpers/SiteStatsImmuTableRows.swift @@ -97,11 +97,23 @@ class SiteStatsImmuTableRows { } enum Constants { - static let viewsHigher = NSLocalizedString("Your views this week are %@ higher than the previous week.\n", comment: "Stats insights views higher than previous week") - static let viewsLower = NSLocalizedString("Your views this week are %@ lower than the previous week.\n", comment: "Stats insights views lower than previous week") - static let visitorsHigher = NSLocalizedString("Your visitors this week are %@ higher than the previous week.\n", comment: "Stats insights visitors higher than previous week") - static let visitorsLower = NSLocalizedString("Your visitors this week are %@ lower than the previous week.\n", comment: "Stats insights visitors lower than previous week") - static let viewsNoDifference = NSLocalizedString("Your views this week are the same as the previous week.\n", comment: "Stats insights label shown when the user's view count is the same as the previous week.") - static let visitorsNoDifference = NSLocalizedString("Your visitors this week are the same as the previous week.\n", comment: "Stats insights label shown when the user's visitor count is the same as the previous week.") + static let viewsHigher = NSLocalizedString("stats.insights.label.views.sevenDays.higher", + value: "Your views in the last 7-days are %@ higher than the previous 7-days.\n", + comment: "Stats insights views higher than previous 7 days") + static let viewsLower = NSLocalizedString("stats.insights.label.views.sevenDays.lower", + value: "Your views in the last 7-days are %@ lower than the previous 7-days.\n", + comment: "Stats insights views lower than previous 7 days") + static let visitorsHigher = NSLocalizedString("stats.insights.label.visitors.sevenDays.higher", + value: "Your visitors in the last 7-days are %@ higher than the previous 7-days.\n", + comment: "Stats insights visitors higher than previous 7 days") + static let visitorsLower = NSLocalizedString("stats.insights.label.visitors.sevenDays.lower", + value: "Your visitors in the last 7-days are %@ lower than the previous 7-days.\n", + comment: "Stats insights visitors lower than previous 7 days") + static let viewsNoDifference = NSLocalizedString("stats.insights.label.views.sevenDays.same", + value: "Your views in the last 7-days are the same as the previous 7-days.\n", + comment: "Stats insights label shown when the user's view count is the same as the previous 7 days.") + static let visitorsNoDifference = NSLocalizedString("stats.insights.label.visitors.sevenDays.same", + value: "Your visitors in the last 7-days are the same as the previous 7-days.\n", + comment: "Stats insights label shown when the user's visitor count is the same as the previous 7 days.") } } diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift b/WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift index 8abf1d1fba78..13688526bf1f 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift @@ -112,13 +112,6 @@ struct StatsSegmentedControlData { var accessibilityValue: String? { return segmentDataStub != nil ? "" : "\(segmentData)" } - - enum Constants { - static let viewsHigher = NSLocalizedString("Your views this week are %@ higher than the previous week.\n", comment: "Stats insights views higher than previous week") - static let viewsLower = NSLocalizedString("Your views this week are %@ lower than the previous week.\n", comment: "Stats insights views lower than previous week") - static let visitorsHigher = NSLocalizedString("Your visitors this week are %@ higher than the previous week.\n", comment: "Stats insights visitors higher than previous week") - static let visitorsLower = NSLocalizedString("Your visitors this week are %@ lower than the previous week.\n", comment: "Stats insights visitors lower than previous week") - } } @@ -230,9 +223,9 @@ private extension ViewsVisitorsLineChartCell { previousData.adjustsFontSizeToFitWidth = true previousLabel.adjustsFontSizeToFitWidth = true - legendLatestLabel.text = NSLocalizedString("This week", comment: "This week legend label") + legendLatestLabel.text = NSLocalizedString("stats.insights.label.viewsVisitorsLastDays", value: "Last 7-days", comment: "Last 7-days legend label") legendLatestLabel.adjustsFontSizeToFitWidth = true - legendPreviousLabel.text = NSLocalizedString("Previous week", comment: "Previous week legend label") + legendPreviousLabel.text = NSLocalizedString("stats.insights.label.viewsVisitorsPreviousDays", value: "Previous 7-days", comment: "Previous 7-days legend label") legendPreviousLabel.adjustsFontSizeToFitWidth = true } From 0c7d515288a8c9771bffb2d36e169e8f8c1d916e Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Thu, 12 Jan 2023 16:52:46 +0200 Subject: [PATCH 3/6] Update TotalLikes and TotalComments labels from "week" to "7-days" --- .../Stats/Insights/StatsTotalInsightsCell.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/StatsTotalInsightsCell.swift b/WordPress/Classes/ViewRelated/Stats/Insights/StatsTotalInsightsCell.swift index a9806a0097c1..6db8b7df7cb3 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/StatsTotalInsightsCell.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/StatsTotalInsightsCell.swift @@ -376,8 +376,14 @@ class StatsTotalInsightsCell: StatsBaseCell { private enum TextContent { static let differenceDelimiter = Character("*") - static let differenceHigher = NSLocalizedString("*%@%@ (%@%%)* higher than the previous week", comment: "Label shown on some metrics in the Stats Insights section, such as Comments count. The placeholders will be populated with a change and a percentage – e.g. '+17 (40%) higher than the previous week'. The *s mark the numerical values, which will be highlighted differently from the rest of the text.") - static let differenceLower = NSLocalizedString("*%@%@ (%@%%)* lower than the previous week", comment: "Label shown on some metrics in the Stats Insights section, such as Comments count. The placeholders will be populated with a change and a percentage – e.g. '-17 (40%) lower than the previous week'. The *s mark the numerical values, which will be highlighted differently from the rest of the text.") - static let differenceSame = NSLocalizedString("The same as the previous week", comment: "Label shown in Stats Insights when a metric is showing the same level as the previous week") + static let differenceHigher = NSLocalizedString("stats.insights.label.totalLikes.higher", + value: "*%@%@ (%@%%)* higher than the previous 7-days", + comment: "Label shown on some metrics in the Stats Insights section, such as Comments count. The placeholders will be populated with a change and a percentage – e.g. '+17 (40%) higher than the previous 7-days'. The *s mark the numerical values, which will be highlighted differently from the rest of the text.") + static let differenceLower = NSLocalizedString("stats.insights.label.totalLikes.higher", + value: "*%@%@ (%@%%)* lower than the previous 7-days", + comment: "Label shown on some metrics in the Stats Insights section, such as Comments count. The placeholders will be populated with a change and a percentage – e.g. '-17 (40%) lower than the previous 7-days'. The *s mark the numerical values, which will be highlighted differently from the rest of the text.") + static let differenceSame = NSLocalizedString("stats.insights.label.totalLikes.same", + value: "The same as the previous 7-days", + comment: "Label shown in Stats Insights when a metric is showing the same level as the previous 7 days") } } From 9161b8f9f17934731f3589beb021f482eba1c70a Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Thu, 12 Jan 2023 17:05:42 +0200 Subject: [PATCH 4/6] Create yesterdayDateForSite() --- .../Classes/ViewRelated/Stats/Helpers/StatsDataHelper.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Stats/Helpers/StatsDataHelper.swift b/WordPress/Classes/ViewRelated/Stats/Helpers/StatsDataHelper.swift index 9977e90c633c..f741c158a2ec 100644 --- a/WordPress/Classes/ViewRelated/Stats/Helpers/StatsDataHelper.swift +++ b/WordPress/Classes/ViewRelated/Stats/Helpers/StatsDataHelper.swift @@ -135,6 +135,11 @@ import Foundation let siteTimeZone = SiteStatsInformation.sharedInstance.siteTimeZone ?? .autoupdatingCurrent return Date().convert(from: siteTimeZone) } + + class func yesterdayDateForSite() -> Date { + let components = DateComponents(day: -1) + return StatsDataHelper.calendar.date(byAdding: components, to: currentDateForSite()) ?? currentDateForSite() + } } fileprivate extension Date { From 5d5fce760f0ad1503475a7c757b3761f0110abcd Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Thu, 12 Jan 2023 18:14:09 +0200 Subject: [PATCH 5/6] Allow opening details from Followers card - For routing to work, we need to include `.insightsFollowersWordPress` in allInsights - For insight management to work, we need to remove `insightsFollowersWordPress` to avoid double `Followers` rows appearing. It happens because `insightsFollowersWordPress` and insightsFollowersEmail` share the same `InsightType` and are represented by a single card. --- .../ViewRelated/Stats/Helpers/StatSection.swift | 1 + .../InsightsManagementViewController.swift | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift b/WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift index dfe04d2a5fe9..00b042eceb77 100644 --- a/WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift +++ b/WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift @@ -47,6 +47,7 @@ .insightsTodaysStats, .insightsPostingActivity, .insightsTagsAndCategories, + .insightsFollowersWordPress, .insightsFollowersEmail, .insightsPublicize] } else { diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/Insights Management/InsightsManagementViewController.swift b/WordPress/Classes/ViewRelated/Stats/Insights/Insights Management/InsightsManagementViewController.swift index 5c4c88b55a92..f4498f580b7e 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/Insights Management/InsightsManagementViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/Insights Management/InsightsManagementViewController.swift @@ -22,7 +22,8 @@ class InsightsManagementViewController: UITableViewController { } private var insightsInactive: [StatSection] { - StatSection.allInsights.filter({ !self.insightsShown.contains($0) }) + StatSection.allInsights + .filter({ !self.insightsShown.contains($0) && !InsightsManagementViewController.insightsNotSupportedForManagement.contains($0) }) } private var hasChanges: Bool { @@ -55,8 +56,9 @@ class InsightsManagementViewController: UITableViewController { self.init(style: FeatureFlag.statsNewAppearance.enabled ? .insetGrouped : .grouped) self.insightsDelegate = insightsDelegate self.insightsManagementDelegate = insightsManagementDelegate - self.insightsShown = insightsShown - self.originalInsightsShown = insightsShown + let insightsShownSupportedForManagement = insightsShown.filter { !InsightsManagementViewController.insightsNotSupportedForManagement.contains($0) } + self.insightsShown = insightsShownSupportedForManagement + self.originalInsightsShown = insightsShownSupportedForManagement } // MARK: - View @@ -388,6 +390,15 @@ private extension InsightsManagementViewController { action: nil) } + /// Insight StatSections who share the same insightType are represented by a single card + /// Only display a single one of them for Insight Management + /// insightsCommentsPosts and insightsCommentsAuthors have the same insightType + /// insightsFollowersEmail and insightsFollowersWordpress have the same insightType + private static let insightsNotSupportedForManagement: [StatSection] = [ + .insightsFollowersWordPress, + .insightsCommentsAuthors + ] + // MARK: - Insights Categories enum InsightsCategories { From e501df9cbc2bc90ab32f11f39ebfe6f3ddd84715 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Thu, 12 Jan 2023 18:20:43 +0200 Subject: [PATCH 6/6] Show "View More" action button for total likes, making it the same as on Android --- .../Classes/ViewRelated/Stats/Insights/StatsBaseCell.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/StatsBaseCell.swift b/WordPress/Classes/ViewRelated/Stats/Insights/StatsBaseCell.swift index bb7b0237b88a..8c64a5cf7ce3 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/StatsBaseCell.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/StatsBaseCell.swift @@ -117,9 +117,9 @@ class StatsBaseCell: UITableViewCell { showDetailsButton.isHidden = false switch statSection { - case .insightsViewsVisitors, .insightsLikesTotals: + case .insightsViewsVisitors: showDetailsButton.setTitle(LocalizedText.buttonTitleThisWeek, for: .normal) - case .insightsFollowerTotals, .insightsCommentsTotals: + case .insightsFollowerTotals, .insightsCommentsTotals, .insightsLikesTotals: showDetailsButton.setTitle(LocalizedText.buttonTitleViewMore, for: .normal) default: showDetailsButton.setTitle("", for: .normal)