Skip to content

Commit 4b9adbd

Browse files
committed
[CM-1580]: Implemented Curve, DataPoint data types as well as CurveData DTO.
1 parent 030c124 commit 4b9adbd

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package ml.comet.experiment.impl.rest;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import lombok.Data;
5+
import ml.comet.experiment.model.Curve;
6+
import ml.comet.experiment.model.DataPoint;
7+
8+
@Data
9+
@JsonInclude(JsonInclude.Include.NON_NULL)
10+
@SuppressWarnings("checkstyle:MemberName")
11+
public class CurveData {
12+
private String name;
13+
private float[] x;
14+
private float[] y;
15+
16+
private CurveData() {
17+
}
18+
19+
/**
20+
* The factory to create data from provided {@code Curve} instance.
21+
*
22+
* @param curve the {@code Curve} instance.
23+
* @return the initialized data holder.
24+
*/
25+
public static CurveData from(Curve curve) {
26+
CurveData data = new CurveData();
27+
data.name = curve.getName();
28+
DataPoint[] dataPoints = curve.getDataPoints();
29+
data.x = new float[dataPoints.length];
30+
data.y = new float[dataPoints.length];
31+
for (int i = 0; i < dataPoints.length; i++) {
32+
data.x[i] = dataPoints[i].getX();
33+
data.y[i] = dataPoints[i].getY();
34+
}
35+
return data;
36+
}
37+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ml.comet.experiment.model;
2+
3+
import lombok.Data;
4+
import lombok.NonNull;
5+
6+
/**
7+
* Represents data of the curve as x/y pairs.
8+
*/
9+
@Data
10+
@SuppressWarnings("checkstyle:MemberName")
11+
public class Curve {
12+
private DataPoint[] dataPoints;
13+
private String name;
14+
15+
/**
16+
* Creates new instance with specified parameters.
17+
*
18+
* @param dataPoints the curve data points.
19+
* @param name the name of the curve.
20+
*/
21+
public Curve(@NonNull DataPoint[] dataPoints, @NonNull String name) {
22+
this.dataPoints = dataPoints;
23+
this.name = name;
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ml.comet.experiment.model;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
6+
/**
7+
* Represents particular data point on the two dimensional curve.
8+
*/
9+
@Data
10+
@AllArgsConstructor
11+
@SuppressWarnings("checkstyle:MemberName")
12+
public class DataPoint {
13+
private float x;
14+
private float y;
15+
16+
/**
17+
* Creates new instance with specified data.
18+
*
19+
* @param x the value by X-axis.
20+
* @param y the value by Y-axis.
21+
* @return initialized instance of {@code DataPoint} with provided values.
22+
*/
23+
public static DataPoint of(float x, float y) {
24+
return new DataPoint(x, y);
25+
}
26+
}

0 commit comments

Comments
 (0)