mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 14:41:02 +00:00
first round time bitmap id
This commit is contained in:
parent
c258de14a8
commit
c81c7229cf
2 changed files with 76 additions and 0 deletions
52
index/timeframe.go
Normal file
52
index/timeframe.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package index
|
||||
|
||||
import "time"
|
||||
|
||||
type TimeQuantum uint
|
||||
|
||||
const (
|
||||
Y TimeQuantum = 0
|
||||
YM
|
||||
YMD
|
||||
YMDH
|
||||
)
|
||||
|
||||
func PackTimeBits(t TimeQuantum, year uint, month uint, day uint, hour uint) uint64 {
|
||||
v := uint64((uint(t) << 30) | (year << 24) | (month << 20) | (day << 15) | (hour << 10))
|
||||
v = v << 32
|
||||
return v
|
||||
}
|
||||
|
||||
func getTimeIds(tile_id uint64, atime time.Time, min_quantum TimeQuantum, offset uint) []uint64 {
|
||||
results := make([]uint64, 0, 4)
|
||||
year := uint(atime.Year()) - offset
|
||||
month := atime.Month()
|
||||
day := atime.Day()
|
||||
hour := atime.Hour()
|
||||
|
||||
if min_quantum <= Y {
|
||||
id := PackTimeBits(Y, year, 0, 0, 0)
|
||||
id = id | tile_id
|
||||
results = append(results, id)
|
||||
}
|
||||
|
||||
if min_quantum <= YM {
|
||||
id := PackTimeBits(YM, uint(year), uint(month), 0, 0)
|
||||
id = id | tile_id
|
||||
results = append(results, id)
|
||||
}
|
||||
|
||||
if min_quantum <= YMD {
|
||||
id := PackTimeBits(YMD, year, uint(month), uint(day), 0)
|
||||
id = id | tile_id
|
||||
results = append(results, id)
|
||||
}
|
||||
|
||||
if min_quantum <= YMDH {
|
||||
id := PackTimeBits(Y, year, uint(month), uint(day), uint(hour))
|
||||
id = id | tile_id
|
||||
results = append(results, id)
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
24
index/timeframe_test.go
Normal file
24
index/timeframe_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package index
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestTimeFrame(t *testing.T) {
|
||||
|
||||
Convey("Test ID", t, func() {
|
||||
const shortForm = "2006-01-02 15:04"
|
||||
x, _ := time.Parse(shortForm, "2014-01-01 10:03")
|
||||
fmt.Println(x)
|
||||
|
||||
m := getTimeIds(uint64(1), x, YMDH, 2014)
|
||||
spew.Dump(m)
|
||||
So(1, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue