@@ -46,15 +46,10 @@ class SiteStatsInsightsViewModel: Observable {
46
46
guard let mostRecentChartData = mostRecentChartData else {
47
47
return
48
48
}
49
-
50
- currentEntryIndex = mostRecentChartData. summaryData. lastIndex ( where: { $0. periodStartDate <= self . lastRequestedDate } )
51
- ?? max ( mostRecentChartData. summaryData. count - 1 , 0 )
52
49
}
53
50
}
54
51
}
55
52
56
- private var currentEntryIndex : Int = 0
57
-
58
53
// MARK: - Constructor
59
54
60
55
init ( insightsToShow: [ InsightType ] ,
@@ -437,6 +432,7 @@ private extension SiteStatsInsightsViewModel {
437
432
segmentData: viewsData. count,
438
433
segmentPrevData: viewsData. prevCount,
439
434
difference: viewsData. difference,
435
+ differenceText: viewsData. difference < 0 ? Constants . viewsLower : Constants . viewsHigher,
440
436
date: periodDate,
441
437
period: period,
442
438
analyticsStat: . statsOverviewTypeTappedViews,
@@ -448,6 +444,7 @@ private extension SiteStatsInsightsViewModel {
448
444
segmentData: visitorsData. count,
449
445
segmentPrevData: visitorsData. prevCount,
450
446
difference: visitorsData. difference,
447
+ differenceText: visitorsData. difference < 0 ? Constants . visitorsLower : Constants . visitorsHigher,
451
448
date: periodDate,
452
449
period: period,
453
450
analyticsStat: . statsOverviewTypeTappedViews,
@@ -845,15 +842,15 @@ extension SiteStatsInsightsViewModel: AsyncBlocksLoadable {
845
842
public static func splitStatsSummaryTimeIntervalData( _ statsSummaryTimeIntervalData: StatsSummaryTimeIntervalData ) ->
846
843
[ StatsSummaryTimeIntervalDataAsAWeek ] {
847
844
switch statsSummaryTimeIntervalData. summaryData. count {
848
- case let count where count == 14 :
845
+ case let count where count == Constants . fourteenDays :
849
846
// normal case api returns 14 rows
850
- let summaryData = statsSummaryTimeIntervalData. summaryData [ 0 ..< 14 ]
847
+ let summaryData = statsSummaryTimeIntervalData. summaryData [ 0 ..< Constants . fourteenDays ]
851
848
return createStatsSummaryTimeIntervalDataAsAWeeks ( summaryData: Array ( summaryData) )
852
- case let count where count > 14 :
849
+ case let count where count > Constants . fourteenDays :
853
850
// when more than 14 rows we take the last 14 rows for most recent data
854
- let summaryData = statsSummaryTimeIntervalData. summaryData [ count- 14 ..< count]
851
+ let summaryData = statsSummaryTimeIntervalData. summaryData [ count- Constants . fourteenDays ..< count]
855
852
return createStatsSummaryTimeIntervalDataAsAWeeks ( summaryData: Array ( summaryData) )
856
- case let count where count < 14 :
853
+ case let count where count < Constants . fourteenDays :
857
854
// when 0 to 14 rows presume the user could be new / doesn't have enough data. Pad 0's to prev week
858
855
var summaryData = statsSummaryTimeIntervalData. summaryData
859
856
summaryData. reverse ( )
@@ -862,7 +859,7 @@ extension SiteStatsInsightsViewModel: AsyncBlocksLoadable {
862
859
return [ ]
863
860
}
864
861
865
- while summaryData. count < 14 {
862
+ while summaryData. count < Constants . fourteenDays {
866
863
if let newPeriodStartDate = Calendar . autoupdatingCurrent. date ( byAdding: . day, value: - 1 , to: date) {
867
864
date = newPeriodStartDate
868
865
summaryData. append ( StatsSummaryData ( period: . day,
@@ -889,12 +886,20 @@ extension SiteStatsInsightsViewModel: AsyncBlocksLoadable {
889
886
summaryData: Array ( prevWeekData) )
890
887
891
888
892
- let thisWeekData = summaryData [ half ..< 14 ]
889
+ let thisWeekData = summaryData [ half ..< Constants . fourteenDays ]
893
890
let thisWeekTimeIntervalData = StatsSummaryTimeIntervalData ( period: . day,
894
891
periodEndDate: thisWeekData. last!. periodStartDate,
895
892
summaryData: Array ( thisWeekData) )
896
893
897
894
return [ StatsSummaryTimeIntervalDataAsAWeek . thisWeek ( data: thisWeekTimeIntervalData) ,
898
895
StatsSummaryTimeIntervalDataAsAWeek . prevWeek ( data: prevWeekTimeIntervalData) ]
899
896
}
897
+
898
+ enum Constants {
899
+ static let fourteenDays = 14
900
+ static let viewsHigher = NSLocalizedString ( " Your views this week are %@ higher than the previous week. \n " , comment: " Stats insights views higher than previous week " )
901
+ static let viewsLower = NSLocalizedString ( " Your views this week are %@ lower than the previous week. \n " , comment: " Stats insights views lower than previous week " )
902
+ static let visitorsHigher = NSLocalizedString ( " Your visitors this week are %@ higher than the previous week. \n " , comment: " Stats insights visitors higher than previous week " )
903
+ static let visitorsLower = NSLocalizedString ( " Your visitors this week are %@ lower than the previous week. \n " , comment: " Stats insights visitors lower than previous week " )
904
+ }
900
905
}
0 commit comments