iOS AILinkBleSDK - 蓝牙SDK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ELEightScaleAlgorithmTool.m 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. //
  2. // ELEightScaleAlgorithmTool.m
  3. // Elink
  4. //
  5. // Created by iot_user on 2020/6/18.
  6. // Copyright © 2020 iot_iMac. All rights reserved.
  7. //
  8. #import "ELEightScaleAlgorithmTool.h"
  9. #import "ELEightScaleRecordModel.h"
  10. #import <AILinkBleSDK/ELEightScaleBleDataModel.h>
  11. #import <AILinkBleSDK/ELEightScaleSDKHeader.h>
  12. #import "HTBodyfat_SDK.h"
  13. #import <AILinkBleSDK/ELHeightAlgorithmusModel.h>
  14. #import <AILinkBleSDK/ELWeightAlgorithmusModel.h>
  15. #import <AILinkBleSDK/ELBodyIndexAlgorithmModel.h>
  16. #import "BhBodyCompositionAllBody50KHz.h"
  17. @implementation ELEightScaleAlgorithmTool
  18. //新算法
  19. /// 根据秤测量的阻抗数据调用算法解析出其他体脂数据
  20. /// @param dataModel 八电极秤测量的数据
  21. /// @param sex 女性传0,男性传1
  22. /// @param height 身高,单位cm
  23. /// @param age 年龄
  24. + (ELEightScaleRecordModel *)getNewRecordModelWithBleDataModel:(ELEightScaleBleDataModel *)dataModel withUserSex:(NSInteger)sex height:(NSInteger)height age:(NSInteger)age {
  25. CGFloat kgWeight = [ELWeightAlgorithmusModel getKgWithWeightShowStr:dataModel.weight weightUnit:dataModel.weightUnit weightPoint:dataModel.weightPoint].floatValue;
  26. HTBodyBasicInfo *bodyBasicInfo = [[HTBodyBasicInfo alloc] initWithSex:sex height:height weight:kgWeight age:age];
  27. bodyBasicInfo.htZAllBodyImpedance = dataModel.RWholeBodyAdc;
  28. bodyBasicInfo.htZLeftLegImpedance = dataModel.leftFootAdc;
  29. bodyBasicInfo.htZRightLegImpedance = dataModel.rightFootAdc;
  30. bodyBasicInfo.htZLeftArmImpedance = dataModel.leftHandAdc;
  31. bodyBasicInfo.htZRightArmImpedance = dataModel.rightHandAdc;
  32. bodyBasicInfo.htTwoArmsImpedance = dataModel.handsAdc;
  33. bodyBasicInfo.htTwoLegsImpedance = dataModel.feetAdc;
  34. //计算体脂参数
  35. HTBodyResultAllBody *bodyResultTwoLegs = [[HTBodyResultAllBody alloc] init];
  36. HTBodyfatErrorType errorType = [bodyResultTwoLegs getBodyfatWithBasicInfo:bodyBasicInfo];
  37. NSLog(@"HTBodyfatErrorType = %lu",errorType);
  38. if(errorType != HTBodyfatErrorTypeNone){
  39. NSMutableString *errorStr = [[NSMutableString alloc]initWithString:@""];
  40. if((errorType & HTBodyfatErrorTypeAge) == HTBodyfatErrorTypeAge){
  41. [errorStr appendString:@"年龄 "];
  42. }
  43. if((errorType & HTBodyfatErrorTypeWeight) == HTBodyfatErrorTypeWeight){
  44. [errorStr appendString:@"体重 "];
  45. }
  46. if((errorType & HTBodyfatErrorTypeHeight) == HTBodyfatErrorTypeHeight){
  47. [errorStr appendString:@"身高 "];
  48. }
  49. if((errorType & HTBodyfatErrorTypeSex) == HTBodyfatErrorTypeSex){
  50. [errorStr appendString:@"性别 "];
  51. }
  52. if((errorType & HTBodyfatErrorTypeImpedance) == HTBodyfatErrorTypeImpedance){
  53. [errorStr appendString:@"阻抗 "];
  54. }
  55. if((errorType & HTBodyfatErrorTypeImpedanceLeftLeg) == HTBodyfatErrorTypeImpedanceLeftLeg){
  56. [errorStr appendString:@"左脚阻抗 "];
  57. }
  58. if((errorType & HTBodyfatErrorTypeImpedanceRightLeg) == HTBodyfatErrorTypeImpedanceRightLeg){
  59. [errorStr appendString:@"右脚阻抗 "];
  60. }
  61. if((errorType & HTBodyfatErrorTypeImpedanceLeftArm) == HTBodyfatErrorTypeImpedanceLeftArm){
  62. [errorStr appendString:@"左手阻抗 "];
  63. }
  64. if((errorType & HTBodyfatErrorTypeImpedanceRightArm) == HTBodyfatErrorTypeImpedanceRightArm){
  65. [errorStr appendString:@"右手阻抗 "];
  66. }
  67. [errorStr appendString:@"参数有误!"];
  68. NSLog(@"errorType = %@",errorStr);
  69. }
  70. ELEightScaleRecordModel *recordModel = [[ELEightScaleRecordModel alloc] init];
  71. recordModel.bmi = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBMI];
  72. recordModel.bfr = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBodyfatPercentage];
  73. recordModel.sfr = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBodyfatSubcut];
  74. recordModel.uvi = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htVFAL];
  75. recordModel.rom = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htMusclePercentage];
  76. recordModel.bmr = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htBMR];
  77. recordModel.vwc = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htWaterPercentage];
  78. recordModel.bodyAge = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htBodyAge];
  79. recordModel.pp = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htProteinPercentage];
  80. recordModel.adc = [NSString stringWithFormat:@"%d",dataModel.trunkAdc];//记录躯干adc
  81. recordModel.heartRate = dataModel.heartRate>0?[NSString stringWithFormat:@"%d",dataModel.heartRate]:@"";
  82. recordModel.createTime = dataModel.createTime;
  83. recordModel.deviceAlgorithm = [NSString stringWithFormat:@"%d",dataModel.algorithmID];
  84. //新算法
  85. [self new_algorithmOfHTWithDataModel:dataModel sex:sex height:height kgWeight:kgWeight age:age updateRecordModel:recordModel];
  86. return recordModel;
  87. }
  88. /// 根据秤测量的阻抗数据调用算法解析出其他体脂数据
  89. /// @param dataModel 八电极秤测量的数据
  90. /// @param sex 女性传0,男性传1
  91. /// @param height 身高,单位cm
  92. /// @param age 年龄
  93. + (ELEightScaleRecordModel *)getRecordModelWithBleDataModel:(ELEightScaleBleDataModel *)dataModel withUserSex:(NSInteger)sex height:(NSInteger)height age:(NSInteger)age {
  94. CGFloat kgWeight = [ELWeightAlgorithmusModel getKgWithWeightShowStr:dataModel.weight weightUnit:dataModel.weightUnit weightPoint:dataModel.weightPoint].floatValue;
  95. HTBodyBasicInfo *bodyBasicInfo = [[HTBodyBasicInfo alloc] initWithSex:sex height:height weight:kgWeight age:age];
  96. bodyBasicInfo.htZAllBodyImpedance = dataModel.RWholeBodyAdc;
  97. bodyBasicInfo.htZLeftLegImpedance = dataModel.leftFootAdc;
  98. bodyBasicInfo.htZRightLegImpedance = dataModel.rightFootAdc;
  99. bodyBasicInfo.htZLeftArmImpedance = dataModel.leftHandAdc;
  100. bodyBasicInfo.htZRightArmImpedance = dataModel.rightHandAdc;
  101. bodyBasicInfo.htTwoArmsImpedance = dataModel.handsAdc;
  102. bodyBasicInfo.htTwoLegsImpedance = dataModel.feetAdc;
  103. //计算体脂参数
  104. HTBodyResultAllBody *bodyResultTwoLegs = [[HTBodyResultAllBody alloc] init];
  105. HTBodyfatErrorType errorType = [bodyResultTwoLegs getBodyfatWithBasicInfo:bodyBasicInfo];
  106. NSLog(@"HTBodyfatErrorType = %lu",errorType);
  107. if(errorType != HTBodyfatErrorTypeNone){
  108. NSMutableString *errorStr = [[NSMutableString alloc]initWithString:@""];
  109. if((errorType & HTBodyfatErrorTypeAge) == HTBodyfatErrorTypeAge){
  110. [errorStr appendString:@"年龄 "];
  111. }
  112. if((errorType & HTBodyfatErrorTypeWeight) == HTBodyfatErrorTypeWeight){
  113. [errorStr appendString:@"体重 "];
  114. }
  115. if((errorType & HTBodyfatErrorTypeHeight) == HTBodyfatErrorTypeHeight){
  116. [errorStr appendString:@"身高 "];
  117. }
  118. if((errorType & HTBodyfatErrorTypeSex) == HTBodyfatErrorTypeSex){
  119. [errorStr appendString:@"性别 "];
  120. }
  121. if((errorType & HTBodyfatErrorTypeImpedance) == HTBodyfatErrorTypeImpedance){
  122. [errorStr appendString:@"阻抗 "];
  123. }
  124. if((errorType & HTBodyfatErrorTypeImpedanceLeftLeg) == HTBodyfatErrorTypeImpedanceLeftLeg){
  125. [errorStr appendString:@"左脚阻抗 "];
  126. }
  127. if((errorType & HTBodyfatErrorTypeImpedanceRightLeg) == HTBodyfatErrorTypeImpedanceRightLeg){
  128. [errorStr appendString:@"右脚阻抗 "];
  129. }
  130. if((errorType & HTBodyfatErrorTypeImpedanceLeftArm) == HTBodyfatErrorTypeImpedanceLeftArm){
  131. [errorStr appendString:@"左手阻抗 "];
  132. }
  133. if((errorType & HTBodyfatErrorTypeImpedanceRightArm) == HTBodyfatErrorTypeImpedanceRightArm){
  134. [errorStr appendString:@"右手阻抗 "];
  135. }
  136. [errorStr appendString:@"参数有误!"];
  137. NSLog(@"errorType = %@",errorStr);
  138. }
  139. ELEightScaleRecordModel *recordModel = [[ELEightScaleRecordModel alloc] init];
  140. recordModel.bmi = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBMI];
  141. recordModel.bfr = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBodyfatPercentage];
  142. recordModel.sfr = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBodyfatSubcut];
  143. recordModel.uvi = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htVFAL];
  144. recordModel.rom = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htMusclePercentage];
  145. recordModel.bmr = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htBMR];
  146. recordModel.vwc = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htWaterPercentage];
  147. recordModel.bodyAge = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htBodyAge];
  148. recordModel.pp = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htProteinPercentage];
  149. recordModel.adc = [NSString stringWithFormat:@"%d",dataModel.trunkAdc];//记录躯干adc
  150. recordModel.heartRate = dataModel.heartRate>0?[NSString stringWithFormat:@"%d",dataModel.heartRate]:@"";
  151. recordModel.createTime = dataModel.createTime;
  152. recordModel.deviceAlgorithm = [NSString stringWithFormat:@"%d",dataModel.algorithmID];
  153. //骨量
  154. if (bodyResultTwoLegs.htBoneKg>0) {
  155. NSUInteger boneMass = roundf(bodyResultTwoLegs.htBoneKg*pow(10, dataModel.weightPoint));
  156. recordModel.bm = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:boneMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  157. }else{
  158. recordModel.bm = @"";
  159. }
  160. //标准体重
  161. if (bodyResultTwoLegs.htIdealWeightKg >0) {
  162. //说明有值
  163. NSUInteger standard = roundf(bodyResultTwoLegs.htIdealWeightKg*pow(10, dataModel.weightPoint));
  164. recordModel.standardWeight = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:standard bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  165. //体重控制量
  166. CGFloat weightControl = kgWeight - bodyResultTwoLegs.htIdealWeightKg;
  167. NSUInteger weightContrlABS = roundf(fabs(weightControl*pow(10, dataModel.weightPoint)));
  168. NSString *weightContrlStr = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:weightContrlABS bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  169. if (weightControl<0) {
  170. recordModel.weightControl = [NSString stringWithFormat:@"-%@",weightContrlStr];
  171. }else{
  172. recordModel.weightControl = weightContrlStr;
  173. }
  174. recordModel.fatLevel = [NSString stringWithFormat:@"%lu",(unsigned long)[ELBodyIndexAlgorithmModel getfatLevelWithweight:kgWeight andStandardWeight:bodyResultTwoLegs.htIdealWeightKg]];
  175. }else{
  176. recordModel.standardWeight = @"";
  177. recordModel.weightControl = @"";
  178. recordModel.fatLevel = @"";
  179. }
  180. //脂肪量
  181. if (bodyResultTwoLegs.htBodyfatKg>0) {
  182. NSUInteger fatMass = roundf(bodyResultTwoLegs.htBodyfatKg*pow(10, dataModel.weightPoint));
  183. recordModel.fatMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:fatMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  184. }else{
  185. recordModel.fatMass = @"";
  186. }
  187. //去脂体重
  188. if (bodyResultTwoLegs.htBodyfatFreeMass>0) {
  189. NSUInteger withoutFatW = roundf(bodyResultTwoLegs.htBodyfatFreeMass*pow(10, dataModel.weightPoint));
  190. recordModel.weightWithoutFat = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:withoutFatW bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  191. }else{
  192. recordModel.weightWithoutFat = @"";
  193. }
  194. //肌肉量
  195. if (bodyResultTwoLegs.htMuscleKg>0) {
  196. NSInteger musleMass = round(bodyResultTwoLegs.htMuscleKg*pow(10, dataModel.weightPoint));
  197. recordModel.musleMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:musleMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  198. }else{
  199. recordModel.musleMass = @"";
  200. }
  201. //蛋白量
  202. if (bodyResultTwoLegs.htProteinPercentage>0) {
  203. NSUInteger proteinMassInt = roundf((bodyResultTwoLegs.htProteinPercentage/100.0)*kgWeight* pow(10, dataModel.weightPoint));
  204. recordModel.proteinMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:proteinMassInt bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  205. }else{
  206. recordModel.proteinMass = @"";
  207. }
  208. //体脂-右手
  209. if (bodyResultTwoLegs.htBodyfatKgRightArm >0) {
  210. NSUInteger rightHand = roundf(bodyResultTwoLegs.htBodyfatKgRightArm*pow(10, dataModel.weightPoint));
  211. recordModel.fatMassRightTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  212. }else{
  213. recordModel.fatMassRightTop = @"";
  214. }
  215. //体脂-右脚
  216. if (bodyResultTwoLegs.htBodyfatKgRightLeg >0) {
  217. NSUInteger rightFoot = roundf(bodyResultTwoLegs.htBodyfatKgRightLeg*pow(10, dataModel.weightPoint));
  218. recordModel.fatMassRightBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  219. }else{
  220. recordModel.fatMassRightBottom = @"";
  221. }
  222. //体脂-左手
  223. if (bodyResultTwoLegs.htBodyfatKgLeftArm >0) {
  224. NSUInteger leftHand = roundf(bodyResultTwoLegs.htBodyfatKgLeftArm*pow(10, dataModel.weightPoint));
  225. recordModel.fatMassLeftTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  226. }else{
  227. recordModel.fatMassLeftTop = @"";
  228. }
  229. //体脂-左脚
  230. if (bodyResultTwoLegs.htBodyfatKgLeftLeg >0) {
  231. NSUInteger leftFoot = roundf(bodyResultTwoLegs.htBodyfatKgLeftLeg*pow(10, dataModel.weightPoint));
  232. recordModel.fatMassLeftBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  233. }else{
  234. recordModel.fatMassLeftBottom = @"";
  235. }
  236. //体脂-躯干
  237. if (bodyResultTwoLegs.htBodyfatKgTrunk >0) {
  238. NSUInteger fatMassBody = roundf(bodyResultTwoLegs.htBodyfatKgTrunk*pow(10, dataModel.weightPoint));
  239. recordModel.fatMassBody = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:fatMassBody bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  240. }else{
  241. recordModel.fatMassBody = @"";
  242. }
  243. //肌肉-右手
  244. if (bodyResultTwoLegs.htMuscleKgRightArm >0) {
  245. NSUInteger rightHand = roundf(bodyResultTwoLegs.htMuscleKgRightArm*pow(10, dataModel.weightPoint));
  246. recordModel.musleMassRightTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  247. }else{
  248. recordModel.musleMassRightTop = @"";
  249. }
  250. //肌肉-右脚
  251. if (bodyResultTwoLegs.htMuscleKgRightLeg >0) {
  252. NSUInteger rightFoot = roundf(bodyResultTwoLegs.htMuscleKgRightLeg*pow(10, dataModel.weightPoint));
  253. recordModel.musleMassRightBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  254. }else{
  255. recordModel.musleMassRightBottom = @"";
  256. }
  257. //肌肉-左手
  258. if (bodyResultTwoLegs.htMuscleKgLeftArm >0) {
  259. NSUInteger leftHand = roundf(bodyResultTwoLegs.htMuscleKgLeftArm*pow(10, dataModel.weightPoint));
  260. recordModel.musleMassLeftTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  261. }else{
  262. recordModel.musleMassLeftTop = @"";
  263. }
  264. //肌肉-左脚
  265. if (bodyResultTwoLegs.htMuscleKgeLeftLeg >0) {
  266. NSUInteger leftFoot = roundf(bodyResultTwoLegs.htMuscleKgeLeftLeg*pow(10, dataModel.weightPoint));
  267. recordModel.musleMassLeftBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  268. }else{
  269. recordModel.musleMassLeftBottom = @"";
  270. }
  271. //肌肉-躯干
  272. if (bodyResultTwoLegs.htMuscleKgTrunk >0) {
  273. NSUInteger muscleMassBody = roundf(bodyResultTwoLegs.htMuscleKgTrunk*pow(10, dataModel.weightPoint));
  274. recordModel.musleMassBody = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:muscleMassBody bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  275. }else{
  276. recordModel.musleMassBody = @"";
  277. }
  278. //四肢肌肉指数 = 四肢肌肉量(kg)/身高的平方(m)
  279. CGFloat heightM = (height/100.0);
  280. CGFloat index = (bodyResultTwoLegs.htMuscleKgLeftArm+bodyResultTwoLegs.htMuscleKgeLeftLeg+bodyResultTwoLegs.htMuscleKgRightArm+bodyResultTwoLegs.htMuscleKgRightLeg)/(heightM*heightM);
  281. recordModel.musleMassLimbs = [NSString stringWithFormat:@"%.1f",index];
  282. return recordModel;
  283. }
  284. #pragma mark - 新算法
  285. +(void)new_algorithmOfHTWithDataModel:(ELEightScaleBleDataModel *)dataModel sex:(BhSexType)sex height:(CGFloat)height kgWeight:(CGFloat)kgWeight age:(NSInteger)age updateRecordModel:(ELEightScaleRecordModel *)recordModel {
  286. #if TARGET_IPHONE_SIMULATOR == 0
  287. //HT算法
  288. BhSexType htSex = sex;
  289. BhBodyCompositionAllBody50KHz *bodyCompositon = [[BhBodyCompositionAllBody50KHz alloc] init];
  290. bodyCompositon.bhSex = htSex;
  291. bodyCompositon.bhPeopleType = BH_PEOPLE_TYPE_NORMAL;
  292. bodyCompositon.bhHeightCm = height;
  293. bodyCompositon.bhWeightKg = kgWeight;
  294. bodyCompositon.bhAge = (int)age;
  295. bodyCompositon.bhZLeftArmEnCode = dataModel.leftHandAdc;
  296. bodyCompositon.bhZRightArmEnCode = dataModel.rightHandAdc;
  297. bodyCompositon.bhZLeftLegEnCode = dataModel.leftFootAdc;
  298. bodyCompositon.bhZRightLegEnCode = dataModel.rightFootAdc;
  299. bodyCompositon.bhZLeftBodyEnCode = dataModel.RWholeBodyAdc;
  300. BhErrorType errType = [bodyCompositon getBhBodyCompositionAllBody50KHz];
  301. NSLog(@"errType(不为0就有问题) = %zd",errType);
  302. //显示体脂参数
  303. recordModel.bmi = [NSString stringWithFormat:@"%.1f",bodyCompositon.bhBMI];
  304. recordModel.bfr = [NSString stringWithFormat:@"%.1f",bodyCompositon.bhBodyFatRate];
  305. recordModel.sfr = [NSString stringWithFormat:@"%.1f",bodyCompositon.bhBodyFatSubCutRate];
  306. recordModel.uvi = [NSString stringWithFormat:@"%u",bodyCompositon.bhVFAL];
  307. recordModel.rom = [NSString stringWithFormat:@"%.1f",bodyCompositon.bhMuscleRate];
  308. recordModel.bmr = [NSString stringWithFormat:@"%u",bodyCompositon.bhBMR];
  309. recordModel.vwc = [NSString stringWithFormat:@"%.1f",bodyCompositon.bhWaterRate];
  310. recordModel.bodyAge = [NSString stringWithFormat:@"%u",bodyCompositon.bhBodyAge];
  311. recordModel.pp = [NSString stringWithFormat:@"%.1f",bodyCompositon.bhProteinRate];
  312. recordModel.adc = [NSString stringWithFormat:@"%d",dataModel.trunkAdc];//记录躯干adc
  313. recordModel.heartRate = dataModel.heartRate>0?[NSString stringWithFormat:@"%d",dataModel.heartRate]:@"";
  314. recordModel.createTime = dataModel.createTime;
  315. recordModel.deviceAlgorithm = [NSString stringWithFormat:@"%d",dataModel.algorithmID];
  316. //骨量
  317. if (bodyCompositon.bhBoneKg>0) {
  318. NSUInteger boneMass = roundf(bodyCompositon.bhBoneKg*pow(10, dataModel.weightPoint));
  319. recordModel.bm = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:boneMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  320. }else{
  321. recordModel.bm = @"";
  322. }
  323. //标准体重
  324. if (bodyCompositon.bhIdealWeightKg >0) {
  325. //说明有值
  326. NSUInteger standard = roundf(bodyCompositon.bhIdealWeightKg*pow(10, dataModel.weightPoint));
  327. recordModel.standardWeight = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:standard bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  328. //体重控制量
  329. CGFloat weightControl = kgWeight - bodyCompositon.bhIdealWeightKg;
  330. NSUInteger weightContrlABS = roundf(fabs(weightControl*pow(10, dataModel.weightPoint)));
  331. NSString *weightContrlStr = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:weightContrlABS bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  332. if (weightControl<0) {
  333. recordModel.weightControl = [NSString stringWithFormat:@"-%@",weightContrlStr];
  334. }else{
  335. recordModel.weightControl = weightContrlStr;
  336. }
  337. recordModel.fatLevel = [NSString stringWithFormat:@"%lu",(unsigned long)[ELBodyIndexAlgorithmModel getfatLevelWithweight:kgWeight andStandardWeight:bodyCompositon.bhIdealWeightKg]];
  338. }else{
  339. recordModel.standardWeight = @"";
  340. recordModel.weightControl = @"";
  341. recordModel.fatLevel = @"";
  342. }
  343. //脂肪量
  344. if (bodyCompositon.bhBodyFatKg>0) {
  345. NSLog(@"---和泰脂肪量:%f",bodyCompositon.bhBodyFatKg);
  346. NSUInteger fatMass = roundf(bodyCompositon.bhBodyFatKg*pow(10, dataModel.weightPoint));
  347. recordModel.fatMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:fatMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  348. }else{
  349. recordModel.fatMass = @"";
  350. }
  351. //去脂体重
  352. if (bodyCompositon.bhBodyFatFreeMassKg>0) {
  353. NSUInteger withoutFatW = roundf(bodyCompositon.bhBodyFatFreeMassKg*pow(10, dataModel.weightPoint));
  354. recordModel.weightWithoutFat = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:withoutFatW bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  355. }else{
  356. recordModel.weightWithoutFat = @"";
  357. }
  358. //肌肉量
  359. if (bodyCompositon.bhMuscleKg>0) {
  360. NSLog(@"---和泰脂肪量:%f",bodyCompositon.bhMuscleKg);
  361. NSInteger musleMass = round(bodyCompositon.bhMuscleKg*pow(10, dataModel.weightPoint));
  362. recordModel.musleMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:musleMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  363. }else{
  364. recordModel.musleMass = @"";
  365. }
  366. //蛋白量
  367. if (bodyCompositon.bhProteinRate>0) {
  368. NSUInteger proteinMassInt = roundf((bodyCompositon.bhProteinRate/100.0)*kgWeight* pow(10, dataModel.weightPoint));
  369. recordModel.proteinMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:proteinMassInt bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  370. }else{
  371. recordModel.proteinMass = @"";
  372. }
  373. //体脂-右手
  374. if (bodyCompositon.bhBodyFatKgRightArm >0) {
  375. NSUInteger rightHand = roundf(bodyCompositon.bhBodyFatKgRightArm*pow(10, dataModel.weightPoint));
  376. recordModel.fatMassRightTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  377. }else{
  378. recordModel.fatMassRightTop = @"";
  379. }
  380. //体脂-右脚
  381. if (bodyCompositon.bhBodyFatKgRightLeg >0) {
  382. NSUInteger rightFoot = roundf(bodyCompositon.bhBodyFatKgRightLeg*pow(10, dataModel.weightPoint));
  383. recordModel.fatMassRightBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  384. }else{
  385. recordModel.fatMassRightBottom = @"";
  386. }
  387. //体脂-左手
  388. if (bodyCompositon.bhBodyFatKgLeftArm >0) {
  389. NSUInteger leftHand = roundf(bodyCompositon.bhBodyFatKgLeftArm*pow(10, dataModel.weightPoint));
  390. recordModel.fatMassLeftTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  391. }else{
  392. recordModel.fatMassLeftTop = @"";
  393. }
  394. //体脂-左脚
  395. if (bodyCompositon.bhBodyFatKgLeftLeg >0) {
  396. NSUInteger leftFoot = roundf(bodyCompositon.bhBodyFatKgLeftLeg*pow(10, dataModel.weightPoint));
  397. recordModel.fatMassLeftBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  398. }else{
  399. recordModel.fatMassLeftBottom = @"";
  400. }
  401. //体脂-躯干
  402. if (bodyCompositon.bhBodyFatKgTrunk >0) {
  403. NSUInteger fatMassBody = roundf(bodyCompositon.bhBodyFatKgTrunk*pow(10, dataModel.weightPoint));
  404. recordModel.fatMassBody = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:fatMassBody bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  405. }else{
  406. recordModel.fatMassBody = @"";
  407. }
  408. //肌肉-右手
  409. if (bodyCompositon.bhMuscleKgRightArm >0) {
  410. NSUInteger rightHand = roundf(bodyCompositon.bhMuscleKgRightArm*pow(10, dataModel.weightPoint));
  411. recordModel.musleMassRightTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  412. }else{
  413. recordModel.musleMassRightTop = @"";
  414. }
  415. //肌肉-右脚
  416. if (bodyCompositon.bhMuscleKgRightLeg >0) {
  417. NSUInteger rightFoot = roundf(bodyCompositon.bhMuscleKgRightLeg*pow(10, dataModel.weightPoint));
  418. recordModel.musleMassRightBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  419. }else{
  420. recordModel.musleMassRightBottom = @"";
  421. }
  422. //肌肉-左手
  423. if (bodyCompositon.bhMuscleKgLeftArm >0) {
  424. NSUInteger leftHand = roundf(bodyCompositon.bhMuscleKgLeftArm*pow(10, dataModel.weightPoint));
  425. recordModel.musleMassLeftTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  426. }else{
  427. recordModel.musleMassLeftTop = @"";
  428. }
  429. //肌肉-左脚
  430. if (bodyCompositon.bhMuscleKgLeftLeg >0) {
  431. NSUInteger leftFoot = roundf(bodyCompositon.bhMuscleKgLeftLeg*pow(10, dataModel.weightPoint));
  432. recordModel.musleMassLeftBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  433. }else{
  434. recordModel.musleMassLeftBottom = @"";
  435. }
  436. //肌肉-躯干
  437. if (bodyCompositon.bhMuscleKgTrunk >0) {
  438. NSUInteger muscleMassBody = roundf(bodyCompositon.bhMuscleKgTrunk*pow(10, dataModel.weightPoint));
  439. recordModel.musleMassBody = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:muscleMassBody bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  440. }else{
  441. recordModel.musleMassBody = @"";
  442. }
  443. //四肢肌肉指数 = 四肢肌肉量(kg)/身高的平方(m)
  444. CGFloat heightM = (height/100.0);
  445. CGFloat index = (bodyCompositon.bhMuscleKgLeftArm+bodyCompositon.bhMuscleKgLeftLeg+bodyCompositon.bhMuscleKgRightArm+bodyCompositon.bhMuscleKgRightLeg)/(heightM*heightM);
  446. recordModel.musleMassLimbs = [NSString stringWithFormat:@"%.1f",index];
  447. NSLog(@"八电极体脂:\n%@",recordModel);
  448. #endif
  449. }
  450. @end