2018-02-07 19:02:18 +01:00
|
|
|
package list
|
|
|
|
|
|
|
|
import (
|
2018-06-22 12:12:35 +02:00
|
|
|
"fmt"
|
|
|
|
|
2018-02-07 19:02:18 +01:00
|
|
|
"github.com/alecthomas/kingpin"
|
2018-02-21 16:06:30 +01:00
|
|
|
"github.com/apex/log"
|
2018-05-03 14:59:55 +02:00
|
|
|
"github.com/ooni/probe-cli/internal/cli/root"
|
2018-05-03 18:40:52 +02:00
|
|
|
"github.com/ooni/probe-cli/internal/database"
|
|
|
|
"github.com/ooni/probe-cli/internal/output"
|
2018-02-07 19:02:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-05-03 18:40:52 +02:00
|
|
|
cmd := root.Command("list", "List results")
|
2018-02-07 19:02:18 +01:00
|
|
|
|
2018-06-22 12:12:35 +02:00
|
|
|
resultID := cmd.Arg("id", "the id of the result to list measurements for").Int64()
|
|
|
|
|
2018-02-07 19:02:18 +01:00
|
|
|
cmd.Action(func(_ *kingpin.ParseContext) error {
|
2018-05-03 18:40:52 +02:00
|
|
|
ctx, err := root.Init()
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to initialize root context")
|
|
|
|
return err
|
|
|
|
}
|
2018-06-22 12:12:35 +02:00
|
|
|
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)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to list results")
|
|
|
|
return err
|
|
|
|
}
|
2018-05-03 18:40:52 +02:00
|
|
|
|
2018-06-22 12:12:35 +02:00
|
|
|
if len(incompleteResults) > 0 {
|
|
|
|
output.SectionTitle("Incomplete results")
|
|
|
|
}
|
|
|
|
for idx, result := range incompleteResults {
|
|
|
|
output.ResultItem(output.ResultItemData{
|
|
|
|
ID: result.ID,
|
|
|
|
Index: idx,
|
|
|
|
TotalCount: len(incompleteResults),
|
|
|
|
Name: result.Name,
|
|
|
|
StartTime: result.StartTime,
|
|
|
|
NetworkName: result.NetworkName,
|
|
|
|
Country: result.Country,
|
|
|
|
ASN: result.ASN,
|
|
|
|
Summary: result.Summary,
|
|
|
|
Done: result.Done,
|
|
|
|
DataUsageUp: result.DataUsageUp,
|
|
|
|
DataUsageDown: result.DataUsageDown,
|
|
|
|
})
|
|
|
|
}
|
2018-06-22 11:53:10 +02:00
|
|
|
|
2018-06-22 12:12:35 +02:00
|
|
|
resultSummary := output.ResultSummaryData{}
|
|
|
|
netCount := make(map[string]int)
|
|
|
|
output.SectionTitle("Results")
|
|
|
|
for idx, result := range doneResults {
|
|
|
|
output.ResultItem(output.ResultItemData{
|
|
|
|
ID: result.ID,
|
|
|
|
Index: idx,
|
|
|
|
TotalCount: len(doneResults),
|
|
|
|
Name: result.Name,
|
|
|
|
StartTime: result.StartTime,
|
|
|
|
NetworkName: result.NetworkName,
|
|
|
|
Country: result.Country,
|
|
|
|
ASN: result.ASN,
|
|
|
|
Summary: result.Summary,
|
|
|
|
Done: result.Done,
|
|
|
|
DataUsageUp: result.DataUsageUp,
|
|
|
|
DataUsageDown: result.DataUsageDown,
|
|
|
|
})
|
|
|
|
resultSummary.TotalTests++
|
|
|
|
netCount[result.ASN]++
|
|
|
|
resultSummary.TotalDataUsageUp += result.DataUsageUp
|
|
|
|
resultSummary.TotalDataUsageDown += result.DataUsageDown
|
|
|
|
}
|
|
|
|
resultSummary.TotalNetworks = int64(len(netCount))
|
2018-06-22 11:53:10 +02:00
|
|
|
|
2018-06-22 12:12:35 +02:00
|
|
|
output.ResultSummary(resultSummary)
|
|
|
|
}
|
2018-06-22 11:53:10 +02:00
|
|
|
|
2018-02-07 19:02:18 +01:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|