blob: d65e1e67141f9b943de2a49df9493d51712b71b3 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// slcli measured data listing support.
package main
import (
"fmt"
"v.io/v23/context"
"v.io/x/lib/cmdline"
"v.io/x/ref/lib/v23cmd"
"v.io/x/sensorlog_lite/internal/client"
"v.io/x/sensorlog_lite/internal/config"
"v.io/x/sensorlog_lite/internal/sbmodel"
"v.io/x/sensorlog_lite/internal/sbutil"
)
var cmdSLList = &cmdline.Command{
Runner: v23cmd.RunnerFunc(runSLList),
Name: "list",
Short: "List measured data",
Long: `
Prints all measured data points for the given stream and device, sorted
chronologically.
`,
ArgsName: "<device_id> <stream_id>",
ArgsLong: `
<device_id> and <stream_id> specify the data stream to print the data points
from.
`,
}
// TODO(ivanpi): Add time interval querying and aggregation functions.
func runSLList(ctx *context.T, env *cmdline.Env, args []string) error {
if len(args) != 2 {
return env.UsageErrorf("expects exactly 2 arguments")
}
streamKey := &sbmodel.KStreamDef{
DevId: args[0],
StreamId: args[1],
}
db, err := sbutil.CreateOrOpenDB(ctx, *flagSbService, sbmodel.MasterTables)
if err != nil {
return fmt.Errorf("failed opening Syncbase db: %v", err)
}
return client.ListStreamData(ctx, db, streamKey, func(key *sbmodel.KDataPoint, val sbmodel.VDataPoint) error {
fmt.Fprintf(env.Stdout, "%s %v\n", key.Timestamp.Format(config.TimeOutputFormat), val.Interface())
return nil
})
}