iOS AILinkBleSDK - 蓝牙SDK
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ELEightScaleAlgorithmTool.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. @implementation ELEightScaleAlgorithmTool
  17. /// 根据秤测量的阻抗数据调用算法解析出其他体脂数据
  18. /// @param dataModel 八电极秤测量的数据
  19. /// @param sex 女性传0,男性传1
  20. /// @param height 身高,单位cm
  21. /// @param age 年龄
  22. +(ELEightScaleRecordModel *)getRecordModelWithBleDataModel:(ELEightScaleBleDataModel *)dataModel withUserSex:(NSInteger)sex height:(NSInteger)height age:(NSInteger)age {
  23. CGFloat kgWeight = [ELWeightAlgorithmusModel getKgWithWeightShowStr:dataModel.weight weightUnit:dataModel.weightUnit weightPoint:dataModel.weightPoint].floatValue;
  24. HTBodyBasicInfo *bodyBasicInfo = [[HTBodyBasicInfo alloc] initWithSex:sex height:height weight:kgWeight age:age];
  25. bodyBasicInfo.htZAllBodyImpedance = dataModel.RWholeBodyAdc;
  26. bodyBasicInfo.htZLeftLegImpedance = dataModel.leftFootAdc;
  27. bodyBasicInfo.htZRightLegImpedance = dataModel.rightFootAdc;
  28. bodyBasicInfo.htZLeftArmImpedance = dataModel.leftHandAdc;
  29. bodyBasicInfo.htZRightArmImpedance = dataModel.rightHandAdc;
  30. bodyBasicInfo.htTwoArmsImpedance = dataModel.handsAdc;
  31. bodyBasicInfo.htTwoLegsImpedance = dataModel.feetAdc;
  32. //计算体脂参数
  33. HTBodyResultAllBody *bodyResultTwoLegs = [[HTBodyResultAllBody alloc] init];
  34. HTBodyfatErrorType errorType = [bodyResultTwoLegs getBodyfatWithBasicInfo:bodyBasicInfo];
  35. NSLog(@"HTBodyfatErrorType = %lu",errorType);
  36. if(errorType != HTBodyfatErrorTypeNone){
  37. NSMutableString *errorStr = [[NSMutableString alloc]initWithString:@""];
  38. if((errorType & HTBodyfatErrorTypeAge) == HTBodyfatErrorTypeAge){
  39. [errorStr appendString:@"年龄 "];
  40. }
  41. if((errorType & HTBodyfatErrorTypeWeight) == HTBodyfatErrorTypeWeight){
  42. [errorStr appendString:@"体重 "];
  43. }
  44. if((errorType & HTBodyfatErrorTypeHeight) == HTBodyfatErrorTypeHeight){
  45. [errorStr appendString:@"身高 "];
  46. }
  47. if((errorType & HTBodyfatErrorTypeSex) == HTBodyfatErrorTypeSex){
  48. [errorStr appendString:@"性别 "];
  49. }
  50. if((errorType & HTBodyfatErrorTypeImpedance) == HTBodyfatErrorTypeImpedance){
  51. [errorStr appendString:@"阻抗 "];
  52. }
  53. if((errorType & HTBodyfatErrorTypeImpedanceLeftLeg) == HTBodyfatErrorTypeImpedanceLeftLeg){
  54. [errorStr appendString:@"左脚阻抗 "];
  55. }
  56. if((errorType & HTBodyfatErrorTypeImpedanceRightLeg) == HTBodyfatErrorTypeImpedanceRightLeg){
  57. [errorStr appendString:@"右脚阻抗 "];
  58. }
  59. if((errorType & HTBodyfatErrorTypeImpedanceLeftArm) == HTBodyfatErrorTypeImpedanceLeftArm){
  60. [errorStr appendString:@"左手阻抗 "];
  61. }
  62. if((errorType & HTBodyfatErrorTypeImpedanceRightArm) == HTBodyfatErrorTypeImpedanceRightArm){
  63. [errorStr appendString:@"右手阻抗 "];
  64. }
  65. [errorStr appendString:@"参数有误!"];
  66. NSLog(@"errorType = %@",errorStr);
  67. }
  68. ELEightScaleRecordModel *recordModel = [[ELEightScaleRecordModel alloc] init];
  69. recordModel.bmi = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBMI];
  70. recordModel.bfr = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBodyfatPercentage];
  71. recordModel.sfr = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htBodyfatSubcut];
  72. recordModel.uvi = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htVFAL];
  73. recordModel.rom = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htMusclePercentage];
  74. recordModel.bmr = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htBMR];
  75. recordModel.vwc = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htWaterPercentage];
  76. recordModel.bodyAge = [NSString stringWithFormat:@"%ld",bodyResultTwoLegs.htBodyAge];
  77. recordModel.pp = [NSString stringWithFormat:@"%.1f",bodyResultTwoLegs.htProteinPercentage];
  78. recordModel.adc = [NSString stringWithFormat:@"%d",dataModel.trunkAdc];//记录躯干adc
  79. recordModel.heartRate = dataModel.heartRate>0?[NSString stringWithFormat:@"%d",dataModel.heartRate]:@"";
  80. recordModel.createTime = dataModel.createTime;
  81. recordModel.deviceAlgorithm = [NSString stringWithFormat:@"%d",dataModel.algorithmID];
  82. //骨量
  83. if (bodyResultTwoLegs.htBoneKg>0) {
  84. NSUInteger boneMass = roundf(bodyResultTwoLegs.htBoneKg*pow(10, dataModel.weightPoint));
  85. recordModel.bm = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:boneMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  86. }else{
  87. recordModel.bm = @"";
  88. }
  89. //标准体重
  90. if (bodyResultTwoLegs.htIdealWeightKg >0) {
  91. //说明有值
  92. NSUInteger standard = roundf(bodyResultTwoLegs.htIdealWeightKg*pow(10, dataModel.weightPoint));
  93. recordModel.standardWeight = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:standard bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  94. //体重控制量
  95. CGFloat weightControl = kgWeight - bodyResultTwoLegs.htIdealWeightKg;
  96. NSUInteger weightContrlABS = roundf(fabs(weightControl*pow(10, dataModel.weightPoint)));
  97. NSString *weightContrlStr = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:weightContrlABS bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  98. if (weightControl<0) {
  99. recordModel.weightControl = [NSString stringWithFormat:@"-%@",weightContrlStr];
  100. }else{
  101. recordModel.weightControl = weightContrlStr;
  102. }
  103. recordModel.fatLevel = [NSString stringWithFormat:@"%lu",(unsigned long)[ELBodyIndexAlgorithmModel getfatLevelWithweight:kgWeight andSatndardWeight:bodyResultTwoLegs.htIdealWeightKg]];
  104. }else{
  105. recordModel.standardWeight = @"";
  106. recordModel.weightControl = @"";
  107. recordModel.fatLevel = @"";
  108. }
  109. //脂肪量
  110. if (bodyResultTwoLegs.htBodyfatKg>0) {
  111. NSUInteger fatMass = roundf(bodyResultTwoLegs.htBodyfatKg*pow(10, dataModel.weightPoint));
  112. recordModel.fatMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:fatMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  113. }else{
  114. recordModel.fatMass = @"";
  115. }
  116. //去脂体重
  117. if (bodyResultTwoLegs.htBodyfatFreeMass>0) {
  118. NSUInteger withoutFatW = roundf(bodyResultTwoLegs.htBodyfatFreeMass*pow(10, dataModel.weightPoint));
  119. recordModel.weightWithoutFat = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:withoutFatW bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  120. }else{
  121. recordModel.weightWithoutFat = @"";
  122. }
  123. //肌肉量
  124. if (bodyResultTwoLegs.htMuscleKg>0) {
  125. NSInteger musleMass = round(bodyResultTwoLegs.htMuscleKg*pow(10, dataModel.weightPoint));
  126. recordModel.musleMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:musleMass bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  127. }else{
  128. recordModel.musleMass = @"";
  129. }
  130. //蛋白量
  131. if (bodyResultTwoLegs.htProteinPercentage>0) {
  132. NSUInteger proteinMassInt = roundf((bodyResultTwoLegs.htProteinPercentage/100.0)*kgWeight* pow(10, dataModel.weightPoint));
  133. recordModel.proteinMass = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:proteinMassInt bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  134. }else{
  135. recordModel.proteinMass = @"";
  136. }
  137. //体脂-右手
  138. if (bodyResultTwoLegs.htBodyfatKgRightArm >0) {
  139. NSUInteger rightHand = roundf(bodyResultTwoLegs.htBodyfatKgRightArm*pow(10, dataModel.weightPoint));
  140. recordModel.fatMassRightTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  141. }else{
  142. recordModel.fatMassRightTop = @"";
  143. }
  144. //体脂-右脚
  145. if (bodyResultTwoLegs.htBodyfatKgRightLeg >0) {
  146. NSUInteger rightFoot = roundf(bodyResultTwoLegs.htBodyfatKgRightLeg*pow(10, dataModel.weightPoint));
  147. recordModel.fatMassRightBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  148. }else{
  149. recordModel.fatMassRightBottom = @"";
  150. }
  151. //体脂-左手
  152. if (bodyResultTwoLegs.htBodyfatKgLeftArm >0) {
  153. NSUInteger leftHand = roundf(bodyResultTwoLegs.htBodyfatKgLeftArm*pow(10, dataModel.weightPoint));
  154. recordModel.fatMassLeftTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  155. }else{
  156. recordModel.fatMassLeftTop = @"";
  157. }
  158. //体脂-左脚
  159. if (bodyResultTwoLegs.htBodyfatKgLeftLeg >0) {
  160. NSUInteger leftFoot = roundf(bodyResultTwoLegs.htBodyfatKgLeftLeg*pow(10, dataModel.weightPoint));
  161. recordModel.fatMassLeftBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  162. }else{
  163. recordModel.fatMassLeftBottom = @"";
  164. }
  165. //体脂-躯干
  166. if (bodyResultTwoLegs.htBodyfatKgTrunk >0) {
  167. NSUInteger fatMassBody = roundf(bodyResultTwoLegs.htBodyfatKgTrunk*pow(10, dataModel.weightPoint));
  168. recordModel.fatMassBody = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:fatMassBody bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  169. }else{
  170. recordModel.fatMassBody = @"";
  171. }
  172. //肌肉-右手
  173. if (bodyResultTwoLegs.htMuscleKgRightArm >0) {
  174. NSUInteger rightHand = roundf(bodyResultTwoLegs.htMuscleKgRightArm*pow(10, dataModel.weightPoint));
  175. recordModel.musleMassRightTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  176. }else{
  177. recordModel.musleMassRightTop = @"";
  178. }
  179. //肌肉-右脚
  180. if (bodyResultTwoLegs.htMuscleKgRightLeg >0) {
  181. NSUInteger rightFoot = roundf(bodyResultTwoLegs.htMuscleKgRightLeg*pow(10, dataModel.weightPoint));
  182. recordModel.musleMassRightBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:rightFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  183. }else{
  184. recordModel.musleMassRightBottom = @"";
  185. }
  186. //肌肉-左手
  187. if (bodyResultTwoLegs.htMuscleKgLeftArm >0) {
  188. NSUInteger leftHand = roundf(bodyResultTwoLegs.htMuscleKgLeftArm*pow(10, dataModel.weightPoint));
  189. recordModel.musleMassLeftTop = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftHand bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  190. }else{
  191. recordModel.musleMassLeftTop = @"";
  192. }
  193. //肌肉-左脚
  194. if (bodyResultTwoLegs.htMuscleKgeLeftLeg >0) {
  195. NSUInteger leftFoot = roundf(bodyResultTwoLegs.htMuscleKgeLeftLeg*pow(10, dataModel.weightPoint));
  196. recordModel.musleMassLeftBottom = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:leftFoot bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  197. }else{
  198. recordModel.musleMassLeftBottom = @"";
  199. }
  200. //肌肉-躯干
  201. if (bodyResultTwoLegs.htMuscleKgTrunk >0) {
  202. NSUInteger muscleMassBody = roundf(bodyResultTwoLegs.htMuscleKgTrunk*pow(10, dataModel.weightPoint));
  203. recordModel.musleMassBody = [ELWeightAlgorithmusModel getWeightShowStrWithTargetUnit:dataModel.weightUnit bleWeightInt:muscleMassBody bleWeightUnit:(ELDeviceWeightUnit_KG) bleWeightPoint:dataModel.weightPoint];
  204. }else{
  205. recordModel.musleMassBody = @"";
  206. }
  207. //四肢肌肉指数 = 四肢肌肉量(kg)/身高的平方(m)
  208. CGFloat heightM = (height/100.0);
  209. CGFloat index = (bodyResultTwoLegs.htMuscleKgLeftArm+bodyResultTwoLegs.htMuscleKgeLeftLeg+bodyResultTwoLegs.htMuscleKgRightArm+bodyResultTwoLegs.htMuscleKgRightLeg)/(heightM*heightM);
  210. recordModel.musleMassLimbs = [NSString stringWithFormat:@"%.1f",index];
  211. return recordModel;
  212. }
  213. @end