Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 7c883fd

Browse files
authored
Merge pull request #88 from wordpress-mobile/feature/stats-insights-fetching
Stats Refresh: Insights fetching
2 parents bbd0ca7 + b34ba51 commit 7c883fd

12 files changed

+782
-5
lines changed

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ PODS:
2727
- OHHTTPStubs/Swift (6.1.0):
2828
- OHHTTPStubs/Default
2929
- UIDeviceIdentifier (1.1.4)
30-
- WordPressKit (2.0.0):
30+
- WordPressKit (2.1.0-beta.1):
3131
- Alamofire (~> 4.7.3)
3232
- CocoaLumberjack (= 3.4.2)
3333
- NSObject-SafeExpectations (= 0.0.3)
3434
- UIDeviceIdentifier (~> 1.1.4)
3535
- WordPressShared (~> 1.4)
3636
- wpxmlrpc (= 0.8.4)
37-
- WordPressShared (1.6.0):
37+
- WordPressShared (1.7.0):
3838
- CocoaLumberjack (~> 3.4)
3939
- FormatterKit/TimeIntervalFormatter (= 1.8.2)
4040
- wpxmlrpc (0.8.4)
@@ -70,8 +70,8 @@ SPEC CHECKSUMS:
7070
OCMock: 43565190abc78977ad44a61c0d20d7f0784d35ab
7171
OHHTTPStubs: 1e21c7d2c084b8153fc53d48400d8919d2d432d0
7272
UIDeviceIdentifier: 8f8a24b257a4d978c8d40ad1e7355b944ffbfa8c
73-
WordPressKit: f495f0631617bef220ed3bf8e55540d03b26b519
74-
WordPressShared: a2fc2db66c210a05d317ae9678b5823dd6a4d708
73+
WordPressKit: acf6dcee93c9158286a17e02b3bba6931cf34e8c
74+
WordPressShared: cfbda56868419842dd7a106a4e807069a0c17aa9
7575
wpxmlrpc: 6ba55c773cfa27083ae4a2173e69b19f46da98e2
7676

7777
PODFILE CHECKSUM: 96aee46d567751451860e27dd476d15d79b40f44

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressKit"
3-
s.version = "2.0.0"
3+
s.version = "2.1.0-beta.1"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@
1818
240315B0A1D6C2B981572B5B /* Pods_WordPressKitTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED05C8FF3E61D93CE5BA527E /* Pods_WordPressKitTests.framework */; };
1919
40247DFA2120D8E100AE1C3C /* AutomatedTransferService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40247DF92120D8E100AE1C3C /* AutomatedTransferService.swift */; };
2020
40247DFC2120E69600AE1C3C /* AutomatedTransferStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40247DFB2120E69600AE1C3C /* AutomatedTransferStatus.swift */; };
21+
4041405E220F9EF500CF7C5B /* StatsDotComFollowersInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4041405D220F9EF500CF7C5B /* StatsDotComFollowersInsight.swift */; };
22+
40414060220F9F1F00CF7C5B /* StatsAllTimesInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4041405F220F9F1F00CF7C5B /* StatsAllTimesInsight.swift */; };
23+
40A71C6E220E1D8E002E3D25 /* StatsServiceRemoteV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40A71C6D220E1D8E002E3D25 /* StatsServiceRemoteV2.swift */; };
2124
40AB1ADA200FED25009B533D /* PluginDirectoryFeedPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40AB1AD9200FED25009B533D /* PluginDirectoryFeedPage.swift */; };
2225
40E4698B2017C2840030DB5F /* plugin-directory-popular.json in Resources */ = {isa = PBXBuildFile; fileRef = 40E4698A2017C2840030DB5F /* plugin-directory-popular.json */; };
2326
40E4698D2017D2E30030DB5F /* plugin-directory-new.json in Resources */ = {isa = PBXBuildFile; fileRef = 40E4698C2017D2E30030DB5F /* plugin-directory-new.json */; };
27+
40E7FEA9220FA4060032834E /* StatsEmailFollowersInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E7FEA8220FA4050032834E /* StatsEmailFollowersInsight.swift */; };
28+
40E7FEAE220FAEA10032834E /* StatsPublicizeInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E7FEAD220FAEA10032834E /* StatsPublicizeInsight.swift */; };
29+
40E7FEB1220FB3B60032834E /* StatsAnnualAndMostPopularTimeInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E7FEB0220FB3B60032834E /* StatsAnnualAndMostPopularTimeInsight.swift */; };
30+
40E7FEB4221063480032834E /* StatsTodayInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E7FEB3221063480032834E /* StatsTodayInsight.swift */; };
31+
40E7FEB722106A8D0032834E /* StatsCommentsInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E7FEB622106A8D0032834E /* StatsCommentsInsight.swift */; };
32+
40E7FEBA2210894B0032834E /* StatsTagsAndCategoriesInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E7FEB92210894B0032834E /* StatsTagsAndCategoriesInsight.swift */; };
2433
40F88F601F85723500AE3FAF /* auth-send-verification-email-already-verified-failure.json in Resources */ = {isa = PBXBuildFile; fileRef = 40F88F5F1F85723400AE3FAF /* auth-send-verification-email-already-verified-failure.json */; };
2534
40F88F621F85799A00AE3FAF /* auth-send-verification-email-success.json in Resources */ = {isa = PBXBuildFile; fileRef = 40F88F611F85799A00AE3FAF /* auth-send-verification-email-success.json */; };
2635
436D56332118D7AA00CEAA33 /* TransactionsServiceRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 436D56322118D7AA00CEAA33 /* TransactionsServiceRemote.swift */; };
@@ -478,9 +487,18 @@
478487
264F5C834541BBF2018F4964 /* Pods-WordPressKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WordPressKitTests/Pods-WordPressKitTests.debug.xcconfig"; sourceTree = "<group>"; };
479488
40247DF92120D8E100AE1C3C /* AutomatedTransferService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomatedTransferService.swift; sourceTree = "<group>"; };
480489
40247DFB2120E69600AE1C3C /* AutomatedTransferStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomatedTransferStatus.swift; sourceTree = "<group>"; };
490+
4041405D220F9EF500CF7C5B /* StatsDotComFollowersInsight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsDotComFollowersInsight.swift; sourceTree = "<group>"; };
491+
4041405F220F9F1F00CF7C5B /* StatsAllTimesInsight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsAllTimesInsight.swift; sourceTree = "<group>"; };
492+
40A71C6D220E1D8E002E3D25 /* StatsServiceRemoteV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsServiceRemoteV2.swift; sourceTree = "<group>"; };
481493
40AB1AD9200FED25009B533D /* PluginDirectoryFeedPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginDirectoryFeedPage.swift; sourceTree = "<group>"; };
482494
40E4698A2017C2840030DB5F /* plugin-directory-popular.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "plugin-directory-popular.json"; sourceTree = "<group>"; };
483495
40E4698C2017D2E30030DB5F /* plugin-directory-new.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "plugin-directory-new.json"; sourceTree = "<group>"; };
496+
40E7FEA8220FA4050032834E /* StatsEmailFollowersInsight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsEmailFollowersInsight.swift; sourceTree = "<group>"; };
497+
40E7FEAD220FAEA10032834E /* StatsPublicizeInsight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsPublicizeInsight.swift; sourceTree = "<group>"; };
498+
40E7FEB0220FB3B60032834E /* StatsAnnualAndMostPopularTimeInsight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsAnnualAndMostPopularTimeInsight.swift; sourceTree = "<group>"; };
499+
40E7FEB3221063480032834E /* StatsTodayInsight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsTodayInsight.swift; sourceTree = "<group>"; };
500+
40E7FEB622106A8D0032834E /* StatsCommentsInsight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsCommentsInsight.swift; sourceTree = "<group>"; };
501+
40E7FEB92210894B0032834E /* StatsTagsAndCategoriesInsight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsTagsAndCategoriesInsight.swift; sourceTree = "<group>"; };
484502
40F88F5F1F85723400AE3FAF /* auth-send-verification-email-already-verified-failure.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "auth-send-verification-email-already-verified-failure.json"; sourceTree = "<group>"; };
485503
40F88F611F85799A00AE3FAF /* auth-send-verification-email-success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "auth-send-verification-email-success.json"; sourceTree = "<group>"; };
486504
436D56322118D7AA00CEAA33 /* TransactionsServiceRemote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionsServiceRemote.swift; sourceTree = "<group>"; };
@@ -963,6 +981,29 @@
963981
name = Frameworks;
964982
sourceTree = "<group>";
965983
};
984+
40414061220F9F2800CF7C5B /* Insights */ = {
985+
isa = PBXGroup;
986+
children = (
987+
4041405D220F9EF500CF7C5B /* StatsDotComFollowersInsight.swift */,
988+
40E7FEA8220FA4050032834E /* StatsEmailFollowersInsight.swift */,
989+
4041405F220F9F1F00CF7C5B /* StatsAllTimesInsight.swift */,
990+
40E7FEAD220FAEA10032834E /* StatsPublicizeInsight.swift */,
991+
40E7FEB0220FB3B60032834E /* StatsAnnualAndMostPopularTimeInsight.swift */,
992+
40E7FEB3221063480032834E /* StatsTodayInsight.swift */,
993+
40E7FEB622106A8D0032834E /* StatsCommentsInsight.swift */,
994+
40E7FEB92210894B0032834E /* StatsTagsAndCategoriesInsight.swift */,
995+
);
996+
path = Insights;
997+
sourceTree = "<group>";
998+
};
999+
40B01BF3220E534900036D10 /* V2 */ = {
1000+
isa = PBXGroup;
1001+
children = (
1002+
40414061220F9F2800CF7C5B /* Insights */,
1003+
);
1004+
name = V2;
1005+
sourceTree = "<group>";
1006+
};
9661007
436D56362118DC2800CEAA33 /* Transactions */ = {
9671008
isa = PBXGroup;
9681009
children = (
@@ -1108,6 +1149,7 @@
11081149
930F52B91ECF8A44002F921B /* Stats */ = {
11091150
isa = PBXGroup;
11101151
children = (
1152+
40B01BF3220E534900036D10 /* V2 */,
11111153
9368C7A51EC630270092CE8E /* StatsItem.h */,
11121154
9368C7A61EC630270092CE8E /* StatsItem.m */,
11131155
9368C7A71EC630270092CE8E /* StatsItemAction.h */,
@@ -1316,6 +1358,7 @@
13161358
730E869E21E44EFD00753E1A /* WordPressComServiceRemote+SiteVerticals.swift */,
13171359
73A2F38921E7F81E00388609 /* WordPressComServiceRemote+SiteVerticalsPrompt.swift */,
13181360
9368C7A11EC62F800092CE8E /* WPStatsServiceRemote.h */,
1361+
40A71C6D220E1D8E002E3D25 /* StatsServiceRemoteV2.swift */,
13191362
9368C7A21EC62F800092CE8E /* WPStatsServiceRemote.m */,
13201363
E182BF691FD961810001D850 /* Endpoint.swift */,
13211364
17CD0CC220C58A0D000D9620 /* ReaderSiteSearchServiceRemote.swift */,
@@ -2173,10 +2216,12 @@
21732216
E11C2AD21FA77FB90023BDE2 /* SitePlugin.swift in Sources */,
21742217
74A44DCC1F13C533006CD8F4 /* NotificationSyncServiceRemote.swift in Sources */,
21752218
74E229501F1E741B0085F7F2 /* RemotePublicizeConnection.swift in Sources */,
2219+
40E7FEB722106A8D0032834E /* StatsCommentsInsight.swift in Sources */,
21762220
9311A6891F22625A00704AC9 /* TaxonomyServiceRemoteREST.m in Sources */,
21772221
9AB6D647218705E90008F274 /* RemoteDiff.swift in Sources */,
21782222
93BD277C1EE73944002BB00B /* HTTPAuthenticationAlertController.swift in Sources */,
21792223
7433BC011EFC4505002D9E92 /* PlanServiceRemote.swift in Sources */,
2224+
4041405E220F9EF500CF7C5B /* StatsDotComFollowersInsight.swift in Sources */,
21802225
74650F721F0EA1A700188EDB /* GravatarServiceRemote.swift in Sources */,
21812226
B5969E1D20A49AC4005E9DF1 /* NSString+MD5.m in Sources */,
21822227
8236EB4D2024B9F8007C7CF9 /* RemoteBlogJetpackModulesSettings.swift in Sources */,
@@ -2188,6 +2233,7 @@
21882233
E1BD95151FD5A2B800CD5CE3 /* PluginDirectoryServiceRemote.swift in Sources */,
21892234
7430C9D71F1933210051B8E6 /* RemoteReaderCrossPostMeta.swift in Sources */,
21902235
9311A68B1F22625A00704AC9 /* TaxonomyServiceRemoteXMLRPC.m in Sources */,
2236+
40414060220F9F1F00CF7C5B /* StatsAllTimesInsight.swift in Sources */,
21912237
93BD277E1EE73944002BB00B /* NSDate+WordPressJSON.m in Sources */,
21922238
7E3E7A4820E443370075D159 /* NSMutableAttributedString+extensions.swift in Sources */,
21932239
E194CB731FBDEF6500B0A8B8 /* PluginState.swift in Sources */,
@@ -2205,6 +2251,7 @@
22052251
9F4E52002088E38200424676 /* ObjectValidation.swift in Sources */,
22062252
7430C9B81F1927C50051B8E6 /* RemoteReaderTopic.m in Sources */,
22072253
7403A3021EF0726E00DED7DC /* AccountSettings.swift in Sources */,
2254+
40E7FEA9220FA4060032834E /* StatsEmailFollowersInsight.swift in Sources */,
22082255
9368C7C01EC630CE0092CE8E /* StatsStringUtilities.m in Sources */,
22092256
826016F11F9FA13A00533B6C /* ActivityServiceRemote.swift in Sources */,
22102257
74BA04FA1F06DC3900ED5CD8 /* RemoteComment.m in Sources */,
@@ -2218,6 +2265,7 @@
22182265
7328420421CD786C00126755 /* WordPressComServiceRemote+SiteCreation.swift in Sources */,
22192266
826016F31F9FA17B00533B6C /* Activity.swift in Sources */,
22202267
7397F01A220A072500C723F3 /* ActivityServiceRemote_ApiVersion1_0.swift in Sources */,
2268+
40E7FEB1220FB3B60032834E /* StatsAnnualAndMostPopularTimeInsight.swift in Sources */,
22212269
7E3E7A4A20E443890075D159 /* Scanner+extensions.swift in Sources */,
22222270
742362E31F1025B400BD0A7F /* RemoteMenuLocation.m in Sources */,
22232271
82FFBF561F460DD400F4573F /* BlogJetpackSettingsServiceRemote.swift in Sources */,
@@ -2245,6 +2293,7 @@
22452293
93BD273D1EE73282002BB00B /* AccountServiceRemoteREST.m in Sources */,
22462294
82FFBF501F45EFD100F4573F /* RemoteBlogJetpackSettings.swift in Sources */,
22472295
74650F741F0EA1E200188EDB /* RemoteGravatarProfile.swift in Sources */,
2296+
40E7FEB4221063480032834E /* StatsTodayInsight.swift in Sources */,
22482297
436D563C2118E18D00CEAA33 /* State.swift in Sources */,
22492298
439A44DA2107C93000795ED7 /* RemotePlan_ApiVersion1_3.swift in Sources */,
22502299
93BD27811EE73944002BB00B /* WordPressOrgXMLRPCApi.swift in Sources */,
@@ -2274,10 +2323,13 @@
22742323
74B5F0DA1EF8299B00B411E7 /* BlogServiceRemoteXMLRPC.m in Sources */,
22752324
E1EF5D5D1F9F329900B6D53E /* SitePluginCapabilities.swift in Sources */,
22762325
7E3E7A4520E443060075D159 /* NSAttributedString+extensions.swift in Sources */,
2326+
40E7FEAE220FAEA10032834E /* StatsPublicizeInsight.swift in Sources */,
22772327
93F50A411F227C9700B5BEBA /* RemoteProfile.swift in Sources */,
2328+
40E7FEBA2210894B0032834E /* StatsTagsAndCategoriesInsight.swift in Sources */,
22782329
439A44D82107C85E00795ED7 /* PlanServiceRemote_ApiVersion1_3.swift in Sources */,
22792330
93C674EE1EE834B700BFAF05 /* RemoteBlogSettings.swift in Sources */,
22802331
436D5641211B7F4400CEAA33 /* DomainContactInformation.swift in Sources */,
2332+
40A71C6E220E1D8E002E3D25 /* StatsServiceRemoteV2.swift in Sources */,
22812333
82FFBF521F45F04100F4573F /* RemoteBlogJetpackMonitorSettings.swift in Sources */,
22822334
9309994E1F1657C600F006A1 /* ThemeServiceRemote.m in Sources */,
22832335
74E229491F1E73060085F7F2 /* SharingServiceRemote.swift in Sources */,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
public struct StatsAllTimesInsight {
2+
public let postsCount: Int
3+
public let viewsCount: Int
4+
public let bestViewsDay: Date
5+
public let visitorsCount: Int
6+
public let bestViewsPerDayCount: Int
7+
}
8+
9+
10+
extension StatsAllTimesInsight: InsightProtocol {
11+
12+
//MARK: - InsightProtocol Conformance
13+
public init?(jsonDictionary: [String: AnyObject]) {
14+
guard
15+
let statsDict = jsonDictionary["stats"] as? [String: AnyObject],
16+
let postsCount = statsDict["posts"] as? Int,
17+
let viewsCount = statsDict["views"] as? Int,
18+
let visitorsCount = statsDict["visitors"] as? Int,
19+
let bestViewsPerDayCount = statsDict["views_best_day_total"] as? Int,
20+
let bestViewsDayString = statsDict["views_best_day"] as? String,
21+
let bestViewsDay = StatsAllTimesInsight.dateFormatter.date(from: bestViewsDayString)
22+
else {
23+
return nil
24+
}
25+
26+
self.postsCount = postsCount
27+
self.bestViewsPerDayCount = bestViewsPerDayCount
28+
self.visitorsCount = visitorsCount
29+
self.viewsCount = viewsCount
30+
self.bestViewsDay = bestViewsDay
31+
}
32+
33+
//MARK: -
34+
private static var dateFormatter: DateFormatter {
35+
let formatter = DateFormatter()
36+
formatter.dateFormat = "yyyy-MM-dd"
37+
return formatter
38+
}
39+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
public struct StatsAnnualAndMostPopularTimeInsight {
2+
3+
/// - A `DateComponents` object with one field populated: `weekday`.
4+
public let mostPopularDayOfWeek: DateComponents
5+
public let mostPopularDayOfWeekPercentage: Int
6+
7+
/// - A `DateComponents` object with one field populated: `hour`.
8+
public let mostPopularHour: DateComponents
9+
public let mostPopularHourPercentage: Int
10+
11+
public let annualInsightsYear: Int
12+
13+
public let annualInsightsTotalPostsCount: Int
14+
public let annualInsightsTotalWordsCount: Int
15+
public let annualInsightsAverageWordsCount: Double
16+
17+
public let annualInsightsTotalLikesCount: Int
18+
public let annualInsightsAverageLikesCount: Double
19+
20+
public let annualInsightsTotalCommentsCount: Int
21+
public let annualInsightsAverageCommentsCount: Double
22+
23+
public let annualInsightsTotalImagesCount: Int
24+
public let annualInsightsAverageImagesCount: Double
25+
}
26+
27+
extension StatsAnnualAndMostPopularTimeInsight: InsightProtocol {
28+
public static var pathComponent: String {
29+
return "stats/insights"
30+
}
31+
32+
public init?(jsonDictionary: [String : AnyObject]) {
33+
guard
34+
let highestHour = jsonDictionary["highest_hour"] as? Int,
35+
let highestHourPercentageValue = jsonDictionary["highest_hour_percent"] as? Double,
36+
let highestDayOfWeek = jsonDictionary["highest_day_of_week"] as? Int,
37+
let highestDayOfWeekPercentageValue = jsonDictionary["highest_day_percent"] as? Double,
38+
let yearlyInsights = jsonDictionary["years"] as? [[String: AnyObject]],
39+
let latestYearlyInsight = yearlyInsights.last,
40+
let yearString = latestYearlyInsight["year"] as? String,
41+
let currentYear = Int(yearString),
42+
let postCount = latestYearlyInsight["total_posts"] as? Int,
43+
let wordsCount = latestYearlyInsight["total_words"] as? Int,
44+
let wordsAverage = latestYearlyInsight["avg_words"] as? Double,
45+
let likesCount = latestYearlyInsight["total_likes"] as? Int,
46+
let likesAverage = latestYearlyInsight["avg_likes"] as? Double,
47+
let commentsCount = latestYearlyInsight["total_comments"] as? Int,
48+
let commentsAverage = latestYearlyInsight["avg_comments"] as? Double,
49+
let imagesCount = latestYearlyInsight["total_images"] as? Int,
50+
let imagesAverage = latestYearlyInsight["avg_images"] as? Double
51+
else {
52+
return nil
53+
}
54+
55+
let mappedWeekday: ((Int) -> Int) = {
56+
// iOS Calendar system is `1-based` and uses Sunday as the first day of the week.
57+
// The data returned from WP.com is `0-based` and uses Monday as the first day of the week.
58+
// This maps the WP.com data to iOS format.
59+
return $0 == 6 ? 0 : $0 + 2
60+
}
61+
62+
let weekDayComponent = DateComponents(weekday: mappedWeekday(highestDayOfWeek))
63+
let hourComponents = DateComponents(hour: highestHour)
64+
65+
self.mostPopularDayOfWeek = weekDayComponent
66+
self.mostPopularDayOfWeekPercentage = Int(highestDayOfWeekPercentageValue)
67+
self.mostPopularHour = hourComponents
68+
self.mostPopularHourPercentage = Int(highestHourPercentageValue)
69+
70+
self.annualInsightsYear = currentYear
71+
72+
self.annualInsightsTotalPostsCount = postCount
73+
self.annualInsightsTotalWordsCount = wordsCount
74+
self.annualInsightsAverageWordsCount = wordsAverage
75+
76+
self.annualInsightsTotalLikesCount = likesCount
77+
self.annualInsightsAverageLikesCount = likesAverage
78+
79+
self.annualInsightsTotalCommentsCount = commentsCount
80+
self.annualInsightsAverageCommentsCount = commentsAverage
81+
82+
self.annualInsightsTotalImagesCount = imagesCount
83+
self.annualInsightsAverageImagesCount = imagesAverage
84+
}
85+
}

0 commit comments

Comments
 (0)