Initial checkin.
This commit is contained in:
commit
8b8ea33025
32
Makefile
Normal file
32
Makefile
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
|
DIST := COPYING Makefile readme.md
|
||||||
|
|
||||||
|
PROJECT := itb-ranking
|
||||||
|
VERSION = 1
|
||||||
|
BUILD = `git describe --tags --always`
|
||||||
|
|
||||||
|
$(PROJECT): main.go
|
||||||
|
go build -ldflags "-X main.Version=$(VERSION) -X main.Build=$(BUILD)" -o $(PROJECT)
|
||||||
|
|
||||||
|
build: $(PROJECT)
|
||||||
|
|
||||||
|
install: $(PROJECT)
|
||||||
|
go install
|
||||||
|
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||||
|
install -m0755 $(PROJECT) $(DESTDIR)$(PREFIX)/bin/$(PROJECT)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
go clean
|
||||||
|
|
||||||
|
dist:
|
||||||
|
rm -rf $(PROJECT)-$(BUILD)
|
||||||
|
mkdir $(PROJECT)-$(BUILD)
|
||||||
|
cp $(DIST) $(PROJECT)-$(BUILD)/
|
||||||
|
GOOS=linux GOARCH=386 go build -ldflags "-X main.Version=$(VERSION) -X main.Build=$(BUILD)" -o $(PROJECT) -o $(PROJECT)-$(BUILD)/$(PROJECT)
|
||||||
|
zip -r $(PROJECT)-$(BUILD)-ia32.zip $(PROJECT)-$(BUILD)/
|
||||||
|
rm -f $(PROJECT)-$(BUILD)/$(PROJECT)
|
||||||
|
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=$(VERSION) -X main.Build=$(BUILD)" -o $(PROJECT) -o $(PROJECT)-$(BUILD)/$(PROJECT)
|
||||||
|
zip -r $(PROJECT)-$(BUILD)-x86_64.zip $(PROJECT)-$(BUILD)/
|
||||||
|
|
80
main.go
Normal file
80
main.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
//
|
||||||
|
// itb-ranking - create rankings from scoring data
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017 - Auke Kok <sofar@foo-projects.org>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
// a copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject
|
||||||
|
// to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included
|
||||||
|
// in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
||||||
|
// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||||
|
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
_ "github.com/mattn/go-sqlite3" // MIT licensed.
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Score struct {
|
||||||
|
playerid int
|
||||||
|
box_id int
|
||||||
|
stype string
|
||||||
|
score float64
|
||||||
|
}
|
||||||
|
var points []Score
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 1 {
|
||||||
|
log.Fatal("Not enough arguments: sqlite_file")
|
||||||
|
}
|
||||||
|
f := os.Args[1]
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite3", f)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := db.Query("select player_id, box_id, type, score from points")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var player_id int
|
||||||
|
var box_id int
|
||||||
|
var stype string
|
||||||
|
var score float64
|
||||||
|
|
||||||
|
err = rows.Scan(&player_id, &box_id, &stype, &score)
|
||||||
|
var s = Score{player_id, box_id, stype, score}
|
||||||
|
points = append(points, s)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Println(player_id, box_id, stype, score)
|
||||||
|
|
||||||
|
}
|
||||||
|
rows.Close()
|
||||||
|
|
||||||
|
defer db.Close()
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user