我想模擬隨機時間戳數據。 每天100條記錄,一年。如何在kdb中模擬一年的日期
我怎麼能做到這一點? 當我設置:2013.01.01D00:00:00.000000000 100?a 隨機數據不會停留在一天。
感謝您的輸入
我想模擬隨機時間戳數據。 每天100條記錄,一年。如何在kdb中模擬一年的日期
我怎麼能做到這一點? 當我設置:2013.01.01D00:00:00.000000000 100?a 隨機數據不會停留在一天。
感謝您的輸入
我不確定,如果這可以輕鬆完成。但是你可能在接下來的方式
daysInYear: 365;
year: 2013.01.01D00:00:00.000000000;
//array of 365 elements, where every element represents corresponding date of year
dates: year + 01D * til daysInYear;
//array of 365 elements, where every element is an array of 100 random timestamps [0 .. 1D)
randomNanos: cut[100; (100 * daysInYear)?1D];
//array of 365 elements, where each element is an array of 100 random dateTimes for given day
result: dates + randomNanos;
//put all the dates in single array
raze result
簡短的版本,其做同樣產生了2013年每天100個隨機時間戳低於:
raze (2013.01.01D+01D * til 365) + cut[100; (100*365)?1D]
爲了模擬數據,一天,可以生成隨機時間(如浮點數小於1)並將它們添加到您想要生成數據的那一天。在這種情況下:
D:2016.03.01;
D+100?1f
將在2016.03.01返回100個隨機時間。如果你想在一個時間範圍內生成數據,你可以將float的大小限制在小於1或者大於某個最小值。
如果您想要處理閏年......除了將最大天數添加到一年的開始時間以及詢問是否是第31天之外,還不確定更好的方法。加上366,它可以是31或1。如果它是第31條,否則放棄最後的日期。
/e.g.
q)last 2015.01.01+til 365
2015.12.31
q)last 2016.01.01+til 365
2016.12.30 /we are a day short
q)
/return the dates and the number of days based on whether its a leap year
q)dd:$[31i~`dd$last d:2016.01.01+til 366;(366;d);(365;-1_d)]
q)/returns (366;2016.01.01 2016.01.02...)
q)/the actual logic below is pretty much the same as the other answer
q)raze{[n;dy;dt] dt+n cut(n*dy)?.z.N}[100;].dd
2016.01.01D16:06:53.957527121 2016.01.01D10:55:10.892935198 2016.01.01D15:36:..