Skip to content

Commit

Permalink
Merge pull request #24 from methodic-labs/fix/npe
Browse files Browse the repository at this point in the history
Filter out null objects and bump versions.
  • Loading branch information
geekbeast authored Feb 8, 2024
2 parents 4b608e5 + 0e1c9a6 commit c0ce816
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 30 deletions.
7 changes: 4 additions & 3 deletions chronicle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"chronicle/Preview Content\"";
DEVELOPMENT_TEAM = T646XVW64T;
ENABLE_PREVIEWS = YES;
Expand All @@ -695,7 +696,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.7;
MARKETING_VERSION = 1.9;
PRODUCT_BUNDLE_IDENTIFIER = com.methodic.chronicle;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -735,7 +736,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.7;
MARKETING_VERSION = 1.9;
PRODUCT_BUNDLE_IDENTIFIER = com.methodic.chronicle;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -783,7 +784,7 @@
repositoryURL = "https://github.com/firebase/firebase-ios-sdk";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 9.0.0;
minimumVersion = 10.8.1;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
{
"pins" : [
{
"identity" : "abseil-cpp-swiftpm",
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/abseil-cpp-SwiftPM.git",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "583de9bd60f66b40e78d08599cc92036c2e7e4e1",
"version" : "0.20220203.2"
"revision" : "bfc0b6f81adc06ce5121eb23f628473638d67c5c",
"version" : "1.2022062300.0"
}
},
{
"identity" : "boringssl-swiftpm",
"identity" : "app-check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/boringssl-SwiftPM.git",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "dd3eda2b05a3f459fc3073695ad1b28659066eab",
"version" : "0.9.1"
"revision" : "3e464dad87dad2d29bb29a97836789bf0f8f67d2",
"version" : "10.18.1"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "7e80c25b51c2ffa238879b07fbfc5baa54bb3050",
"version" : "9.6.0"
"revision" : "f91c8167141d0279726c6f6d9d4a47c026785cbc",
"version" : "10.21.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "c1cfde8067668027b23a42c29d11c246152fe046",
"version" : "9.6.0"
"revision" : "cb8617fab75d181270a1d8f763f26b15c73e2e1e",
"version" : "10.21.0"
}
},
{
"identity" : "googledatatransport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleDataTransport.git",
"state" : {
"revision" : "5056b15c5acbb90cd214fe4d6138bdf5a740e5a8",
"version" : "9.2.0"
"revision" : "a732a4b47f59e4f725a2ea10f0c77e93a7131117",
"version" : "9.3.0"
}
},
{
"identity" : "googleutilities",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "68ea347bdb1a69e2d2ae2e25cd085b6ef92f64cb",
"version" : "7.9.0"
"revision" : "bc27fad73504f3d4af235de451f02ee22586ebd3",
"version" : "7.12.1"
}
},
{
"identity" : "grpc-ios",
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/grpc/grpc-ios.git",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "8440b914756e0d26d4f4d054a1c1581daedfc5b6",
"version" : "1.44.3-grpc"
"revision" : "a673bc2937fbe886dd1f99c401b01b6d977a9c98",
"version" : "1.49.1"
}
},
{
Expand All @@ -72,6 +72,15 @@
"version" : "2.1.0"
}
},
{
"identity" : "interop-ios-for-google-sdks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/interop-ios-for-google-sdks.git",
"state" : {
"revision" : "2d12673670417654f08f5f90fdd62926dc3a2648",
"version" : "100.0.0"
}
},
{
"identity" : "leveldb",
"kind" : "remoteSourceControl",
Expand All @@ -95,8 +104,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "3e4e743631e86c8c70dbc6efdc7beaa6e90fd3bb",
"version" : "2.1.1"
"revision" : "e70e889c0196c76d22759eb50d6a0270ca9f1d9e",
"version" : "2.3.1"
}
},
{
Expand Down
14 changes: 11 additions & 3 deletions chronicle/CoreData/UploadDataOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ class UploadDataOperation: Operation {

fetchRequest.fetchLimit = fetchLimit

let objects = try bgContext.fetch(fetchRequest)
let objects = try bgContext.fetch(fetchRequest).filter() { obj in
if(obj.sensorType == nil ) {
false
} else {
true
}
}
let itemsRemaining = try bgContext.count(for: countRequest)

var params = enrollment.toDict()
Expand Down Expand Up @@ -94,7 +100,8 @@ class UploadDataOperation: Operation {
UserDefaults.standard.set(true, forKey: UserSettingsKeys.isUploading)

var eventLogParams = enrollment.toDict() // { participantId: xx, studyId: xx }



ApiClient.uploadData(sensorData: data, enrollment: enrollment, deviceId: deviceId) {
// let uploadContext = NSManagedObjectContext(NSManagedObjectContext.ConcurrencyType.privateQueue)
// let objects = objectIds.map { try self.bgContext.existingObject(with: $0)}
Expand All @@ -108,11 +115,12 @@ class UploadDataOperation: Operation {
let stats = Dictionary(grouping: objects, by: { $0.sensorType }).compactMapValues { values in
UploadStatEvent(timestamp: uploadDate, sensorType: (values.first?.sensorType )!, samples: values.count)
}
let latestRecordedDate = objects.max {a,b in a.writeTimestamp! < b.writeTimestamp! }?.writeTimestamp
let statObjects = UploadHistory(context: self.viewContext)
statObjects.timestamp = uploadDate
statObjects.data = try? JSONEncoder().encode(stats)
try? self.viewContext.save()
let latestRecordedDate = objects.max {a,b in a.writeTimestamp! < b.writeTimestamp! }?.writeTimestamp

objects.forEach (self.bgContext.delete) // delete uploaded data from local db
try? self.bgContext.save()
// record last successful upload
Expand Down
2 changes: 1 addition & 1 deletion chronicle/SensorReader/SensorReaderDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class SensorReaderDelegate: NSObject, SRSensorReaderDelegate {
logger.error("sensor \(sensor.rawValue) is not supported")
return false
}

let lastFetch = Utils.getLastFetch(
device: SensorReaderDevice(device: fetchRequest.device),
sensor: Sensor.getSensor(sensor: reader.sensor))
Expand Down
2 changes: 1 addition & 1 deletion chronicle/Utilities/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ApiClient {
}

// upload SensorData to server
static func uploadData(sensorData: Data, enrollment: Enrollment, deviceId: String, onCompletion: @escaping() -> Void, onError: @escaping (String) -> Void) {
static func uploadData(sensorData: Data, enrollment: Enrollment, deviceId: String, onCompletion: @escaping() -> Void, onError: @escaping (String) -> Void) {

guard let url = ApiUtils.getSensorDataUploadURL(enrollment: enrollment, deviceId: deviceId) else {
onError("failed to upload sensor data: invalid url")
Expand Down

0 comments on commit c0ce816

Please sign in to comment.