Skip to content

Instantly share code, notes, and snippets.

@tsmx
Last active November 26, 2021 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsmx/b7eecb4c8f65eac4efe710ad3e976308 to your computer and use it in GitHub Desktop.
Save tsmx/b7eecb4c8f65eac4efe710ad3e976308 to your computer and use it in GitHub Desktop.
Creating time-series dummy mass data CSV file, e.g. for DB stress-test.
#!/bin/bash
# Creates time series dummy data in a CSV with random hourly values.
#
# timeseries: array of name|from|to for the time series
# -> name: name of the series (string)
# -> from: lower limit of the hourly values (number)
# -> to: upper limit of the hourly values (number)
# amount: number of hourly values to create for each series, 24 for one complete day, 24*365 for a year etc.
# startdate: date-time of the first hour
declare -a timeseries=( "TS1|50|100" "TS2|100|120" "TS3|5|15" "TS4|10000|13000" "TS5|9000|11000" )
amount=$((10*365*24))
startdate="06:00:00 2017-01-01"
create_ts_values () {
i=0
while [[ $i -lt $amount ]]
do
echo -ne "$1... ${i}"\\r
echo "\"$1\";$(date -d"$startdate +${i} hours" +"%Y-%m-%d %H:%M:%S");$(($2 + $RANDOM % ($3-$2)))" >> ts.csv
i=$((i+1))
done
}
rm -f ts.csv
echo "Generating timeseries values..."
for val in ${timeseries[@]}; do
ts=$(echo $val | cut -d '|' -f 1)
from=$(echo $val | cut -d '|' -f 2)
to=$(echo $val | cut -d '|' -f 3)
create_ts_values $ts $from $to
echo "$ts... $amount"
done
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment