Skip to content

Commit f76730b

Browse files
committed
feat: add WIP code
1 parent 946f201 commit f76730b

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

chart.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var htmlSecondHalf string = `<hr>
5858

5959
type entry struct {
6060
Label string
61-
Value int
61+
Value float64
6262
}
6363

6464
// Create custom type that implements 'sort.Interface' for easier sorting
@@ -155,7 +155,7 @@ func createBarChart(r *http.Request) string {
155155
key = strings.Replace(key, "%20", " ", -1)
156156
}
157157

158-
entries = append(entries, entry{Label: key, Value: count})
158+
entries = append(entries, entry{Label: key, Value: float64(count)})
159159
if count > maxValue {
160160
maxValue = count
161161
}
@@ -185,11 +185,11 @@ func createBarChart(r *http.Request) string {
185185

186186
avg := math.Round(float64(total) / float64(len(entries)))
187187

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))
190190

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)))
193193

194194
increment := float64(maxValue) / 25.0
195195

@@ -220,13 +220,22 @@ func createBarChart(r *http.Request) string {
220220
bar := calculateBars(barChunks, remainder)
221221
chartContent.WriteString(
222222
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,
225227
),
226228
)
227229
}
228230
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+
)
230239
return chartContent.String()
231240
}
232241

examplequery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131
"February", "March", "April", "May", "June", "July", "August", "September",
3232
},
3333
Values: []string{
34-
"15", "23", "29", "23", "23", "20", "9", "10",
34+
"14.71", "22.83", "28.57", "22.58", "23.29", "20.29", "9.30", "9.52",
3535
},
3636
}
3737
Examples = exampleQueries{presidentQuery, terraformQuery}

0 commit comments

Comments
 (0)