Skip to content

Commit e5c40d4

Browse files
author
Joris Janssen
committed
Updated functionality and tests of getting local data
1 parent 06bbd23 commit e5c40d4

10 files changed

Lines changed: 210 additions & 116 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//
2+
// CSStorageTest.m
3+
// SensePlatform
4+
//
5+
// Created by Joris Janssen on 07/01/15.
6+
//
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import <XCTest/XCTest.h>
11+
#import "CSSensePlatform.h"
12+
#import "CSSensorStore.h"
13+
#import "CSStorage.h"
14+
15+
16+
17+
@interface CSStorageTest : XCTestCase
18+
19+
@end
20+
21+
@implementation CSStorageTest {
22+
CSStorage* storage;
23+
NSDate* startDate;
24+
NSString* sensorName;
25+
}
26+
27+
- (void)setUp {
28+
[super setUp];
29+
30+
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
31+
NSString* dbPath =[rootPath stringByAppendingPathComponent:@"data.db"];
32+
33+
storage = [[CSStorage alloc] initWithPath:dbPath];
34+
35+
startDate = [NSDate date];
36+
sensorName = @"testSensor";
37+
38+
//put one datapoint in the database
39+
[storage storeSensor:sensorName description:@"testDescription" deviceType:@"testDeviceType" device:@"testDevice" dataType:@"testDataType" value:@"somevalue" timestamp:[startDate timeIntervalSince1970]];
40+
41+
}
42+
43+
- (void)tearDown {
44+
// Put teardown code here. This method is called after the invocation of each test method in the class.
45+
[super tearDown];
46+
}
47+
48+
/**
49+
* Tests the function for getting data in CSStorage
50+
*/
51+
- (void)testSensorDataPointsFromId {
52+
NSArray* result = [storage getSensorDataPointsFromId:0 limit:5];
53+
// NSLog(@"Number of rows is %i", result.count);
54+
XCTAssertGreaterThan(result.count, 0, @"No data found in sensordata store!");
55+
XCTAssertEqual(result.count, 1, @"Not one row found in sensordata store although only one point should have been added!");
56+
}
57+
58+
/**
59+
* Tests the function for getting data from a sensor getDataFromSensor in CSStorage
60+
*/
61+
- (void) testGetDataFromSensor {
62+
63+
NSDate* endDate = [startDate dateByAddingTimeInterval: 2.0];
64+
65+
NSArray* result = [storage getDataFromSensor:sensorName from:startDate to:endDate];
66+
XCTAssertGreaterThan(result.count, 0, @"No data found in sensordata store!");
67+
XCTAssertEqual(result.count, 1, @"Not one row found in sensordata store although only one point should have been added!");
68+
69+
//this time we expect no data points because we use a non existing sensor name
70+
result = [storage getDataFromSensor:@"nonExistingSensorName" from:startDate to:endDate];
71+
XCTAssertEqual(result.count, 0, @"Data found in sensordata store despite using non existing sensor name");
72+
73+
//shifting the interval
74+
startDate = endDate;
75+
endDate = [startDate dateByAddingTimeInterval: 2.0];
76+
77+
// this time we expect no datapoints because they do not fit in the correct time interval
78+
result = [storage getDataFromSensor:sensorName from:startDate to:endDate];
79+
XCTAssertEqual(result.count, 0, @"Data found in sensordata store despite using incorrect time interval");
80+
}
81+
82+
@end

Sense Library Tests/CSStorageTests.m

Lines changed: 0 additions & 40 deletions
This file was deleted.

Sense Library Tests/Sense_Library_Tests.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ - (void)tearDown {
2525
[super tearDown];
2626
}
2727

