Search in sources :

Example 6 with Second

use of org.jfree.data.time.Second in project cubrid-manager by CUBRID.

the class ReplicationMonitorViewPart method update.

/**
	 * Update the data of chart
	 * 
	 * @param updatedData List<Map<String, String>>
	 */
private void update(List<Map<String, String>> updatedData) {
    if (updatedData == null) {
        return;
    }
    for (int i = 0; i < updatedData.size(); i++) {
        Map<String, String> data = updatedData.get(i);
        String slaveTime = data.get("slave_time");
        if (slaveTime == null) {
            continue;
        }
        String value = data.get("delay");
        if (value == null || !value.matches("\\d+")) {
            continue;
        }
        DateFormat df = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss", Locale.getDefault());
        try {
            Date date = df.parse(slaveTime);
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            Second sec = new Second(cal.get(Calendar.SECOND), cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH), cal.get(Calendar.YEAR));
            replTimeSeries.addOrUpdate(sec, Integer.parseInt(value));
        } catch (ParseException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : Second(org.jfree.data.time.Second) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 7 with Second

use of org.jfree.data.time.Second in project cubrid-manager by CUBRID.

the class CombinedBarTimeSeriesChart method updateValueMapIfArea.

/**
	 * Update the value based on the new value if series chart uses the area
	 * renderer
	 * 
	 * @param valueMap the valueMap to set
	 * @param barLabel the label text in the bar chart
	 */
private void updateValueMapIfArea(TreeMap<String, String> valueMap, String barLabel) {
    this.valueMap = valueMap;
    bardataset.clear();
    double allValue = 0;
    for (Map.Entry<String, String> entry : valueMap.entrySet()) {
        String value = entry.getValue();
        String key = entry.getKey();
        if (value != null) {
            double newValue = Double.parseDouble(value);
            bardataset.addValue(newValue, key, "");
            ((TimeTableXYDataset) seriesdataset).add(new Second(), newValue, key);
            allValue += newValue;
        }
    }
    if (allValue > barMax) {
        barMax = allValue;
    }
    bardataset.addValue(barMax - allValue, "100", "");
    numberaxis.setRange(0 - 1, barMax + barMax / 100);
    String label = barLabel;
    if ("%".equals(label)) {
        label = Integer.toString((int) (allValue + 0.5)) + label;
    }
    categoryAxis.setLabel(label);
}
Also used : TimeTableXYDataset(org.jfree.data.time.TimeTableXYDataset) Second(org.jfree.data.time.Second) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 8 with Second

use of org.jfree.data.time.Second in project cubrid-manager by CUBRID.

the class ChartCompositePart method stuffedChart.

/**
	 * This method provides data from local fill for History chart showing
	 *
	 * @param file the instance of CounterFile, which includes data info
	 * @param types a array which includes one or more data type
	 * @param beginTime the begin time
	 * @param endTime the ending time
	 */
private void stuffedChart(CounterFile file, List<String> types, long beginTime, long endTime) {
    List<String> fileTypes = new ArrayList<String>();
    for (String type : types) {
        fileTypes.add(type);
    }
    long distance = endTime - beginTime;
    // in milliseconds
    int interval = file.getInterval() * 1000;
    long quotient = distance / interval;
    if (distance % interval != 0) {
        quotient++;
    }
    int factor = (int) (quotient / SWITCH_VALUE);
    if (quotient % SWITCH_VALUE != 0) {
        factor++;
    }
    Result[] results = new Result[(int) (quotient / factor + 1L)];
    int length = 0;
    for (long time = beginTime; time < endTime; time += (interval * factor)) {
        Result res;
        try {
            res = file.readData(time, fileTypes.toArray(new String[fileTypes.size()]));
            results[length] = res;
            for (String type : types) {
                double result = results[length].getAvgAsDouble(type);
                if (result < 0) {
                    result = 0;
                }
                // if (result > 0) {
                seriesMap.get(type).addOrUpdate(new Second(new Date(time)), result);
            // }
            }
        } catch (IOException ex) {
            LOGGER.error(ex.getMessage());
        }
        length++;
    }
}
Also used : Second(org.jfree.data.time.Second) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) Result(com.cubrid.cubridmanager.ui.monitoring.editor.count.Result)

Example 9 with Second

use of org.jfree.data.time.Second in project cubrid-manager by CUBRID.

the class MonitorStatisticChart method createDataset.

private XYDataset createDataset() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    if (statisticDataList == null) {
        return dataset;
    }
    double maxForRang = 0;
    List<StatisticData> dataItemWithoutDataList = new ArrayList<StatisticData>();
    TimeType timeType = null;
    Date current = new Date();
    long interalMillisecs = 0;
    for (StatisticData statisticData : statisticDataList) {
        if (statisticData == null) {
            continue;
        }
        MetricType metricType = MetricType.getEnumByMetric(statisticData.getMetric());
        if (metricType == null) {
            continue;
        }
        int size = statisticData.getData().size();
        if (size == 0) {
            dataItemWithoutDataList.add(statisticData);
            continue;
        } else if (dataSize == 0) {
            //record data size for build invalid data
            dataSize = size;
        }
        //check data type, record 'isHasValidData = true'
        if (!isHasValidData) {
            isHasValidData = true;
            chartType = getChartType(statisticData.getMetric());
            if (chartType == ChartType.PERCENT) {
                rangMax = 100;
            }
            String dateType = statisticData.getDtype();
            timeType = TimeType.getEnumByType(dateType);
            //CMS return -1 for invalid data, so for invalid data(<0), display as -1.
            switch(timeType) {
                case DAILY:
                    interalMillisecs = 1000 * 60 * 60 * 24 / size;
                    break;
                case WEEKLY:
                    interalMillisecs = 1000 * 60 * 60;
                    break;
                case MONTHLY:
                    interalMillisecs = 1000 * 60 * 60;
                    break;
                case YEARLY:
                    interalMillisecs = 1000 * 60 * 60 * 24;
                    break;
                default:
                    break;
            }
        }
        TimeSeries series = null;
        if (isDetailView) {
            series = new TimeSeries(statisticData.getDescription(isMultiHost));
        } else {
            series = new TimeSeries(statisticData.getSimpleDescription(isMultiHost));
        }
        Date point = (Date) current.clone();
        long curMillisecs = current.getTime();
        int count = 0;
        int max = 0;
        int min = 0;
        boolean isInitMinVal = false;
        for (int val : statisticData.getData()) {
            point.setTime(curMillisecs - (size - count) * interalMillisecs);
            switch(timeType) {
                case DAILY:
                    if (val < 0) {
                        series.add(new Second(point), -1);
                    } else {
                        series.add(new Second(point), val / 100);
                    }
                    break;
                case WEEKLY:
                    if (val < 0) {
                        series.add(new Hour(point), -1);
                    } else {
                        series.add(new Hour(point), val / 100);
                    }
                    break;
                case MONTHLY:
                    if (val < 0) {
                        series.add(new Hour(point), -1);
                    } else {
                        series.add(new Hour(point), val / 100);
                    }
                    break;
                case YEARLY:
                    if (val < 0) {
                        series.add(new Day(point), -1);
                    } else {
                        series.add(new Day(point), val / 100);
                    }
                    break;
                default:
                    break;
            }
            if (chartType != ChartType.PERCENT && val > maxForRang) {
                maxForRang = val;
            }
            if (!isInitMinVal && val >= 0) {
                min = val;
                isInitMinVal = true;
            }
            if (val > max) {
                max = val;
            }
            if (val < min && val >= 0) {
                min = val;
            }
            count++;
        }
        maxValueMap.put(statisticData, max / 100d);
        minValueMap.put(statisticData, min / 100d);
        dataset.addSeries(series);
    }
    if (!isHasValidData) {
        return dataset;
    }
    if (chartType != ChartType.PERCENT) {
        decideRangMax(maxForRang / 100);
    }
    /*[TOOLS-3742] Build invalid data for StatisticData which has no data*/
    buildInvalidData(dataset, timeType, dataItemWithoutDataList, current, interalMillisecs);
    if (isDetailView) {
        chartTitle = Messages.monStatisticDetailChartTitle;
        timeAxisLabel = Messages.lblChartTime;
        valueAxisLabel = Messages.lblChartValue;
        switch(chartType) {
            case PERCENT:
                valueAxisLabel += " (%)";
                break;
            case MEMORY:
            case SPACE:
                valueAxisLabel += " (MB)";
                break;
            case OTHERS:
                break;
            default:
                break;
        }
    }
    return dataset;
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) Hour(org.jfree.data.time.Hour) MetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType) ArrayList(java.util.ArrayList) StatisticData(com.cubrid.cubridmanager.core.monstatistic.model.StatisticData) Date(java.util.Date) TimeType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.TimeType) Second(org.jfree.data.time.Second) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Day(org.jfree.data.time.Day)

Aggregations

Second (org.jfree.data.time.Second)9 Date (java.util.Date)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 StatisticData (com.cubrid.cubridmanager.core.monstatistic.model.StatisticData)2 Result (com.cubrid.cubridmanager.ui.monitoring.editor.count.Result)2 IOException (java.io.IOException)2 Day (org.jfree.data.time.Day)2 Hour (org.jfree.data.time.Hour)2 TimeSeries (org.jfree.data.time.TimeSeries)2 TimeTableXYDataset (org.jfree.data.time.TimeTableXYDataset)2 MetricType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType)1 TimeType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.TimeType)1 GradientPaint (java.awt.GradientPaint)1 HeadlessException (java.awt.HeadlessException)1 Paint (java.awt.Paint)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1