Skip to content

Commit

Permalink
#2770 Fixed minimum/maximum calculate in Meta Data Point script - cor…
Browse files Browse the repository at this point in the history
…rected performance
  • Loading branch information
Limraj committed Jan 8, 2024
1 parent be78cfb commit ea322c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
26 changes: 25 additions & 1 deletion src/org/scada_lts/dao/pointvalues/PointValueDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public class PointValueDAO implements GenericDaoCR<PointValue> {
public static final String POINT_VALUE_FILTER_BEFORE_TIME_STAMP_BASE_ON_DATA_POINT_ID = " "
+ "pv."+COLUMN_NAME_DATA_POINT_ID+"=? and "
+ "pv."+COLUMN_NAME_TIME_STAMP+"<? "
+ "order by pv."+COLUMN_NAME_TIME_STAMP+" desc";
+ "order by pv."+COLUMN_NAME_TIME_STAMP;

public static final String POINT_VALUE_FILTER_AT_TIME_STAMP_BASE_ON_DATA_POINT_ID = " "
+ "pv."+COLUMN_NAME_DATA_POINT_ID+"=? and "
Expand Down Expand Up @@ -701,4 +701,28 @@ public PointHistoryCount mapRow(ResultSet rs, int rowNum) throws SQLException {
}
});
}

public PointValueTime getPointValueBefore(int dataPointId, long time) {
try {
Long valueTime = DAO.getInstance().getJdbcTemp().queryForObject("select max(ts) from pointValues where dataPointId=? and ts<?",
new Object[] { dataPointId, time }, Long.class);
if (valueTime == null)
return null;
return getPointValueAt(dataPointId, valueTime);
} catch (EmptyResultDataAccessException ex) {
return null;
}
}

public PointValueTime getPointValueAt(int dataPointId, long time) {
List<PointValue> pointValues = DAO.getInstance().getJdbcTemp().query(POINT_VALUE_SELECT + " where pv.dataPointId=? and pv.ts=?",
new Object[]{dataPointId, time}, new PointValueRowMapper());
if(pointValues.isEmpty())
return null;
long maxId = pointValues.stream().mapToLong(PointValue::getId).max().orElse(-1);
PointValue pointValue = pointValues.stream().filter(a -> a.getId() == maxId).findAny().orElse(null);
if(pointValue == null)
return null;
return pointValue.getPointValue();
}
}
18 changes: 4 additions & 14 deletions src/org/scada_lts/mango/service/PointValueService.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,23 +370,13 @@ public PointValueTime getLatestPointValue(int dataPointId) {
}

public PointValueTime getPointValueBefore(int dataPointId, long time) {
List<PointValue> lst = PointValueDAO.getInstance().filtered(
PointValueDAO.POINT_VALUE_FILTER_BEFORE_TIME_STAMP_BASE_ON_DATA_POINT_ID,
new Object[]{dataPointId, time}, 1);
if (lst != null && lst.size() > 0) {
return lst.get(0).getPointValue();
} else {
return null;
}
return PointValueDAO.getInstance().getPointValueBefore(dataPointId, time);
}

public PointValueTime getPointValueAt(int dataPointId, long time) {
List<PointValue> lst = PointValueDAO.getInstance().filtered(
PointValueDAO.POINT_VALUE_FILTER_AT_TIME_STAMP_BASE_ON_DATA_POINT_ID,
new Object[]{dataPointId, time}, 1);
if (lst != null && lst.size() > 0) {
return lst.get(0).getPointValue();
} else {
try {
return PointValueDAO.getInstance().getPointValueAt(dataPointId, time);
} catch (Exception ex) {
return null;
}
}
Expand Down

0 comments on commit ea322c5

Please sign in to comment.