mirror of
https://github.com/thebaer/tildes.git
synced 2018-07-20 07:15:21 +00:00
Merge branch 'master' of github.com:thebaer/tildes
This commit is contained in:
commit
865d4a1b0a
@ -1,11 +1,11 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"strings"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Row struct {
|
||||
@ -41,10 +41,12 @@ func ReadRows(path, delimiter string) *[]Row {
|
||||
}
|
||||
|
||||
func WriteData(path string, data []byte) {
|
||||
f, err := os.OpenFile(path, os.O_CREATE | os.O_RDWR | os.O_TRUNC, 0644)
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
// TODO: check for Close() errors
|
||||
// https://github.com/ncw/swift/blob/master/swift.go#L170
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.Write(data)
|
||||
@ -54,7 +56,7 @@ func WriteData(path string, data []byte) {
|
||||
}
|
||||
|
||||
func WriteRows(path string, rows *[]Row, delimeter string) {
|
||||
f, err := os.OpenFile(path, os.O_CREATE | os.O_RDWR, 0644)
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"fmt"
|
||||
"time"
|
||||
"flag"
|
||||
"sort"
|
||||
"bufio"
|
||||
"strconv"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/thebaer/tildes/store"
|
||||
)
|
||||
@ -41,7 +41,7 @@ func main() {
|
||||
addictionData = "/home/bear/addicted.sh"
|
||||
}
|
||||
|
||||
headers := []string{ "User", "Tildes", "Last Collected", "Addiction", "# Asks", "Avg.", "Last Amt." }
|
||||
headers := []string{"User", "Tildes", "Last Collected", "Addiction", "# Asks", "Avg.", "Last Amt."}
|
||||
|
||||
scoresData := store.ReadRows(scoresPath, "&^%")
|
||||
updatesData := store.ReadRows(scoreDeltasPath, deltaDelimiter)
|
||||
@ -58,17 +58,20 @@ type table struct {
|
||||
}
|
||||
|
||||
type By func(r1, r2 *store.Row) bool
|
||||
|
||||
func (by By) Sort(rows []store.Row) {
|
||||
rs := &rowSorter {
|
||||
rs := &rowSorter{
|
||||
rows: rows,
|
||||
by: by,
|
||||
}
|
||||
sort.Sort(rs)
|
||||
}
|
||||
|
||||
type rowSorter struct {
|
||||
rows []store.Row
|
||||
by func(r1, r2 *store.Row) bool
|
||||
}
|
||||
|
||||
func (r *rowSorter) Len() int {
|
||||
return len(r.rows)
|
||||
}
|
||||
@ -117,11 +120,11 @@ func niceTime(sec int) string {
|
||||
if sec < 60 {
|
||||
return fmt.Sprintf("%dsec", sec)
|
||||
} else if sec < 3600 {
|
||||
return fmt.Sprintf("%smin", trimTrailingZerosShort(float64(sec) / 60.0))
|
||||
return fmt.Sprintf("%smin", trimTrailingZerosShort(float64(sec)/60.0))
|
||||
} else if sec < 86400 {
|
||||
return fmt.Sprintf("%shr", trimTrailingZerosShort(float64(sec) / 3600.0))
|
||||
return fmt.Sprintf("%shr", trimTrailingZerosShort(float64(sec)/3600.0))
|
||||
}
|
||||
return fmt.Sprintf("%sdy", trimTrailingZerosShort(float64(sec) / 86400.0))
|
||||
return fmt.Sprintf("%sdy", trimTrailingZerosShort(float64(sec)/86400.0))
|
||||
}
|
||||
|
||||
type LastScore struct {
|
||||
@ -150,7 +153,7 @@ func checkScoreDelta(scoreRows, deltaRows *[]store.Row) *[]store.Row {
|
||||
times, _ := strconv.Atoi(r.Data[4])
|
||||
so, _ := strconv.Atoi(r.Data[5])
|
||||
|
||||
users[r.Data[0]] = LastScore{ LastScore: score, LastUpdate: update, LastIncrement: inc, Times: times, ScoreOffset: so }
|
||||
users[r.Data[0]] = LastScore{LastScore: score, LastUpdate: update, LastIncrement: inc, Times: times, ScoreOffset: so}
|
||||
}
|
||||
|
||||
// Fetch IRC log data
|
||||
@ -175,7 +178,7 @@ func checkScoreDelta(scoreRows, deltaRows *[]store.Row) *[]store.Row {
|
||||
|
||||
u, exists := users[uname]
|
||||
if !exists {
|
||||
u = LastScore{ ScoreOffset: 0 }
|
||||
u = LastScore{ScoreOffset: 0}
|
||||
}
|
||||
u.ScoreOffset = 0
|
||||
u.Times = asks
|
||||
@ -197,7 +200,7 @@ func checkScoreDelta(scoreRows, deltaRows *[]store.Row) *[]store.Row {
|
||||
|
||||
// Fill in any missing users
|
||||
if !exists {
|
||||
u = LastScore{ LastScore: score, LastIncrement: -1, LastUpdate: update, Times: 0, ScoreOffset: score, Addiction: 0 }
|
||||
u = LastScore{LastScore: score, LastIncrement: -1, LastUpdate: update, Times: 0, ScoreOffset: score, Addiction: 0}
|
||||
users[r.Data[0]] = u
|
||||
}
|
||||
|
||||
@ -221,7 +224,7 @@ func checkScoreDelta(scoreRows, deltaRows *[]store.Row) *[]store.Row {
|
||||
|
||||
var avgStr string
|
||||
if u.Times > 0 {
|
||||
avg := float64(score - u.ScoreOffset) / float64(u.Times)
|
||||
avg := float64(score-u.ScoreOffset) / float64(u.Times)
|
||||
avgStr = trimTrailingZeros(avg)
|
||||
} else {
|
||||
avgStr = "-"
|
||||
@ -241,7 +244,7 @@ func checkScoreDelta(scoreRows, deltaRows *[]store.Row) *[]store.Row {
|
||||
}
|
||||
|
||||
// Write deltas
|
||||
f, err := os.OpenFile(scoreDeltasPath, os.O_CREATE | os.O_RDWR, 0644)
|
||||
f, err := os.OpenFile(scoreDeltasPath, os.O_CREATE|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
@ -306,7 +309,7 @@ func generate(title, jackpot string, table *table, outputFile string) {
|
||||
|
||||
defer f.Close()
|
||||
|
||||
funcMap := template.FuncMap {
|
||||
funcMap := template.FuncMap{
|
||||
"add": add,
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"bufio"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"net/http"
|
||||
"flag"
|
||||
"time"
|
||||
"text/template"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/thebaer/geo"
|
||||
"github.com/thebaer/tildes/store"
|
||||
@ -269,7 +269,7 @@ func generate(users []user, outputFile string) {
|
||||
|
||||
defer f.Close()
|
||||
|
||||
funcMap := template.FuncMap {
|
||||
funcMap := template.FuncMap{
|
||||
"Location": prettyLocation,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user