Skip to content

Commit c3c1bc8

Browse files
committed
Modify a minor issue on AWAREFetchSizeAdjuster
1 parent 0b588c8 commit c3c1bc8

File tree

11 files changed

+6417
-6000
lines changed

11 files changed

+6417
-6000
lines changed

AWAREFramework.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'AWAREFramework'
11-
s.version = '1.14.13'
11+
s.version = '1.14.14'
1212
s.summary = 'AWARE: An Open-source Context Instrumentation Framework'
1313

1414
# This description is used to generate tags and improve search results.

AWAREFramework/Classes/Core/Storage/SQLite/SQLiteSeparatedStorage.h

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#import "AWAREStorage.h"
99
#import "BaseCoreDataHandler.h"
10+
#import "AWAREFetchSizeAdjuster.h"
1011

1112
NS_ASSUME_NONNULL_BEGIN
1213

@@ -18,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
1819
//typedef void (^InsertCallBack)(NSDictionary <NSString *, id> * _Nonnull dataDict,
1920
// NSManagedObjectContext * _Nonnull childContext,
2021
// NSString * _Nonnull entity );
22+
@property AWAREFetchSizeAdjuster * fetchSizeAdjuster;
2123

2224
- (instancetype _Nonnull )initWithStudy:(AWAREStudy * _Nullable) study
2325
sensorName:(NSString * _Nonnull) name

AWAREFramework/Classes/Core/Storage/SQLite/SQLiteSeparatedStorage.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ @implementation SQLiteSeparatedStorage{
2929
BaseCoreDataHandler * coreDataHandler;
3030
// SyncExecutor * executor;
3131
id<AWARESyncExecutorDelegate> executorDelegate;
32-
AWAREFetchSizeAdjuster * fetchSizeAdjuster;
3332
}
3433

