Skip to content

Instantly share code, notes, and snippets.

@heppu
Created May 11, 2020 10:48
Show Gist options
  • Save heppu/5886a72579024925bf29562694cedcae to your computer and use it in GitHub Desktop.
Save heppu/5886a72579024925bf29562694cedcae to your computer and use it in GitHub Desktop.
package main
import (
"encoding/csv"
"flag"
"log"
"math/rand"
"os"
"strconv"
"time"
"github.com/bxcodec/faker/v3"
)
const dateFormat = "2006/01/02"
func main() {
var (
start = flag.String("start", "", "start date")
end = flag.String("end", "", "end date")
testN = flag.Uint("initTest", 100, "number of tests on first day")
testMul = flag.Float64("testMul", 1.2, "test result multiplier per day")
prob = flag.Float64("prob", 0.1, "start probability to get positive test result")
posMul = flag.Float64("posMul", 1.2, "positive probability multiplier per day")
city = flag.String("city", "", "name of city")
)
flag.Parse()
d, err := time.Parse(dateFormat, *start)
checkErr(err)
endDate, err := time.Parse(dateFormat, *end)
checkErr(err)
w := csv.NewWriter(os.Stdout)
checkErr(w.Write([]string{
"first_name",
"last_name",
"birth_year",
"personal_id",
"test_location_latitude",
"test_location_longitude",
"area",
"test_date",
"test_result",
"unique_test_id",
}))
day := 0
for ; endDate.After(d); d = d.AddDate(0, 0, 1) {
for i := uint(0); i < *testN; i++ {
checkErr(w.Write([]string{
faker.FirstName(),
faker.LastName(),
strconv.Itoa(1940 + rand.Intn(80)),
strconv.Itoa(1000000000 + rand.Intn(8999999999)),
"",
"",
*city,
d.Format(dateFormat),
strconv.FormatBool(rand.Float64() < *prob),
faker.UUIDHyphenated(),
}))
}
*testN = uint(*testMul * float64(*testN))
day++
*prob *= *posMul
}
w.Flush()
checkErr(w.Error())
}
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment