Skip to content

Commit

Permalink
[fix] reflect database changes (#34)
Browse files Browse the repository at this point in the history
small changes to reflect upcoming changes
DOES NOT implement codecharts changes (config + datapoints + strings)!
  • Loading branch information
joshuajeschek authored Jan 10, 2022
1 parent d983bd9 commit 1696f6a
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 206 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package github.weichware10.util.config;

import java.util.Arrays;
import java.util.List;

/**
* Beinhaltet Konfiguration für CodeCharts-Versuche.
*/
public class CodeChartsConfiguration {
protected List<String> strings = Arrays.asList("foo", "bar");
protected String stringId = "OBST";
protected int[] initialSize = { 10, 20 };
protected long[] timings = { 200, 200 };

Expand All @@ -22,23 +21,23 @@ protected CodeChartsConfiguration() {
/**
* Konstruktor für die CodeCharts Konfiguration.
*
* @param strings - Strings für die CodeCharts Konfiguration
* @param stringid - String-ID für die CodeCharts Konfiguration
* @param initialSize - Rastergröße der CodeCharts Konfiguration
* @param timings - Zeit zum Wechsel von Bild zu Raster & Raster zu Eingabefeld
* der CodeCharts Konfiguration
* @param tutorial - Anzeige des Tutorials
*/
public CodeChartsConfiguration(List<String> strings, int[] initialSize, long[] timings,
public CodeChartsConfiguration(String stringid, int[] initialSize, long[] timings,
boolean tutorial) {
this.strings = strings;
this.stringId = stringid;
this.initialSize = initialSize;
this.timings = timings;
}

// --- GETTERS ---

public List<String> getStrings() {
return strings;
public String getStringId() {
return stringId;
}

public int[] getInitialSize() {
Expand All @@ -60,7 +59,7 @@ public boolean equals(Object obj) {
return false;
}
CodeChartsConfiguration that = (CodeChartsConfiguration) (obj);
return strings.equals(that.strings)
return stringId.equals(that.stringId)
&& Arrays.equals(initialSize, that.initialSize)
&& Arrays.equals(timings, that.timings);
}
Expand All @@ -69,8 +68,8 @@ public boolean equals(Object obj) {
public String toString() {
return String.format("""
codeChartsConfiguration: {
strings: %s, initialSize: %s, timings: %s }""",
strings.toString(),
stringId: %s, initialSize: %s, timings: %s }""",
stringId,
Arrays.toString(initialSize),
Arrays.toString(timings));
}
Expand Down
23 changes: 1 addition & 22 deletions src/main/java/github/weichware10/util/data/DataPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Arrays;
import java.util.Map;
import javafx.geometry.Rectangle2D;

Expand All @@ -14,31 +13,23 @@
public class DataPoint {
public final int dataId;
public final int timeOffset;
public final double[] coordinates; // ! double[2]
public final double[] rasterSize; // ! double[2]
public final Rectangle2D viewport; // ! double[4]

/**
* Konstruktor für Jackson.
*
* @param dataId - the id of the dataPoint
* @param timeOffset - the time since the trial started
* @param coordinates - the coordinates on the viewed picture
* @param rasterSize - width and height of the raster
* @param viewport - aktueller Ausschnitt beim ZoomBild
*
* @since v1.0
*/
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public DataPoint(@JsonProperty("dataId") int dataId,
@JsonProperty("timeOffset") int timeOffset,
@JsonProperty("coordinates") double[] coordinates,
@JsonProperty("rasterSize") double[] rasterSize,
@JsonProperty("viewport") Map<String, Double> viewport) {
this.dataId = dataId;
this.timeOffset = timeOffset;
this.coordinates = coordinates;
this.rasterSize = rasterSize;
this.viewport = (viewport != null) ? new Rectangle2D(
viewport.get("minX"),
viewport.get("minY"),
Expand All @@ -59,8 +50,6 @@ public DataPoint(@JsonProperty("dataId") int dataId,
public DataPoint(int dataId, int timeOffset, Rectangle2D viewport) {
this.dataId = dataId;
this.timeOffset = timeOffset;
this.coordinates = null;
this.rasterSize = null;
this.viewport = viewport;
}

Expand All @@ -69,16 +58,12 @@ public DataPoint(int dataId, int timeOffset, Rectangle2D viewport) {
*
* @param dataId - the id of the dataPoint
* @param timeOffset - the time since the trial started
* @param coordinates - the coordinates on the viewed picture
* @param rasterSize - width and height of the raster
*
* @since v0.3
*/
public DataPoint(int dataId, int timeOffset, double[] coordinates, double[] rasterSize) {
public DataPoint(int dataId, int timeOffset) {
this.dataId = dataId;
this.timeOffset = timeOffset;
this.coordinates = coordinates;
this.rasterSize = rasterSize;
this.viewport = null;
}

Expand All @@ -96,14 +81,10 @@ public String toString() {
DataPoint: {
dataId: %d,
timeOffset: %d,
coordinates: %s,
rasterSize: %s,
viewport: %s
}""",
dataId,
timeOffset,
Arrays.toString(coordinates),
Arrays.toString(rasterSize),
viewportStr);
}

Expand All @@ -117,8 +98,6 @@ public boolean equals(Object other) {
}
DataPoint that = (DataPoint) (other);
return dataId == that.dataId && timeOffset == that.timeOffset
&& Arrays.equals(coordinates, that.coordinates)
&& Arrays.equals(rasterSize, that.rasterSize)
&& viewport == that.viewport || (
viewport.getMinX() == that.viewport.getMinX()
&& viewport.getMinY() == that.viewport.getMinY()
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/github/weichware10/util/data/TrialData.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,26 @@ public void setAnswer(String answer) {
/**
* Add a DataPoint for CodeCharts.
*
* @param coordinates - the coordinates on the viewed picture
* @param rasterSize - width and height of the raster
*
* @since v0.2
*/
public void addDataPoint(double[] coordinates, double[] rasterSize) {
public void addDataPoint() {

if (toolType != ToolType.CODECHARTS) {
throw new IllegalArgumentException("Can only add CODECHARTS DataPoints.");
}

if (coordinates.length != 2) {
throw new IllegalArgumentException("coordinates[] needs to have a length of 2");
}
if (rasterSize.length != 2) {
throw new IllegalArgumentException("rasterSize[] needs to have a length of 2");
}

// kann "ohne" Bedenken gecastet werden,
// damit Overflow auftritt, müsste zwischen Anfang und jetzt ca 25 Tage liegen.
int timeOffset = (int) (DateTime.now().getMillis() - startTime.getMillis());

dataPoints.add(new DataPoint(dataPoints.size(), timeOffset, coordinates, rasterSize));
dataPoints.add(new DataPoint(dataPoints.size(), timeOffset));
}

/**
* Add a DataPoint for ZoomMaps.
*
* @param viewport - aktueller Ausschnitt beim ZoomBild
* @param viewport - aktueller Ausschnitt beim ZoomBild
*
* @since v1.2
*/
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/github/weichware10/util/db/Configurations.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

/**
* Die Configurations-Tabelle beinhaltet die gespeicherten Konfigurationen.
Expand Down Expand Up @@ -62,7 +61,7 @@ public Configuration get(String configId) {

if (toolType == ToolType.CODECHARTS) {
// CODECHARTS spezifische Werte
List<String> strings = Util.stringsToList(rs.getString("strings"));
String stringId = rs.getString("stringid");
int[] initialSize = new int[] {
rs.getInt("initialsize_x"),
rs.getInt("initialsize_y") };
Expand All @@ -72,7 +71,7 @@ public Configuration get(String configId) {

// CodeChartsConfiguration erstellen
CodeChartsConfiguration codeChartsConfiguration = new CodeChartsConfiguration(
strings, initialSize, timings, tutorial);
stringId, initialSize, timings, tutorial);

// komplette Konfiguration zurückgeben
configuration = new Configuration(
Expand Down Expand Up @@ -115,7 +114,7 @@ public String set(Configuration configuration) {
INSERT INTO %s.configurations
(configid, tooltype, tutorial, question, imageurl,
intro, outro,
strings, initialsize_x, initialsize_y, timings_0, timings_1,
stringid, initialsize_x, initialsize_y, timings_0, timings_1,
imageview_width, imageview_height, speed)
VALUES
(?, ?, ?, ?, ?,
Expand Down Expand Up @@ -149,7 +148,7 @@ public String set(Configuration configuration) {
CodeChartsConfiguration ccConfig = configuration.getCodeChartsConfiguration();
pst.setString(2, "CODECHARTS");
// Felder für CodeCharts
pst.setString(8, ccConfig.getStrings().toString());
pst.setString(8, ccConfig.getStringId());
pst.setInt(9, ccConfig.getInitialSize()[0]);
pst.setInt(10, ccConfig.getInitialSize()[1]);
pst.setLong(11, ccConfig.getTimings()[0]);
Expand Down
51 changes: 5 additions & 46 deletions src/main/java/github/weichware10/util/db/Datapoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ public List<DataPoint> get(String trialId) {
st = conn.createStatement();
rs = st.executeQuery(query);
while (rs.next()) {
// bei codecharts versuchen
double[] coordinates = new double[] { rs.getDouble("coordinates_x"),
rs.getDouble("coordinates_y") };
coordinates = rs.wasNull() ? null : coordinates;
double[] rasterSize = new double[] { rs.getDouble("rastersize_x"),
rs.getDouble("rastersize_y") };
rasterSize = rs.wasNull() ? null : rasterSize;

// bei zoommaps versuchen
Map<String, Double> viewport = new HashMap<>();
viewport.put("minX", rs.getDouble("viewportmin_x"));
Expand All @@ -69,8 +61,6 @@ public List<DataPoint> get(String trialId) {
dataPoints.add(new DataPoint(
rs.getInt("dataid"),
rs.getInt("timeoffset"),
coordinates,
rasterSize,
viewport));
}

Expand All @@ -92,34 +82,13 @@ public List<DataPoint> get(String trialId) {
* @param trialId - trialId des Versuchs
*/
public void set(List<DataPoint> dataPoints, String trialId) {
// final String ccQuery = """
// INSERT INTO %s.datapoints
// (trialid, dataid, timeoffset,
// coordinates_x, coordinates_y, rastersize_x, rastersize_y,
// viewportmin_x, viewportmin_y, viewport_width, viewport_height)
// VALUES
// ('%s', %d, %d,
// %s, %s, %s, %s,
// null, null, null, null);""";

// final String zmQuery = """
// INSERT INTO %s.datapoints
// (trialid, dataid, timeoffset,
// coordinates_x, coordinates_y, rastersize_x, rastersize_y,
// viewportmin_x, viewportmin_y, viewport_width, viewport_height)
// VALUES
// ('%s', %d, %d,
// null, null, null, null,
// %s, %s, %s, %s);""";

final String queryF = String.format("""
INSERT INTO %s.datapoints
(trialid, dataid, timeoffset,
coordinates_x, coordinates_y, rastersize_x, rastersize_y,
viewportmin_x, viewportmin_y, viewport_width, viewport_height)
VALUES
(?, ?, ?,
?, ?, ?, ?,
?, ?, ?, ?);""", dataBaseClient.schema);

Connection conn = null;
Expand All @@ -137,27 +106,17 @@ public void set(List<DataPoint> dataPoints, String trialId) {

// CODECHARTS
if (dp.viewport == null) {
// Felder für CodeCharts
pst.setDouble(4, dp.coordinates[0]);
pst.setDouble(5, dp.coordinates[1]);
pst.setDouble(6, dp.rasterSize[0]);
pst.setDouble(7, dp.rasterSize[1]);
// Felder für ZoomMaps
pst.setNull(8, java.sql.Types.DOUBLE);
pst.setNull(9, java.sql.Types.DOUBLE);
pst.setNull(10, java.sql.Types.DOUBLE);
pst.setNull(11, java.sql.Types.DOUBLE);
} else { // ZOOMMAPS
// Felder für CodeCharts
pst.setNull(4, java.sql.Types.DOUBLE);
pst.setNull(5, java.sql.Types.DOUBLE);
pst.setNull(6, java.sql.Types.DOUBLE);
pst.setNull(7, java.sql.Types.DOUBLE);
} else { // ZOOMMAPS
// Felder für ZoomMaps
pst.setDouble(8, dp.viewport.getMinX());
pst.setDouble(9, dp.viewport.getMinY());
pst.setDouble(10, dp.viewport.getWidth());
pst.setDouble(11, dp.viewport.getHeight());
pst.setDouble(4, dp.viewport.getMinX());
pst.setDouble(5, dp.viewport.getMinY());
pst.setDouble(6, dp.viewport.getWidth());
pst.setDouble(7, dp.viewport.getHeight());
}
pst.executeUpdate();
}
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/github/weichware10/util/db/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;

class Util {

// wandelt eine als String gespeicherte Liste um
protected static List<String> stringsToList(String strings) {
return Arrays.asList(strings.substring(1, strings.length() - 1).split(", "));
}

/**
* Generiert eine ID. Muss nicht eindeutig sein!
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import org.junit.Test;

/**
Expand All @@ -16,7 +15,7 @@ public class CodeChartsConfigurationTest {
@Test
public void toStringShouldWork() {
CodeChartsConfiguration config = new CodeChartsConfiguration(
Arrays.asList("a"),
"OBST",
new int[] { 1, 2 },
new long[] { 200, 200 },
true);
Expand All @@ -29,12 +28,12 @@ public void toStringShouldWork() {
@Test
public void newlyCreatedConfigsShouldBeEqual() {
CodeChartsConfiguration config1 = new CodeChartsConfiguration(
Arrays.asList("a"),
"OBST",
new int[] { 1, 2 },
new long[] { 200, 200 },
true);
CodeChartsConfiguration config2 = new CodeChartsConfiguration(
Arrays.asList("a"),
"OBST",
new int[] { 1, 2 },
new long[] { 200, 200 },
true);
Expand Down
Loading

0 comments on commit 1696f6a

Please sign in to comment.