-
Notifications
You must be signed in to change notification settings - Fork 0
/
DummyHistoryHandler.java
47 lines (36 loc) · 1.53 KB
/
DummyHistoryHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ngordnet.main;
import ngordnet.browser.NgordnetQuery;
import ngordnet.browser.NgordnetQueryHandler;
import ngordnet.ngrams.TimeSeries;
import ngordnet.plotting.Plotter;
import org.knowm.xchart.XYChart;
import java.util.ArrayList;
public class DummyHistoryHandler extends NgordnetQueryHandler {
@Override
public String handle(NgordnetQuery q) {
System.out.println("Got query that looks like:");
System.out.println("Words: " + q.words());
System.out.println("Start Year: " + q.startYear());
System.out.println("End Year: " + q.endYear());
System.out.println("But I'm totally ignoring that and just plotting a parabola\n" +
"and a sine wave, because your job will be to figure out how to\n" +
"actually use the query data.");
TimeSeries parabola = new TimeSeries();
for (int i = 0; i < 100; i += 1) {
parabola.put(i, (i - 50.0) * (i - 50.0) + 3);
}
TimeSeries sinWave = new TimeSeries();
for (int i = 0; i < 100; i += 1) {
sinWave.put(i, 1000 + 500 * Math.sin(i/100.0*2*Math.PI));
}
ArrayList<TimeSeries> lts = new ArrayList<>();
ArrayList<String> labels = new ArrayList<>();
labels.add("parabola");
labels.add("sine wave");
lts.add(parabola);
lts.add(sinWave);
XYChart chart = Plotter.generateTimeSeriesChart(labels, lts);
String encodedImage = Plotter.encodeChartAsString(chart);
return encodedImage;
}
}