Implement quick and dirty measurement listing
This commit is contained in:
parent
04eb07624c
commit
eb4e6988b3
@ -1,6 +1,8 @@
|
|||||||
package list
|
package list
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin"
|
"github.com/alecthomas/kingpin"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/ooni/probe-cli/internal/cli/root"
|
"github.com/ooni/probe-cli/internal/cli/root"
|
||||||
@ -11,12 +13,24 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
cmd := root.Command("list", "List results")
|
cmd := root.Command("list", "List results")
|
||||||
|
|
||||||
|
resultID := cmd.Arg("id", "the id of the result to list measurements for").Int64()
|
||||||
|
|
||||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||||
ctx, err := root.Init()
|
ctx, err := root.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("failed to initialize root context")
|
log.WithError(err).Error("failed to initialize root context")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if *resultID > 0 {
|
||||||
|
measurements, err := database.ListMeasurements(ctx.DB, *resultID)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("failed to list measurements")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for idx, msmt := range measurements {
|
||||||
|
fmt.Printf("%d: %v\n", idx, msmt)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
doneResults, incompleteResults, err := database.ListResults(ctx.DB)
|
doneResults, incompleteResults, err := database.ListResults(ctx.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("failed to list results")
|
log.WithError(err).Error("failed to list results")
|
||||||
@ -69,6 +83,7 @@ func init() {
|
|||||||
resultSummary.TotalNetworks = int64(len(netCount))
|
resultSummary.TotalNetworks = int64(len(netCount))
|
||||||
|
|
||||||
output.ResultSummary(resultSummary)
|
output.ResultSummary(resultSummary)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -10,7 +10,12 @@ func init() {
|
|||||||
cmd := root.Command("show", "Show a specific measurement")
|
cmd := root.Command("show", "Show a specific measurement")
|
||||||
|
|
||||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||||
log.Info("Show")
|
_, err := root.Init()
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("failed to initialize root context")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,42 @@ func UpdateOne(db *sqlx.DB, query string, arg interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListMeasurements given a result ID
|
||||||
|
func ListMeasurements(db *sqlx.DB, resultID int64) ([]*Measurement, error) {
|
||||||
|
measurements := []*Measurement{}
|
||||||
|
|
||||||
|
rows, err := db.Query(`SELECT id, name,
|
||||||
|
start_time, runtime,
|
||||||
|
country,
|
||||||
|
asn,
|
||||||
|
summary,
|
||||||
|
input
|
||||||
|
FROM measurements
|
||||||
|
WHERE result_id = ?
|
||||||
|
ORDER BY start_time;`, resultID)
|
||||||
|
if err != nil {
|
||||||
|
return measurements, errors.Wrap(err, "failed to get measurement list")
|
||||||
|
}
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
msmt := Measurement{}
|
||||||
|
err = rows.Scan(&msmt.ID, &msmt.Name,
|
||||||
|
&msmt.StartTime, &msmt.Runtime,
|
||||||
|
&msmt.CountryCode,
|
||||||
|
&msmt.ASN,
|
||||||
|
&msmt.Summary, &msmt.Input,
|
||||||
|
//&result.DataUsageUp, &result.DataUsageDown)
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("failed to fetch a row")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
measurements = append(measurements, &msmt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return measurements, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Measurement model
|
// Measurement model
|
||||||
type Measurement struct {
|
type Measurement struct {
|
||||||
ID int64 `db:"id"`
|
ID int64 `db:"id"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user