28-
- (void)testExample {
28+
- (void)testStoreData {
29+
2930
// This is an example of a functional test case.
3031
XCTAssert(YES, @"Pass");
3132
}

SensePlatform.xcodeproj/project.pbxproj

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,18 @@
110110
3EE091ED18FD597300A04ED4 /* CSSensorIdKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EE091EC18FD597300A04ED4 /* CSSensorIdKey.m */; };
111111
3EF47FBA19093D3E00104D69 /* NSData+GZIP.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EF47FB919093D3E00104D69 /* NSData+GZIP.m */; };
112112
A96D6ECF1A5C49FF00554BBC /* Sense_Library_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = A96D6ECE1A5C49FF00554BBC /* Sense_Library_Tests.m */; };
113-
A96D6ED01A5C49FF00554BBC /* libSensePlatform.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E820D6A15D40AB50001A3EC /* libSensePlatform.a */; };
114-
A96D6ED71A5C4B2500554BBC /* CSStorageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A96D6ED61A5C4B2500554BBC /* CSStorageTests.m */; };
115-
A96D6ED81A5C4B2500554BBC /* CSStorageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A96D6ED61A5C4B2500554BBC /* CSStorageTests.m */; };
113+
A99F99CF1A5D16D300D6CB76 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E148BD0160A18DC0010A0D1 /* UIKit.framework */; };
114+
A99F99D41A5D18B100D6CB76 /* CSStorageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A99F99D31A5D18B100D6CB76 /* CSStorageTest.m */; };
115+
A99F99D51A5D8A5D00D6CB76 /* libSensePlatform.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E820D6A15D40AB50001A3EC /* libSensePlatform.a */; };
116+
A99F99D61A5D8B7800D6CB76 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E513F4F18F7DDE60008415A /* libsqlite3.dylib */; };
117+
A99F99D91A5D8C2400D6CB76 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E9C157D15D574D300F520D0 /* CoreAudio.framework */; };
118+
A99F99DA1A5D8C2D00D6CB76 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E9C158315D574E700F520D0 /* CoreLocation.framework */; };
119+
A99F99DB1A5D8C3600D6CB76 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E9C158115D574E100F520D0 /* CoreMotion.framework */; };
120+
A99F99DC1A5D8C4300D6CB76 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E9C157F15D574DB00F520D0 /* AVFoundation.framework */; };
121+
A99F99DD1A5D8C4D00D6CB76 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E9C157B15D574C300F520D0 /* AudioToolbox.framework */; };
122+
A99F99DE1A5D8C5700D6CB76 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E9C157915D574BB00F520D0 /* CoreTelephony.framework */; };
123+
A99F99DF1A5D8C6100D6CB76 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E9C157615D574B500F520D0 /* SystemConfiguration.framework */; };
124+
A99F99E01A5D8C6B00D6CB76 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E820D6D15D40AB50001A3EC /* Foundation.framework */; };
116125
FFC80BE6183CCF5900E3EF27 /* CSScreenSensor.m in Sources */ = {isa = PBXBuildFile; fileRef = FFC80BE5183CCF5900E3EF27 /* CSScreenSensor.m */; };
117126
/* End PBXBuildFile section */
118127

