-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathoutput.go
198 lines (170 loc) · 4.62 KB
/
output.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package main
import (
//"strings"
"fmt"
"math"
"github.com/fogleman/gg"
)
func PrintLayout(keys []string) {
for i, k := range keys {
fmt.Printf("%s ", k)
if (i+1) % 5 == 0 {
fmt.Printf(" ")
}
if (i+1) % 10 == 0 {
fmt.Println()
if StaggerFlag {
if i == 9 {
fmt.Printf(" ")
} else {
fmt.Printf(" ")
}
}
}
}
}
func PrintAnalysis(l Layout) {
fmt.Println(l.Name)
PrintLayout(l.Keys)
k := l.Keys
//tri := Trigrams(k)
ftri := FastTrigrams(l, 500)
//total := float64(Data.Total)
ftotal := float64(ftri[4])
//fmt.Printf("Rolls: %.2f%%\n", float64(100*Rolls(k)) / total)
fmt.Printf("Rolls: ~%.2f%%\n", 100*float64(ftri[0]) / ftotal)
//fmt.Printf("Alternates: %.2f%%\n", float64(100*tri[1]) / total)
fmt.Printf("Alternates: ~%.2f%%\n", 100*float64(ftri[1]) / ftotal)
//fmt.Printf("Onehands: %.2f%%\n", float64(100*tri[2]) / total)
fmt.Printf("Onehands: ~%.2f%%\n", 100*float64(ftri[2]) / ftotal)
//fmt.Printf("Redirects: %.2f%%\n", float64(100*Redirects(k)) / total)
fmt.Printf("Redirects: ~%.2f%%\n", 100*float64(ftri[3]) / ftotal)
speeds := FingerSpeed(k)
speed, highestWeighted, f := WeightedSpeed(speeds)
highestWeightedFinger := FingerNames[f]
var highestUnweightedFinger string
var highestUnweighted float64
var unweighted float64
for i, v := range speeds {
unweighted += v
if v > highestUnweighted {
highestUnweighted = v
highestUnweightedFinger = FingerNames[i]
}
}
fmt.Printf("Finger Speed (weighted): %.2f\n", speed)
fmt.Printf("Finger Speed (unweighted): %.2f\n", unweighted)
fmt.Printf("Highest Speed (weighted): %.2f (%s)\n", highestWeighted, highestWeightedFinger)
fmt.Printf("Highest Speed (unweighted): %.2f (%s)\n", highestUnweighted, highestUnweightedFinger)
left, right := IndexUsage(l.Keys)
fmt.Printf("Index Usage: %.1f%% %1.f%%\n", left, right)
var sfb int
var sfbs []FreqPair
if !DynamicFlag {
sfb = SFBs(k)
sfbs = ListSFBs(k)
} else {
_, sfbs = ListRepeats(k)
sfb, _ = SFBsMinusTop(k)
}
fmt.Printf("SFBs: %.3f%%\n", 100*float64(sfb)/float64(Data.TotalBigrams))
fmt.Printf("DSFBs: %.3f%%\n", 100*float64(DSFBs(k))/float64(Data.TotalBigrams))
dsfbs := ListDSFBs(k)
SortFreqList(sfbs)
SortFreqList(dsfbs)
fmt.Println("Top SFBs:")
PrintFreqList(sfbs, 8)
fmt.Println("Top DSFBs:")
PrintFreqList(dsfbs, 16)
if DynamicFlag {
dynamic, _ := ListRepeats(k)
SortFreqList(dynamic)
fmt.Println("Dynamic Completions:")
PrintFreqList(dynamic, 30)
}
fmt.Printf("Score: %.2f\n", Score(l))
fmt.Println()
}
// func InteractiveAnalysis(l Layout) {
// tracked := []string{"sfb", "dsfb", "highest_speed"}
// for {
// fmt.Printf(":")
// var input string
// fmt.Scanln(&input)
// terms := strings.Split(input, " ")
// command := terms[0]
// switch command {
// case "track":
// if len(terms) <= 1 {
// for _, v := range tracked {
// fmt.Printf("\t%s\n", v)
// }
// } else {
// fmt.Println(terms[1:])
// }
// case "sfb":
// fmt.Printf("%.4f%%\n", sfb_cmd(l))
// case "dsfb":
// fmt.Printf("%.4f%%\n", dsfb_cmd(l))
// case "printl":
// printl_cmd(l)
// case "printl_s":
// printl_s_cmd(l)
// }
// }
// }
// func sfb_cmd(l string) float64 {
// return 100*float64(SFBs(l))/float64(Data.TotalBigrams)
// }
// func dsfb_cmd(l string) float64 {
// return 100*float64(DSFBs(l))/float64(Data.TotalBigrams)
// }
// func printl_cmd(l string) {
// PrintLayout(l)
// }
// func printl_s_cmd(l string) {
// fmt.Println(l)
// }
func PrintFreqList(list []FreqPair, length int) {
for i, v := range list[0:length] {
fmt.Printf("\t%s %.3f%%", v.Bigram, 100*float64(v.Count)/float64(Data.TotalBigrams))
if (i+1)%4 == 0 {
fmt.Println()
}
}
fmt.Println()
}
func Heatmap(l []string) {
dc := gg.NewContext(500, 170)
cols := []float64{0,0,0,0,0,0,0,0,0,0}
for i, r := range l {
c := r
col, row := ColRow(i)
dc.DrawRectangle(float64(50*col), float64(50*row), 50, 50)
freq := float64(Data.Letters[c]) / float64(Data.Total)
cols[col] += freq
pc := freq/0.1 //percent
log := math.Log(1+pc)
base := 0.3
dc.SetRGB(0.8*(base+log), base*(1-pc), base+log)
dc.Fill()
dc.SetRGB(0, 0, 0)
dc.DrawString(c, 22.5+float64(50*col), 27.5+float64(50*row))
}
speeds := FingerSpeed(l)
_, highest, _ := WeightedSpeed(speeds)
for i, c := range cols {
dc.DrawRectangle(float64(50*i), 150, 50, 10)
pc := c / 0.2
log := math.Log(1+pc)
base := 0.3
dc.SetRGB(0.8*(base+log), base*(1-pc), base+log)
dc.Fill()
dc.DrawRectangle(float64(50*i), 160, 50, 10)
speed := speeds[finger(i)] / (10*highest)
log = math.Log(1+speed)
dc.SetRGB(0.5*(base+log), base, base+log)
dc.Fill()
}
dc.SavePNG("heatmap.png")
}