Add result testkeys projection

This commit is contained in:
Arturo Filastò 2018-09-10 15:03:52 +02:00
parent 73fafacc2c
commit 898332064b
2 changed files with 23 additions and 2 deletions

View File

@ -41,7 +41,6 @@ func init() {
output.SectionTitle("Incomplete results")
}
for idx, result := range incompleteResults {
output.ResultItem(output.ResultItemData{
ID: result.Result.ID,
Index: idx,
@ -68,6 +67,10 @@ func init() {
if err != nil {
log.WithError(err).Error("failed to list measurement counts")
}
testKeys, err := database.GetResultTestKeys(ctx.DB, result.Result.ID)
if err != nil {
log.WithError(err).Error("failed to get testKeys")
}
output.ResultItem(output.ResultItemData{
ID: result.Result.ID,
Index: idx,
@ -77,7 +80,7 @@ func init() {
NetworkName: result.Network.NetworkName,
Country: result.Network.CountryCode,
ASN: fmt.Sprintf("AS%d", result.Network.ASN),
TestKeys: "{}", // FIXME this used to be Summary we probably need to use a list now
TestKeys: testKeys,
MeasurementCount: totalCount,
MeasurementAnomalyCount: anmlyCount,
Done: result.IsDone,

View File

@ -37,6 +37,24 @@ func ListMeasurements(sess sqlbuilder.Database, resultID int64) ([]MeasurementUR
return measurements, nil
}
// GetResultTestKeys returns a list of TestKeys for a given measurements
func GetResultTestKeys(sess sqlbuilder.Database, resultID int64) (string, error) {
res := sess.Collection("measurements").Find("result_id", resultID)
defer res.Close()
var msmt Measurement
for res.Next(&msmt) {
if msmt.TestName == "web_connectivity" {
break
}
// We only really care about the NDT TestKeys
if msmt.TestName == "ndt" {
return msmt.TestKeys, nil
}
}
return "{}", nil
}
// GetMeasurementCounts returns the number of anomalous and total measurement for a given result
func GetMeasurementCounts(sess sqlbuilder.Database, resultID int64) (uint64, uint64, error) {
var (