地质所 沉降监测网建设项目
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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 DishResult extends BaseResult {
 
    /*{
        "log_id": 2471272194,
            "result_num": 5,
            "result": [
        {
            "name": "烧烤(串类)",
                "calorie": 333.33,
                "probability": 0.35874313116074
        },
        {
            "name": "鱿鱼",
                "calorie": 333.33,
                "probability": 0.20610593259335
        },
        {
            "name": "板筋",
                "calorie": 333.33,
                "probability": 0.15860831737518
        },
        {
            "name": "鸡脆骨",
                "calorie": 333.33,
                "probability": 0.077698558568954
        },
        {
            "name": "麻辣烫",
                "calorie": 333.33,
                "probability": 0.041968926787376
        }
        ]
 
    }
   {"log_id": 2677811678621716503, "result_num": 1, "result": [{"calorie": "-1", "has_calorie": true, "name": "非菜", "probability": "0.202248"}]}
    */
    private Integer result_num;
    /**
     * 是否菜品
     */
    private boolean isDish;
    /**
     * 认定为是哪个菜品的阈值概率
     */
    private Double dishProbability=0.7;
    /**
     *根据阈值概率最总认定为是那个菜品名称
     */
    private String result_name;
    /**
     *定为是那个菜品的概率
     */
    private Double result_probability;
    /**
     *
     */
    private Double result_calorie;
    /**
     *如 返回概率大于0.1的结果   Map 中   key:name、calorie、probability
     */
    private List<Map> result;
 
    public DishResult(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);
                this.result_num=jsonObject.getInteger("result_num");
                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("probability")));
                        Double cal=Double.valueOf(String.valueOf(t.get("calorie")));
                        if((result_num==1&&"非菜".equals(name))||(pro>0.5&&"非菜".equals(name))){
                            isDish=false;
                            this.result_name=name;
                            this.result_probability=pro;
                            break;
                        }
                        if(pro>dishProbability){
                            isDish=true;
                            this.result_name=name;
                            this.result_probability=pro;
                            this.result_calorie=cal;
                        }
                    }
                    this.result=list;
                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
            this.setRequestOk(false);
            this.setError_msg("解析json字符串出现异常!");
        }
    }
    public static DishResult create(String jsonStr) {
        return new DishResult(jsonStr);
    }
 
    public List<Map> getResult() {
        return result;
    }
 
    public void setResult(List<Map> result) {
        this.result = result;
    }
 
    public Integer getResult_num() {
        return result_num;
    }
 
    public void setResult_num(Integer result_num) {
        this.result_num = result_num;
    }
 
    public boolean isDish() {
        return isDish;
    }
 
    public void setDish(boolean isDish) {
        this.isDish = isDish;
    }
 
    public Double getDishProbability() {
        return dishProbability;
    }
 
    public void setDishProbability(Double dishProbability) {
        this.dishProbability = dishProbability;
    }
 
    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 Double getResult_calorie() {
        return result_calorie;
    }
 
    public void setResult_calorie(Double result_calorie) {
        this.result_calorie = result_calorie;
    }
 
    @Override
    public String toString() {
        if(isRequestOk()){
            return "DishResult{" +
                    "result_num=" + result_num +
                    ", isDish=" + isDish +
                    ", result_name='" + result_name + '\'' +
                    ", result_probability=" + result_probability +
                    ", result_calorie=" + result_calorie +
                    ", result=" + result +
                    '}';
        }else{
            return getError_msg()+";错误代码["+getError_code()+"]"+";log_id["+getLog_id()+"]";
        }
 
    }
}