feature():1.增加iOS动态血糖的算法
This commit is contained in:
parent
984d90855e
commit
afcba2e630
|
|
@ -594,10 +594,7 @@
|
|||
"-DFOLLY_USE_LIBCPP=1",
|
||||
"-DFOLLY_CFG_NO_COROUTINES=1",
|
||||
);
|
||||
OTHER_LDFLAGS = (
|
||||
"$(inherited)",
|
||||
" ",
|
||||
);
|
||||
OTHER_LDFLAGS = "$(inherited) ";
|
||||
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
||||
SDKROOT = iphoneos;
|
||||
USE_HERMES = true;
|
||||
|
|
@ -665,10 +662,7 @@
|
|||
"-DFOLLY_USE_LIBCPP=1",
|
||||
"-DFOLLY_CFG_NO_COROUTINES=1",
|
||||
);
|
||||
OTHER_LDFLAGS = (
|
||||
"$(inherited)",
|
||||
" ",
|
||||
);
|
||||
OTHER_LDFLAGS = "$(inherited) ";
|
||||
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
||||
SDKROOT = iphoneos;
|
||||
USE_HERMES = true;
|
||||
|
|
|
|||
|
|
@ -26,12 +26,13 @@
|
|||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<!-- Do not change NSAllowsArbitraryLoads to true, or you will risk app rejection! -->
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<false/>
|
||||
<key>NSAllowsLocalNetworking</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>for test</string>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string></string>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// Algorithm20.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#ifndef Algorithm20_h
|
||||
#define Algorithm20_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "IValue.h"
|
||||
#import "IValueManager.h"
|
||||
#import "ReferenceManager.h"
|
||||
#import "ParamX.h"
|
||||
#import "I4Algorithm.h"
|
||||
|
||||
@interface Algorithm20 : NSObject
|
||||
|
||||
@property (nonatomic, strong) ParamX *X;
|
||||
@property (nonatomic, strong) NSMutableArray<IValue *> *calIValue;
|
||||
@property (nonatomic, strong) IValueManager *iValueManager;
|
||||
@property (nonatomic, strong) ReferenceManager *rfManager;
|
||||
|
||||
- (instancetype)init;
|
||||
- (IValue *)getInitParam;
|
||||
- (void)setInitParam:(IValue *)iValue;
|
||||
- (void)addRef:(NSNumber *)value time:(NSDate *)time;
|
||||
- (NSNumber *)calcBloodGlucose:(double)current datetime:(NSDate *)datetime;
|
||||
- (NSNumber *)calcBloodGlucose:(double)current index:(NSInteger)index;
|
||||
- (NSMutableArray<NSNumber *> *)calculateBloodGlucose:(NSInteger)index refValue:(NSNumber *)refValue values:(NSMutableArray<NSNumber *> *)values;
|
||||
- (IValue *)calTest:(double)current datetime:(NSDate *)datetime;
|
||||
- (int)calRoc;
|
||||
- (NSString *)dateformate:(NSDate *)date;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* Algorithm20_h */
|
||||
|
|
@ -0,0 +1,279 @@
|
|||
#import "Algorithm20.h"
|
||||
|
||||
@implementation Algorithm20
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.X = [[ParamX alloc] init];
|
||||
self.iValueManager = [[IValueManager alloc] init];
|
||||
self.rfManager = [[ReferenceManager alloc] init];
|
||||
self.calIValue = [NSMutableArray array];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (IValue *)getInitParam {
|
||||
return [self.iValueManager getPreIValue];
|
||||
}
|
||||
|
||||
- (void)setInitParam:(IValue *)iValue {
|
||||
[self.iValueManager setPreIValue:iValue];
|
||||
}
|
||||
|
||||
- (void)addRef:(NSNumber *)value time:(NSDate *)time {
|
||||
[self.rfManager addReference:value.doubleValue time:time];
|
||||
}
|
||||
|
||||
- (NSNumber *)calcBloodGlucose:(double)current datetime:(NSDate *)datetime {
|
||||
NSNumber *bgValue = @(0.0);
|
||||
IValue *cur_data = [[IValue alloc] initWithCurrentTime:datetime current:@(current)];
|
||||
IValue *i4_data = nil;
|
||||
[self.rfManager findReferenceByDate:datetime];
|
||||
|
||||
if ([self.rfManager isCalK]) {
|
||||
i4_data = [self calKValueAlgorithm:cur_data];
|
||||
} else {
|
||||
i4_data = [self I4Algorith:cur_data];
|
||||
}
|
||||
|
||||
if ([self.rfManager isCalK]) {
|
||||
bgValue = @([self.rfManager getRefValue].value);
|
||||
} else if ([self.rfManager isWaitCalK]) {
|
||||
bgValue = @([self.rfManager getRefValue].value);
|
||||
[i4_data setRfTime:[self.rfManager getRefValue].time];
|
||||
[i4_data setRf:@([self.rfManager getRefValue].value)];
|
||||
} else if ([i4_data getK] != nil) {
|
||||
bgValue = @([i4_data.getI4 doubleValue] / [i4_data.getK doubleValue]);
|
||||
}
|
||||
|
||||
bgValue = [self roundDouble:bgValue.doubleValue precision:1];
|
||||
if ((current >= 600.0) || (current <= 30.0)) {
|
||||
bgValue = @(0.0);
|
||||
}
|
||||
|
||||
[i4_data setBg:bgValue];
|
||||
[self.iValueManager setPreIValue:i4_data];
|
||||
|
||||
NSString *rft = [i4_data getRfTime] == nil ? @"" : [self dateformate:[i4_data getRfTime]];
|
||||
|
||||
NSLog(@"%@\t%@\t%@", [i4_data getCurrent], [self dateformate:[i4_data getCurrentTime]], bgValue);
|
||||
return bgValue;
|
||||
}
|
||||
|
||||
- (NSNumber *)calcBloodGlucose:(double)current index:(NSInteger)index {
|
||||
NSNumber *bgValue = @(0.0);
|
||||
IValue *cur_data = [[IValue alloc] initWithCurrentTime:nil current:@(current)];
|
||||
IValue *i4_data = nil;
|
||||
[self.rfManager findReferenceByIndex:index];
|
||||
|
||||
if ([self.rfManager isCalK]) {
|
||||
i4_data = [self calKValueAlgorithm:cur_data];
|
||||
} else {
|
||||
i4_data = [self I4Algorith:cur_data];
|
||||
}
|
||||
|
||||
if ([self.rfManager isCalK]) {
|
||||
bgValue = @([self.rfManager getRefValue].value);
|
||||
} else if ([self.rfManager isWaitCalK]) {
|
||||
bgValue = @([self.rfManager getRefValue].value);
|
||||
[i4_data setRfTime:[self.rfManager getRefValue].time];
|
||||
[i4_data setRf:@([self.rfManager getRefValue].value)];
|
||||
} else if ([i4_data getK] != nil) {
|
||||
bgValue = @([i4_data.getI4 doubleValue] / [i4_data.getK doubleValue]);
|
||||
}
|
||||
|
||||
bgValue = [self roundDouble:bgValue.doubleValue precision:1];
|
||||
if ((current >= 600.0) || (current <= 30.0)) {
|
||||
bgValue = @(0.0);
|
||||
}
|
||||
|
||||
[i4_data setBg:bgValue];
|
||||
[self.iValueManager setPreIValue:i4_data];
|
||||
[self.calIValue addObject:i4_data];
|
||||
|
||||
return bgValue;
|
||||
}
|
||||
|
||||
- (NSMutableArray<NSNumber *> *)calculateBloodGlucose:(NSInteger)index refValue:(NSNumber *)refValue values:(NSMutableArray<NSNumber *> *)values {
|
||||
[self.rfManager addCurrentReference:refValue.doubleValue index:index];
|
||||
|
||||
NSMutableArray<NSNumber *> *dataList = [NSMutableArray array];
|
||||
for (NSInteger i = 0; i < values.count; i++) {
|
||||
NSNumber *electricValue = values[i];
|
||||
NSNumber *bgValue = [self calcBloodGlucose:electricValue.doubleValue index:(index + i)];
|
||||
[dataList addObject:bgValue];
|
||||
}
|
||||
|
||||
return dataList;
|
||||
}
|
||||
|
||||
- (IValue *)calTest:(double)current datetime:(NSDate *)datetime {
|
||||
NSNumber *bgValue = @(0.0);
|
||||
IValue *cur_data = [[IValue alloc] initWithCurrentTime:datetime current:@(current)];
|
||||
IValue *i4_data = nil;
|
||||
[self.rfManager findReferenceByDate:datetime];
|
||||
|
||||
if ([self.rfManager isCalK]) {
|
||||
i4_data = [self calKValueAlgorithm:cur_data];
|
||||
} else {
|
||||
i4_data = [self I4Algorith:cur_data];
|
||||
}
|
||||
|
||||
if ([self.rfManager isCalK]) {
|
||||
bgValue = @([self.rfManager getRefValue].value);
|
||||
} else if ([self.rfManager isWaitCalK]) {
|
||||
bgValue = @([self.rfManager getRefValue].value);
|
||||
[i4_data setRfTime:[self.rfManager getRefValue].time];
|
||||
[i4_data setRf:@([self.rfManager getRefValue].value)];
|
||||
} else if ([i4_data getK] != nil) {
|
||||
bgValue = @([i4_data.getI4 doubleValue] / [i4_data.getK doubleValue]);
|
||||
}
|
||||
|
||||
bgValue = [self roundDouble:bgValue.doubleValue precision:1];
|
||||
if ((current >= 600.0) || (current <= 30.0)) {
|
||||
bgValue = @(0.0);
|
||||
}
|
||||
|
||||
[i4_data setBg:bgValue];
|
||||
[self.iValueManager setPreIValue:i4_data];
|
||||
|
||||
NSString *rft = [i4_data getRfTime] == nil ? @"" : [self dateformate:[i4_data getRfTime]];
|
||||
|
||||
NSLog(@"%@\t%@\t%@", [i4_data getI0], [i4_data getI1], [i4_data getI2], [i4_data getI3], [i4_data getI4], [i4_data getK], [i4_data getRf], [i4_data getBg], [i4_data getCurrent], [self dateformate:[i4_data getCurrentTime]], [i4_data getRf], rft);
|
||||
|
||||
return i4_data;
|
||||
}
|
||||
|
||||
- (IValue *)calKValueAlgorithm:(IValue *)cur_data {
|
||||
NSNumber *kValue = @(0.0);
|
||||
cur_data = [self calI4ForK:cur_data];
|
||||
kValue = [cur_data getK];
|
||||
I4Algorithm *i4Temp = nil;
|
||||
|
||||
if (kValue.doubleValue >= 10.0 && kValue.doubleValue <= 20.0) {
|
||||
[cur_data setK:kValue];
|
||||
return cur_data;
|
||||
}
|
||||
|
||||
if (kValue.doubleValue < 10.0) {
|
||||
[cur_data setI4:@([cur_data.getI3 doubleValue] - [I4Algorithm I4_20].value)];
|
||||
kValue = @([cur_data.getI4 doubleValue] / [self.rfManager getRefValue].value);
|
||||
i4Temp = [I4Algorithm I4_20];
|
||||
} else if (kValue.doubleValue > 20.0) {
|
||||
[cur_data setI4:@([cur_data.getI3 doubleValue] - [I4Algorithm I4_60].value)];
|
||||
kValue = @([cur_data.getI4 doubleValue] / [self.rfManager getRefValue].value);
|
||||
i4Temp = [I4Algorithm I4_60];
|
||||
}
|
||||
|
||||
if (kValue.doubleValue >= 7.5 && kValue.doubleValue <= 25.0) {
|
||||
[cur_data setK:kValue];
|
||||
[cur_data setBgCurrent:i4Temp.value];
|
||||
return cur_data;
|
||||
}
|
||||
|
||||
if (kValue.doubleValue < 7.5) {
|
||||
[cur_data setI4:@([cur_data.getI3 doubleValue] - [I4Algorithm I4_0].value)];
|
||||
kValue = @([cur_data.getI4 doubleValue] / [self.rfManager getRefValue].value);
|
||||
i4Temp = [I4Algorithm I4_0];
|
||||
} else if (kValue.doubleValue > 25.0) {
|
||||
[cur_data setI4:@([cur_data.getI3 doubleValue] - [I4Algorithm I4_80].value)];
|
||||
kValue = @([cur_data.getI4 doubleValue] / [self.rfManager getRefValue].value);
|
||||
i4Temp = [I4Algorithm I4_80];
|
||||
}
|
||||
|
||||
if (kValue.doubleValue > 2.5 && kValue.doubleValue < 40.0) {
|
||||
[cur_data setK:kValue];
|
||||
[cur_data setBgCurrent:i4Temp.value];
|
||||
}
|
||||
|
||||
return cur_data;
|
||||
}
|
||||
|
||||
- (int)calRoc {
|
||||
if (self.calIValue == nil) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSInteger size = self.calIValue.count;
|
||||
if (size == 0 || size <= 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double b0 = [[self.calIValue[size - 3] getBg] doubleValue];
|
||||
double b1 = [[self.calIValue[size - 2] getBg] doubleValue];
|
||||
double b2 = [[self.calIValue[size - 1] getBg] doubleValue];
|
||||
|
||||
if (b0 == 0.0 || b1 == 0.0 || b2 == 0.0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double roc = (0.3 * ((b1 - b0) / 3.0)) + (0.7 * ((b2 - b1) / 3.0));
|
||||
|
||||
if (roc >= 0.1) {
|
||||
return 1;
|
||||
} else if (roc > 0.05 && roc < 0.1) {
|
||||
return 2;
|
||||
} else if (roc >= -0.05 && roc <= 0.05) {
|
||||
return 3;
|
||||
} else if (roc > -0.1 && roc < -0.05) {
|
||||
return 4;
|
||||
} else if (roc <= -0.1) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (IValue *)calI4ForK:(IValue *)cur_data {
|
||||
IValue *I4_redta = [self I4Algorith:cur_data];
|
||||
NSNumber *kValue = @([I4_redta.getI4 doubleValue] / [self.rfManager getRefValue].value);
|
||||
[I4_redta setK:kValue];
|
||||
return I4_redta;
|
||||
}
|
||||
|
||||
- (IValue *)I4Algorith:(IValue *)cur_data {
|
||||
IValue *prev_data = [self.iValueManager getPreIValue];
|
||||
|
||||
[cur_data setI0:[cur_data getCurrent]];
|
||||
|
||||
[cur_data setI1:@([cur_data.getI0 doubleValue] * (1.0 + self.X.X1 * (32.0 - self.X.X2)))];
|
||||
|
||||
if (prev_data != nil && [prev_data getI3] != nil) {
|
||||
[cur_data setI3:@(self.X.X4 * [cur_data.getI1 doubleValue] + (1.0 - self.X.X4) * [prev_data.getI3 doubleValue])];
|
||||
[cur_data setBgCurrent:[prev_data getBgCurrent]];
|
||||
[cur_data setK:[prev_data getK]];
|
||||
|
||||
if ([cur_data getRf] != nil && [cur_data getRf].doubleValue != 0.0) {
|
||||
[cur_data setRf:[prev_data getRf]];
|
||||
[cur_data setRfTime:[prev_data getRfTime]];
|
||||
}
|
||||
} else {
|
||||
[cur_data setBgCurrent:[I4Algorithm I4_40].value];
|
||||
[cur_data setI3:[cur_data getI1]];
|
||||
}
|
||||
|
||||
[cur_data setI4:@([cur_data.getI3 doubleValue] - [cur_data getBgCurrent])];
|
||||
|
||||
return cur_data;
|
||||
}
|
||||
|
||||
- (NSNumber *)roundDouble:(double)val precision:(int)precision {
|
||||
NSNumber *ret = nil;
|
||||
@try {
|
||||
double factor = pow(10.0, precision);
|
||||
ret = @(floor(val * factor + 0.5) / factor);
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"%@", exception.reason);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (NSString *)dateformate:(NSDate *)date {
|
||||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||||
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
|
||||
return [formatter stringFromDate:date];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// Algorithm.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#ifndef Algorithm_h
|
||||
#define Algorithm_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface I4Algorithm : NSObject
|
||||
|
||||
@property (nonatomic, strong) NSString *code;
|
||||
@property (nonatomic, assign) int value;
|
||||
|
||||
+ (instancetype)I4_0;
|
||||
+ (instancetype)I4_20;
|
||||
+ (instancetype)I4_40;
|
||||
+ (instancetype)I4_60;
|
||||
+ (instancetype)I4_80;
|
||||
|
||||
- (instancetype)initWithCode:(NSString *)code value:(int)value;
|
||||
- (double)getI4Value:(double)i3value;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* Algorithm_h */
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
// Algorithm.m
|
||||
// react-native-bt-device
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#import "I4Algorithm.h"
|
||||
|
||||
@implementation I4Algorithm
|
||||
|
||||
static I4Algorithm *I4_0 = nil;
|
||||
static I4Algorithm *I4_20 = nil;
|
||||
static I4Algorithm *I4_40 = nil;
|
||||
static I4Algorithm *I4_60 = nil;
|
||||
static I4Algorithm *I4_80 = nil;
|
||||
|
||||
+ (void)initialize {
|
||||
if (self == [I4Algorithm class]) {
|
||||
I4_0 = [[I4Algorithm alloc] initWithCode:@"00" value:0];
|
||||
I4_20 = [[I4Algorithm alloc] initWithCode:@"01" value:20];
|
||||
I4_40 = [[I4Algorithm alloc] initWithCode:@"02" value:40];
|
||||
I4_60 = [[I4Algorithm alloc] initWithCode:@"03" value:60];
|
||||
I4_80 = [[I4Algorithm alloc] initWithCode:@"04" value:80];
|
||||
}
|
||||
}
|
||||
|
||||
+ (instancetype)I4_0 {
|
||||
return I4_0;
|
||||
}
|
||||
|
||||
+ (instancetype)I4_20 {
|
||||
return I4_20;
|
||||
}
|
||||
|
||||
+ (instancetype)I4_40 {
|
||||
return I4_40;
|
||||
}
|
||||
|
||||
+ (instancetype)I4_60 {
|
||||
return I4_60;
|
||||
}
|
||||
|
||||
+ (instancetype)I4_80 {
|
||||
return I4_80;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCode:(NSString *)code value:(int)value {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.code = code;
|
||||
self.value = value;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (double)getI4Value:(double)i3value {
|
||||
return i3value - self.value;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// IValue.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#ifndef IValue_h
|
||||
#define IValue_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface IValue : NSObject <NSCoding>
|
||||
|
||||
@property (nonatomic, strong) NSNumber *I0;
|
||||
@property (nonatomic, strong) NSNumber *I1;
|
||||
@property (nonatomic, strong) NSNumber *I2;
|
||||
@property (nonatomic, strong) NSNumber *I3;
|
||||
@property (nonatomic, strong) NSNumber *I4;
|
||||
@property (nonatomic, assign) int bgCurrent;
|
||||
@property (nonatomic, strong) NSNumber *k;
|
||||
@property (nonatomic, strong) NSNumber *rf;
|
||||
@property (nonatomic, strong) NSNumber *current;
|
||||
@property (nonatomic, strong) NSDate *currentTime;
|
||||
@property (nonatomic, strong) NSNumber *bg;
|
||||
@property (nonatomic, strong) NSDate *rfTime;
|
||||
|
||||
- (instancetype)initWithCurrentTime:(NSDate *)currentTime current:(NSNumber *)current;
|
||||
- (NSDate *)getRfTime;
|
||||
- (void)setRfTime:(NSDate *)rfTime;
|
||||
- (NSNumber *)getBg;
|
||||
- (void)setBg:(NSNumber *)bg;
|
||||
- (NSNumber *)getI0;
|
||||
- (void)setI0:(NSNumber *)i0;
|
||||
- (NSNumber *)getI1;
|
||||
- (void)setI1:(NSNumber *)i1;
|
||||
- (NSNumber *)getI2;
|
||||
- (void)setI2:(NSNumber *)i2;
|
||||
- (NSNumber *)getI3;
|
||||
- (void)setI3:(NSNumber *)i3;
|
||||
- (NSNumber *)getI4;
|
||||
- (void)setI4:(NSNumber *)i4;
|
||||
- (int)getBgCurrent;
|
||||
- (void)setBgCurrent:(int)bgCurrent;
|
||||
- (NSNumber *)getK;
|
||||
- (void)setK:(NSNumber *)k;
|
||||
- (NSNumber *)getRf;
|
||||
- (void)setRf:(NSNumber *)rf;
|
||||
- (NSNumber *)getCurrent;
|
||||
- (void)setCurrent:(NSNumber *)current;
|
||||
- (NSDate *)getCurrentTime;
|
||||
- (void)setCurrentTime:(NSDate *)currentTime;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* IValue_h */
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
//
|
||||
// IValue.m
|
||||
// react-native-bt-device
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#import "IValue.h"
|
||||
|
||||
@implementation IValue
|
||||
|
||||
- (instancetype)initWithCurrentTime:(NSDate *)currentTime current:(NSNumber *)current {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.current = current;
|
||||
self.currentTime = currentTime;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSDate *)getRfTime {
|
||||
return self.rfTime;
|
||||
}
|
||||
|
||||
- (void)setRfTime:(NSDate *)rfTime {
|
||||
self.rfTime = rfTime;
|
||||
}
|
||||
|
||||
- (NSNumber *)getBg {
|
||||
return self.bg;
|
||||
}
|
||||
|
||||
- (void)setBg:(NSNumber *)bg {
|
||||
self.bg = bg;
|
||||
}
|
||||
|
||||
- (NSNumber *)getI0 {
|
||||
return self.I0;
|
||||
}
|
||||
|
||||
- (void)setI0:(NSNumber *)i0 {
|
||||
self.I0 = i0;
|
||||
}
|
||||
|
||||
- (NSNumber *)getI1 {
|
||||
return self.I1;
|
||||
}
|
||||
|
||||
- (void)setI1:(NSNumber *)i1 {
|
||||
self.I1 = i1;
|
||||
}
|
||||
|
||||
- (NSNumber *)getI2 {
|
||||
return self.I2;
|
||||
}
|
||||
|
||||
- (void)setI2:(NSNumber *)i2 {
|
||||
self.I2 = i2;
|
||||
}
|
||||
|
||||
- (NSNumber *)getI3 {
|
||||
return self.I3;
|
||||
}
|
||||
|
||||
- (void)setI3:(NSNumber *)i3 {
|
||||
self.I3 = i3;
|
||||
}
|
||||
|
||||
- (NSNumber *)getI4 {
|
||||
return self.I4;
|
||||
}
|
||||
|
||||
- (void)setI4:(NSNumber *)i4 {
|
||||
self.I4 = i4;
|
||||
}
|
||||
|
||||
- (int)getBgCurrent {
|
||||
return self.bgCurrent;
|
||||
}
|
||||
|
||||
- (void)setBgCurrent:(int)bgCurrent {
|
||||
self.bgCurrent = bgCurrent;
|
||||
}
|
||||
|
||||
- (NSNumber *)getK {
|
||||
return self.k;
|
||||
}
|
||||
|
||||
- (void)setK:(NSNumber *)k {
|
||||
self.k = k;
|
||||
}
|
||||
|
||||
- (NSNumber *)getRf {
|
||||
return self.rf;
|
||||
}
|
||||
|
||||
- (void)setRf:(NSNumber *)rf {
|
||||
self.rf = rf;
|
||||
}
|
||||
|
||||
- (NSNumber *)getCurrent {
|
||||
return self.current;
|
||||
}
|
||||
|
||||
- (void)setCurrent:(NSNumber *)current {
|
||||
self.current = current;
|
||||
}
|
||||
|
||||
- (NSDate *)getCurrentTime {
|
||||
return self.currentTime;
|
||||
}
|
||||
|
||||
- (void)setCurrentTime:(NSDate *)currentTime {
|
||||
self.currentTime = currentTime;
|
||||
}
|
||||
|
||||
#pragma mark - NSCoding
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:self.I0 forKey:@"I0"];
|
||||
[coder encodeObject:self.I1 forKey:@"I1"];
|
||||
[coder encodeObject:self.I2 forKey:@"I2"];
|
||||
[coder encodeObject:self.I3 forKey:@"I3"];
|
||||
[coder encodeObject:self.I4 forKey:@"I4"];
|
||||
[coder encodeInt:self.bgCurrent forKey:@"bgCurrent"];
|
||||
[coder encodeObject:self.k forKey:@"k"];
|
||||
[coder encodeObject:self.rf forKey:@"rf"];
|
||||
[coder encodeObject:self.current forKey:@"current"];
|
||||
[coder encodeObject:self.currentTime forKey:@"currentTime"];
|
||||
[coder encodeObject:self.bg forKey:@"bg"];
|
||||
[coder encodeObject:self.rfTime forKey:@"rfTime"];
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.I0 = [coder decodeObjectForKey:@"I0"];
|
||||
self.I1 = [coder decodeObjectForKey:@"I1"];
|
||||
self.I2 = [coder decodeObjectForKey:@"I2"];
|
||||
self.I3 = [coder decodeObjectForKey:@"I3"];
|
||||
self.I4 = [coder decodeObjectForKey:@"I4"];
|
||||
self.bgCurrent = [coder decodeIntForKey:@"bgCurrent"];
|
||||
self.k = [coder decodeObjectForKey:@"k"];
|
||||
self.rf = [coder decodeObjectForKey:@"rf"];
|
||||
self.current = [coder decodeObjectForKey:@"current"];
|
||||
self.currentTime = [coder decodeObjectForKey:@"currentTime"];
|
||||
self.bg = [coder decodeObjectForKey:@"bg"];
|
||||
self.rfTime = [coder decodeObjectForKey:@"rfTime"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// IValueManager.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#ifndef IValueManager_h
|
||||
#define IValueManager_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "IValue.h"
|
||||
|
||||
@interface IValueManager : NSObject
|
||||
|
||||
@property (nonatomic, strong) IValue *preIValue;
|
||||
|
||||
- (instancetype)init;
|
||||
- (IValue *)getPreIValue;
|
||||
- (void)setPreIValue:(IValue *)preIValue;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* IValueManager_h */
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// IValueManager.m
|
||||
// react-native-bt-device
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#import "IValueManager.h"
|
||||
|
||||
@implementation IValueManager
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.preIValue = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (IValue *)getPreIValue {
|
||||
return self.preIValue;
|
||||
}
|
||||
|
||||
- (void)setPreIValue:(IValue *)preIValue {
|
||||
self.preIValue = preIValue;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// ParamX.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#ifndef ParamX_h
|
||||
#define ParamX_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ParamX : NSObject
|
||||
|
||||
@property (nonatomic, assign) double X1;
|
||||
@property (nonatomic, assign) double X2;
|
||||
@property (nonatomic, assign) double X3;
|
||||
@property (nonatomic, assign) double X4;
|
||||
@property (nonatomic, assign) double X5;
|
||||
@property (nonatomic, assign) int X6;
|
||||
@property (nonatomic, assign) int X7;
|
||||
@property (nonatomic, assign) double X8;
|
||||
@property (nonatomic, assign) double X9;
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* ParamX_h */
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// ParamX.m
|
||||
// react-native-bt-device
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#import "ParamX.h"
|
||||
|
||||
@implementation ParamX
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.X1 = 0.02;
|
||||
self.X2 = 32.0;
|
||||
self.X3 = 10.0;
|
||||
self.X4 = 0.3;
|
||||
self.X5 = 40.0;
|
||||
self.X6 = 40;
|
||||
self.X7 = 60;
|
||||
self.X8 = 0.004;
|
||||
self.X9 = 0.8;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// Reference.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#ifndef Reference_h
|
||||
#define Reference_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface Reference : NSObject
|
||||
|
||||
@property (nonatomic, assign) double value;
|
||||
@property (nonatomic, strong) NSDate *time;
|
||||
@property (nonatomic, assign) int index;
|
||||
|
||||
- (instancetype)initWithValue:(double)value time:(NSDate *)time;
|
||||
- (instancetype)initWithValue:(double)value index:(int)index;
|
||||
- (double)getValue;
|
||||
- (void)setValue:(double)value;
|
||||
- (NSDate *)getTime;
|
||||
- (void)setTime:(NSDate *)time;
|
||||
- (int)getIndex;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* Reference_h */
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// Reference.m
|
||||
// react-native-bt-device
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#import "Reference.h"
|
||||
|
||||
@implementation Reference
|
||||
|
||||
- (instancetype)initWithValue:(double)value time:(NSDate *)time {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.value = value;
|
||||
self.time = time;
|
||||
self.index = 0; // 默认为0
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithValue:(double)value index:(int)index {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.value = value;
|
||||
self.index = index;
|
||||
self.time = nil; // 默认为nil
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (double)getValue {
|
||||
return self.value;
|
||||
}
|
||||
|
||||
- (void)setValue:(double)value {
|
||||
self.value = value;
|
||||
}
|
||||
|
||||
- (NSDate *)getTime {
|
||||
return self.time;
|
||||
}
|
||||
|
||||
- (void)setTime:(NSDate *)time {
|
||||
self.time = time;
|
||||
}
|
||||
|
||||
- (int)getIndex {
|
||||
return self.index;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// ReferenceManager.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#ifndef ReferenceManager_h
|
||||
#define ReferenceManager_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Reference.h"
|
||||
|
||||
@interface ReferenceManager : NSObject
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray<Reference *> *refList;
|
||||
@property (nonatomic, strong) Reference *curReference;
|
||||
@property (nonatomic, strong) Reference *mCurrentReference;
|
||||
@property (nonatomic, assign) int kCount;
|
||||
|
||||
- (instancetype)init;
|
||||
- (Reference *)getRefValue;
|
||||
- (void)addCurrentReference:(double)value index:(NSInteger)index;
|
||||
- (void)addReference:(double)value time:(NSDate *)time;
|
||||
- (BOOL)isCalK;
|
||||
- (BOOL)isWaitCalK;
|
||||
- (Reference *)findReferenceByDate:(NSDate *)curTime;
|
||||
- (Reference *)findReferenceByIndex:(NSInteger)index;
|
||||
+ (NSDate *)stringToDate:(NSString *)dateStr;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* ReferenceManager_h */
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
//
|
||||
// ReferenceManager.m
|
||||
// react-native-bt-device
|
||||
//
|
||||
// Created by Ran Zhao on 9/2/24.
|
||||
//
|
||||
|
||||
#import "ReferenceManager.h"
|
||||
|
||||
@implementation ReferenceManager
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.refList = [NSMutableArray array];
|
||||
self.curReference = nil;
|
||||
self.mCurrentReference = nil;
|
||||
self.kCount = -1;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Reference *)getRefValue {
|
||||
return self.curReference;
|
||||
}
|
||||
|
||||
- (void)addCurrentReference:(double)value index:(NSInteger)index {
|
||||
self.mCurrentReference = [[Reference alloc] initWithValue:value index:index];
|
||||
}
|
||||
|
||||
- (void)addReference:(double)value time:(NSDate *)time {
|
||||
Reference *ref = [[Reference alloc] initWithValue:value time:time];
|
||||
if (![self isExist:ref]) {
|
||||
[self.refList addObject:ref];
|
||||
}
|
||||
[self.refList sortUsingComparator:^NSComparisonResult(Reference *lhs, Reference *rhs) {
|
||||
return [lhs.time compare:rhs.time];
|
||||
}];
|
||||
}
|
||||
|
||||
- (BOOL)isExist:(Reference *)bgRef {
|
||||
for (Reference *bg in self.refList) {
|
||||
if ([bg.time timeIntervalSince1970] == [bgRef.time timeIntervalSince1970]) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isCalK {
|
||||
return self.kCount == 0;
|
||||
}
|
||||
|
||||
- (BOOL)isWaitCalK {
|
||||
return self.kCount == 2 || self.kCount == 1;
|
||||
}
|
||||
|
||||
- (Reference *)findReferenceByDate:(NSDate *)curTime {
|
||||
for (Reference *d in self.refList) {
|
||||
double interval = ([curTime timeIntervalSince1970] - [d.time timeIntervalSince1970]) / 60.0;
|
||||
if (interval <= 0.0) {
|
||||
self.kCount -= 1;
|
||||
return nil;
|
||||
}
|
||||
if (interval <= 3.0) {
|
||||
self.kCount = 2;
|
||||
self.curReference = d;
|
||||
return d;
|
||||
}
|
||||
}
|
||||
self.kCount -= 1;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (Reference *)findReferenceByIndex:(NSInteger)index {
|
||||
double interval = (index - self.mCurrentReference.index) * 3;
|
||||
if (interval < 0.0) {
|
||||
self.kCount -= 1;
|
||||
return nil;
|
||||
}
|
||||
if (interval <= 3.0) {
|
||||
self.kCount = 2;
|
||||
self.curReference = self.mCurrentReference;
|
||||
return self.mCurrentReference;
|
||||
}
|
||||
self.kCount -= 1;
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSDate *)stringToDate:(NSString *)dateStr {
|
||||
NSString *formatStr = @"yyyy/MM/dd HH:mm:ss";
|
||||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||||
[formatter setDateFormat:formatStr];
|
||||
NSDate *date = [formatter dateFromString:dateStr];
|
||||
return date;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
#import "ENBPDevice.h"
|
||||
#import "ENCholesterolDevice.h"
|
||||
#import "ENSanDyGlucoseDevice.h"
|
||||
#import "Algorithm20.h"
|
||||
|
||||
@interface RNSanModule:NSObject<RCTBridgeModule,BLEDeviceProtocol,ENSanDyGlucoseDeviceProtocal>
|
||||
|
||||
|
|
|
|||
|
|
@ -394,6 +394,62 @@ RCT_EXPORT_METHOD(getAllDataFromIndexDYG:(NSString *)deviceMac RequestCode:(int)
|
|||
[nativeDevice getAllDataFromIndex:index];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(caculateBloodGlucose:(NSDictionary *)info
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
Algorithm20 *algorithm = [[Algorithm20 alloc] init];
|
||||
|
||||
NSArray *values = info[@"values"];
|
||||
NSMutableArray<NSNumber *> *valueList = [NSMutableArray array];
|
||||
|
||||
for (id value in values) {
|
||||
[valueList addObject:@([value doubleValue])];
|
||||
}
|
||||
|
||||
NSInteger index = [RCTConvert NSInteger:info[@"index"]];
|
||||
double refValue = [RCTConvert double:info[@"refValue"]];
|
||||
|
||||
NSMutableArray<NSNumber *> *bgValues = [algorithm calculateBloodGlucose:index
|
||||
refValue:@(refValue)
|
||||
values:valueList];
|
||||
|
||||
NSMutableArray *bgRNValues = [NSMutableArray array];
|
||||
|
||||
for (NSNumber *bgValue in bgValues) {
|
||||
RCTLogInfo(@"%@", [bgValue stringValue]);
|
||||
[bgRNValues addObject:bgValue];
|
||||
}
|
||||
|
||||
resolve(bgRNValues);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(caculateDyRoc:(NSDictionary *)info
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
Algorithm20 *algorithm = [[Algorithm20 alloc] init];
|
||||
|
||||
// 获取 values 数组并转换为 NSMutableArray
|
||||
NSArray *values = info[@"values"];
|
||||
NSMutableArray<NSNumber *> *valueList = [NSMutableArray array];
|
||||
|
||||
for (id value in values) {
|
||||
[valueList addObject:@([value doubleValue])];
|
||||
}
|
||||
|
||||
NSInteger index = [RCTConvert NSInteger:info[@"index"]];
|
||||
double refValue = [RCTConvert double:info[@"refValue"]];
|
||||
|
||||
// 调用 Algorithm20 的方法进行计算
|
||||
[algorithm calculateBloodGlucose:index refValue:@(refValue) values:valueList];
|
||||
int result = [algorithm calRoc];
|
||||
|
||||
// 将计算结果返回给 JavaScript
|
||||
resolve(@(result));
|
||||
}
|
||||
|
||||
|
||||
-(void)onCreatedChannel:(BLEDevice *)device{
|
||||
device.nativeDevice.deviceDelegate = self;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue