Skip to content
Snippets Groups Projects
Verified Commit f5a702f6 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fixed statistics

parent 405dbff0
No related branches found
No related tags found
No related merge requests found
...@@ -181,7 +181,7 @@ func main() { ...@@ -181,7 +181,7 @@ func main() {
func retrievePercentageStats(db *sql.DB, stats string) ([]FloatEntry, error) { func retrievePercentageStats(db *sql.DB, stats string) ([]FloatEntry, error) {
var data []FloatEntry var data []FloatEntry
result, err := db.Query("SELECT coalesce(users.nick, '[Unknown]'), t." + stats + " FROM (SELECT coalesce(groups.\"group\", messages.sender) AS hash, round((count(nullif(messages." + stats + ", false)) * 100) :: numeric / count(*)) as " + stats + " FROM messages LEFT JOIN groups ON messages.sender = groups.nick AND groups.channel = 1 WHERE messages.channel = 1 GROUP BY hash ORDER BY " + stats + " DESC) t LEFT JOIN users ON t.hash = users.hash LIMIT 2;") result, err := db.Query("SELECT coalesce(users.nick, '[Unknown]'), t." + stats + " FROM (SELECT coalesce(groups.\"group\", messages.sender) AS hash, round((count(nullif(messages." + stats + ", false)) * 100) :: numeric / count(*)) as " + stats + " FROM messages LEFT JOIN groups ON messages.sender = groups.nick AND groups.channel = 1 WHERE messages.channel = 1 GROUP BY hash ORDER BY " + stats + " DESC) t LEFT JOIN users ON t.hash = users.hash WHERE t." + stats + " > 0 LIMIT 2;")
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -53,84 +53,94 @@ ...@@ -53,84 +53,94 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{with index .Questions 0}} {{range $i, $e := .Questions}}
{{with $e}}
<tr> <tr>
{{if eq $i 0}}
<td>Is <b>{{.Name}}</b> stupid or just asking too many questions? {{.Value}}% of lines contained a question! <td>Is <b>{{.Name}}</b> stupid or just asking too many questions? {{.Value}}% of lines contained a question!
</td> </td>
</tr> {{ else }}
{{end}}
{{with index .Questions 1}}
<tr>
<td><b>{{.Name}}</b> didn't know that much either. {{.Value}}% of their lines were questions.</td> <td><b>{{.Name}}</b> didn't know that much either. {{.Value}}% of their lines were questions.</td>
{{end}}
</tr> </tr>
{{end}} {{end}}
{{end}}
</tbody> </tbody>
<tbody> <tbody>
{{with index .Exclamations 0}} {{range $i, $e := .Exclamations}}
{{with $e}}
<tr> <tr>
{{if eq $i 0}}
<td>The loudest one was <b>{{.Name}}</b>, who yelled {{.Value}}% of the time!</td> <td>The loudest one was <b>{{.Name}}</b>, who yelled {{.Value}}% of the time!</td>
</tr> {{ else }}
{{end}}
{{with index .Exclamations 1}}
<tr>
<td>Another <i>old yeller</i> was <b>{{.Name}}</b>, who shouted {{.Value}}% of the time!</td> <td>Another <i>old yeller</i> was <b>{{.Name}}</b>, who shouted {{.Value}}% of the time!</td>
{{end}}
</tr> </tr>
{{end}} {{end}}
{{end}}
</tbody> </tbody>
<tbody> <tbody>
{{with index .Caps 0}} {{range $i, $e := .Caps}}
{{with $e}}
<tr> <tr>
{{if eq $i 0}}
<td>It seems that <b>{{.Name}}</b>'s shift-key is hanging: {{.Value}}% of the time they wrote UPPERCASE.</td> <td>It seems that <b>{{.Name}}</b>'s shift-key is hanging: {{.Value}}% of the time they wrote UPPERCASE.</td>
</tr> {{ else }}
{{end}}
{{with index .Caps 1}}
<tr>
<td><b>{{.Name}}</b> just forgot to deactivate their Caps-Lock. They wrote UPPERCASE {{.Value}}% of the time. <td><b>{{.Name}}</b> just forgot to deactivate their Caps-Lock. They wrote UPPERCASE {{.Value}}% of the time.
</td> </td>
{{end}}
</tr> </tr>
{{end}} {{end}}
{{end}}
</tbody> </tbody>
<tbody> <tbody>
{{with index .EmojiHappy 0}} {{range $i, $e := .EmojiHappy}}
{{with $e}}
<tr> <tr>
{{if eq $i 0}}
<td><b>{{.Name}}</b> brings happiness to the world. {{.Value}}% lines contained smiling faces. :)</td> <td><b>{{.Name}}</b> brings happiness to the world. {{.Value}}% lines contained smiling faces. :)</td>
</tr> {{ else }}
{{end}}
{{with index .EmojiHappy 1}}
<tr>
<td><b>{{.Name}}</b> isn't a sad person either, smiling {{.Value}}% of the time.</td> <td><b>{{.Name}}</b> isn't a sad person either, smiling {{.Value}}% of the time.</td>
{{end}}
</tr> </tr>
{{end}} {{end}}
{{end}}
</tbody> </tbody>
<tbody> <tbody>
{{with index .EmojiSad 0}} {{range $i, $e := .EmojiSad}}
{{with $e}}
<tr> <tr>
{{if eq $i 0}}
<td><b>{{.Name}}</b> seems to be sad at the moment: {{.Value}}% lines contained sad faces. :(</td> <td><b>{{.Name}}</b> seems to be sad at the moment: {{.Value}}% lines contained sad faces. :(</td>
</tr> {{ else }}
{{end}}
{{with index .EmojiSad 1}}
<tr>
<td><b>{{.Name}}</b> is also a sad person, crying {{.Value}}% of the time.</td> <td><b>{{.Name}}</b> is also a sad person, crying {{.Value}}% of the time.</td>
{{end}}
</tr> </tr>
{{end}} {{end}}
{{end}}
</tbody> </tbody>
<tbody> <tbody>
{{with index .LongestLines 0}} {{range $i, $e := .LongestLines}}
{{with $e}}
<tr> <tr>
{{if eq $i 0}}
<td><b>{{.Name}}</b> wrote the longest lines, averaging {{printf "%.1f" .Value}} letters per line.</td> <td><b>{{.Name}}</b> wrote the longest lines, averaging {{printf "%.1f" .Value}} letters per line.</td>
{{end}}
</tr> </tr>
{{end}} {{end}}
{{end}}
</tbody> </tbody>
<tbody> <tbody>
{{with index .ShortestLines 0}} {{range $i, $e := .ShortestLines}}
{{with $e}}
<tr> <tr>
{{if eq $i 0}}
<td><b>{{.Name}}</b> wrote the shortest lines, averaging {{printf "%.1f" .Value}} characters per line.</td> <td><b>{{.Name}}</b> wrote the shortest lines, averaging {{printf "%.1f" .Value}} characters per line.</td>
</tr> {{ else }}
{{end}}
{{with index .ShortestLines 1}}
<tr>
<td><b>{{.Name}}</b> was tight-lipped, too, averaging {{printf "%.1f" .Value}} characters.</td> <td><b>{{.Name}}</b> was tight-lipped, too, averaging {{printf "%.1f" .Value}} characters.</td>
{{end}}
</tr> </tr>
{{end}} {{end}}
{{end}}
</tbody> </tbody>
</table> </table>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment