本文整理汇总了Golang中github.com/SoftwareDefinedBuildings/btrdb.Quasar.QueryStatisticalValuesStream方法的典型用法代码示例。如果您正苦于以下问题:Golang Quasar.QueryStatisticalValuesStream方法的具体用法?Golang Quasar.QueryStatisticalValuesStream怎么用?Golang Quasar.QueryStatisticalValuesStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/SoftwareDefinedBuildings/btrdb.Quasar
的用法示例。
在下文中一共展示了Quasar.QueryStatisticalValuesStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: request_get_CSV
func request_get_CSV(q *btrdb.Quasar, w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(&outstandingHttpReqs, 1)
defer func() {
atomic.AddInt32(&outstandingHttpReqs, -1)
}()
r.ParseForm()
ids := r.Form.Get(":uuid")
id := uuid.Parse(ids)
if id == nil {
log.Critical("ids: '%v'", ids)
doError(w, "malformed uuid")
return
}
st, ok, msg := parseInt(r.Form.Get("starttime"), -(16 << 56), (48 << 56))
if !ok {
doError(w, "bad start time: "+msg)
return
}
et, ok, msg := parseInt(r.Form.Get("endtime"), -(16 << 56), (48 << 56))
if !ok {
doError(w, "bad end time: "+msg)
return
}
if et <= st {
doError(w, "end time <= start time")
return
}
versions := r.Form.Get("ver")
if versions == "" {
versions = "0"
}
//Technically this is incorrect, but I doubt we will overflow this
versioni, ok, msg := parseInt(versions, 0, 1<<63-1)
version := uint64(versioni)
if !ok {
doError(w, "malformed version: "+msg)
return
}
if version == 0 {
version = btrdb.LatestGeneration
}
unitoftime := r.Form.Get("unitoftime")
divisor := int64(1)
switch unitoftime {
case "":
fallthrough
case "ms":
divisor = 1000000 //ns to ms
case "ns":
divisor = 1
case "us":
divisor = 1000 //ns to us
case "s":
divisor = 1000000000 //ns to s
default:
doError(w, "unitoftime must be 'ns', 'ms', 'us' or 's'")
return
}
if st >= btrdb.MaximumTime/divisor ||
st <= btrdb.MinimumTime/divisor {
doError(w, "start time out of bounds")
return
}
if et >= btrdb.MaximumTime/divisor ||
et <= btrdb.MinimumTime/divisor {
doError(w, "end time out of bounds")
return
}
st *= divisor
et *= divisor
pws := r.Form.Get("pw")
pw := uint8(0)
if pws != "" {
pwl, ok, msg := parseInt(pws, 0, 63)
if !ok {
doError(w, "bad point width: "+msg)
return
}
if divisor != 1 {
doError(w, "statistical results require unitoftime=ns")
return
}
pw = uint8(pwl)
}
logh("QSVSn", fmt.Sprintf("u=%s st=%v et=%v pw=%v", id.String(), st, et, pw), r)
rvchan, echan, _ := q.QueryStatisticalValuesStream(id, st, et, version, pw)
w.WriteHeader(200)
w.Write([]byte("Time[ns],Mean,Min,Max,Count\n"))
for {
select {
case v, ok := <-rvchan:
if ok {
w.Write([]byte(fmt.Sprintf("%d,%f,%f,%f,%d\n", v.Time, v.Mean, v.Min, v.Max, v.Count)))
} else {
//Done
return
}
case err, ok := <-echan:
if ok {
//.........这里部分代码省略.........
示例2: dispatchCommands
//.........这里部分代码省略.........
sendresp(rvseg)
return
}
records := NewRecords(rvseg)
rl := NewRecordList(rvseg, len(bufarr))
rla := rl.ToArray()
for i, v := range bufarr {
rla[i].SetTime(v.Time)
rla[i].SetValue(v.Val)
}
records.SetVersion(gen)
records.SetValues(rl)
resp.SetRecords(records)
resp.SetStatusCode(STATUSCODE_OK)
if fin {
resp.SetFinal(true)
}
sendresp(rvseg)
bufarr = bufarr[:0]
if fin {
return
}
}
}
case REQUEST_QUERYSTATISTICALVALUES:
st := req.QueryStatisticalValues().StartTime()
et := req.QueryStatisticalValues().EndTime()
uuid := uuid.UUID(req.QueryStatisticalValues().Uuid())
pw := req.QueryStatisticalValues().PointWidth()
ver := req.QueryStatisticalValues().Version()
if ver == 0 {
ver = btrdb.LatestGeneration
}
recordc, errorc, gen := q.QueryStatisticalValuesStream(uuid, st, et, ver, pw)
if recordc == nil {
log.Warning("RESPONDING ERR: %v", err)
resp, rvseg := mkresp()
resp.SetStatusCode(STATUSCODE_INTERNALERROR)
resp.SetFinal(true)
sendresp(rvseg)
return
} else {
bufarr := make([]qtree.StatRecord, 0, 4096)
for {
resp, rvseg := mkresp()
fail := false
fin := false
for {
select {
case _, ok := <-errorc:
if ok {
fin = true
fail = true
goto donestat
}
case r, ok := <-recordc:
if !ok {
fin = true
goto donestat
}
bufarr = append(bufarr, r)
if len(bufarr) == cap(bufarr) {
goto donestat
}
}
}
示例3: request_post_MULTICSV_IMPL
func request_post_MULTICSV_IMPL(q *btrdb.Quasar, w http.ResponseWriter, bdy io.Reader, r *http.Request) {
dec := json.NewDecoder(bdy)
req := multi_csv_req{}
err := dec.Decode(&req)
if err != nil {
doError(w, "bad request")
return
}
if len(req.UUIDS) != len(req.Labels) {
doError(w, "UUIDS and Labels must be the same length")
return
}
uids := make([]uuid.UUID, len(req.UUIDS))
for i := 0; i < len(uids); i++ {
uids[i] = uuid.Parse(req.UUIDS[i])
if uids[i] == nil {
doError(w, "UUID "+string(i)+" is malformed")
return
}
}
unitoftime := req.UnitofTime
divisor := int64(1)
switch unitoftime {
case "":
fallthrough
case "ms":
divisor = 1000000 //ns to ms
case "ns":
divisor = 1
case "us":
divisor = 1000 //ns to us
case "s":
divisor = 1000000000 //ns to s
default:
doError(w, "unitoftime must be 'ns', 'ms', 'us' or 's'")
return
}
if req.StartTime >= btrdb.MaximumTime/divisor ||
req.StartTime <= btrdb.MinimumTime/divisor {
doError(w, "start time out of bounds")
return
}
if req.EndTime >= btrdb.MaximumTime/divisor ||
req.EndTime <= btrdb.MinimumTime/divisor {
doError(w, "end time out of bounds")
return
}
st := req.StartTime * divisor
et := req.EndTime * divisor
if req.PointWidth < 0 || req.PointWidth >= 63 {
doError(w, "PointWidth must be between 0 and 63")
return
}
pw := uint8(req.PointWidth)
chanVs := make([]chan qtree.StatRecord, len(uids))
chanEs := make([]chan error, len(uids))
chanBad := make([]bool, len(uids))
chanHead := make([]qtree.StatRecord, len(uids))
for i := 0; i < len(uids); i++ {
logh("QSVS", fmt.Sprintf("u=%v st=%v et=%v pw=%v", uids[i].String(), st, et, pw), r)
chanVs[i], chanEs[i], _ = q.QueryStatisticalValuesStream(uids[i], st, et, btrdb.LatestGeneration, pw)
}
reload := func(c int) {
select {
case v, ok := <-chanVs[c]:
if ok {
chanHead[c] = v
} else {
chanBad[c] = true
}
case e, ok := <-chanEs[c]:
if ok {
log.Critical("MultiCSV error: ", e)
chanBad[c] = true
}
}
}
emit := func(r qtree.StatRecord) {
w.Write([]byte(fmt.Sprintf(",%d,%f,%f,%f", r.Count, r.Min, r.Mean, r.Max)))
}
emitb := func() {
w.Write([]byte(",,,,"))
}
emitt := func(t int64) {
w.Write([]byte(fmt.Sprintf("%d", t)))
}
emitnl := func() {
w.Write([]byte("\n"))
}
//Prime the first results
for i := 0; i < len(uids); i++ {
reload(i)
}
w.Header().Set("Content-Disposition", "attachment; filename=\"quasar_results.csv\"")
//Print the headers
w.Write([]byte("Time[ns]"))
for i := 0; i < len(uids); i++ {
w.Write([]byte(fmt.Sprintf(",%s(cnt),%s(min),%s(mean),%s(max)",
req.Labels[i],
req.Labels[i],
//.........这里部分代码省略.........