Add support for generating the Measurement summary
To generate the result summary we need to refactor how the SummaryMap works
This commit is contained in:
parent
00859e87a6
commit
f5ff3ac87a
|
@ -129,13 +129,19 @@ func (m *Measurement) WriteSummary(db *sqlx.DB, summary string) error {
|
|||
|
||||
// AddToResult adds a measurement to a result
|
||||
func (m *Measurement) AddToResult(db *sqlx.DB, result *Result) error {
|
||||
var err error
|
||||
|
||||
m.ResultID = result.ID
|
||||
finalPath := filepath.Join(result.MeasurementDir,
|
||||
filepath.Base(m.ReportFilePath))
|
||||
|
||||
err := os.Rename(m.ReportFilePath, finalPath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "moving report file")
|
||||
// If the finalPath already exists, it means it has already been moved there.
|
||||
// This happens in multi input reports
|
||||
if _, err = os.Stat(finalPath); os.IsNotExist(err) {
|
||||
err = os.Rename(m.ReportFilePath, finalPath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "moving report file")
|
||||
}
|
||||
}
|
||||
m.ReportFilePath = finalPath
|
||||
|
||||
|
|
|
@ -37,6 +37,12 @@ type IMSummary struct {
|
|||
Detected bool
|
||||
}
|
||||
|
||||
// WebsitesSummary is the summary for the websites test
|
||||
type WebsitesSummary struct {
|
||||
Tested uint
|
||||
Blocked uint
|
||||
}
|
||||
|
||||
// NettestGroups that can be run by the user
|
||||
var NettestGroups = map[string]NettestGroup{
|
||||
"websites": NettestGroup{
|
||||
|
@ -45,6 +51,7 @@ var NettestGroups = map[string]NettestGroup{
|
|||
websites.WebConnectivity{},
|
||||
},
|
||||
Summary: func(m database.SummaryMap) (string, error) {
|
||||
// XXX to generate this I need to create the summary map as a list
|
||||
return "{}", nil
|
||||
},
|
||||
},
|
||||
|
|
|
@ -11,11 +11,13 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// URLInfo contains the URL and the citizenlab category code for that URL
|
||||
type URLInfo struct {
|
||||
URL string `json:"url"`
|
||||
CategoryCode string `json:"category_code"`
|
||||
}
|
||||
|
||||
// URLResponse is the orchestrate url response containing a list of URLs
|
||||
type URLResponse struct {
|
||||
Results []URLInfo `json:"results"`
|
||||
}
|
||||
|
@ -69,9 +71,46 @@ func (n WebConnectivity) Run(ctl *nettests.Controller) error {
|
|||
return nt.Run()
|
||||
}
|
||||
|
||||
// WebConnectivitySummary for the test
|
||||
type WebConnectivitySummary struct {
|
||||
Accessible bool
|
||||
Blocking string
|
||||
Blocked bool
|
||||
}
|
||||
|
||||
// Summary generates a summary for a test run
|
||||
func (n WebConnectivity) Summary(tk map[string]interface{}) interface{} {
|
||||
return nil
|
||||
var (
|
||||
blocked bool
|
||||
blocking string
|
||||
accessible bool
|
||||
)
|
||||
|
||||
// We need to do these complicated type assertions, because some of the fields
|
||||
// are "nullable" and/or can be of different types
|
||||
switch v := tk["blocking"].(type) {
|
||||
case bool:
|
||||
blocked = false
|
||||
blocking = "none"
|
||||
case string:
|
||||
blocked = true
|
||||
blocking = v
|
||||
default:
|
||||
blocked = false
|
||||
blocking = "none"
|
||||
}
|
||||
|
||||
if tk["accessible"] == nil {
|
||||
accessible = false
|
||||
} else {
|
||||
accessible = tk["accessible"].(bool)
|
||||
}
|
||||
|
||||
return WebConnectivitySummary{
|
||||
Accessible: accessible,
|
||||
Blocking: blocking,
|
||||
Blocked: blocked,
|
||||
}
|
||||
}
|
||||
|
||||
// LogSummary writes the summary to the standard output
|
||||
|
|
Loading…
Reference in New Issue
Block a user