Search in sources :

Example 6 with LongPair

use of com.serotonin.m2m2.vo.pair.LongPair in project ma-core-public by infiniteautomation.

the class AsyncImageChartServlet method getImageData.

private byte[] getImageData(String imageInfo, HttpServletRequest request) throws IOException {
    // Hex colour definitions need to be prefixed with '0x' instead of '#'.
    try {
        // Remove the / and the .png
        imageInfo = imageInfo.substring(1, imageInfo.length() - 4);
        // Split by underscore.
        String[] imageBits = imageInfo.split("_");
        // Get the data.
        long from, to;
        int pointIdStart;
        if (imageBits[0].equals("ft")) {
            from = Long.parseLong(imageBits[2]);
            to = Long.parseLong(imageBits[3]);
            pointIdStart = 4;
        } else {
            from = Common.timer.currentTimeMillis() - Long.parseLong(imageBits[1]);
            to = -1;
            pointIdStart = 2;
        }
        int width = getIntRequestParameter(request, "w", 200);
        int height = getIntRequestParameter(request, "h", 100);
        TimeZone timeZone = Common.getUserTimeZone(Common.getUser(request));
        // Create the datasets
        Synchronizer<PointDataRetriever> tasks = new Synchronizer<PointDataRetriever>();
        List<Integer> dataPointIds = new ArrayList<Integer>();
        for (int i = pointIdStart; i < imageBits.length; i++) {
            if (imageBits[i].startsWith("w"))
                width = NumberUtils.toInt(imageBits[i].substring(1), width);
            else if (imageBits[i].startsWith("h"))
                height = NumberUtils.toInt(imageBits[i].substring(1), height);
            else {
                String dataPointStr = imageBits[i];
                Color colour = null;
                int dataPointId;
                int pipe = dataPointStr.indexOf('|');
                if (pipe == -1)
                    dataPointId = Integer.parseInt(dataPointStr);
                else {
                    try {
                        String colourStr = dataPointStr.substring(pipe + 1);
                        if (colourStr.startsWith("0x"))
                            colourStr = "#" + colourStr.substring(2);
                        colour = ColorUtils.toColor(colourStr);
                    } catch (InvalidArgumentException e) {
                        throw new IOException(e);
                    }
                    dataPointId = Integer.parseInt(dataPointStr.substring(0, pipe));
                }
                dataPointIds.add(dataPointId);
                PointDataRetriever pdr = new PointDataRetriever(dataPointId, colour, width * 3, timeZone);
                tasks.addTask(pdr);
            }
        }
        if (tasks.getSize() == 0)
            return null;
        long start = from;
        long end = to;
        if (from == -1 && to == -1) {
            LongPair sae = pointValueDao.getStartAndEndTime(dataPointIds);
            start = sae.getL1();
            end = sae.getL2();
        } else if (from == -1)
            start = pointValueDao.getStartTime(dataPointIds);
        else if (to == -1)
            end = pointValueDao.getEndTime(dataPointIds);
        for (PointDataRetriever pdr : tasks.getTasks()) pdr.setRange(start, end);
        // Get the timer
        tasks.executeAndWait(Providers.get(TimerProvider.class).getTimer());
        PointTimeSeriesCollection ptsc = new PointTimeSeriesCollection(timeZone);
        for (PointDataRetriever pdr : tasks.getTasks()) pdr.addToCollection(ptsc);
        return ImageChartUtils.getChartData(ptsc, width, height, from, to);
    } catch (StringIndexOutOfBoundsException e) {
    // no op
    } catch (NumberFormatException e) {
    // no op
    } catch (ArrayIndexOutOfBoundsException e) {
    // no op
    }
    return null;
}
Also used : Synchronizer(com.serotonin.timer.sync.Synchronizer) LongPair(com.serotonin.m2m2.vo.pair.LongPair) PointTimeSeriesCollection(com.serotonin.m2m2.util.chart.PointTimeSeriesCollection) Color(java.awt.Color) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TimeZone(java.util.TimeZone) InvalidArgumentException(com.serotonin.InvalidArgumentException)

Example 7 with LongPair

use of com.serotonin.m2m2.vo.pair.LongPair in project ma-core-public by infiniteautomation.

the class PointValueDaoMetrics method getStartAndEndTime.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.PointValueDao#getStartAndEndTime(java.util.List)
	 */
@Override
public LongPair getStartAndEndTime(List<Integer> pointIds) {
    LogStopWatch LogStopWatch = new LogStopWatch();
    LongPair result = dao.getStartAndEndTime(pointIds);
    String sqlIn = "[";
    for (int i = 0; i < pointIds.size(); i++) {
        sqlIn += pointIds.get(i);
        if (i < pointIds.size())
            sqlIn += ",";
    }
    sqlIn += "]";
    LogStopWatch.stop("getStartAndEndTime(pointIds) + (" + sqlIn + ")", this.metricsThreshold);
    return result;
}
Also used : LongPair(com.serotonin.m2m2.vo.pair.LongPair) LogStopWatch(com.serotonin.log.LogStopWatch)

Aggregations

LongPair (com.serotonin.m2m2.vo.pair.LongPair)7 DateTime (org.joda.time.DateTime)3 User (com.serotonin.m2m2.vo.User)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 LogStopWatch (com.serotonin.log.LogStopWatch)1 EventDao (com.serotonin.m2m2.db.dao.EventDao)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)1 PointTimeSeriesCollection (com.serotonin.m2m2.util.chart.PointTimeSeriesCollection)1 EventExportDefinition (com.serotonin.m2m2.web.dwr.beans.EventExportDefinition)1 Synchronizer (com.serotonin.timer.sync.Synchronizer)1 Color (java.awt.Color)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TimeZone (java.util.TimeZone)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1