-
Notifications
You must be signed in to change notification settings - Fork 11
/
reports.go
54 lines (47 loc) · 1.2 KB
/
reports.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"time"
)
// SparkleStats datatype
type SparkleStats struct {
TopGiven []string `json:"top_given,omitempty"`
TopGivers []string `json:"top_givers,omitempty"`
FirstSparkle time.Time `json:"first_sparkle"`
SimilarUsers []string `json:"similar_users,omitempty"`
Categories []string `json:"categories"`
}
type SparkleGraph struct {
Edges []SparkleGraphEdge `json:"edges"`
}
type SparkleGraphEdge struct {
Sparkler string `json:"sparkler"`
Sparklee string `json:"sparklee"`
Weight int `json:"weight"`
}
func (s *SparkleDatabase) Graph() SparkleGraph {
var sg SparkleGraph
for _, v := range s.Sparkles {
// See if the edge already exists. If it does, increment the score.
// Otherwise, insert it.
exists := false
for k1, v1 := range sg.Edges {
if (v.Sparkler == v1.Sparkler && v.Sparklee == v1.Sparklee) {
sg.Edges[k1].Weight++
exists = true
}
}
if !exists {
// Construct an edge
var e SparkleGraphEdge
e.Sparkler = v.Sparkler
e.Sparklee = v.Sparklee
e.Weight = 1
sg.Edges = append(sg.Edges, e)
}
}
return sg
}
func StatsForUser(user string) SparkleStats {
var ss SparkleStats
return ss
}