Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Data generators

Alberto Rodriguez edited this page May 9, 2017 · 3 revisions

Based on Faker we have develop random generators that will produce random messages for you. So far, we have developed the following generators:

  • Name generation:
  fullname() → Paul Brown
  middleName() → George Michael
  firstName() → Steven
  lastName() → Robinson
  • Number generation:
  number(2) → 23
  number(2,Positive) → 23
  decimal(2) → 23.45
  decimal(2,Negative) → -45.89
  decimal(2,4) → 45.7568
  decimal(3,2,Positive) → 354.89
  numberInRange(1,9) → 2
  decimalInRange(1,9) → 2.6034840849740117
  • Geolocation generation:
  geolocation() → (40.493556, -3.566764, Madrid)
  geolocationWithoutCity() → (28.452717, -13.863761)
  city() → Tenerife
  country() → ES
  • Timestamp generation:
  dateTime("1970-1-12" ,"2017-1-1") → 2005-03-01T20:34:30.000+01:00
  time() → 15:30:00.000+01:00
  • Email generation:
  address(fullname) → [email protected]
  • Music generation:
  playedSong() → {"song": "Shape of You", "artist": "Ed Sheeran", "album": "Shape of You", "genre": "Pop"}

See below a twirl template example to better understand how these generators should be used in the khermes configuration:

@import scala.util.Random
@import com.stratio.khermes.helpers.faker.Faker
@import com.stratio.khermes.helpers.faker.generators.Positive

@(faker: Faker)
@defining(faker.Geo.geolocation, faker.Music.playedSong) { case (randomGeo, randomSong) =>
  {
    "song": "@(randomSong.song)",
    "artist": "@(randomSong.artist)",
    "album": "@(randomSong.album)",
    "genre": "@(randomSong.genre)",
    "playduration": @(faker.Number.number(3,Positive)),
    "rating": @(faker.Number.rating(5)),
    "user": "@(faker.Name.fullName)",
    "usertype": "@(Seq("free", "membership")(Random.nextInt(2)))",
    "city": "@(randomGeo.city)",
    "location": "@(randomGeo.latitude),@(randomGeo.longitude)",
    "starttime": "@(s"${Random.nextInt(24)}:${Random.nextInt(60)}:${Random.nextInt(60)}.${Random.nextInt(1000)}")"
  }
}
Clone this wiki locally