@@ -58,7 +58,7 @@ var htmlSecondHalf string = `<hr>
58
58
59
59
type entry struct {
60
60
Label string
61
- Value int
61
+ Value float64
62
62
}
63
63
64
64
// Create custom type that implements 'sort.Interface' for easier sorting
@@ -155,7 +155,7 @@ func createBarChart(r *http.Request) string {
155
155
key = strings .Replace (key , "%20" , " " , - 1 )
156
156
}
157
157
158
- entries = append (entries , entry {Label : key , Value : count })
158
+ entries = append (entries , entry {Label : key , Value : float64 ( count ) })
159
159
if count > maxValue {
160
160
maxValue = count
161
161
}
@@ -185,11 +185,11 @@ func createBarChart(r *http.Request) string {
185
185
186
186
avg := math .Round (float64 (total ) / float64 (len (entries )))
187
187
188
- entries = append (entries , entry {Label : "Avg." , Value : int ( avg ) })
189
- orderedParams = append (orderedParams , fmt .Sprintf ("%s=%d " , "Avg." , int ( avg ) ))
188
+ entries = append (entries , entry {Label : "Avg." , Value : avg })
189
+ orderedParams = append (orderedParams , fmt .Sprintf ("%s=%f " , "Avg." , avg ))
190
190
191
- entries = append (entries , entry {Label : "Total" , Value : total })
192
- orderedParams = append (orderedParams , fmt .Sprintf ("%s=%d " , "Total" , total ))
191
+ entries = append (entries , entry {Label : "Total" , Value : float64 ( total ) })
192
+ orderedParams = append (orderedParams , fmt .Sprintf ("%s=%f " , "Total" , float64 ( total ) ))
193
193
194
194
increment := float64 (maxValue ) / 25.0
195
195
@@ -220,13 +220,22 @@ func createBarChart(r *http.Request) string {
220
220
bar := calculateBars (barChunks , remainder )
221
221
chartContent .WriteString (
222
222
fmt .Sprintf (
223
- "%s %4d %s\n " ,
224
- padRight (entries [i ].Label , longestLabelLength ), entries [i ].Value , bar ,
223
+ "%s %s %s\n " ,
224
+ padRight (entries [i ].Label , longestLabelLength ),
225
+ padRight (fmt .Sprintf ("%.2f" , entries [i ].Value ), len (fmt .Sprintf ("%.2f" , float64 (total )))),
226
+ bar ,
225
227
),
226
228
)
227
229
}
228
230
bar := calculateBars (maximumBarChunk , 0 )
229
- chartContent .WriteString (fmt .Sprintf ("%s %4d %s\n " , padRight ("Total" , longestLabelLength ), total , bar ))
231
+ chartContent .WriteString (
232
+ fmt .Sprintf (
233
+ "%s %s %s\n " ,
234
+ padRight ("Total" , longestLabelLength ),
235
+ padRight (fmt .Sprintf ("%.2f" , float64 (total )), 1 ),
236
+ bar ,
237
+ ),
238
+ )
230
239
return chartContent .String ()
231
240
}
232
241
0 commit comments