Created
November 1, 2017 12:28
-
-
Save MayukhSobo/e61a49ecc7c80dc533e99b1d8c2f4c73 to your computer and use it in GitHub Desktop.
Generate time stamp interval for CSV dummy data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Common dummy data generation scripts | |
""" | |
from random import randint | |
from datetime import datetime as dt | |
from datetime import timedelta | |
start_times = [] | |
end_times = [] | |
def duration_generator(duration, nrows, from_date, timestamp_fmt='%Y-%m-%d %H:%M:%S', rest=timedelta(minutes=0)): | |
if nrows == 0: | |
return | |
start_time = dt.strptime(from_date, timestamp_fmt) + rest | |
end_time = start_time + timedelta(minutes=duration) | |
start_time_str = dt.strftime(start_time, timestamp_fmt) | |
end_time_str = dt.strftime(end_time, timestamp_fmt) | |
start_times.append(start_time_str) | |
end_times.append(end_time_str) | |
duration_generator(randint(1, 2*60), nrows - 1, end_time_str, timestamp_fmt, timedelta(minutes=30, days=randint(0, 2))) | |
duration_generator(duration=randint(1, 2*60), | |
nrows=500, | |
from_date='2016-01-01 00:00:00') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment