| | |
| | | import com.googlecode.aviator.AviatorEvaluator; |
| | | import com.googlecode.aviator.Expression; |
| | | import com.moral.api.entity.DeviceAdjustValue; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | @Slf4j |
| | |
| | | //数据,公式 |
| | | public Map<String, Object> adjust(Map<String, Object> deviceData, Map<String, Object> adjustFormula, Map<String, Object> aqiMap) { |
| | | try { |
| | | Object dataTime = deviceData.get("DataTime"); |
| | | //清除毫秒,四舍五入 |
| | | long time = Math.round(new Double((String) dataTime) / 1000) * 1000L; |
| | | long finalTime = DateUtils.dataToTimeStampTime(new Date(time), DateUtils.HH_mm_ss_EN).getTime(); |
| | | Date time = DateUtils.getDate((String) deviceData.get("DataTime"), DateUtils.yyyyMMddHHmmss_EN); |
| | | long finalTime = DateUtils.dataToTimeStampTime(time, DateUtils.HH_mm_ss_EN).getTime(); |
| | | for (String key : deviceData.keySet()) { |
| | | if (!key.equals("mac") && !key.equals("time") && !key.equals("DataTime") && !key.equals("ver") && !key.contains("Flag")) { |
| | | //测量值 |
| | |
| | | env.put("aqi", ObjectUtils.isEmpty(aqiValue) ? 0F : Float.parseFloat((String) aqiValue)); |
| | | } |
| | | if (formula.contains("vocs")) { |
| | | Object vocsValue = ObjectUtils.isEmpty(deviceData.get("a99054")) ? 0F : deviceData.get("a99054"); |
| | | Object vocsValue = ObjectUtils.isEmpty(deviceData.get(Constants.SENSOR_CODE_VOCS)) ? 0F : deviceData.get(Constants.SENSOR_CODE_VOCS); |
| | | env.put("vocs", vocsValue); |
| | | } |
| | | if (formula.contains("cel")) { |
| | |
| | | //校准 |
| | | measuredValue = expression.execute(env); |
| | | //温度处理 |
| | | if (Float.parseFloat(measuredValue.toString()) < 0 && !"a01001".equals(measuredValue)) { |
| | | if (!Constants.SENSOR_CODE_TEMP.equals(measuredValue) && Float.parseFloat(measuredValue.toString()) < 0) { |
| | | measuredValue = 0F; |
| | | } |
| | | deviceData.put(key, Double.parseDouble(String.format("%.3f", measuredValue))); |
| | | deviceData.put(key, Double.parseDouble(String.format("%.4f", measuredValue))); |
| | | } |
| | | } |
| | | } catch (Exception e) { |