use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class IdPointValueStatisticsQuantizerCsvCallback method closePeriod.
/* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.statistics.ParentStatisticsQuantizerCallback#closePeriod(java.util.Map, long)
*/
@Override
public void closePeriod(Map<Integer, StatisticsGenerator> periodStatsMap, long periodStartTime) {
try {
if (!wroteHeaders) {
this.writer.writeNext(headers);
this.wroteHeaders = true;
}
// Write out the period start time
if (dateFormatter == null)
this.rowData[1] = Long.toString(periodStartTime);
else
this.rowData[1] = dateFormatter.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(periodStartTime), TimeZone.getDefault().toZoneId()));
Iterator<Integer> it = periodStatsMap.keySet().iterator();
while (it.hasNext()) {
Integer id = it.next();
StatisticsGenerator stats = periodStatsMap.get(id);
DataPointVO vo = this.voMap.get(id);
if (stats instanceof ValueChangeCounter) {
ValueChangeCounter statisticsGenerator = (ValueChangeCounter) stats;
switch(rollup) {
case FIRST:
if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
this.writeImageValue(statisticsGenerator.getFirstValue(), statisticsGenerator.getFirstTime(), periodStartTime, vo);
else
this.writeDataValue(periodStartTime, statisticsGenerator.getFirstValue(), vo);
break;
case LAST:
if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
this.writeImageValue(statisticsGenerator.getLastValue(), statisticsGenerator.getLastTime(), periodStartTime, vo);
else
this.writeDataValue(periodStartTime, statisticsGenerator.getLastValue(), vo);
break;
case COUNT:
this.rowData[this.columnMap.get(vo.getId())] = Integer.toString(statisticsGenerator.getCount());
break;
default:
// Default to first
this.writeDataValue(periodStartTime, statisticsGenerator.getFirstValue(), vo);
}
} else if (stats instanceof AnalogStatistics) {
AnalogStatistics statisticsGenerator = (AnalogStatistics) stats;
switch(rollup) {
case AVERAGE:
this.writeDouble(statisticsGenerator.getAverage(), vo);
break;
case DELTA:
this.writeDouble(statisticsGenerator.getDelta(), vo);
break;
case MINIMUM:
this.writeDouble(statisticsGenerator.getMinimumValue(), vo);
break;
case MAXIMUM:
this.writeDouble(statisticsGenerator.getMaximumValue(), vo);
break;
// TODO This should be removed after discussion with Jared
case ACCUMULATOR:
Double accumulatorValue = statisticsGenerator.getLastValue();
if (accumulatorValue == null) {
accumulatorValue = statisticsGenerator.getMaximumValue();
}
this.writeDouble(accumulatorValue, vo);
break;
case SUM:
this.writeDouble(statisticsGenerator.getSum(), vo);
break;
case START:
this.writeDouble(statisticsGenerator.getStartValue(), vo);
break;
case FIRST:
this.writeDouble(statisticsGenerator.getFirstValue(), vo);
break;
case LAST:
this.writeDouble(statisticsGenerator.getLastValue(), vo);
break;
case COUNT:
this.rowData[this.columnMap.get(vo.getId())] = Integer.toString(statisticsGenerator.getCount());
break;
case INTEGRAL:
this.writeIntegral(statisticsGenerator.getIntegral(), vo);
break;
default:
// Default to first
this.writeDouble(statisticsGenerator.getFirstValue(), vo);
}
} else {
throw new ShouldNeverHappenException("Unsuported statistics type: " + stats.getClass().getName());
}
}
this.writer.writeNext(this.rowData);
// Clear out the row data
for (int i = 1; i < this.rowData.length; i++) this.rowData[i] = null;
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class MaintenanceEventRT method createTrigger.
public TimerTrigger createTrigger(boolean activeTrigger) {
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_MANUAL)
return null;
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_CRON) {
try {
if (activeTrigger)
return new CronTimerTrigger(vo.getActiveCron());
return new CronTimerTrigger(vo.getInactiveCron());
} catch (ParseException e) {
// Should never happen, so wrap and rethrow
throw new ShouldNeverHappenException(e);
}
}
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_ONCE) {
DateTime dt;
if (activeTrigger)
dt = new DateTime(vo.getActiveYear(), vo.getActiveMonth(), vo.getActiveDay(), vo.getActiveHour(), vo.getActiveMinute(), vo.getActiveSecond(), 0);
else
dt = new DateTime(vo.getInactiveYear(), vo.getInactiveMonth(), vo.getInactiveDay(), vo.getInactiveHour(), vo.getInactiveMinute(), vo.getInactiveSecond(), 0);
return new OneTimeTrigger(new Date(dt.getMillis()));
}
int month = vo.getActiveMonth();
int day = vo.getActiveDay();
int hour = vo.getActiveHour();
int minute = vo.getActiveMinute();
int second = vo.getActiveSecond();
if (!activeTrigger) {
month = vo.getInactiveMonth();
day = vo.getInactiveDay();
hour = vo.getInactiveHour();
minute = vo.getInactiveMinute();
second = vo.getInactiveSecond();
}
StringBuilder expression = new StringBuilder();
expression.append(second).append(' ');
expression.append(minute).append(' ');
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_HOURLY)
expression.append("* * * ?");
else {
expression.append(hour).append(' ');
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_DAILY)
expression.append("* * ?");
else if (vo.getScheduleType() == MaintenanceEventVO.TYPE_WEEKLY)
expression.append("? * ").append(weekdays[day]);
else {
if (day > 0)
expression.append(day);
else if (day == -1)
expression.append('L');
else
expression.append(-day).append('L');
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_MONTHLY)
expression.append(" * ?");
else
expression.append(' ').append(month).append(" ?");
}
}
CronTimerTrigger cronTrigger;
try {
cronTrigger = new CronTimerTrigger(expression.toString());
} catch (ParseException e) {
// Should never happen, so wrap and rethrow
throw new ShouldNeverHappenException(e);
}
return cronTrigger;
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class InternalDataSourceRT method defaultNewPointToDataSource.
private void defaultNewPointToDataSource(DataPointVO dpvo, String dsXid) {
DataSourceVO<?> dsvo = DataSourceDao.instance.getDataSource(dsXid);
if (dsvo == null)
throw new ShouldNeverHappenException("Error creating point, unknown data source: " + dsXid);
dpvo.setDeviceName(dsvo.getName());
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class PointValueTimeCsvWriter method writeMultiplePointStatsAtSameTime.
@Override
public void writeMultiplePointStatsAtSameTime(List<DataPointStatisticsGenerator> periodStats, long timestamp) throws IOException {
this.jgen.writeStartObject();
boolean first = true;
for (DataPointStatisticsGenerator gen : periodStats) {
if (info.isMultiplePointsPerArray()) {
writeEntry(gen, true, first);
} else {
throw new ShouldNeverHappenException("Implement me?");
}
first = false;
}
this.jgen.writeEndObject();
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class PointValueTimeJsonWriter method writeMultiplePointStatsAtSameTime.
/* (non-Javadoc)
* @see com.infiniteautomation.mango.rest.v2.model.pointValue.query.PointValueTimeWriter#writeMultipleStatsAsObject(java.util.List)
*/
@Override
public void writeMultiplePointStatsAtSameTime(List<DataPointStatisticsGenerator> periodStats, long timestamp) throws IOException {
this.jgen.writeStartObject();
if (info.fieldsContains(PointValueField.TIMESTAMP))
writeTimestamp(timestamp);
for (DataPointStatisticsGenerator gen : periodStats) {
if (info.isMultiplePointsPerArray()) {
DataPointVO vo = gen.getVo();
this.jgen.writeObjectFieldStart(vo.getXid());
writeEntry(gen, false, false);
this.jgen.writeEndObject();
} else {
throw new ShouldNeverHappenException("Implement me?");
}
}
this.jgen.writeEndObject();
}
Aggregations