Initial checkin.

This commit is contained in:
Auke Kok 2017-10-26 12:11:45 -07:00
commit 8b8ea33025
3 changed files with 115 additions and 0 deletions

32
Makefile Normal file
View 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
View 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()
}

3
readme.md Normal file
View File

@ -0,0 +1,3 @@
## itb-ranking