Add hooks for generating result summaries
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package groups
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/openobservatory/gooni/internal/database"
|
||||
"github.com/openobservatory/gooni/nettests"
|
||||
"github.com/openobservatory/gooni/nettests/performance"
|
||||
"github.com/openobservatory/gooni/nettests/websites"
|
||||
@@ -10,7 +14,15 @@ import (
|
||||
type NettestGroup struct {
|
||||
Label string
|
||||
Nettests []nettests.Nettest
|
||||
Summary func(s string) string
|
||||
Summary database.ResultSummaryFunc
|
||||
}
|
||||
|
||||
// PerformanceSummary is the result summary for a performance test
|
||||
type PerformanceSummary struct {
|
||||
Upload int64
|
||||
Download int64
|
||||
Ping float64
|
||||
Bitrate int64
|
||||
}
|
||||
|
||||
// NettestGroups that can be run by the user
|
||||
@@ -20,8 +32,8 @@ var NettestGroups = map[string]NettestGroup{
|
||||
Nettests: []nettests.Nettest{
|
||||
websites.WebConnectivity{},
|
||||
},
|
||||
Summary: func(s string) string {
|
||||
return "{}"
|
||||
Summary: func(m database.SummaryMap) (string, error) {
|
||||
return "{}", nil
|
||||
},
|
||||
},
|
||||
"performance": NettestGroup{
|
||||
@@ -30,22 +42,46 @@ var NettestGroups = map[string]NettestGroup{
|
||||
performance.Dash{},
|
||||
performance.NDT{},
|
||||
},
|
||||
Summary: func(s string) string {
|
||||
return "{}"
|
||||
Summary: func(m database.SummaryMap) (string, error) {
|
||||
var (
|
||||
err error
|
||||
ndtSummary performance.NDTSummary
|
||||
dashSummary performance.DashSummary
|
||||
summary PerformanceSummary
|
||||
)
|
||||
err = json.Unmarshal([]byte(m["Dash"]), &dashSummary)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("failed to unmarshal Dash summary")
|
||||
return "", err
|
||||
}
|
||||
err = json.Unmarshal([]byte(m["Ndt"]), &ndtSummary)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("failed to unmarshal Dash summary")
|
||||
return "", err
|
||||
}
|
||||
summary.Bitrate = dashSummary.Bitrate
|
||||
summary.Download = ndtSummary.Download
|
||||
summary.Upload = ndtSummary.Upload
|
||||
summary.Ping = ndtSummary.AvgRTT
|
||||
summaryBytes, err := json.Marshal(summary)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(summaryBytes), nil
|
||||
},
|
||||
},
|
||||
"middleboxes": NettestGroup{
|
||||
Label: "Middleboxes",
|
||||
Nettests: []nettests.Nettest{},
|
||||
Summary: func(s string) string {
|
||||
return "{}"
|
||||
Summary: func(m database.SummaryMap) (string, error) {
|
||||
return "{}", nil
|
||||
},
|
||||
},
|
||||
"im": NettestGroup{
|
||||
Label: "Instant Messaging",
|
||||
Nettests: []nettests.Nettest{},
|
||||
Summary: func(s string) string {
|
||||
return "{}"
|
||||
Summary: func(m database.SummaryMap) (string, error) {
|
||||
return "{}", nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user