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

Fixes char/word/line stats

parent f5a702f6
Branches
No related tags found
No related merge requests found
...@@ -47,8 +47,9 @@ func formatTemplate(w http.ResponseWriter, templateName string, data interface{} ...@@ -47,8 +47,9 @@ func formatTemplate(w http.ResponseWriter, templateName string, data interface{}
type ChannelData struct { type ChannelData struct {
Id int Id int
Name string Name string
TotalWords int
TotalCharacters int TotalCharacters int
TotalWords int
TotalLines int
Users []UserData Users []UserData
Questions []FloatEntry Questions []FloatEntry
Exclamations []FloatEntry Exclamations []FloatEntry
...@@ -75,6 +76,7 @@ type UserData struct { ...@@ -75,6 +76,7 @@ type UserData struct {
Name string Name string
Total int Total int
Words int Words int
Lines int
LastSeen time.Time LastSeen time.Time
} }
...@@ -96,19 +98,19 @@ func main() { ...@@ -96,19 +98,19 @@ func main() {
println(err.Error()) println(err.Error())
return return
} }
err = db.QueryRow("SELECT SUM(characters), SUM(words) FROM messages WHERE channel = $1", channelData.Id).Scan(&channelData.TotalCharacters, &channelData.TotalWords) err = db.QueryRow("SELECT COUNT(*), SUM(characters), SUM(words) FROM messages WHERE channel = $1", channelData.Id).Scan(&channelData.TotalLines, &channelData.TotalCharacters, &channelData.TotalWords)
if err != nil { if err != nil {
println(err.Error()) println(err.Error())
return return
} }
result, err := db.Query("SELECT coalesce(users.nick, '[Unknown]'), t.characters, t.words, t.lastSeen FROM (SELECT coalesce(groups.\"group\", messages.sender) AS hash, SUM(messages.characters) as characters, SUM(messages.words) as words, MAX(messages.time) AS lastSeen FROM messages LEFT JOIN groups ON messages.sender = groups.nick AND groups.channel = 1 WHERE messages.channel = 1 GROUP BY hash ORDER BY characters DESC) t LEFT JOIN users ON t.hash = users.hash LIMIT 20") result, err := db.Query("SELECT coalesce(users.nick, '[Unknown]'), t.characters, t.words, t.lines, t.lastSeen FROM (SELECT coalesce(groups.\"group\", messages.sender) AS hash, SUM(messages.characters) as characters, SUM(messages.words) as words, COUNT(*) as lines, MAX(messages.time) AS lastSeen FROM messages LEFT JOIN groups ON messages.sender = groups.nick AND groups.channel = 1 WHERE messages.channel = 1 GROUP BY hash ORDER BY characters DESC) t LEFT JOIN users ON t.hash = users.hash LIMIT 20")
if err != nil { if err != nil {
println(err.Error()) println(err.Error())
return return
} }
for result.Next() { for result.Next() {
var info UserData var info UserData
err := result.Scan(&info.Name, &info.Total, &info.Words, &info.LastSeen) err := result.Scan(&info.Name, &info.Total, &info.Words, &info.Lines, &info.LastSeen)
if err != nil { if err != nil {
panic(err) panic(err)
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="#FFC107"> <meta name="apple-mobile-web-app-status-bar-style" content="#FFC107">
<link href="/assets/css/style.css" rel="stylesheet"> <link href="/assets/css/style.css" rel="stylesheet">
<p>Total: {{.TotalCharacters}} Characters, {{.TotalWords}} Words</p> <p>Total: {{.TotalCharacters}} Characters, {{.TotalWords}} Words, {{.TotalLines}} Lines</p>
<table> <table>
<thead> <thead>
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
</tr> </tr>
<tr> <tr>
<th>Nick</th> <th>Nick</th>
<th>Number of lines</th> <th>Number of Characters</th>
<th>Number of Words</th> <th>Number of Words</th>
<th>Number of Lines</th>
<th>Last seen</th> <th>Last seen</th>
</tr> </tr>
</thead> </thead>
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
<td>{{.Name}}</td> <td>{{.Name}}</td>
<td>{{.Total}}</td> <td>{{.Total}}</td>
<td>{{.Words}}</td> <td>{{.Words}}</td>
<td>{{.Lines}}</td>
<td>{{.LastSeen.Format "2006-01-02"}}</td> <td>{{.LastSeen.Format "2006-01-02"}}</td>
</tr> </tr>
{{end}} {{end}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment