Skip to content

Commit

Permalink
fix url description for GCCOnnectStatsReq and support for message sum…
Browse files Browse the repository at this point in the history
…mary first method for fit files
  • Loading branch information
roznet committed Oct 28, 2023
1 parent 1d6d0d9 commit aebd7b0
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 6 deletions.
8 changes: 6 additions & 2 deletions ConnectStats.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
422B343E1CA7321200B345CD /* GCFieldCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 422B343C1CA7321200B345CD /* GCFieldCache.m */; };
422B34411CA7322600B345CD /* GCFieldInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 422B34401CA7322600B345CD /* GCFieldInfo.m */; };
422B34421CA7322600B345CD /* GCFieldInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 422B34401CA7322600B345CD /* GCFieldInfo.m */; };
422B4D252AED7FE100DB037A /* ExampleSummaryFirst.fit in Resources */ = {isa = PBXBuildFile; fileRef = 422B4D242AED7FE100DB037A /* ExampleSummaryFirst.fit */; };
422C70AE1642B677003779E0 /* GCHistoryAggregatedStats.m in Sources */ = {isa = PBXBuildFile; fileRef = 422C70AD1642B677003779E0 /* GCHistoryAggregatedStats.m */; };
422CC8761E6ACA1700195414 /* GCUnit+FIT.m in Sources */ = {isa = PBXBuildFile; fileRef = 423B462E1CDFE03400743D79 /* GCUnit+FIT.m */; };
422CC8781E6ACA1700195414 /* GCField+FitFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42769BC51DD1D225000390F1 /* GCField+FitFile.swift */; };
Expand Down Expand Up @@ -1396,6 +1397,7 @@
422B343F1CA7322600B345CD /* GCFieldInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GCFieldInfo.h; path = src/GCFieldInfo.h; sourceTree = "<group>"; };
422B34401CA7322600B345CD /* GCFieldInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GCFieldInfo.m; path = src/GCFieldInfo.m; sourceTree = "<group>"; };
422B34431CA7345200B345CD /* GCFieldsDefs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = GCFieldsDefs.h; path = src/GCFieldsDefs.h; sourceTree = "<group>"; };
422B4D242AED7FE100DB037A /* ExampleSummaryFirst.fit */ = {isa = PBXFileReference; lastKnownFileType = file; path = ExampleSummaryFirst.fit; sourceTree = "<group>"; };
422C70AC1642B2ED003779E0 /* GCHistoryAggregatedStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = GCHistoryAggregatedStats.h; path = src/GCHistoryAggregatedStats.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
422C70AD1642B677003779E0 /* GCHistoryAggregatedStats.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GCHistoryAggregatedStats.m; path = src/GCHistoryAggregatedStats.m; sourceTree = "<group>"; };
422CCE7B1B7E9B6300A4DAEB /* Cells.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Cells.xcassets; path = ConnectStats/icons/Cells.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2904,6 +2906,7 @@
4253B46D1CD4A53400437E6A /* fit_files */ = {
isa = PBXGroup;
children = (
422B4D242AED7FE100DB037A /* ExampleSummaryFirst.fit */,
422A24EB247325FB00D6C2FB /* activity_424479793.json */,
42C3118A24731B09004DF872 /* activity_424479793.fit */,
4285C20F2427C5E5003C522E /* last_connectstats_single_544406.json */,
Expand Down Expand Up @@ -4937,6 +4940,7 @@
42A5D917232874A600898FD5 /* modern_activity_types.json in Resources */,
42880C462381EEE00030C3C1 /* track_cs_5582.fit in Resources */,
4277C0E123BD133D00C1B1B9 /* activity_217470507.tcx in Resources */,
422B4D252AED7FE100DB037A /* ExampleSummaryFirst.fit in Resources */,
427B79D72465A11F005EDEAD /* track_cs_857090.fit in Resources */,
420A57EC1CB32C5900EA3B42 /* withings_getmeas_188427.json in Resources */,
427B79D62465A11F005EDEAD /* track_cs_728599.fit in Resources */,
Expand Down Expand Up @@ -6660,7 +6664,7 @@
CODE_SIGN_ENTITLEMENTS = ConnectStats/ConnectStats.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = M7QSSF3624;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
Expand Down Expand Up @@ -6717,7 +6721,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = M7QSSF3624;
ENABLE_TESTABILITY = NO;
Expand Down
8 changes: 7 additions & 1 deletion ConnectStats/src/GCActivity+Import.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ extension GCActivity {
if let messageStart = message.interpretedField(key: "start_time")?.time{
if messageStart == startTime {
sessionStart = messageStart
sessionEnd = message.time()
if let messageElapsed = message.interpretedField(key: "total_elapsed_time")?.valueUnit,
messageElapsed.unit == "s"{
let total_elapsed_time = TimeInterval(messageElapsed.value)
sessionEnd = messageStart.addingTimeInterval(total_elapsed_time)
}else{
sessionEnd = message.time()
}
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion ConnectStats/src/GCConnectStatsRequestAPICheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class GCConnectStatsRequestAPICheck : GCConnectStatsRequest {
let status : Int
let redirect : String?
}


override var urlDescription: String! {
return GCWebConnectStatsApiCheck(GCAppGlobal.webConnectsStatsConfig())
}
@objc override func preparedUrlRequest() -> URLRequest? {
if let url = URL(string: GCWebConnectStatsApiCheck(GCAppGlobal.webConnectsStatsConfig())){
return URLRequest(url: url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class GCConnectStatsRequestBackgroundFitFile: GCConnectStatsRequestFitFile {
self.cache = GCWebRequestCache(db: cacheDb, classname: String(describing: type(of: self)))
super.init(activity:activity)
}


override var urlDescription: String! {
return GCWebConnectStatsFitFile(GCAppGlobal.webConnectsStatsConfig())
}
@objc override func preparedUrlRequest() -> URLRequest? {
switch self.requestMode {
case .downloadAndProcess,.downloadAndCache:
Expand Down
4 changes: 4 additions & 0 deletions ConnectStats/src/GCConnectStatsRequestBackgroundSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class GCConnectStatsRequestBackgroundSearch: GCConnectStatsRequest {
super.init(nextWith: current)
}

override var urlDescription: String! {
return GCWebConnectStatsSearch(GCAppGlobal.webConnectsStatsConfig())
}

@objc override func preparedUrlRequest() -> URLRequest? {
switch self.requestMode {
case .downloadAndProcess,.downloadAndCache:
Expand Down
8 changes: 8 additions & 0 deletions ConnectStats/src/GCConnectStatsRequestFitFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ -(BOOL)validAlternativeService{
return nil;
}

-(NSString*)urlDescription{
NSString * path = GCWebConnectStatsFitFile([GCAppGlobal webConnectsStatsConfig]);
GCService * service = self.activity.service;
NSString * aid = [service serviceIdFromActivityId:self.activity.activityId ];

return [NSString stringWithFormat:@"%@?activity_id=%@", path, aid];
}

-(NSURLRequest*)preparedUrlRequest{
if( [self isSignedIn] ){
self.navigationController = nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import UIKit
import RZUtilsSwift

class GCConnectStatsRequestRegisterNotifications : GCConnectStatsRequest {
override var urlDescription : String! {
let path = GCWebConnectStatsRegisterNotification(GCAppGlobal.webConnectsStatsConfig())
return path
}

@objc override func preparedUrlRequest() -> URLRequest? {
#if GC_USE_SANDBOX_APN
Expand Down
6 changes: 6 additions & 0 deletions ConnectStats/src/GCConnectStatsRequestWeather.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ -(void)dealloc{
-(NSString*)url{
return nil;
}
-(NSString*)urlDescription{
NSString * path = GCWebConnectStatsWeather([GCAppGlobal webConnectsStatsConfig]);
GCService * service = self.activity.service;
NSString * aid = [service serviceIdFromActivityId:self.activity.activityId ];
return [NSString stringWithFormat:@"%@?activity_id=%@", path, aid];
}
-(NSString*)debugDescription{
return [NSString stringWithFormat:@"<%@: %@ %@>",
NSStringFromClass([self class]),
Expand Down
27 changes: 26 additions & 1 deletion ConnectStatsTests/GCTestActivityFitFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ class GCTestActivityFitFile: XCTestCase {

}

func testParseFitMultiSportSummaryFirstMethod() {
let url = URL(fileURLWithPath: RZFileOrganizer.bundleFilePath("ExampleSummaryFirst.fit", for: type(of: self)))
let activityId = "example"
if
let fitFile = FitFile(file: url){
let messages = fitFile.messages(forMessageType: FitMessageType.session)
var activities : [GCActivity] = []
for message in messages {
if let messageStart = message.interpretedField(key: "start_time")?.time,
let activity = GCActivity(withId: activityId, fitFile: fitFile, startTime: messageStart){
activities.append(activity)
}
}
XCTAssertEqual(activities.count, messages.count)
var lastEndTime : Date? = nil
for activity in activities {
if let shouldBeAfter = lastEndTime {
// Adding a Tolerance of 1 sec as one of the transition elapsed time is of by 0.1 sec or so.
XCTAssertGreaterThanOrEqual(activity.startTime, shouldBeAfter.addingTimeInterval(TimeInterval(-1.0)))
}
lastEndTime = activity.endTime
}
}
print("finished")
}

func testParseFitSwimAndMultiSport() {

RZFileOrganizer.removeEditableFile("multisport.db")
Expand All @@ -71,7 +97,6 @@ class GCTestActivityFitFile: XCTestCase {
if let messageStart = message.interpretedField(key: "start_time")?.time,
let activity = GCActivity(withId: activityId, fitFile: fitFile, startTime: messageStart){
activities.append(activity)
//print( "\(activity) \(activity.summaryData)")
var downloaded : GCActivity? = nil
for act in organizer.activities {
if act.date == messageStart && act.activityType == activity.activityType{
Expand Down
Binary file not shown.

0 comments on commit aebd7b0

Please sign in to comment.