@@ -293,7 +302,9 @@
293302
A96D6ECA1A5C49FF00554BBC /* Sense Library Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Sense Library Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
294303
A96D6ECD1A5C49FF00554BBC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
295304
A96D6ECE1A5C49FF00554BBC /* Sense_Library_Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Sense_Library_Tests.m; sourceTree = "<group>"; };
296-
A96D6ED61A5C4B2500554BBC /* CSStorageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CSStorageTests.m; path = "Sense Library Tests/CSStorageTests.m"; sourceTree = "<group>"; };
305+
A96D6ED91A5D147700554BBC /* Xcode.app */ = {isa = PBXFileReference; lastKnownFileType = wrapper.application; name = Xcode.app; path = ../../../../../../Applications/Xcode.app; sourceTree = "<group>"; };
306+
A99F99D31A5D18B100D6CB76 /* CSStorageTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSStorageTest.m; sourceTree = "<group>"; };
307+
A99F99D71A5D8C1300D6CB76 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
297308
FFC80BE4183CCF5900E3EF27 /* CSScreenSensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSScreenSensor.h; sourceTree = "<group>"; };
298309
FFC80BE5183CCF5900E3EF27 /* CSScreenSensor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSScreenSensor.m; sourceTree = "<group>"; };
299310
/* End PBXFileReference section */
@@ -358,7 +369,17 @@
358369
isa = PBXFrameworksBuildPhase;
359370
buildActionMask = 2147483647;
360371
files = (
361-
A96D6ED01A5C49FF00554BBC /* libSensePlatform.a in Frameworks */,
372+
A99F99E01A5D8C6B00D6CB76 /* Foundation.framework in Frameworks */,
373+
A99F99DF1A5D8C6100D6CB76 /* SystemConfiguration.framework in Frameworks */,
374+
A99F99DE1A5D8C5700D6CB76 /* CoreTelephony.framework in Frameworks */,
375+
A99F99DD1A5D8C4D00D6CB76 /* AudioToolbox.framework in Frameworks */,
376+
A99F99DC1A5D8C4300D6CB76 /* AVFoundation.framework in Frameworks */,
377+
A99F99DB1A5D8C3600D6CB76 /* CoreMotion.framework in Frameworks */,
378+
A99F99DA1A5D8C2D00D6CB76 /* CoreLocation.framework in Frameworks */,
379+
A99F99D91A5D8C2400D6CB76 /* CoreAudio.framework in Frameworks */,
380+
A99F99D61A5D8B7800D6CB76 /* libsqlite3.dylib in Frameworks */,
381+
A99F99D51A5D8A5D00D6CB76 /* libSensePlatform.a in Frameworks */,
382+
A99F99CF1A5D16D300D6CB76 /* UIKit.framework in Frameworks */,
362383
);
363384
runOnlyForDeploymentPostprocessing = 0;
364385
};
@@ -406,7 +427,6 @@
406427
3E820D5F15D40AB50001A3EC = {
407428
isa = PBXGroup;
408429
children = (
409-
A96D6ED61A5C4B2500554BBC /* CSStorageTests.m */,
410430
3EACDD84172E927900975C8D /* plugins */,
411431
3E148BD0160A18DC0010A0D1 /* UIKit.framework */,
412432
3E148BCC160A18130010A0D1 /* CFNetwork.framework */,
@@ -445,6 +465,8 @@
445465
3E820D6C15D40AB50001A3EC /* Frameworks */ = {
446466
isa = PBXGroup;
447467
children = (
468+
A99F99D71A5D8C1300D6CB76 /* libz.dylib */,
469+
A96D6ED91A5D147700554BBC /* Xcode.app */,
448470
3E513F4F18F7DDE60008415A /* libsqlite3.dylib */,
449471
3E820D6D15D40AB50001A3EC /* Foundation.framework */,
450472
3E148B7A160A11280010A0D1 /* SenTestingKit.framework */,
@@ -599,6 +621,7 @@
599621
A96D6ECB1A5C49FF00554BBC /* Sense Library Tests */ = {
600622
isa = PBXGroup;
601623
children = (
624+
A99F99D31A5D18B100D6CB76 /* CSStorageTest.m */,
602625
A96D6ECE1A5C49FF00554BBC /* Sense_Library_Tests.m */,
603626
A96D6ECC1A5C49FF00554BBC /* Supporting Files */,
604627
);
@@ -844,7 +867,6 @@
844867
3E820E4415D40B190001A3EC /* CSUserProximity.m in Sources */,
845868
3E820E4615D40B190001A3EC /* CSSensorStore.m in Sources */,
846869
3E513F5318F81D2C0008415A /* CSDataPoint.m in Sources */,
847-
A96D6ED71A5C4B2500554BBC /* CSStorageTests.m in Sources */,
848870
3E820E4715D40B190001A3EC /* CSSettings.m in Sources */,
849871
3E59ACBE15F4DB9D00C07D59 /* UIDevice+IdentifierAddition.m in Sources */,
850872
3E11261B16A7086400805102 /* UIDevice+Hardware.m in Sources */,
@@ -859,7 +881,7 @@
859881
buildActionMask = 2147483647;
860882
files = (
861883
A96D6ECF1A5C49FF00554BBC /* Sense_Library_Tests.m in Sources */,
862-
A96D6ED81A5C4B2500554BBC /* CSStorageTests.m in Sources */,
884+
A99F99D41A5D18B100D6CB76 /* CSStorageTest.m in Sources */,
863885
);
864886
runOnlyForDeploymentPostprocessing = 0;
865887
};
@@ -1212,6 +1234,7 @@
12121234
A96D6ED51A5C49FF00554BBC /* Release */,
12131235
);
12141236
defaultConfigurationIsVisible = 0;
1237+
defaultConfigurationName = Release;
12151238
};
12161239
/* End XCConfigurationList section */
12171240
};

SensePlatformTestAppTests/SensePlatformTestAppTests.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,4 @@ - (void)testAddDataFunction
8282
[NSThread sleepForTimeInterval:15];
8383
}
8484

85-
- (void) testStorage {
86-
CSSt
87-
}
88-
8985
@end

sense platform/CSSensePlatform.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ + (void) logout {
116116
[[CSSettings sharedSettings] setSettingType:kCSSettingTypeGeneral setting:kCSGeneralSettingUploadToCommonSense value:kCSSettingNO];
117117
}
118118

119+
+ (NSArray*) getLocalDataForSensor:(NSString *)name from:(NSDate *)startDate to:(NSDate *)endDate {
120+
return [[CSSensorStore sharedSensorStore] getLocalDataForSensor: name from: startDate to: endDate];
121+
}
122+
119123
+ (NSArray*) getDataForSensor:(NSString*) name onlyFromDevice:(bool) onlyFromDevice nrLastPoints:(NSInteger) nrLastPoints {
120124
return [[CSSensorStore sharedSensorStore] getDataForSensor:name onlyFromDevice:onlyFromDevice nrLastPoints:nrLastPoints];
121125
}
@@ -266,9 +270,9 @@ + (void) synchronizeWithBloodPressureMonitor:(bpmCallBack) callback {
266270
*/
267271
}
268272

