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