Переглянути джерело

window系统默认会从jdk的-jre/bin目录下寻找,该demo使用默认位置,将dll文件放在jdk->jre->bin目录中

master
elinkthings 3 роки тому
джерело
коміт
13af5ca2a5
23 змінених файлів з 345 додано та 29 видалено
  1. 31
    0
      algorithm-lib/.classpath
  2. 29
    0
      algorithm-lib/.project
  3. 5
    0
      algorithm-lib/.settings/org.eclipse.core.resources.prefs
  4. 5
    0
      algorithm-lib/.settings/org.eclipse.jdt.core.prefs
  5. 4
    0
      algorithm-lib/.settings/org.eclipse.m2e.core.prefs
  6. 5
    3
      algorithm-lib/src/main/java/com/elink/aicare/BodyFatAlgorithmAicare.java
  7. BIN
      algorithm-lib/src/main/java/com/elink/aicare/BodyFatAlgorithmAicareWin.class
  8. 151
    25
      algorithm-lib/src/main/java/com/elink/aicare/BodyFatAlgorithmUtils.java
  9. 112
    0
      algorithm-lib/src/main/java/com/elink/aicare/BodyFatData.java
  10. 3
    1
      algorithm-lib/src/main/java/com/elink/aicare/DemoController.java
  11. BIN
      algorithm-lib/src/main/java/com/elink/aicare/com/elink/aicare/BodyFatAlgorithmAicareWin.class
  12. 0
    0
      algorithm-lib/src/main/resources/libMacAlgorithm-aicare.so
  13. 0
    0
      algorithm-lib/src/main/resources/libalgorithm-aicare.so
  14. BIN
      algorithm-lib/src/main/resources/libalgorithm-aicare_x64.dll
  15. BIN
      algorithm-lib/target/classes/com/elink/aicare/AicareDemoAppApplication.class
  16. BIN
      algorithm-lib/target/classes/com/elink/aicare/BodyFatAlgorithmAicare.class
  17. BIN
      algorithm-lib/target/classes/com/elink/aicare/BodyFatAlgorithmUtils.class
  18. BIN
      algorithm-lib/target/classes/com/elink/aicare/BodyFatData$FatLevel.class
  19. BIN
      algorithm-lib/target/classes/com/elink/aicare/BodyFatData.class
  20. BIN
      algorithm-lib/target/classes/com/elink/aicare/DemoController.class
  21. 0
    0
      algorithm-lib/target/classes/libMacAlgorithm-aicare.so
  22. 0
    0
      algorithm-lib/target/classes/libalgorithm-aicare.so
  23. BIN
      algorithm-lib/target/classes/libalgorithm-aicare_x64.dll

+ 31
- 0
algorithm-lib/.classpath Переглянути файл

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

+ 29
- 0
algorithm-lib/.project Переглянути файл

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>algorithm-lib</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

+ 5
- 0
algorithm-lib/.settings/org.eclipse.core.resources.prefs Переглянути файл

@@ -0,0 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8

+ 5
- 0
algorithm-lib/.settings/org.eclipse.jdt.core.prefs Переглянути файл

@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

+ 4
- 0
algorithm-lib/.settings/org.eclipse.m2e.core.prefs Переглянути файл

@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

+ 5
- 3
algorithm-lib/src/main/java/com/elink/aicare/BodyFatAlgorithmAicare.java Переглянути файл

@@ -8,11 +8,13 @@ import com.sun.jna.Native;

