use of itor.topnetwork.com.dxditor.bean.BridgeTrend in project Dxditor by kimi2009.
the class BridgeModel method getTrendData.
@Override
public void getTrendData(final ValueCallBack<String> callBack, final int position) {
if (Constants.testData) {
BridgeBean bridgeBean = new BridgeBean();
ArrayList<String> x = new ArrayList<String>();
for (int i = 0; i < 8; i++) {
x.add("03-2" + i + " 08:00");
}
bridgeBean.xData = x;
ArrayList<Float> f = new ArrayList<Float>();
if (position == 0) {
for (int i = 0; i < 8; i++) {
f.add(Float.parseFloat("2." + i));
}
} else if (position == 1) {
for (int i = 0; i < 8; i++) {
f.add(Float.parseFloat("1.0" + i));
}
;
} else if (position == 2) {
for (int i = 1; i < 9; i++) {
f.add(Float.parseFloat("0.8" + i));
}
}
bridgeBean.seriesData = f;
if (position == 0) {
bridgeBean.initValue = 2.3f;
} else if (position == 1) {
bridgeBean.initValue = 1.1f;
} else if (position == 2) {
bridgeBean.initValue = 0.8f;
}
callBack.onSuccess(gson.toJson(bridgeBean));
} else {
bridgeTrends = new ArrayList<BridgeTrend>();
// Form表单格式的参数传递
FormBody formBody = new FormBody.Builder().add("bridgeCode", bridgeWarnings.get(position).getBridgeCode()).add("monitotObjectCode", bridgeWarnings.get(position).getMonitorObjectCode()).add("monitorItemCode", bridgeWarnings.get(position).getMonitorItemCode()).add("storageTime", Constants.MONTH).build();
Request request = new Request.Builder().post(formBody).url(Constants.getAppBridgeMonthDisplacementInfo).build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String res = response.body().string();
try {
JSONObject js = new JSONObject(res);
if (js.getBoolean("success")) {
bridgeTrends = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<BridgeTrend>>() {
}.getType());
BridgeBean bridgeBean = new BridgeBean();
List<String> time = new ArrayList<>();
for (int i = 0; i < bridgeTrends.size(); i++) {
time.add(bridgeTrends.get(i).getStorageTime());
}
bridgeBean.xData = time;
List<Float> lineDatas = new ArrayList<>();
for (int i = 0; i < bridgeTrends.size(); i++) {
lineDatas.add(Float.parseFloat(bridgeTrends.get(i).getValue()));
}
bridgeBean.seriesData = lineDatas;
bridgeBean.initValue = Float.parseFloat(bridgeWarnings.get(position).getInitValue());
callBack.onSuccess(gson.toJson(bridgeBean));
} else {
callBack.onFail("01");
}
} catch (Exception e) {
callBack.onFail("01");
e.printStackTrace();
}
}
});
}
}
Aggregations