269-
+ (NSArray*) getDataForSensor:(NSString *)name onlyFromDevice:(bool)onlyFromDevice nrLastPoints:(NSInteger)nrLastPoints {
270-
271-
}
273+
//+ (NSArray*) getDataForSensor:(NSString *)name onlyFromDevice:(bool)onlyFromDevice nrLastPoints:(NSInteger)nrLastPoints {
274+
//
275+
//}
272276

273277
+ (NSString*) dataTypeOf:(NSString*) value {
274278
NSNumberFormatter* f = [[NSNumberFormatter alloc] init];

sense platform/CSSensorStore.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@
3636
- (void) enabledChanged:(id) notification;
3737
- (void) setSyncRate: (int) newRate;
3838
- (void) addSensor:(CSSensor*) sensor;
39+
3940
- (NSArray*) getDataForSensor:(NSString*) name onlyFromDevice:(bool) onlyFromDevice nrLastPoints:(NSInteger) nrLastPoints;
41+
42+
/**
43+
*
44+
*/
45+
- (NSArray*) getLocalDataForSensor:(NSString *)name from:(NSDate *)startDate to:(NSDate *)endDate;
46+
4047
- (void) giveFeedbackOnState:(NSString*) state from:(NSDate*)from to:(NSDate*) to label:(NSString*)label;
4148

4249
/* Ensure all sensor data is flushed, used to reduce memory usage.

sense platform/CSSensorStore.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ - (NSArray*) getDataForSensor:(NSString*) name onlyFromDevice:(bool) onlyFromDev
434434
}
435435
}
436436

437+
- (NSArray*) getLocalDataForSensor:(NSString *)name from:(NSDate *)startDate to:(NSDate *)endDate {
438+
return [self->storage getDataFromSensor:name from:startDate to:endDate];
439+
}
440+
437441
- (void) giveFeedbackOnState:(NSString*) state from:(NSDate*)from to:(NSDate*) to label:(NSString*)label {
438442
NSString* sensorId = [self resolveSensorIdForSensorName:state onlyThisDevice:NO];
439443

sense platform/CSStorage.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,27 @@
99
#import <Foundation/Foundation.h>
1010

1111
@interface CSStorage : NSObject
12+
1213
- (id) initWithPath:(NSString*) databaseFilePath;
14+
1315
- (void) storeSensor:(NSString*) sensor description:(NSString*) description deviceType:(NSString*) deviceType device:(NSString*) device dataType:(NSString*) dataType value:(NSString*) value timestamp:(double) timestamp;
16+
1417
- (NSArray*) getSensorDataPointsFromId:(long long) start limit:(size_t) limit;
18+
19+
/** Retrieve all the sensor data stored in the database between a certain time interval.
20+
* @param name The name of the sensor to get the data from
21+
* @param startDate The date and time at which to start looking for datapoints
22+
* @param endDate The date and time at which to stop looking for datapoints
23+
* @return an array of values, each value is a dictonary that descirbes the data point
24+
*/
25+
- (NSArray*) getDataFromSensor: (NSString*) name from: (NSDate*) startDate to: (NSDate*) endDate;
26+
27+
1528
- (void) removeDataBeforeId:(long long) rowId;
1629

17-
/*
30+
/**
1831
* Removes all data from before a certain date from buffer and main data store
19-
* @param: dateThreshold Date which marks the threshold, all data older than (from before) the date will be removed
32+
* @param dateThreshold NSDate which marks the threshold, all data older than (from before) the date will be removed
2033
*/
2134
- (void) removeDataBeforeTime:(NSDate *) dateThreshold;
2235

@@ -25,13 +38,8 @@
2538
- (void) flush;
2639

2740
- (void) storeSensorDescription:(NSString*) jsonDescription forSensor:(NSString*) sensor description:(NSString*) description deviceType:(NSString*) deviceType device:(NSString*) device;
41+
2842
- (NSString*) getSensorDescriptionForSensor:(NSString*) sensor description:(NSString*) description deviceType:(NSString*) deviceType device:(NSString*) device;
2943

30-
/** Retrieve all the sensor data stored in the database between a certain time interval.
31-
* @param name The name of the sensor to get the data from
32-
* @param startDate The date and time at which to start looking for datapoints
33-
* @param endDate The date and time at which to stop looking for datapoints
34-
* @return an array of values, each value is a dictonary that descirbes the data point
35-
*/
36-
- (NSArray*) getDataFromSensor: (NSString*) name from: (NSDate*) startDate to: (NSDate*) endDate;
37-
@end
44+
45+
@end

0 commit comments

Comments
 (0)