地质所 沉降监测网建设项目
chenhuan
2024-05-16 f992b4e508b358eba4170b1e9b1bb21319f7a3cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.javaweb.third.baidu.bean.imgClassify;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.javaweb.third.baidu.bean.BaseResult;
 
import java.util.List;
import java.util.Map;
 
/**
 * 动物识别结果
 * @author wujiyue
 */
public class AnimalResult extends BaseResult {
 
    //{"log_id": 4413670068622107758, "result": [{"score": "0.663324", "name": "金吉拉猫"}, {"score": "0.113101", "name": "布偶猫"}]}
    //{"log_id": 55148098712447112, "result": [{"score": "0.999139", "name": "非动物"}]}
    private boolean isAnimal;
    //认定为是哪个动物的阈值概率
    private Double animalProbability=0.7;
    //根据阈值概率最总认定为是那个动物名称
    private String result_name;
    //定为是那个动物的概率
    private Double result_probability;
    private List<Map> result;
 
    public AnimalResult(String json){
        this.setJson(json);
        try{
            JSONObject jsonObject= JSONObject.parseObject(json);
            this.setLog_id(jsonObject.getString("log_id"));
            String e_code=String.valueOf(jsonObject.get("error_code"));
            if(notNull(e_code)){
                this.setError_code(e_code);
                String e_msg=String.valueOf(jsonObject.get("error_msg"));
                this.setError_msg(e_msg);
                this.setRequestOk(false);
            }else {
                this.setRequestOk(true);
 
                List<Map> list = JSONArray.parseArray(jsonObject.get("result").toString(), Map.class);
                if(list!=null&&list.size()>0){
                    for(Map t:list){
                        String name=String.valueOf(t.get("name"));
                        Double pro=Double.valueOf(String.valueOf(t.get("score")));
                        if((list.size()==1&&"非动物".equals(name))||(pro>=0.5 && "非动物".equals(name))){
                            isAnimal=false;
                            this.result_name=name;
                            this.result_probability=pro;
                            break;
                        }
                        if(pro>animalProbability){
                            isAnimal=true;
                            this.result_name=name;
                            this.result_probability=pro;
 
                        }
                    }
                    this.result=list;
                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
            this.setRequestOk(false);
            this.setError_msg("解析json字符串出现异常!");
        }
    }
    public static AnimalResult create(String jsonStr) {
        return new AnimalResult(jsonStr);
    }
 
    public boolean isAnimal() {
        return isAnimal;
    }
 
    public void setAnimal(boolean isAnimal) {
        this.isAnimal = isAnimal;
    }
 
    public Double getAnimalProbability() {
        return animalProbability;
    }
 
    public void setAnimalProbability(Double animalProbability) {
        this.animalProbability = animalProbability;
    }
 
    public String getResult_name() {
        return result_name;
    }
 
    public void setResult_name(String result_name) {
        this.result_name = result_name;
    }
 
    public Double getResult_probability() {
        return result_probability;
    }
 
    public void setResult_probability(Double result_probability) {
        this.result_probability = result_probability;
    }
 
    public List<Map> getResult() {
        return result;
    }
 
    public void setResult(List<Map> result) {
        this.result = result;
    }
 
    @Override
    public String toString() {
        if(isRequestOk()){
            return "AnimalResult{" +
                    "isAnimal=" + isAnimal +
                    ", result_name='" + result_name + '\'' +
                    ", result_probability=" + result_probability +
                    ", result=" + result +
                    '}';
        }else{
            return getError_msg()+";错误代码["+getError_code()+"]"+";log_id["+getLog_id()+"]";
        }
    }
 
 
}