34+
@synthesize fetchSizeAdjuster;
35+
3536
- (instancetype)initWithStudy:(AWAREStudy *)study sensorName:(NSString *)name{
3637
NSLog(@"[NOTE] Please use -initWithStudy:sensorName:objectModelName:indexModelName:dbHandler:");
3738
BaseCoreDataHandler * handler = [[BaseCoreDataHandler alloc] init];
@@ -286,6 +287,7 @@ - (void) syncTask {
286287
NSDate * s = [NSDate new];
287288
NSArray * indexes = [private executeFetchRequest:fetchRequest error:&error];
288289
if (self.isDebug) NSLog(@"[%@][%@] FETCH SPEED: (%ld) New SQLite ---> %f", self.sensorName, self, indexes.count, [[NSDate new] timeIntervalSinceDate:s] );
290+
if (self.isDebug) NSLog(@"[%@] FetchSize: %ld", self.sensorName, self->fetchSizeAdjuster.fetchSize );
289291

290292
NSMutableArray * results = [@[] mutableCopy];
291293
if (indexes!=nil && indexes.count>0) {

AWAREFramework/Classes/Core/Storage/Tools/AWAREFetchSizeAdjuster.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
1515
@property (readonly) NSInteger fetchSize;
1616
@property BOOL debug;
1717

18+
- (void) setMaxFetchSize:(NSInteger) maxFetchSize;
19+
1820
- (instancetype) initWithSensorName:(NSString *)sensorName;
1921
- (void) success;
2022
- (void) failure;

AWAREFramework/Classes/Core/Storage/Tools/AWAREFetchSizeAdjuster.m

+23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@implementation AWAREFetchSizeAdjuster{
1111
NSString * sensor;
1212
NSString * key;
13+
NSNumber * _maxFetchSize;
1314
}
1415

1516
@synthesize totalSuccess;
@@ -33,6 +34,8 @@ -(instancetype)initWithSensorName:(NSString *)sensorName{
3334
return self;
3435
}
3536

37+
38+
3639
- (void)success{
3740
totalSuccess = totalSuccess + 1;
3841
if(self.debug) NSLog(@"[AWAREFetchSizeAdjuster] SUCCESS : %ld", totalSuccess);
@@ -41,6 +44,16 @@ - (void)success{
4144

4245
if(self.debug) NSLog(@"[AWAREFetchSizeAdjuster] THRESHOLD TO INCREASE FETCH SIZE : %f", threshold);
4346
if (totalSuccess >= threshold) {
47+
48+
if (_maxFetchSize != NULL) {
49+
if(self.debug) NSLog(@"[AWAREFetchSizeAdjuster] MAX_FETCH_SIZE: %@, FETCH_SIZE: %ld", _maxFetchSize, (long)fetchSize);
50+
if (_maxFetchSize.integerValue <= fetchSize) {
51+
fetchSize = _maxFetchSize.integerValue;
52+
[self updateFetchSize:fetchSize];
53+
return;
54+
}
55+
}
56+
4457
totalSuccess = 0;
4558
fetchSize = fetchSize + 1;
4659
if(self.debug) NSLog(@"[AWAREFetchSizeAdjuster] Fetch Size INCREASE : %ld", (long)fetchSize);
@@ -71,4 +84,14 @@ - (void) updateFetchSize:(NSInteger)fetchSize{
7184
[defaults synchronize];
7285
}
7386

87+
88+
- (void) setMaxFetchSize:(NSInteger) maxFetchSize {
89+
if (maxFetchSize <= fetchSize) {
90+
fetchSize = maxFetchSize;
91+
[self updateFetchSize:fetchSize];
92+
_maxFetchSize = [[NSNumber alloc] initWithInteger:maxFetchSize];
93+
}
94+
}
95+
96+
7497
@end

Example/AWARE-SensingApp/AppDelegate.swift

+58-23
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,76 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2323
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2424
// Override point for customization after applicatio
2525
// setup AWARECore
26+
2627
let core = AWARECore.shared()
2728
core.requestPermissionForBackgroundSensing { (status) in
2829
core.requestPermissionForPushNotification(completion: nil)
2930
core.activate()
3031

32+
print(cleanOldDataTypeDaily)
33+
AWAREStudy.shared().setCleanOldDataType(cleanOldDataTypeDaily)
34+
AWAREStudy.shared().setDebug(true)
35+
36+
AWAREStudy.shared().setStudyURL("https://yahoo-earable.an.r.appspot.com/index.php/webservice/index/1/hlkrKP13AB")
37+
38+
print(AWAREStudy.shared().getCleanOldDataType())
39+
40+
let study = AWAREStudy.shared()
3141
// init sensors
32-
let accelerometer = Accelerometer()
33-
// let gyroscope = Gyroscope()
34-
// let battery = Battery()
35-
// let screen = Screen()
36-
// let call = Calls()
37-
// let ambientNoise = AmbientNoise()
38-
// let activity = IOSActivityRecognition()
39-
// let step = Pedometer()
40-
// let bluetooth = Bluetooth()
41-
// let cal = Calendar()
42-
// let healthKit = AWAREHealthKit()
43-
let weather = OpenWeather()
44-
self.sensorManager.add(weather)
45-
weather.setSensorEventHandler { sensor, data in
46-
if let d = data {
47-
print(d)
48-
}
49-
}
42+
let accelerometer = Accelerometer(awareStudy: study)
43+
accelerometer.setSensingIntervalWithHz(100)
44+
accelerometer.setSavingIntervalWithSecond(5)
45+
(accelerometer.storage as! SQLiteSeparatedStorage).fetchSizeAdjuster.setMaxFetchSize(2);
46+
accelerometer.storage?.setDebug(true)
47+
48+
let gyroscope = Gyroscope(awareStudy: study)
49+
gyroscope.setSensingIntervalWithHz(100)
50+
gyroscope.setSavingIntervalWithSecond(5)
51+
(gyroscope.storage as! SQLiteSeparatedStorage).fetchSizeAdjuster.setMaxFetchSize(3);
52+
53+
54+
let rotation = Rotation(awareStudy: study)
55+
rotation.setSensingIntervalWithHz(100)
56+
rotation.setSavingIntervalWithSecond(5)
57+
(rotation.storage as! SQLiteSeparatedStorage).fetchSizeAdjuster.setMaxFetchSize(3);
58+
59+
let lAccelerometer = LinearAccelerometer(awareStudy: study)
60+
lAccelerometer.setSensingIntervalWithHz(100)
61+
lAccelerometer.setSavingIntervalWithSecond(5)
62+
(lAccelerometer.storage as! SQLiteSeparatedStorage).fetchSizeAdjuster.setMaxFetchSize(3);
63+
64+
let mag = Magnetometer(awareStudy: study)
65+
mag.setSensingIntervalWithHz(100)
66+
mag.setSavingIntervalWithSecond(5)
67+
(mag.storage as! SQLiteSeparatedStorage).fetchSizeAdjuster.setMaxFetchSize(3);
68+
69+
let headphone = HeadphoneMotion(awareStudy: study)
70+
headphone.setSensingIntervalWithHz(100)
71+
headphone.setSavingIntervalWithSecond(5)
72+
(headphone.storage as! SQLiteSeparatedStorage).fetchSizeAdjuster.setMaxFetchSize(3);
73+
74+
// let battery = Battery()
75+
// let screen = Screen()
76+
// let call = Calls()
77+
// let ambientNoise = AmbientNoise()
78+
// let activity = IOSActivityRecognition()
79+
// let step = Pedometer()
80+
// let bluetooth = Bluetooth()
81+
// let cal = Calendar()
82+
// let healthKit = AWAREHealthKit()
5083

5184
// add the sensors into AWARESensorManager
52-
self.sensorManager.add(accelerometer)
53-
// self.sensorManager.add([accelerometer, gyroscope, battery, screen, call, ambientNoise, activity, step, bluetooth, cal, healthKit])
85+
self.sensorManager.add([accelerometer,gyroscope,rotation,lAccelerometer,mag,headphone])
86+
// self.sensorManager.add(accelerometer)
87+
// self.sensorManager.add([accelerometer, gyroscope, battery, screen, call, ambientNoise, activity, step, bluetooth, cal, healthKit])
5488
self.sensorManager.startAllSensors()
55-
89+
5690
// setup ESMs
5791
// generate ESMItem
5892
let pam = ESMItem(asPAMESMWithTrigger: "pam")
5993
pam.setTitle("How do you feeling now?")
6094
pam.setInstructions("Please select an image.")
61-
95+
6296
// generate ESMSchedule
6397
let esm = ESMSchedule()
6498
esm.scheduleId = "schedule_1"
@@ -68,11 +102,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
68102
esm.expirationThreshold = 60
69103
esm.addESM(pam)
70104
esm.notificationTitle = "Tap to answer the question."
71-
105+
72106
// add the ESMSchedules into ESMScheduleManager
73107
let esmManager = ESMScheduleManager.shared()
74108
esmManager.deleteAllSchedules(withNotification: true)
75109
esmManager.add(esm, withNotification: true)
110+
76111
}
77112

78113
// monitoring battery consumption

Example/AWARE-SensingApp/ViewController.swift

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ViewController: UIViewController {
2929

3030
override func viewDidAppear(_ animated: Bool) {
3131

32+
AWARESensorManager.shared().syncAllSensorsForcefully()
33+
3234
checkESMSchedules()
3335

3436
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { (timer) in

Example/Podfile.lock

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
PODS:
2-
- AWAREFramework (1.14.9):
3-
- AWAREFramework/Core (= 1.14.9)
4-
- AWAREFramework/Bluetooth (1.14.9):
2+
- AWAREFramework (1.14.14):
3+
- AWAREFramework/Core (= 1.14.14)
4+
- AWAREFramework/Bluetooth (1.14.14):
55
- AWAREFramework/Core
6-
- AWAREFramework/Calendar (1.14.9):
6+
- AWAREFramework/Calendar (1.14.14):
77
- AWAREFramework/Core
8-
- AWAREFramework/Contact (1.14.9):
8+
- AWAREFramework/Contact (1.14.14):
99
- AWAREFramework/Core
10-
- AWAREFramework/Core (1.14.9)
11-
- AWAREFramework/HealthKit (1.14.9):
10+
- AWAREFramework/Core (1.14.14)
11+
- AWAREFramework/HealthKit (1.14.14):
1212
- AWAREFramework/Core
13-
- AWAREFramework/Microphone (1.14.9):
13+
- AWAREFramework/Microphone (1.14.14):
1414
- AWAREFramework/Core
15-
- AWAREFramework/MotionActivity (1.14.9):
15+
- AWAREFramework/MotionActivity (1.14.14):
1616
- AWAREFramework/Core
1717

1818
DEPENDENCIES:
@@ -29,8 +29,8 @@ EXTERNAL SOURCES:
2929
:path: "../"
3030

3131
SPEC CHECKSUMS:
32-
AWAREFramework: 782dc3162417afc67f313a8b3bf298b46654acf1
32+
AWAREFramework: a4a008d93c81832975ff9a00cbcd132fe9ff0c78
3333

3434
PODFILE CHECKSUM: b61851acdb08152e0f516a94053544d7f18c88bf
3535

36-
COCOAPODS: 1.12.1
36+
COCOAPODS: 1.16.1

Example/Pods/Local Podspecs/AWAREFramework.podspec.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)