Exemplo n.º 1
0
func dialWebsocket(db *sql.DB, wg *sync.WaitGroup, i int) {

	origin := "http://localhost/"
	url := "ws://localhost:8080/scoreboard"

	ws, err := websocket.Dial(url, "", origin)
	if err != nil {
		log.Fatal(err)
	}

	res, err := scoreboard.CollectLastResult(db)
	if err != nil {
		log.Fatal(err)
	}

	html_res := res.ToHTML(false)

	var msg = make([]byte, len(html_res))
	if _, err = ws.Read(msg); err != nil {
		log.Fatal(err)
	}

	if string(msg) != html_res {
		log.Fatalln("Received result invalid",
			html_res, msg)
	}

	wg.Done()
}
Exemplo n.º 2
0
func scoreboardShow(db *sql.DB) {
	res, err := scoreboard.CollectLastResult(db)
	if err != nil {
		log.Fatalln("Get last result fail:", err)
	}

	scoreboard.CountScoreAndSort(&res)

	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Rank", "Name", "Score", "Attack",
		"Defence", "Advisory"})

	for _, tr := range res.Teams {

		var row []string

		row = append(row, fmt.Sprintf("%d", tr.Rank))
		row = append(row, tr.Name)
		row = append(row, fmt.Sprintf("%05.2f%%", tr.ScorePercent))
		row = append(row, fmt.Sprintf("%.3f", tr.Attack))
		row = append(row, fmt.Sprintf("%.3f", tr.Defence))
		row = append(row, fmt.Sprintf("%d", tr.Advisory))

		table.Append(row)
	}

	table.Render()
}