イベント時間をバケットサイズで割り、そのバケットカウントにバケットサイズを掛けます。これは残余を削除するだけです。これで、イベントはイベント時間に使用できます。ここで
はスクリプトであり、これのpythonを使用しているか、簡単な実証するための出力です:
from datetime import datetime
import time
TS='%m/%d/%Y %H:%M:%S'
def mkdate(d):
return time.strftime(TS, time.gmtime(d))
def mkhash(time_bucket_size, current_time):
blocks_in_epoch = int(current_time/time_bucket_size)
return blocks_in_epoch * time_bucket_size
if __name__ == "__main__":
epoch = int(time.time())
time_bucket_size = (60 * 60 * 6) # n hrs block size
event_time_adjustment_modifier = (60 * 60) # test every hour
test_events_into_past=-10
test_events_into_future=10
print("---------------\ntime_bucket_size=%s, epoch=%s, date=%s\n---------------"%(time_bucket_size, epoch, mkdate(epoch)))
# print up the hashed times for current to n hrs ahead and n hrs behind
for event_time_adjustment in range(test_events_into_past, test_events_into_future):
test_epoch = epoch + (event_time_adjustment * event_time_adjustment_modifier)
time_block_hash = mkhash(time_bucket_size=time_bucket_size, current_time=test_epoch)
print("test_date=%s, event_time_adjustment=%s, time_block=%s"%(mkdate(test_epoch), event_time_adjustment, mkdate(time_block_hash)))
そして、ここでは、今日のために出力されます...
---------------
time_bucket_size=21600, epoch=1468370760, date=07/13/2016 00:46:00
---------------
test_date=07/12/2016 14:46:00, event_time_adjustment=-10, time_block=07/12/2016 12:00:00
test_date=07/12/2016 15:46:00, event_time_adjustment=-9, time_block=07/12/2016 12:00:00
test_date=07/12/2016 16:46:00, event_time_adjustment=-8, time_block=07/12/2016 12:00:00
test_date=07/12/2016 17:46:00, event_time_adjustment=-7, time_block=07/12/2016 12:00:00
test_date=07/12/2016 18:46:00, event_time_adjustment=-6, time_block=07/12/2016 18:00:00
test_date=07/12/2016 19:46:00, event_time_adjustment=-5, time_block=07/12/2016 18:00:00
test_date=07/12/2016 20:46:00, event_time_adjustment=-4, time_block=07/12/2016 18:00:00
test_date=07/12/2016 21:46:00, event_time_adjustment=-3, time_block=07/12/2016 18:00:00
test_date=07/12/2016 22:46:00, event_time_adjustment=-2, time_block=07/12/2016 18:00:00
test_date=07/12/2016 23:46:00, event_time_adjustment=-1, time_block=07/12/2016 18:00:00
test_date=07/13/2016 00:46:00, event_time_adjustment=0, time_block=07/13/2016 00:00:00
test_date=07/13/2016 01:46:00, event_time_adjustment=1, time_block=07/13/2016 00:00:00
test_date=07/13/2016 02:46:00, event_time_adjustment=2, time_block=07/13/2016 00:00:00
test_date=07/13/2016 03:46:00, event_time_adjustment=3, time_block=07/13/2016 00:00:00
test_date=07/13/2016 04:46:00, event_time_adjustment=4, time_block=07/13/2016 00:00:00
test_date=07/13/2016 05:46:00, event_time_adjustment=5, time_block=07/13/2016 00:00:00
test_date=07/13/2016 06:46:00, event_time_adjustment=6, time_block=07/13/2016 06:00:00
test_date=07/13/2016 07:46:00, event_time_adjustment=7, time_block=07/13/2016 06:00:00
test_date=07/13/2016 08:46:00, event_time_adjustment=8, time_block=07/13/2016 06:00:00
test_date=07/13/2016 09:46:00, event_time_adjustment=9, time_block=07/13/2016 06:00:00