@@ -24,6 +24,16 @@ final class StatsV4DataHelper {
2424 }
2525 }
2626
27+ /// Creates the text to display for the total revenue delta.
28+ ///
29+ static func createTotalRevenueDelta( from previousPeriod: OrderStatsV4 ? , to currentPeriod: OrderStatsV4 ? , locale: Locale = . current) -> String {
30+ if let previousRevenue = totalRevenue ( at: nil , orderStats: previousPeriod) , let currentRevenue = totalRevenue ( at: nil , orderStats: currentPeriod) {
31+ return createDeltaText ( from: previousRevenue, to: currentRevenue, locale: locale)
32+ } else {
33+ return Constants . placeholderText
34+ }
35+ }
36+
2737 // MARK: Orders Stats
2838
2939 /// Creates the text to display for the order count.
@@ -36,6 +46,16 @@ final class StatsV4DataHelper {
3646 }
3747 }
3848
49+ /// Creates the text to display for the order count delta.
50+ ///
51+ static func createOrderCountDelta( from previousPeriod: OrderStatsV4 ? , to currentPeriod: OrderStatsV4 ? , locale: Locale = . current) -> String {
52+ if let previousCount = orderCount ( at: nil , orderStats: previousPeriod) , let currentCount = orderCount ( at: nil , orderStats: currentPeriod) {
53+ return createDeltaText ( from: previousCount, to: currentCount, locale: locale)
54+ } else {
55+ return Constants . placeholderText
56+ }
57+ }
58+
3959 /// Creates the text to display for the average order value.
4060 ///
4161 static func createAverageOrderValueText( orderStats: OrderStatsV4 ? , currencyFormatter: CurrencyFormatter , currencyCode: String ) -> String {
@@ -48,6 +68,16 @@ final class StatsV4DataHelper {
4868 }
4969 }
5070
71+ /// Creates the text to display for the average order value delta.
72+ ///
73+ static func createAverageOrderValueDelta( from previousPeriod: OrderStatsV4 ? , to currentPeriod: OrderStatsV4 ? , locale: Locale = . current) -> String {
74+ if let previousAverage = averageOrderValue ( orderStats: previousPeriod) , let currentAverage = averageOrderValue ( orderStats: currentPeriod) {
75+ return createDeltaText ( from: previousAverage, to: currentAverage, locale: locale)
76+ } else {
77+ return Constants . placeholderText
78+ }
79+ }
80+
5181 // MARK: Views and Visitors Stats
5282
5383 /// Creates the text to display for the visitor count.
@@ -60,6 +90,16 @@ final class StatsV4DataHelper {
6090 }
6191 }
6292
93+ /// Creates the text to display for the visitor count delta.
94+ ///
95+ static func createVisitorCountDelta( from previousPeriod: SiteVisitStats ? , to currentPeriod: SiteVisitStats ? , locale: Locale = . current) -> String {
96+ if let previousCount = visitorCount ( at: nil , siteStats: previousPeriod) , let currentCount = visitorCount ( at: nil , siteStats: currentPeriod) {
97+ return createDeltaText ( from: previousCount, to: currentCount, locale: locale)
98+ } else {
99+ return Constants . placeholderText
100+ }
101+ }
102+
63103 // MARK: Conversion Stats
64104
65105 /// Creates the text to display for the conversion rate.
@@ -82,12 +122,15 @@ final class StatsV4DataHelper {
82122 return Constants . placeholderText
83123 }
84124 }
125+ }
126+
127+ extension StatsV4DataHelper {
85128
86129 // MARK: Delta Calculations
87130
88131 /// Creates the text showing the percent change from the previous `Decimal` value to the current `Decimal` value
89132 ///
90- static func createDeltaText( from previousValue: Decimal , to currentValue: Decimal , locale: Locale = Locale . current) -> String {
133+ static func createDeltaText( from previousValue: Decimal , to currentValue: Decimal , locale: Locale = . current) -> String {
91134 let numberFormatter = NumberFormatter ( )
92135 numberFormatter. numberStyle = . percent
93136 numberFormatter. positivePrefix = numberFormatter. plusSign
@@ -103,7 +146,7 @@ final class StatsV4DataHelper {
103146
104147 /// Creates the text showing the percent change from the previous `Double` value to the current `Double` value
105148 ///
106- static func createDeltaText( from previousValue: Double , to currentValue: Double , locale: Locale = Locale . current) -> String {
149+ static func createDeltaText( from previousValue: Double , to currentValue: Double , locale: Locale = . current) -> String {
107150 createDeltaText ( from: Decimal ( previousValue) , to: Decimal ( currentValue) )
108151 }
109152
0 commit comments