-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: UUID rate semver FPF-14284 #38
base: master
Are you sure you want to change the base?
Changes from all commits
ce73ae5
70566e0
35320d6
e5379e5
1fb4438
6831e34
2c177ab
b19cfd9
187afbb
f701fa5
13db1ef
b10e25d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import io.confluent.avro.random.generator.geojson.crs.CRS; | ||
import io.confluent.avro.random.generator.geojson.crs.EPSG4326; | ||
import com.telefonica.baikal.utils.Validations; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
@@ -74,27 +75,44 @@ private String randomCoordinates() { | |
) | ||
).toString(); | ||
case MultiPolygon: | ||
String first1 = new Point(null, null, crs).toString(); | ||
String first2 = new Point(null, null, crs).toString(); | ||
|
||
return Arrays.asList( | ||
List.of( | ||
int i = 0; | ||
String result = null; | ||
while (i < 10000) { | ||
String first1 = new Point(null, null, crs).toString(); | ||
String first2 = new Point(null, null, crs).toString(); | ||
Point point1 = new Point(null, null, crs); | ||
Point point2 = new Point(point1.latitude, null, crs); | ||
Point point3 = new Point(null, point2.longitude, crs); | ||
Point point4 = new Point(null, null, crs); | ||
Point point5 = new Point(point4.latitude, null, crs); | ||
Point point6 = new Point(null, point5.longitude, crs); | ||
/* NOTE: The polygon is formed by 5 points due to geojson library */ | ||
result = Arrays.asList( | ||
List.of( | ||
Arrays.asList( | ||
first1, | ||
new Point(null, null, crs).toString(), | ||
new Point(null, null, crs).toString(), | ||
point1.toString(), | ||
point2.toString(), | ||
point3.toString(), | ||
first1 | ||
) | ||
), | ||
List.of( | ||
), | ||
Arrays.asList( | ||
first2, | ||
new Point(null, null, crs).toString(), | ||
new Point(null, null, crs).toString(), | ||
point4.toString(), | ||
point5.toString(), | ||
point6.toString(), | ||
first2 | ||
) | ||
) | ||
).toString(); | ||
) | ||
).toString(); | ||
|
||
String geojson = "{\"type\": \"" + geometryType + "\", \"coordinates\": " + result + "}"; | ||
if (Validations.isValidGeometry(geojson)) { | ||
return result; | ||
} | ||
i++; | ||
} | ||
throw new RuntimeException("Could not generate a valid MultiPolygon after 1000 attempts."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ¿Sabemos las iteraciones, en media, que esto suele tardar? |
||
default: | ||
return null; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,12 @@ protected void setBounds( | |
|
||
public double randomLatitude() { | ||
Random r = new Random(); | ||
return bottomBound + (upperBound - bottomBound) * r.nextDouble(); | ||
return -90 + r.nextInt(180) + r.nextDouble(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ¿No funcionaba el mecanismo anterior? |
||
} | ||
|
||
public double randomLongitude() { | ||
Random r = new Random(); | ||
return leftBound + (rightBound - leftBound) * r.nextDouble(); | ||
return -180 + r.nextInt(360) + r.nextDouble(); | ||
} | ||
|
||
public abstract String toString(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,12 @@ public void shouldStringifyCorrectly() { | |
FeatureCollection featureCollection = createFeatureCollection(); | ||
assertNotNull(featureCollection.toString()); | ||
Gson gson = new Gson(); | ||
|
||
String fcollection = featureCollection.toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No parece necesario sacarlo fuera, ¿no? Si se fuera a usar en otro sitio la variable, ahí sí. |
||
try { | ||
gson.fromJson(featureCollection.toString(), JsonObject.class); | ||
} catch (JsonSyntaxException exception) { | ||
gson.fromJson(fcollection, JsonObject.class); | ||
} catch (Exception exception) { | ||
|
||
exception.printStackTrace(); | ||
fail(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ "type": "record", | ||
"name": "logicals", | ||
"namespace": "io.confluent.avro.random.generator", | ||
"fields": | ||
[ | ||
{ | ||
"name": "rate", | ||
"type": { | ||
"type": "float", | ||
"logicalType": "rate" | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ "type": "record", | ||
"name": "logicals", | ||
"namespace": "io.confluent.avro.random.generator", | ||
"fields": | ||
[ | ||
{ | ||
"name": "semver", | ||
"type": { | ||
"type": "string", | ||
"logicalType": "semver" | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ "type": "record", | ||
"name": "logicals", | ||
"namespace": "io.confluent.avro.random.generator", | ||
"fields": | ||
[ | ||
{ | ||
"name": "uuid", | ||
"type": { | ||
"type": "string", | ||
"logicalType": "uuid-string" | ||
} | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Es curioso que el
.isValid()
no permita "triángulos" (4 puntos, el primero coincidiendo con el último).