List of usage examples for org.jfree.data.time TimeSeries addOrUpdate
public TimeSeriesDataItem addOrUpdate(TimeSeriesDataItem item)
From source file:org.miloss.fgsms.services.rs.impl.reports.AvailabilityByService.java
@Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try {//from ww w. j a v a 2s . c o m JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URI</th><th>Number of status changes</th><th>Percent Uptime</th><th>Percent Downtime</th></tr>"); DecimalFormat percentFormat = new DecimalFormat("###.#####"); TimeSeriesCollection col = new TimeSeriesCollection(); for (int i = 0; i < urls.size(); i++) { //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); TimeSeries s1 = new TimeSeries(url, org.jfree.data.time.Millisecond.class); try { data.append("<tr><td>").append(url).append("</td>"); List<StatusRecordsExt> records = getStatusRecords(urls.get(i), range, con); //special case, no status records available if (records == null || records.isEmpty()) { data.append("<td>-</td><td>-</td></tr>"); continue; } double uptime = getUptimePercentage(records, range); data.append("<td>").append(records.size() + "").append("</td><td>") .append(percentFormat.format(uptime)).append("</td><td>") .append(percentFormat.format(100 - uptime)).append("</td></tr>"); TimeSeriesDataItem t = null; for (int k = 0; k < records.size(); k++) { if (records.get(k).status) { try { t = new TimeSeriesDataItem(new Millisecond(records.get(k).gcal.getTime()), 1); s1.addOrUpdate(t); } catch (Exception ex) { log.log(Level.WARN, null, ex); } } else { try { t = new TimeSeriesDataItem(new Millisecond(records.get(k).gcal.getTime()), 0); s1.addOrUpdate(t); } catch (Exception ex) { log.log(Level.WARN, null, ex); } } col.addSeries(s1); } } catch (Exception ex) { log.log(Level.ERROR, "Error opening or querying the database.", ex); } } chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Status", col, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, 800); data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }