Feature list sorting

This commit is contained in:
Jakob Borg
2015-09-30 08:29:41 +02:00
parent c8c4b090ef
commit 1ded36fcff
2 changed files with 24 additions and 9 deletions

View File

@@ -693,11 +693,14 @@ func getReport(db *sql.DB) map[string]interface{} {
featureNames = append(featureNames, key)
}
sort.Strings(featureNames)
for _, key := range featureNames {
featureList = append(featureList, feature{
Key: key,
Pct: (100 * features[key]) / v2Reports,
})
if v2Reports > 0 {
for _, key := range featureNames {
featureList = append(featureList, feature{
Key: key,
Pct: (100 * features[key]) / v2Reports,
})
}
sort.Sort(sort.Reverse(sortableFeatureList(featureList)))
}
r := make(map[string]interface{})
@@ -881,3 +884,15 @@ func getMovement(db *sql.DB) ([][]interface{}, error) {
return res, nil
}
type sortableFeatureList []feature
func (l sortableFeatureList) Len() int {
return len(l)
}
func (l sortableFeatureList) Swap(a, b int) {
l[a], l[b] = l[b], l[a]
}
func (l sortableFeatureList) Less(a, b int) bool {
return l[a].Pct < l[b].Pct
}