Skip to content

Commit

Permalink
Show future on color guess submit #17
Browse files Browse the repository at this point in the history
  • Loading branch information
ogallagher committed Aug 28, 2021
1 parent 226c478 commit c1a824d
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 17 deletions.
2 changes: 1 addition & 1 deletion fxgraph
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ogallagher</groupId>
<artifactId>marketsense</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>

<name>marketsense</name>
<url>https://github.com/ogallagher/marketsense</url>
Expand Down
3 changes: 3 additions & 0 deletions src/ogallagher/marketsense/MarketSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ public AudioInputStream getSound() {
return sound;
}

/**
* @return {@link #futureMovement}
*/
public double getFutureMovement() {
return futureMovement;
}
Expand Down
72 changes: 57 additions & 15 deletions src/ogallagher/marketsense/MarketSense.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import ogallagher.marketsense.test.Test;
import ogallagher.marketsense.test.TestDatabase;
import ogallagher.marketsense.test.TestMarketSynth;
import ogallagher.marketsense.util.PointFilter;
import ogallagher.temp_fx_logger.System;

/**
Expand All @@ -96,7 +97,7 @@ public class MarketSense {
/**
* Program version string.
*/
public static final String VERSION = "0.1.1";
public static final String VERSION = "0.1.2";

/**
* Path to program parent directory. In development, this is the parent folder of the one containing
Expand Down Expand Up @@ -633,6 +634,7 @@ public static class ShowTrainingSession implements Runnable {
private TrainingSession session;

private CartesianGraph currentSampleGraph;
private PointFilter dataFilter;

public ShowTrainingSession(TrainingSession session) {
this.session = session;
Expand Down Expand Up @@ -865,6 +867,25 @@ public void handle(ActionEvent event) {
// update average score
session.updateScore(score);

// add future to sample graph
dataFilter.setInput(new Point2D(dataFilter.getMaxX(), sample.getFuture().getClose()));
try {
Point2D futurePoint = dataFilter.call().get(0);

currentSampleGraph.addPoint(
futurePoint,
null,
CartesianPoint.RADIUS_DEFAULT,
CartesianPoint.BulletType.CIRCLE,
javafx.scene.paint.Color.BLUEVIOLET
);

currentSampleGraph.addLastEdge();
}
catch (Exception e) {
System.out.println("ERROR failed to use data filter for future point: " + e.getMessage());
}

// enable next sample button
nextSample.setDisable(false);
}
Expand Down Expand Up @@ -912,21 +933,42 @@ private CartesianGraph loadSampleGraph(MarketSample sample, int graphWidth, int
points.add(p);
}

for (i=0; i<points.size(); i++) {
p = points.get(i);
x = p.getX(); y = p.getY();
points.set(i, new Point2D(
(x-minX)/(maxX-minX) * (graphWidth-50),
// 1 - ... flips y axis
(1 - (y-minY)/(maxY-minY)) * (graphHeight-50)
));
}
// reserve space for future point
double postmaxX = maxX + (maxX-minX)/points.size();

// define data filter
dataFilter = new PointFilter(minX,postmaxX,minY,maxY,graphWidth,graphHeight) {
@Override
public List<Point2D> call() {
List<Point2D> output = new ArrayList<>(this.input.size());

for (Point2D point : input) {
output.add(new Point2D(
(point.getX()-this.minX)/(this.maxX-minX) * (this.graphWidth-50),
// 1 - ... flips y axis
(1 - (point.getY()-this.minY)/(this.maxY-this.minY)) * (this.graphHeight-50)
));
}

return output;
}
};

graph.addDataset(
points,
"sample " + session.getSampleIdProperty().get(),
5, CartesianPoint.BulletType.CIRCLE, javafx.scene.paint.Color.CRIMSON
);
try {
// filter data
dataFilter.setInput(points);
points = dataFilter.call();

// add filtered data to graph
graph.addDataset(
points,
"sample " + session.getSampleIdProperty().get(),
5, CartesianPoint.BulletType.CIRCLE, javafx.scene.paint.Color.CRIMSON
);
}
catch (Exception e) {
System.out.println("ERROR error using data filter: " + e.getMessage());
}

return graph;
}
Expand Down
71 changes: 71 additions & 0 deletions src/ogallagher/marketsense/util/PointFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package ogallagher.marketsense.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

import javafx.geometry.Point2D;

public abstract class PointFilter implements Callable<List<Point2D>> {
protected List<Point2D> input = new ArrayList<>();
protected double minX, maxX, graphWidth, minY, maxY, graphHeight;

public PointFilter() {
this(0,0,0,0,0,0);
}

/**
* @param x Min x.
* @param X Max x.
* @param y Min y.
* @param Y Max y.
* @param w Graph width.
* @param h Graph height.
*/
public PointFilter(double x, double X, double y, double Y, double w, double h) {
minX = x;
maxX = X;
minY = y;
maxY = Y;
graphWidth = w;
graphHeight = h;
}

public void setInput(List<Point2D> input) {
this.input.clear();
this.input.addAll(input);
}

public void setInput(Point2D input) {
this.input.clear();
this.input.add(input);
}

public double getMinX() {
return minX;
}

public double getMaxX() {
return maxX;
}

public double getMinY() {
return minY;
}

public double getMaxY() {
return maxY;
}

public double getGraphWidth() {
return graphWidth;
}

public double getGraphHeight() {
return graphHeight;
}

public List<Point2D> call() throws Exception {
throw new UnsupportedOperationException("must be defined by implementing class");
}
}
1 change: 1 addition & 0 deletions src/ogallagher/marketsense/util/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package ogallagher.marketsense.util;

0 comments on commit c1a824d

Please sign in to comment.