Пример #1
0
  private ArrayList<MetricsChartDataKeyValuesJson> getAllAfter(
      AGGREGATION_TYPE aggregationType, int sensorId) {
    MetricsAggregationBase metricsAggregationBase = new MetricsAggregationBase();
    Sensor sensor =
        DaoUtils.getSensorDao()
            .get(sensorId); // Here sensorId means 'id'(db reference) not actual sensorId

    ArrayList<MetricsChartDataKeyValuesJson> finalData =
        new ArrayList<MetricsChartDataKeyValuesJson>();

    if (sensor.getMetricType() == null) {
      // Sensor pay load type not up to date
      _logger.debug("Payload type not updated in sensor.");
      return null;
    } else if (sensor.getMetricType() == MyMessages.PAYLOAD_TYPE.PL_DOUBLE.ordinal()) {
      _logger.debug("Payload type: {}", MyMessages.PAYLOAD_TYPE.PL_DOUBLE.toString());
      List<MetricsDoubleTypeDevice> metrics =
          metricsAggregationBase.getMetricsDoubleTypeAllAfter(aggregationType, sensor);
      if (metrics == null) {
        // throw new ApiError("No data available");
        return null;
      }

      MetricsChartDataKeyValuesJson minChartData = new MetricsChartDataKeyValuesJson("Minimum");
      MetricsChartDataKeyValuesJson avgChartData = new MetricsChartDataKeyValuesJson("Average");
      MetricsChartDataKeyValuesJson maxChartData = new MetricsChartDataKeyValuesJson("Maximum");

      for (MetricsDoubleTypeDevice metric : metrics) {
        minChartData.add(new Object[] {metric.getTimestamp(), metric.getMin()});
        avgChartData.add(new Object[] {metric.getTimestamp(), metric.getAvg()});
        maxChartData.add(new Object[] {metric.getTimestamp(), metric.getMax()});
      }

      finalData.add(minChartData);
      finalData.add(avgChartData);
      finalData.add(maxChartData);
    } else if (sensor.getMetricType() == MyMessages.PAYLOAD_TYPE.PL_BOOLEAN.ordinal()) {
      _logger.debug("Payload type: {}", MyMessages.PAYLOAD_TYPE.PL_BOOLEAN.toString());
      List<MetricsOnOffTypeDevice> metrics =
          metricsAggregationBase.getMetricsBooleanTypeAllAfter(aggregationType, sensor);
      if (metrics == null) {
        // throw new ApiError("No data available");
        return null;
      }

      String name = sensor.getName() != null ? sensor.getName() : "State";
      MetricsChartDataKeyValuesJson minChartData = new MetricsChartDataKeyValuesJson(name);

      for (MetricsOnOffTypeDevice metric : metrics) {
        minChartData.add(new Object[] {metric.getTimestamp(), metric.getState() ? 1 : 0});
      }

      finalData.add(minChartData);
    }

    return finalData;
  }
Пример #2
0
 @GET
 @Path("/sensorVariableTypesBySenRef/{sensorRefId}")
 public Response getSensorVariableTypesBySensorRefId(@PathParam("sensorRefId") int sensorRefId) {
   Sensor sensor = DaoUtils.getSensorDao().get(sensorRefId);
   if (sensor != null && sensor.getType() != null) {
     return RestUtils.getResponse(
         Status.OK,
         TypesUtils.getSensorVariableTypes(sensor.getType(), sensor.getVariableTypes()));
   }
   return RestUtils.getResponse(
       Status.BAD_REQUEST,
       new ApiError(
           "Requested Sensor["
               + sensor.getName()
               + "] type not available or Sensor not available"));
 }
 private String getFileName(SensorVariable sensorVariable, AGGREGATION_TYPE aggrType) {
   Sensor sensor = DaoUtils.getSensorDao().getById(sensorVariable.getSensor().getId());
   StringBuilder builder = new StringBuilder();
   builder
       .append(sensor.getNode().getName())
       .append("_")
       .append(sensor.getName())
       .append("_Nid-")
       .append(sensor.getNode().getEui())
       .append("_Sid-")
       .append(sensor.getSensorId())
       .append("_")
       .append(sensorVariable.getVariableType().getText());
   if (sensorVariable.getMetricType() == METRIC_TYPE.DOUBLE) {
     builder.append("_").append("SampleType_").append(aggrType);
   }
   builder
       .append("_")
       .append(new SimpleDateFormat("yyyy-MMM-dd_hh-mm-ss").format(new Date()))
       .append(".csv");
   return builder.toString().replaceAll(" ", "_");
 }