Examples of XYDataSetCollection


Examples of org.jsflot.xydata.XYDataSetCollection

    }

    @Test
    @Ignore
    public void test_that_XYDataCollection_returns_correct_json() throws JSONException {
        XYDataSetCollection xyCollection = new XYDataSetCollection();
        XYDataList xyList = new XYDataList();
        xyList.setLabel("Set1");
        xyList.addDataPoint(new XYDataPoint(1, 1));
        xyList.addDataPoint(new XYDataPoint(2, 2));
        xyList.addDataPoint(new XYDataPoint(3, 3));
        xyList.addDataPoint(new XYDataPoint(5, 5));
        xyCollection.addDataList(xyList);

        StringBuilder expected = new StringBuilder();
        expected.append("{\"chart\": [ {\"label\": \"Set1\", \"data\": [[1,1], [2,2], [3,3], [5,5]]}],\"instrumentationNode\":\"chartId\"}");
        String jsonString = BuildJsonObjectsUtil.generateChartData("chartId", "something", xyCollection, 0l);
        assertEquals(expected.toString(), jsonString);
View Full Code Here

Examples of org.jsflot.xydata.XYDataSetCollection

                List<LiveStatistics> liveList = null;
                String seriesLabel = null;
                Alert alert = null;
                GroupedStatistics groupedStatistics = null;
                XYDataSetCollection valueCollection = new XYDataSetCollection();

                //TODO: This if-else code block needs refactoring. Its not DRY
                if (isAlertChart(id)) {
                    id = id.replaceAll("\\%20", " ").replaceAll("\\%25", "%");
                    String alertName = id.substring(8, id.length());
                    log.info("isAlert! " + alertName);
                    alert = getBerkeleyTreeMenuService().getAlert(alertName, loggedInAccountName);
                    if (alert != null) {
                        chartPath = alert.getGuiPath();
                        seriesLabel = "Alert: " + alert.getAlertName();
                    }

                    liveList = getBerkeleyTreeMenuService().getLiveStatistics(chartPath, loggedInAccountName, fromPeriod, toPeriod);
                    Collections.sort(liveList);
                    valueCollection = ChartUtil.generateChart(liveList, seriesLabel, fromPeriod * 15000, toPeriod * 15000, chartResolution);
                    valueCollection.addDataList(ChartUtil.buildWarningList(alert, AlertStatus.CRITICAL, fromPeriod * 15000, toPeriod * 15000));
                    valueCollection.addDataList(ChartUtil.buildWarningList(alert, AlertStatus.WARNING, fromPeriod * 15000, toPeriod * 15000));

                    log.info("alert: " + alert);
                    log.info("chartPath: " + chartPath);
                } else if (isGroupedStatisticsChart(id)) {
                    id = id.replaceAll("\\%20", " ").replaceAll("\\%25", "%");
                    chartPath = id;
                    String groupName = id.substring(5, id.length());

                    log.info("isGroupedStat! " + groupName);
                    groupedStatistics = getBerkeleyTreeMenuService().getGroupedStatistics(groupName, loggedInAccountName);
                    if (groupedStatistics != null) {
                        log.info("groupedStats: " + groupedStatistics.getName() + " :. " + groupedStatistics.getGroupedPathList().size());
                        seriesLabel = "Grouped Statistics: " + groupedStatistics.getName();
                        for (String gsPath : groupedStatistics.getGroupedPathList()) {
                            log.info("\tgroupedStats Path: " + gsPath);
                            liveList = getBerkeleyTreeMenuService().getLiveStatistics(gsPath, loggedInAccountName, fromPeriod, toPeriod);
                            Collections.sort(liveList);
                            for (XYDataList dataList : ChartUtil.generateChart(liveList, gsPath, fromPeriod * 15000, toPeriod * 15000, chartResolution).getDataList()) {
                                valueCollection.addDataList(dataList);
                            }
                        }
                    }
                } else {
                    id = id.replaceAll("\\%20", " ").replaceAll("\\%25", "%");
View Full Code Here

Examples of org.jsflot.xydata.XYDataSetCollection

    }

    @Test
    @Ignore
    public void test_that_chart_generator_generates_correct_data_for_data_with_no_holes_and_15_second_resolution() {
        XYDataSetCollection xyDataSetCollection = ChartUtil.generateChart(liveStatisticsList, "name", dateFrom.getTime(), dateTo.getTime(), 15);
        assertNotNull(xyDataSetCollection.getDataList().get(0));

        XYDataList xyDataList = xyDataSetCollection.getDataList().get(0);
        assertNotNull(xyDataList.getDataPointList());
        assertEquals(32, xyDataList.size());

        assertEquals(xyDataList.getDataPointList().get(0).getX().doubleValue(), new Double(1295540055000d), 0.0d);
        assertEquals(xyDataList.getDataPointList().get(0).getY(), 6d);
View Full Code Here

Examples of org.jsflot.xydata.XYDataSetCollection

    }

    @Test
    @Ignore
    public void test_that_chart_generator_generates_correct_data_for_data_with_no_holes_and_30_second_resolution() {
        XYDataSetCollection xyDataSetCollection = ChartUtil.generateChart(liveStatisticsList, "name", dateFrom.getTime(), dateTo.getTime(), 30);
        assertNotNull(xyDataSetCollection.getDataList().get(0));

        XYDataList xyDataList = xyDataSetCollection.getDataList().get(0);
        assertNotNull(xyDataList.getDataPointList());

        assertEquals(xyDataList.getDataPointList().get(0).getX().doubleValue(), 1295540055000d, 0.0d);
        assertEquals(xyDataList.getDataPointList().get(0).getY(), 7d);
View Full Code Here

Examples of org.jsflot.xydata.XYDataSetCollection

    }

    @Test
    @Ignore
    public void test_that_chart_generator_generates_correct_data_for_data_with_no_holes_and_180_second_resolution() {
        XYDataSetCollection xyDataSetCollection = ChartUtil.generateChart(liveStatisticsList, "name", dateFrom.getTime(), dateTo.getTime(), 180);
        assertNotNull(xyDataSetCollection.getDataList().get(0));

        XYDataList xyDataList = xyDataSetCollection.getDataList().get(0);
        assertNotNull(xyDataList.getDataPointList());

        //108 / 12 = 9
        assertEquals(xyDataList.getDataPointList().get(0).getX().doubleValue(), 1295540055000d, 0.0d);
        assertEquals(xyDataList.getDataPointList().get(0).getY(), 9d);
View Full Code Here

Examples of org.jsflot.xydata.XYDataSetCollection

        List<LiveStatistics> newStats = new ArrayList<LiveStatistics>();
        for (int i = 0; i < liveStatisticsList.size(); i += 2) {
            newStats.add(liveStatisticsList.get(i));
        }

        XYDataSetCollection xyDataSetCollection = ChartUtil.generateChart(newStats, "name", dateFrom.getTime(), dateTo.getTime(), 15);
        assertNotNull(xyDataSetCollection.getDataList().get(0));

        XYDataList xyDataList = xyDataSetCollection.getDataList().get(0);
        assertNotNull(xyDataList.getDataPointList());

        assertEquals(xyDataList.getDataPointList().get(0).getX().doubleValue(), 1295540055000d, 0.0d);
        assertEquals(xyDataList.getDataPointList().get(0).getY(), 6d);
        assertEquals(xyDataList.getDataPointList().get(1).getX().doubleValue(), 1295540070000d, 0.0d);
View Full Code Here

Examples of org.jsflot.xydata.XYDataSetCollection

        List<LiveStatistics> newStats = new ArrayList<LiveStatistics>();
        for (int i = 0; i < liveStatisticsList.size(); i += 2) {
            newStats.add(liveStatisticsList.get(i));
        }

        XYDataSetCollection xyDataSetCollection = ChartUtil.generateChart(newStats, "name", dateFrom.getTime(), dateTo.getTime(), 45);
        assertNotNull(xyDataSetCollection.getDataList().get(0));

        XYDataList xyDataList = xyDataSetCollection.getDataList().get(0);
        assertNotNull(xyDataList.getDataPointList());

        assertEquals(xyDataList.getDataPointList().get(0).getX().doubleValue(), 1295540055000d, 0.0d);
        assertEquals(xyDataList.getDataPointList().get(0).getY(), 6d);
View Full Code Here

Examples of org.jsflot.xydata.XYDataSetCollection

public class ChartUtil {
  private static Logger log = Logger.getLogger(ChartUtil.class);

    public static XYDataSetCollection generateChart(List<LiveStatistics> liveList, String seriesLabel, Long millisStart, Long millisEnd, int resolution) {
        XYDataSetCollection valueCollection = new XYDataSetCollection();
        XYDataList valueList = new XYDataList();
        valueList.setLabel(seriesLabel);

        //Hashtable is used for quick lookup
        Hashtable<Long, LiveStatistics> liveHash = new Hashtable<Long, LiveStatistics>();
    for (LiveStatistics l : liveList) {
      liveHash.put(l.getTimeperiod() * 15000, l);
    }

        int numTicksInResolution = resolution / 15;

        //Round down to nearest 15 seconds timeperiod
        millisStart = millisStart - (millisStart % 15000);
    millisEnd = millisEnd - (millisEnd % 15000) + 15000;


        Long currentMillis = millisStart;

        //Iterate over the time-range given and average ticks based on resolution
        while (currentMillis <= (millisEnd - (resolution * 1000))) {
            XYDataPoint currentTick = new XYDataPoint();
            currentTick.setX(currentMillis);
            currentTick.setY(null);
            double aggregatedValue = 0.0d;
            double averageValue = 0.0d;
            ValueType valueType = null;

            int numStatsInCurrentTick = 0;

            for (int i = 0; i < numTicksInResolution; i++) {
                LiveStatistics currStat = liveHash.get(currentMillis);
                if (currStat == null || currStat.getValue() == null) {
                    //No stat for this timeperiod, skipping
                } else {
                    if (valueType == null) {
                        valueType = ValueType.fromValue(currStat.getValueType());
                    }
                    //Add to current
                    aggregatedValue += currStat.getValue();
                    numStatsInCurrentTick++;
                }

                currentMillis += 15000;
            }

            if (numStatsInCurrentTick > 0) {
                //If value type is aggregate, return the aggregate value
                if (ValueType.AGGREGATE.equals(valueType)) {
                    currentTick.setY(aggregatedValue);
                } else {
                    //Otherwise return the average
                    currentTick.setY(aggregatedValue / numStatsInCurrentTick);
                }
            }

            valueList.addDataPoint(currentTick);
        }

        valueCollection.addDataList(valueList);
        return valueCollection;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.