use of org.jfree.data.time.Second in project zaproxy by zaproxy.
the class ScanProgressDialog method updateProgress.
/**
* Updates the scan progress shown by the dialogue (scanners' progress/state and chart).
*/
private void updateProgress() {
// Start panel data settings
HostProcess hp = getSelectedHostProcess();
if (scan.getHostProcesses() != null && hp != null) {
// Update the main table entries
model.updateValues(scan, hp);
if (scan.isStopped()) {
this.stopThread = true;
}
if (chart != null) {
ResponseCountSnapshot snapshot = scan.getRequestHistory();
while (snapshot != null) {
try {
Second second = new Second(snapshot.getDate());
this.seriesTotal.add(second, snapshot.getTotal());
this.series100.add(second, snapshot.getResp100());
this.series200.add(second, snapshot.getResp200());
this.series300.add(second, snapshot.getResp300());
this.series400.add(second, snapshot.getResp400());
this.series500.add(second, snapshot.getResp500());
snapshot = scan.getRequestHistory();
for (Plugin plugin : scan.getHostProcesses().get(0).getRunning()) {
if (!labelsAdded.contains(plugin.getName())) {
// Add a vertical line with the plugin name
ValueMarker vm = new ValueMarker(plugin.getTimeStarted().getTime());
double center = chart.getXYPlot().getRangeAxis().getRange().getCentralValue();
if (lastCentre != center) {
if (lastCentre != -1) {
// Move the existing labels so they stay in the centre
@SuppressWarnings("rawtypes") List annotations = chart.getXYPlot().getAnnotations();
for (Object o : annotations) {
if (o instanceof XYTextAnnotation) {
XYTextAnnotation annotation = (XYTextAnnotation) o;
annotation.setY(center);
}
}
}
lastCentre = center;
}
XYTextAnnotation updateLabel = new XYTextAnnotation(plugin.getName(), plugin.getTimeStarted().getTime(), center);
updateLabel.setFont(FontUtils.getFont("Sans Serif"));
updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER);
updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER);
updateLabel.setRotationAngle(-3.14 / 2);
updateLabel.setPaint(Color.black);
chart.getXYPlot().addDomainMarker(vm, Layer.BACKGROUND);
chart.getXYPlot().addAnnotation(updateLabel);
labelsAdded.add(plugin.getName());
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
snapshot = null;
}
}
}
}
}
use of org.jfree.data.time.Second in project cubrid-manager by CUBRID.
the class CombinedBarTimeSeriesChart method createTableSeriesDataset.
/**
* Creates a table dataset for series
*
* @return Series 2.
*/
private XYDataset createTableSeriesDataset() {
timeTableXYCollection = new TimeTableXYDataset();
for (Map.Entry<String, String> entry : valueMap.entrySet()) {
String key = entry.getKey();
timeTableXYCollection.add(new Second(), 0, key);
}
return timeTableXYCollection;
}
use of org.jfree.data.time.Second in project cubrid-manager by CUBRID.
the class CombinedBarTimeSeriesChart method updateValueMapIfSeries.
/**
* Update the value based on the new value if series chart uses series
* renderer
*
* @param valueMap the valueMap to set
* @param barLabel the label text in the bar chart
*/
private void updateValueMapIfSeries(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();
if (value != null) {
double newValue = Double.parseDouble(value);
bardataset.addValue(newValue, entry.getKey(), "");
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);
for (Map.Entry<String, String> entry : valueMap.entrySet()) {
String value = entry.getValue();
if (value != null) {
double newValue = Double.parseDouble(value);
seriesMap.get(entry.getKey()).addOrUpdate(new Second(), newValue);
}
}
}
use of org.jfree.data.time.Second in project cubrid-manager by CUBRID.
the class CombinedBarTimeSeriesChart 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
* @param maxType the type name representative of the proportion of the
* given types.
*/
private void stuffedChart(CounterFile file, List<String> types, long beginTime, long endTime, String maxType) {
List<String> fileTypes = new ArrayList<String>();
for (String type : types) {
fileTypes.add(type);
}
if (maxType != null) {
fileTypes.add(maxType);
}
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) {
if (isAreaRender) {
double result = results[length].getAvgAsDouble(type);
timeTableXYCollection.add(new Second(new Date(time)), result, type);
} else {
double result = results[length].getAvgAsDouble(type);
seriesMap.get(type).addOrUpdate(new Second(new Date(time)), result);
if (maxType == null) {
if (barMax < result) {
barMax = result;
numberaxis.setRange(0 - 1, barMax + 1);
numberaxis.setVisible(isShowSeriesAxis);
}
} else {
double maxPercent = results[length].getAvgAsDouble(maxType);
double max = maxPercent <= 0 ? barMax : result / maxPercent * 10000;
if (barMax < max) {
barMax = max;
numberaxis.setRange(0 - 1, barMax + 1);
numberaxis.setVisible(isShowSeriesAxis);
}
}
}
}
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
length++;
}
}
use of org.jfree.data.time.Second in project cubrid-manager by CUBRID.
the class MonitorStatisticChart method buildInvalidData.
/**
* Build TimeSeries for StatisticData which has no data. After build, each
* TimeSeries accompany with the StatisticData will have the same time
* series with ordinary TimeSeries, but all the values will be -1.
*
* @param dataset
* @param timeType
* @param dataItemWithoutDataList
* @param current
* @param interalMillisecs
*/
private void buildInvalidData(TimeSeriesCollection dataset, TimeType timeType, List<StatisticData> dataItemWithoutDataList, Date current, long interalMillisecs) {
for (StatisticData statisticData : dataItemWithoutDataList) {
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();
for (int i = 0; i < dataSize; i++) {
point.setTime(curMillisecs - (dataSize - i) * interalMillisecs);
switch(timeType) {
case DAILY:
series.add(new Second(point), -1);
break;
case WEEKLY:
series.add(new Hour(point), -1);
break;
case MONTHLY:
series.add(new Hour(point), -1);
break;
case YEARLY:
series.add(new Day(point), -1);
break;
default:
break;
}
}
maxValueMap.put(statisticData, -1d);
minValueMap.put(statisticData, -1d);
dataset.addSeries(series);
}
}
Aggregations