Skip to content

Commit

Permalink
feat: add WIP code
Browse files Browse the repository at this point in the history
  • Loading branch information
usrme committed Jun 25, 2024
1 parent 946f201 commit f76730b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var htmlSecondHalf string = `<hr>

type entry struct {
Label string
Value int
Value float64
}

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

entries = append(entries, entry{Label: key, Value: count})
entries = append(entries, entry{Label: key, Value: float64(count)})
if count > maxValue {
maxValue = count
}
Expand Down Expand Up @@ -185,11 +185,11 @@ func createBarChart(r *http.Request) string {

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

entries = append(entries, entry{Label: "Avg.", Value: int(avg)})
orderedParams = append(orderedParams, fmt.Sprintf("%s=%d", "Avg.", int(avg)))
entries = append(entries, entry{Label: "Avg.", Value: avg})
orderedParams = append(orderedParams, fmt.Sprintf("%s=%f", "Avg.", avg))

entries = append(entries, entry{Label: "Total", Value: total})
orderedParams = append(orderedParams, fmt.Sprintf("%s=%d", "Total", total))
entries = append(entries, entry{Label: "Total", Value: float64(total)})
orderedParams = append(orderedParams, fmt.Sprintf("%s=%f", "Total", float64(total)))

increment := float64(maxValue) / 25.0

Expand Down Expand Up @@ -220,13 +220,22 @@ func createBarChart(r *http.Request) string {
bar := calculateBars(barChunks, remainder)
chartContent.WriteString(
fmt.Sprintf(
"%s %4d %s\n",
padRight(entries[i].Label, longestLabelLength), entries[i].Value, bar,
"%s %s %s\n",
padRight(entries[i].Label, longestLabelLength),
padRight(fmt.Sprintf("%.2f", entries[i].Value), len(fmt.Sprintf("%.2f", float64(total)))),
bar,
),
)
}
bar := calculateBars(maximumBarChunk, 0)
chartContent.WriteString(fmt.Sprintf("%s %4d %s\n", padRight("Total", longestLabelLength), total, bar))
chartContent.WriteString(
fmt.Sprintf(
"%s %s %s\n",
padRight("Total", longestLabelLength),
padRight(fmt.Sprintf("%.2f", float64(total)), 1),
bar,
),
)
return chartContent.String()
}

Expand Down
2 changes: 1 addition & 1 deletion examplequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
"February", "March", "April", "May", "June", "July", "August", "September",
},
Values: []string{
"15", "23", "29", "23", "23", "20", "9", "10",
"14.71", "22.83", "28.57", "22.58", "23.29", "20.29", "9.30", "9.52",
},
}
Examples = exampleQueries{presidentQuery, terraformQuery}
Expand Down

0 comments on commit f76730b

Please sign in to comment.