forked from arschles/pc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeakers.go
78 lines (69 loc) · 1.54 KB
/
speakers.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"encoding/json"
"fmt"
"os"
"sort"
"strings"
"github.com/olekukonko/tablewriter"
)
func speakers(id int) {
f, err := os.Open(fmt.Sprintf("papercall.%d.json", id))
check(err)
var subs []*Submission
dec := json.NewDecoder(f)
err = dec.Decode(&subs)
check(err)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"name", "email", "shirt size", "talks"})
type p struct {
Profile
submissions []*Submission
}
profiles := make(map[string]p)
for _, s := range subs {
prof := profiles[s.Profile.Name]
prof.Profile = *s.Profile
switch s.State {
case "submitted", "accepted":
prof.submissions = append(prof.submissions, s)
}
profiles[s.Profile.Name] = prof
}
var keys []string
for k := range profiles {
keys = append(keys, k)
}
sort.Strings(keys)
var rows, n int
for _, k := range keys {
prof := profiles[k]
table.Append([]string{
prof.Name,
prof.Email,
prof.ShirtSize,
summarise(prof.submissions),
})
rows++
n += len(prof.submissions)
}
table.SetFooter([]string{"Count", fmt.Sprintf("%d", rows), "Proposals", fmt.Sprintf("%d", n)})
table.Render()
}
func summarise(subs []*Submission) string {
s := make(map[string]int)
for _, sub := range subs {
s[strings.SplitN(sub.Format, " ", -1)[0]]++
}
var r string
if n, ok := s["Keynote"]; ok {
r += fmt.Sprintf("Keynote (%d) ", n)
}
if n, ok := s["Tutorial"]; ok {
r += fmt.Sprintf("Tutorial (%d) ", n)
}
if n, ok := s["Workshop"]; ok {
r += fmt.Sprintf("Workshop (%d) ", n)
}
return strings.TrimRight(r, " ")
}