public interface BodyFatAlgorithmAicare extends Library {
String osName = System.getProperty("os.name"); // 获取当前操作系统的类型
//window系统默认会从jdk的-jre/bin目录下寻找,该demo使用默认位置,将dll文件放在jdk->jre->bin目录中
String libWindows = "libalgorithm-aicare_x64";
//MacOS,需要手动在IDE中添加对SO库的引用,类似添加普通jar包文件
String rootResource = BodyFatAlgorithmAicare.class.getResource("/").getPath();
String libWindows = "/libalgorithm-aicare.dll";
String libMacOS = rootResource+ "libMacAlgorithm-aicare.so";
//System调用so时,调用了:java.lang.System.mapLibraryName()方法。这个方法会在咱们的给定的名字前拼接上”lib”
//此种调用方式,linux系统对应的so库,需要放在usr/lib下
//linux->System调用so时,调用了:java.lang.System.mapLibraryName()方法。这个方法会在给定的名字前拼接上”lib”
//默认调用方式,linux系统对应的so库,需要放在usr/lib下
String liblinux = "algorithm-aicare";
//根据不同的操作系统,使用不同的库
String libPath = (osName != null && osName.startsWith("Windows")) ? libWindows : ((osName != null && osName.startsWith("Mac")) ? libMacOS : liblinux);

BIN
algorithm-lib/src/main/java/com/elink/aicare/BodyFatAlgorithmAicareWin.class Переглянути файл


+ 151
- 25
algorithm-lib/src/main/java/com/elink/aicare/BodyFatAlgorithmUtils.java Переглянути файл

@@ -1,13 +1,14 @@
package com.elink.aicare;

import com.alibaba.fastjson.JSON;
import java.math.BigDecimal;

import com.alibaba.fastjson.JSON;
/**
*
*/
public class BodyFatAlgorithmUtils {
public static void main(String args[]){
public static void main(String args[]) throws Exception{
int sex=1;
int age=24;
double weight = 60.5;
@@ -27,31 +28,41 @@ public class BodyFatAlgorithmUtils {
* @param height 身高;单位:cm,取值范围:0< height <=270
* @param adc 阻抗;取值范围:0 < adc <= 1000
* @return
* @throws Exception
*/
public static BodyFatData getBodyFatData(int algorithmType,int sex, int age, double weight,int height, int adc){

if (age < 0 || age > 120){
System.out.println("年龄age取值不正确,取值范围:0<=age<=120 ;单位:年");
return null;
}
if (weight <= 0.0 && weight > 220.0){
System.out.println("体重weight取值不正确,取值范围:0.0< weight < 220 ;单位:kg");
return null;
}
if (height <= 0 && height > 270){
System.out.println("身高height取值不正确,取值范围:0< height <=270 ;单位:cm");
return null;
}
if (adc < 0 && adc > 1000){
System.out.println("阻抗adc取值不正确,取值范围:0 < adc <= 1000");
return null;
}
return getDataByAicare(sex, age, weight,height, adc);

try {
if (age < 0 || age > 120){
throw new Exception("年龄age取值不正确,取值范围:0<=age<=120 ;单位:年");
}
if (weight <= 0.0 && weight > 220.0){
throw new Exception("体重weight取值不正确,取值范围:0.0< weight < 220 ;单位:kg");
}
if (height <= 0 && height > 270){
throw new Exception("身高height取值不正确,取值范围:0< height <=270 ;单位:cm");
}
if (adc < 0 && adc > 1000){
throw new Exception("阻抗adc取值不正确,取值范围:0 < adc <= 1000");
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return getDataByAicare(sex, age, weight,height, adc);
}

/**
* 调用体脂算法库文件,计算对应的数据
* @param sex
* @param age
* @param weight
* @param heightCM
* @param adc
* @return
*/
private static BodyFatData getDataByAicare(int sex, int age, double weight,int heightCM, int adc){
BodyFatAlgorithmAicare bodyFatAlgorithmAicare = BodyFatAlgorithmAicare.INSTANTCE;
//调用体脂算法库,计算基础数据
BodyFatAlgorithmAicare bodyFatAlgorithmAicare = BodyFatAlgorithmAicare.INSTANTCE;
double height = bodyFatAlgorithmAicare.getHeight(heightCM);
double bmi = bodyFatAlgorithmAicare.getBMI(weight,height);
double bm = bodyFatAlgorithmAicare.getBM(sex,bmi, height, age, adc, weight);
@@ -64,7 +75,7 @@ public class BodyFatAlgorithmUtils {
int uvi = bodyFatAlgorithmAicare.getUVI( sex, weight, height, age, adc);
int bmr = bodyFatAlgorithmAicare.getBMR( sex, weight, height, age, adc);
int bodyAge = bodyFatAlgorithmAicare.getBodyAge( age, bmi, sex);
//处理返回数据
//处理基础数据
BodyFatData fatData = new BodyFatData();
fatData.setBmi(bmi);
fatData.setBfr(Math.round(bfr * 10) / 10.0);
@@ -76,6 +87,121 @@ public class BodyFatAlgorithmUtils {
fatData.setVwc(Math.floor(vwc * 10) / 10);
fatData.setBodyAge(bodyAge);
fatData.setPp(Math.floor(pp * 10) / 10);
//依据基础数据,计算其他体脂数据
double standardWeight = returnStandardWeight(sex, heightCM);
double controlWeight = returnControlWeight(weight, standardWeight);
double fat = returnFat(weight, bfr);
double removeFatWeight = returnRemoveFatWeight(weight, fat);
double muscleMass = returnMuscleMass(weight, rom);
double protein = returnProtein(weight, pp);
fatData.setStandardWeight(keepDecimal(standardWeight, 1));
fatData.setControlWeight(keepDecimal(controlWeight, 1));
fatData.setFat(keepDecimal(fat, 1));
fatData.setRemoveFatWeight(keepDecimal(removeFatWeight, 1));
fatData.setMuscleMass(keepDecimal(muscleMass, 1));
fatData.setProtein(keepDecimal(protein, 1));
BodyFatData.FatLevel fatLevel = returnFatLevel(weight, standardWeight);
fatData.setFatLevel(fatLevel);
return fatData;
}
}
/**
* 标准体重(kg)
* @param sex 性别
* @param height 身高
* @return
*/
private static double returnStandardWeight(int sex, int height) {
double standardWeight = 0.0D;
switch(sex) {
case 1:
standardWeight = (double)(height - 80) * 0.7D;
break;
case 2:
standardWeight = (double)(height - 70) * 0.6D;
}

return standardWeight;
}

/**
* 体重控制量(kg)
* @param curWeight 体重
* @param standardWeight 标准体重
* @return
*/
private static double returnControlWeight(double curWeight, double standardWeight) {
return curWeight - standardWeight;
}

/**
* 脂肪量
* @param curWeight 体重
* @param bfr 脂肪
* @return
*/
private static double returnFat(double curWeight, double bfr) {
return curWeight * bfr / 100.0D;
}

/**
* 去脂体重
* @param curWeight 体重
* @param fat 脂肪量
* @return
*/
private static double returnRemoveFatWeight(double curWeight, double fat) {
return curWeight - fat;
}

/**
* 肌肉量
* @param curWeight 体重
* @param rom 肌肉率
* @return
*/
private static double returnMuscleMass(double curWeight, double rom) {
return curWeight * rom / 100.0D;
}

/**
* 蛋白量
* @param curWeight 体重
* @param pp 蛋白率
* @return
*/
private static double returnProtein(double curWeight, double pp) {
return curWeight * pp / 100.0D;
}

/**
* 肥胖等级
* @param curWeight 体重
* @param standardWeight 标准体重
* @return
*/
private static BodyFatData.FatLevel returnFatLevel(double curWeight, double standardWeight) {
double level = (curWeight - standardWeight) / standardWeight * 100.0D;
if (level < -20.0D) {
return BodyFatData.FatLevel.UNDER;
} else if (level >= -20.0D && level < -10.0D) {
return BodyFatData.FatLevel.THIN;
} else if (level >= -10.0D && level <= 10.0D) {
return BodyFatData.FatLevel.NORMAL;
} else {
return level > 10.0D && level <= 20.0D ? BodyFatData.FatLevel.OVER : BodyFatData.FatLevel.FAT;
}
}

/**
* 四舍五入
* @param d 值
* @param count 保留小数位
* @return double
*/
private static double keepDecimal(double d, int count) {
BigDecimal decimal = new BigDecimal(d);
return decimal.setScale(count, BigDecimal.ROUND_HALF_UP).doubleValue();
}
}

+ 112
- 0
algorithm-lib/src/main/java/com/elink/aicare/BodyFatData.java Переглянути файл

@@ -41,6 +41,61 @@ public class BodyFatData {
* 蛋白率
*/
private double pp;
/**
* 标准体重(kg)
*/
private double standardWeight;
/**
* 体重控制量(kg)
*/
private double controlWeight;
/**
* 脂肪量
*/
private double fat;
/**
* 去脂体重
*/
private double removeFatWeight;
/**
* 肌肉量
*/
private double muscleMass;
/**
* 蛋白量
*/
private double protein;
/**
* 肥胖等级
*/
private FatLevel fatLevel;
public static enum FatLevel {
/**
* 体重不足
*/
UNDER,
/**
* 偏瘦
*/
THIN,
/**
* 标准
*/
NORMAL,
/**
* 偏重
*/
OVER,
/**
* 超重
*/
FAT;

private FatLevel() {
}
}

public double getBmi() {
return bmi;
@@ -122,4 +177,61 @@ public class BodyFatData {
public void setPp(double pp) {
this.pp = pp;
}
public double getStandardWeight() {
return this.standardWeight;
}

public void setStandardWeight(double standardWeight) {
this.standardWeight = standardWeight;
}

public double getControlWeight() {
return this.controlWeight;
}

public void setControlWeight(double controlWeight) {
this.controlWeight = controlWeight;
}

public double getFat() {
return this.fat;
}

public void setFat(double fat) {
this.fat = fat;
}

public double getRemoveFatWeight() {
return this.removeFatWeight;
}

public void setRemoveFatWeight(double removeFatWeight) {
this.removeFatWeight = removeFatWeight;
}

public double getMuscleMass() {
return this.muscleMass;
}

public void setMuscleMass(double muscleMass) {
this.muscleMass = muscleMass;
}

public double getProtein() {
return this.protein;
}

public void setProtein(double protein) {
this.protein = protein;
}

public FatLevel getFatLevel() {
return this.fatLevel;
}

public void setFatLevel(FatLevel fatLevel) {
this.fatLevel = fatLevel;
}
}

+ 3
- 1
algorithm-lib/src/main/java/com/elink/aicare/DemoController.java Переглянути файл

@@ -1,6 +1,7 @@
package com.elink.aicare;

import com.alibaba.fastjson.JSON;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,10 +16,11 @@ public class DemoController {

/**
* 获取体脂数据
* @throws Exception
*
*/
@RequestMapping(value = "getBodyFat")
public Object sendCode(@RequestBody BodyFatData bodyFatData, HttpServletRequest request, BindingResult result) {
public Object sendCode(@RequestBody BodyFatData bodyFatData, HttpServletRequest request, BindingResult result) throws Exception {
int sex=1;
int age=24;
double weight = 60.5;

BIN
algorithm-lib/src/main/java/com/elink/aicare/com/elink/aicare/BodyFatAlgorithmAicareWin.class Переглянути файл


+ 0
- 0
algorithm-lib/src/main/resources/libMacAlgorithm-aicare.so Переглянути файл


+ 0
- 0
algorithm-lib/src/main/resources/libalgorithm-aicare.so Переглянути файл


BIN
algorithm-lib/src/main/resources/libalgorithm-aicare_x64.dll Переглянути файл


BIN
algorithm-lib/target/classes/com/elink/aicare/AicareDemoAppApplication.class Переглянути файл


BIN
algorithm-lib/target/classes/com/elink/aicare/BodyFatAlgorithmAicare.class Переглянути файл


BIN
algorithm-lib/target/classes/com/elink/aicare/BodyFatAlgorithmUtils.class Переглянути файл


BIN
algorithm-lib/target/classes/com/elink/aicare/BodyFatData$FatLevel.class Переглянути файл


BIN
algorithm-lib/target/classes/com/elink/aicare/BodyFatData.class Переглянути файл


BIN
algorithm-lib/target/classes/com/elink/aicare/DemoController.class Переглянути файл


+ 0
- 0
algorithm-lib/target/classes/libMacAlgorithm-aicare.so Переглянути файл


+ 0
- 0
algorithm-lib/target/classes/libalgorithm-aicare.so Переглянути файл


BIN
algorithm-lib/target/classes/libalgorithm-aicare_x64.dll Переглянути файл


Завантаження…
Відмінити
Зберегти