Commit 95052086 authored by Florian Fittkau's avatar Florian Fittkau

init

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/jfreechart-1.0.19.jar"/>
<classpathentry kind="lib" path="lib/jcommon-1.0.23.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin
Thumbs.db
/dist
/build
/reports
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JPetStoreLoadForecaster</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
package explorviz.loadforecaster;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.data.xy.XYSeries;
public class Main extends JFrame {
private static final double INTENSITY = 25;
private static final int THREAD_COUNT = 32;
private static final int JMETER_INSTANCES = 1;
private static final float SESSION_TO_REQUEST_RATIO = 2.55f;
private static final long serialVersionUID = 5555101911354600988L;
public static void main(String[] args) {
final Main demo = new Main("JPetStore Load Forecaster", "Approximate JPetStore Load");
demo.pack();
demo.setExtendedState(demo.getExtendedState() | JFrame.MAXIMIZED_BOTH);
demo.setVisible(true);
}
public Main(String applicationTitle, String chartTitle) {
super(applicationTitle);
final DefaultXYDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset, chartTitle);
final ChartPanel chartPanel = new ChartPanel(chart);
final Dimension fullScreen = Toolkit.getDefaultToolkit().getScreenSize();
getContentPane().setBounds(0, 0, fullScreen.width, fullScreen.height);
chartPanel.setPreferredSize(fullScreen);
setContentPane(chartPanel);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
System.exit(0);
}
});
}
private DefaultXYDataset createDataset() {
final DefaultXYDataset dataset = new DefaultXYDataset();
final XYSeries series1 = new XYSeries("Approximate requests per sec");
for (float minute = 0f; minute <= 1440f; minute += 0.2f) {
series1.add((minute + 1380) * 1000 * 60, getWorkload(minute) * THREAD_COUNT
* JMETER_INSTANCES * SESSION_TO_REQUEST_RATIO);
}
dataset.addSeries("Approximate requests per sec", series1.toArray());
return dataset;
}
private JFreeChart createChart(DefaultXYDataset dataset, String title) {
final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Time",
"Requests per sec", dataset, false, true, false);
final XYPlot plot = (XYPlot) chart.getPlot();
// plot.setBackgroundPaint(Color.white);
// plot.setRangeGridlinePaint(Color.black);
final XYItemRenderer renderer = plot.getRenderer();
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1} -> {2}",
new SimpleDateFormat("HH:mm"), NumberFormat.getInstance()));
final DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
return chart;
}
private static int getWorkload(float expiredMinute) {
final int numSessions = (int) ((numSessions(expiredMinute) / 2d) * INTENSITY);
return numSessions > 1 ? numSessions : 5;
}
private static double numSessions(double min) {
double retVal = 0;
retVal += (min <= 230) ? 1 / ((min + 80) / 20d) * 1.2 : 0;
retVal += (min > 230 && min <= 320) ? (min - 160) * 0.001d : 0;
retVal += (min > 320 && min <= 410) ? (min - 280) * 0.004d : 0;
retVal += (min > 410 && min <= 620) ? Math.cos((min - 545) / 120d) * 1.2 : 0;
retVal += (min > 620 && min <= 650) ? (min - 1600) * -0.001d : 0;
retVal += (min > 650 && min <= 690) ? (min + 1250) * 0.0005d : 0;
retVal += (min > 690 && min <= 850) ? Math.cos((min - 790) / 200d) * 1.1 : 0;
retVal += (min > 850 && min <= 965) ? (min - 330) * 0.0020d : 0;
retVal += (min > 965) ? Math.cos((min - 1150) / 200d) * 2.1 : 0;
return retVal;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment