* Use embedded assets for templates
* All Critical functions are working
This commit is contained in:
Brian Buller 2017-07-08 21:51:43 -05:00
parent 02dbfc39ca
commit 262c855643
8 changed files with 293 additions and 194 deletions

View File

@ -46,6 +46,7 @@ func handleAdmin(w http.ResponseWriter, req *http.Request) {
case "mode":
handleAdminSetMode(w, req, page)
default:
page.TemplateData = getCondorcetResult()
page.show("admin-main.html", w)
}
}

View File

@ -1,84 +1,110 @@
package main
import (
"fmt"
"errors"
"net/http"
"time"
"github.com/gorilla/mux"
)
// getCondorcetResult returns the ranking of teams based on the condorcet method
// https://en.wikipedia.org/wiki/Condorcet_method
func getCondorcetResult() []Team {
type teamPair struct {
winner *Team
loser *Team
majority float32
}
var allPairs []teamPair
var ret []Team
type rankedTeam struct {
tm *Team
wins map[string]int
losses map[string]int
for i := 0; i < len(site.Teams); i++ {
for j := i + 1; j < len(site.Teams); j++ {
// For each pairing find a winner
winner, pct, _ := findWinnerBetweenTeams(&site.Teams[i], &site.Teams[j])
if winner != nil {
newPair := new(teamPair)
newPair.winner = winner
if winner.UUID == site.Teams[i].UUID {
newPair.loser = &site.Teams[j]
} else {
newPair.loser = &site.Teams[i]
}
newPair.majority = pct
allPairs = append(allPairs, *newPair)
}
}
}
// Build our Ranked Teams slice
allRanks := make(map[string]rankedTeam)
teamWins := make(map[string]int)
for i := range site.Teams {
rt := new(rankedTeam)
rt.wins = make(map[string]int)
rt.losses = make(map[string]int)
rt.tm = &site.Teams[i]
for j := range site.Teams {
if site.Teams[i].UUID != site.Teams[j].UUID {
rt.wins[site.Teams[j].UUID] = 0
rt.losses[site.Teams[j].UUID] = 0
}
}
allRanks[site.Teams[i].UUID] = *rt
teamWins[site.Teams[i].UUID] = 0
}
/*
Go through all votes, for each choice (ct):
* Go through all teams (tm)
* if tm was processed earlier, do nothing
* otherwise mark a win for ct against tm, and a loss for tm against cm
*/
// Now go through all of the votes and figure wins/losses for each team
for _, vt := range site.Votes {
for i := 0; i < len(vt.Choices); i++ {
var p []string
for j := i; j < len(vt.Choices); j++ {
// vt.Choices[i] wins against vt.Choices[j]
p = append(p, vt.Choices[j].Team)
allRanks[vt.Choices[i].Team].wins[vt.Choices[j].Team]++
allRanks[vt.Choices[j].Team].losses[vt.Choices[i].Team]++
}
// Now go through site.Teams for every team that isn't vt.Choices[i]
// and isn't in 'p', mark it as a loss for the unused team
for j := range site.Teams {
var isUsed bool
if site.Teams[j].UUID == vt.Choices[i].Team {
continue
}
for k := range p {
if site.Teams[j].UUID == p[k] {
isUsed = true
}
}
if !isUsed {
allRanks[vt.Choices[i].Team].wins[site.Teams[j].UUID]++
allRanks[site.Teams[j].UUID].losses[vt.Choices[i].Team]++
}
}
}
for i := range allPairs {
teamWins[allPairs[i].winner.UUID]++
}
for _, v := range allRanks {
fmt.Println("\n" + v.tm.UUID)
fmt.Println(" Wins:")
for k, v := range v.wins {
fmt.Print(" ", k, ":", v, "\n")
for len(teamWins) > 0 { //len(ret) <= len(site.Teams) {
topWins := 0
var topTeam string
for k, v := range teamWins {
// If this team is already in ret, carry on
if uuidIsInTeamSlice(k, ret) {
continue
}
// If this is the last key in teamWins, just add it
if len(teamWins) == 1 || v > topWins {
topWins = v
topTeam = k
}
}
fmt.Println(" Losses:")
for k, v := range v.losses {
fmt.Print(" ", k, ":", v, "\n")
// Remove topTeam from map
delete(teamWins, topTeam)
// Now add topTeam to ret
addTeam := site.getTeamByUUID(topTeam)
if addTeam != nil {
ret = append(ret, *addTeam)
} else {
break
}
}
return ret
}
// This is a helper function for calculating results
func uuidIsInTeamSlice(uuid string, sl []Team) bool {
for _, v := range sl {
if v.UUID == uuid {
return true
}
}
return false
}
// findWinnerBetweenTeams returns the team that got the most votes
// and the percentage of votes they received
// or an error if a winner couldn't be determined.
func findWinnerBetweenTeams(tm1, tm2 *Team) (*Team, float32, error) {
// tally gets incremented for a tm1 win, decremented for a tm2 win
var tm1votes, tm2votes float32
for _, v := range site.Votes {
for _, chc := range v.Choices {
if chc.Team == tm1.UUID {
tm1votes++
break
} else if chc.Team == tm2.UUID {
tm2votes++
break
}
}
}
ttlVotes := tm1votes + tm2votes
if tm1votes > tm2votes {
return tm1, 100 * (tm1votes / ttlVotes), nil
} else if tm1votes < tm2votes {
return tm2, 100 * (tm2votes / ttlVotes), nil
}
return nil, 50, errors.New("Unable to determine a winner")
}
func getInstantRunoffResult() []Team {
var ret []Team
return ret
@ -95,6 +121,7 @@ func handleAdminVotes(w http.ResponseWriter, req *http.Request, page *pageData)
}
type votePageData struct {
AllVotes []vpdVote
Results []Team
}
vpd := new(votePageData)
for i := range site.Votes {
@ -111,8 +138,8 @@ func handleAdminVotes(w http.ResponseWriter, req *http.Request, page *pageData)
}
vpd.AllVotes = append(vpd.AllVotes, *v)
}
vpd.Results = getCondorcetResult()
page.TemplateData = vpd
_ = getCondorcetResult()
switch vars["function"] {
default:

162
assets.go
View File

@ -202,28 +202,28 @@ Y8Pj6dAeZ3gBzLZbhMnSW8r0f78+9y+zlDVuQ3ZNXD8zD+/mGzZjDfK53gEAAP//D/6XxHkAAAA=
"/assets/css/gjvote.css": {
local: "assets/css/gjvote.css",
size: 3763,
modtime: 1499342234,
size: 3784,
modtime: 1499536516,
compressed: `
H4sIAAAAAAAA/6xX62rrOBD+36cQhIUWVsbpaU4bF8pCT/sesqXYQ2TJSHKSdum7L7rYsWy5e2GhP2Jp
7vPNN2pjWo7+vEGoBYEbBnVjCrTN89+eb75ubkpJP9xtJblUBdo8Pj4+rwkTJ2nYxWDKKqmIASkKJKRg
7p7CKaukMEwYJ9kRSkHUBdruukva6ui45KQ6jlYawg/OxBmoaQq0CxFkDSOUKZ8PUTUIzNnBFCj3152C
lqg4ozx/fGKP0T0uaydSkupYK9kLihPSILreZAfgLM4m27EWZT9Za8OnoDtOPgoEgoNguOTS5oFQKRVl
qkDb7oK05EDRpqoqf3PBuiFUnq2WZgblTupHd0EbSulVGytCodcFerD1G0NSRBxB1Nh9xWXydZ5p76an
UUSvr6/PQ0sJh1oUqGLCMOXB0RsjRab7sgWDT9LYQ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COOFwil++0RpDqM19FsyW46/
yWfRgCwm1rAeF8/alYb9o2UUCLq1r94A8iFn7Z1DfX0dLZfmMpXT0hzgwtwb8etmtLN4LyT250J8XDMz
BRBggPDnCFsA4owstn4qhATgGZVsgv2UDwfe+OSJP+uZ0boTJHYLZQdOdPOvhLPrmPubQReNusCWhTXd
VxXTet3e/f2eHPbf2ov+a1qP48opXSnGBCKCotuWXAK9fuzsY/QuvBpOfnRY00pybFF1iJOS8Ww4c1/B
6XJv/hOXPx+sQ384ofnT/w/jrwAAAP//9ey+zsgOAAA=
`,
},
@ -12055,14 +12055,15 @@ vh6n2F5nK55X3h/q0K8AAAD//5F9arwmAwAA
"/templates/admin-main.html": {
local: "templates/admin-main.html",
size: 836,
modtime: 1498141850,
size: 1024,
modtime: 1499533906,
compressed: `
H4sIAAAAAAAA/6yRzWrrMBCF9/cpBm2yspWQrW24q64Khf6tFWlsD5U1qSQnFON3L4pdSJvQhpDVAY/1
6dOcwtAOtFUhlEKzi+iiqP4BpO8pAYp2XT30G0sa7tlgIdv1PNj0MbIDdtqSfivFnpzhfW5Zq0js8tZj
XS6kMh052bFBuVyIr8u2vcdsImSRm8ZiVpMPEY4GMAxANeA75JNBEoAljOPx6a2nTvmPYQB0BsZRVK+K
IrmmkNMfV+uuftW16hLb1Z+2L/xTtpDz9r+38D+ZwSPqpBtOizhVFRe+dscRw+KgguH82q6HR1Rdgj+l
vDW8Ud3B/C7lreF9QJ/gzynPFDTHZwAAAP//9zFOd0QDAAA=
H4sIAAAAAAAA/6ySX0vzMBTG799PcSiD3bxrNnYnbUEUvFJEp15n7VkXzJ+ZnHZI6HeXLHNUN3WMXT2l
p/n1x3OSVaKFUnLn8qQ0mlBTUvwDCO9DAmTLaXHfzKUo4dZUmLHldDuYN0RGg9GlFOVrnqyFrsw6labk
JIxOlxYX+ZDxSgnNlKmQjYfJ589WjcVRJIzI1LXE0UJYR9AbgPcgFoBvkEaDIABj6Lr+6ZUVitt37wF1
BV2XFC9ckNB1xuIXJ+tOftWV/BjbyZ+2z+a7bMa27f9I3NvQVWMtaoIHdI0k19uSkfHBe7Bc1wgD8R8G
LVzkkM5QrSQnvObEI3VzRIrCexi06R1XCF2XMSl2kKgd2SzC+7678Ve/y9AqPGIZqnb7l2i/5uTITbWG
0A03NaI7vPLT4YRcBfgs5LnhNVcb85uQ54Y3Dm2AP4U8cLm28REAAP//GzmHcgAEAAA=
`,
},
@ -12114,14 +12115,15 @@ GXvy3PwYKZ6fyZHhEKvyv82bVJmo3N8XAPZYvcMb01mHkXzjyL9wpz4sHABCwHMXXoE7Wthy9p3rhfjJ
"/templates/admin-votes.html": {
local: "templates/admin-votes.html",
size: 591,
modtime: 1499344306,
size: 747,
modtime: 1499532926,
compressed: `
H4sIAAAAAAAA/2xSwW7CMAy98xVW1CO0h92mtNI0Llx22NDuJjEQLU2qxKs0Vf33KW0hG3B7tl/8nu1I
xoMlMLoWvWeKmykWoCzGWIvow0zovgNtbuHm4IOmQBoUOaYgmhWA5DOhTijhMIMp3exNS5Gx7WTF57+F
V2vIMey2t4V3dF/GnWLOy2rumTKLjuSD1z9zeRggoDsRFGYNRQ/PNZR7ajuLTFtkLF+s/UyDwjjeW9TN
MEDRl1ejMI6yYn3PmB3v9APCArMTlayoyUt6efZGZf2FWqi+fMOWYBzXuQE5nXlZ57KD/xxZXfcg+eg9
P7iBvhzW0pEFKG9jh64WTyLNZclB+WGYysuKYO8ZLUzhvb6sFh1ZTf+hWf0GAAD//xnIVWJPAgAA
H4sIAAAAAAAA/4RSTYvqMBTd91dcistnA77dIy08dONmFo7MPjZXGyZNSnIVhtL/PiRNrVOF2d3vc3JO
eLOptlfn0BAc0F81ec6aTZVxq6us78EJc0FYqT+wusG/Eoojtp0WhDtBokgrMAwZANeq6ntY3Yo30SIM
A2daxSNoZBjhLBzlJE4aQckyv1lCv455DrUW3pe5t24c6K4O18twfbJOokMJNRpCl1cBmBoUMkQhdmMQ
y9VRtehJtB1n1Dw2tlqFN+93y8ZBmE9lLn6uczbeDJWEw+lk5dfY/lWk/1p/hIeOKi0oyiTZnWjUjeTz
xMh4L18MpBAgujYlM7E6MKsjtXCosaqe6aTNZF69cO/hWHLxvsFmsJnQJNbPDc7ugnE6W0svzJLTD9B4
phxqq30nTJn/zQMxjQaKd0VYTFrC0ZLQENNnfM4SDmfx41TZdwAAAP//q70AIOsCAAA=
`,
},
@ -12176,50 +12178,56 @@ AAD//1puW/YhAwAA
"/templates/public-voting.html": {
local: "templates/public-voting.html",
size: 9253,
modtime: 1499346016,
size: 10440,
modtime: 1499536431,
compressed: `
H4sIAAAAAAAA/+xa0Y/bNvJ+379i6l9QebFrq+lj1jaQbH53l0ObAskmh0NRFLQ4tphIpEBSdgzD//th
SEqmbGnX6TVAHy4PiSySH4ffzHwcUtnvQaxAKgvTByyrgll8zSybPiArDRwOVzMuNou3CtasRAM52yAs
ESVkGplFPkup/Wq/BywMNgMgK5gx81GmpEVpR4urd0x+BiURlIZSaQx4K61K2Klaw4ptlBYWwSookBnb
vplehUn6kQFm+Y+LfxPGfa5EhmaW5j+695YtCwTB5yPN5GfkE/di1GBUtUb/Co6Pk6XSHDVyyFBa1G4G
wsqRcf9Mv3Tz6JoWtLxZavPu27+zEuEtK/G8ifgdaHqfaURpcmXNeWP8ZpY2ZtDb1ryZXSq+axuaH7PU
rW9xCZsfpCcMaAV9fNbyWzP6jdm8gDuA/R40k2uEZ+IWnm3gxXwgS+C4CkePRVZqtZ3s98820w8f3rw+
HEbAmWUTaqEecUtsMG+obBlmmRVKmtFixjo0L2trlYToeVJpUTK9G0GucTUffWIbZjItKvuiVBt8UO8c
4jiJJk+u70aLmWiQVwxWbFIVNc2XigW85Jwy8qOyOEsZeYX3mrtRVsj1JFOFy+yJZCWOFvs9PNtMyXFT
8g4cDpcAEEcdgK8Y6yY3R58H2o3JVC0t8V6gbI2KgqPjB+f6oIs9fUnmjl1P2RMlW2Ogb/xWQTTwujtD
I5kR1tHHjS8tWwrJ8ct8NHne41mTq200wzjybZ9rO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qLB7izanOBEuRGvSC8+4dKWZCq1C5lCmelKclhgbbHfWuT6sY92IaN+
AC3M4YNLo07CpVd2Ia/Sk65ggmyZjWrrI5R4DYJ/ac4onD2DdrLUasnsaI32Hln+y+IT6R5toL5GDu7/
AVKDNop1GBoH2yPiN3hi9LAB+xh2aTqa+6QPcn7Sl8ntb0vKKPGYlP1cTa9aCX4TvK6PqRTL8YaGDpJe
c2Tmir49+6kt1IdsD1tpDigHrJTlC10pe4Yr0Umdt1UHNtxTeYqtWag3ts0hkrsL8PXYlrevANquXdfQ
JADQAL0iG/XeCq9eliAafnI3ua7W674rI86lwnPnWFDo0gJ+KaiwQNi+MndHW22ywDxmgNtODiXJ0Gle
7xleXR9wBYY6SkqHq+Q6GYaq9zAkvPWoWR7YWhOvMSnrDsbv266z8QeprmzYEc+5zqTB4MGzlwYSe86Z
kO09DTruJ5rPygcseve9vtMdMFx/gV5DGt1BHf0cW71eSxyvqE87loXrqngqVyZ/u//5J5hDenwJyQwR
RFWEe8ifqfd6V6Qtn0pRWlRowom5cgfdzrCvOtwgVVzqjqpTyoJraOi1Tpu+o6uWOi0PW/+LTEg+csYb
aLk6H1qn+xC07tP4LHBzwbnEB9H1s52BLs0a40tfto8h7Ix/E8Lxd/Mgxs58izHKrwDZKR/thHM/YSvu
D4LvU8+LgGSn2Y3GaNNx40H43dVwQN5/VzwKu7P6OO4wumxxP/2UGsbd2Y8bBsu7RHnSj9d/NNZDlW5T
iP5MJA08ecyGgz3+f8qH/bcA7vuM8/NTyisPplQQH839bRnUqeBg+MEc6v+DnLReZ8EMy8umP/JZ5O0O
ZdFpBnojg9kVNu5elEKqnWaa1z7NtNm0vkn+dwAAAP//YbS+bcgoAAA=
`,
},

View File

@ -115,6 +115,7 @@ img.thumbnail {
display: block;
height: 120px;
background-color: #EEE;
padding-top: 20px;
}
.padding {

View File

@ -37,6 +37,15 @@ type siteData struct {
Votes []Vote
}
func (s *siteData) getTeamByUUID(uuid string) *Team {
for i := range s.Teams {
if s.Teams[i].UUID == uuid {
return &s.Teams[i]
}
}
return nil
}
// pageData is stuff that changes per request
type pageData struct {
Site *siteData

View File

@ -4,6 +4,16 @@
<button onclick="window.location.href='/admin/mode/0'" class="pure-button-toggle-first pure-button {{ if eq .PublicMode 0 }}pure-button-primary{{ end }}">Waiting</button>
<button onclick="window.location.href='/admin/mode/1'" class="pure-button-toggle-last pure-button {{ if eq .PublicMode 1 }}pure-button-primary{{ end }}">Voting</button>
</div>
{{ if eq .PublicMode 1 }}
<div>
<h3>Current Results</h3>
<ol>
{{ range $i, $v := .TemplateData }}
<li>{{ $v.Name }}</li>
{{ end }}
</ol>
</div>
{{ end }}
<div>
<h3>Admin Sections</h3>
<button class="pure-button" onclick="window.location.href='/admin/votes'">Votes</button>

View File

@ -1,3 +1,9 @@
<h2>Current Results</h2>
<ol>
{{ range $i, $v := .TemplateData.Results }}
<li>{{ $v.Name }}</li>
{{ end }}
</ol>
<table id="votes-table" class="sortable pure-table pure-table-bordered center">
<thead>
<tr>

View File

@ -1,63 +1,100 @@
{{ if not .TemplateData.Teams }}
<div>No games have been created</div>
{{ else }}
<div class="content">
Rank one or more games from your favorite to least favorite.
</div>
<div class="content">
<h2>Your Choices</h2>
<table id="ranked-table" class="pure-table pure-table-bordered center">
<thead>
<tr>
<th>Rank</th>
<th>Game Name</th>
<th>Team Name</th>
<th>Screenshots</th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="content">
<h2>Unranked Games</h2>
<table id="unranked-table" class="pure-table pure-table-bordered center">
<thead>
<tr>
<th></th>
<th>Game Name</th>
<th>Team Name</th>
<th>Screenshots</th>
</tr>
</thead>
<tbody>
{{ range $i, $v := .TemplateData.Teams }}
<tr id="teamrow-{{$v.UUID}}" data-teamid="{{$v.UUID}}">
<td class="unranked-actions"><a class="pure-button pure-button-primary" href="javascript:moveToRanked('{{$v.UUID}}');"><i class="fa fa-plus"></i> Add to Vote</a></td>
<td class="voting-col game-name">{{ $v.Game.Name }}</td>
<td class="voting-col team-name">{{ $v.Name }}</td>
<td class="voting-col game-screenshots" data-sscount="{{len $v.Game.Screenshots}}">
{{ if not $v.Game.Screenshots }}
<i class="fa fa-image"></i> (No Screenshots)
{{ else }}
<a class="primary" tabindex="-1" href="javascript:showScreenshots({{$v.UUID}});"><i class="fa fa-image"></i> ({{ len $v.Game.Screenshots }})</a>
{{ end }}
</td>
</tr>
<div>No games have been created</div>
{{ else }}
<div class="content">
Rank one or more games from your favorite to least favorite.
</div>
<div class="content">
<h2>Your Choices</h2>
<table id="ranked-table" class="pure-table pure-table-bordered center">
<thead>
<tr>
<th>Rank</th>
<th>Game Name</th>
<th>Team Name</th>
<th>Screenshots</th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="content">
<h2>Unranked Games</h2>
<table id="unranked-table" class="pure-table pure-table-bordered center">
<thead>
<tr>
<th></th>
<th>Game Name</th>
<th>Team Name</th>
<th>Screenshots</th>
</tr>
</thead>
<tbody>
{{ range $i, $v := .TemplateData.Teams }}
<tr id="teamrow-{{$v.UUID}}" data-teamid="{{$v.UUID}}">
<td class="unranked-actions"><a class="pure-button pure-button-primary" href="javascript:moveToRanked('{{$v.UUID}}');"><i class="fa fa-plus"></i> Add to Vote</a></td>
<td class="voting-col game-name">{{ $v.Game.Name }}</td>
<td class="voting-col team-name">{{ $v.Name }}</td>
<td class="voting-col game-screenshots" data-sscount="{{len $v.Game.Screenshots}}">
{{ if not $v.Game.Screenshots }}
<i class="fa fa-image"></i> (No Screenshots)
{{ else }}
<a class="primary" tabindex="-1" href="javascript:showScreenshots('{{$v.UUID}}');"><i class="fa fa-image"></i> ({{ len $v.Game.Screenshots }}) Click to View</a>
{{ end }}
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
<div class="content half">
<form action="/vote">
<input id="uservote" type="hidden" name="uservote" value="" />
<input id="timestamp" type="hidden" name="timestamp" value="{{.TemplateData.Timestamp}}" />
<button class="pure-button pure-button-primary space-vertical pull-right" type="submit">Submit Vote!</button>
</form>
</div>
{{ range $i, $v := .TemplateData.Teams }}
<div class="pure-control-group" id="screenshots-{{ $v.UUID }}" style="display:none;">
<h3>{{ $v.Game.Name }} by {{ $v.Name }}</h3>
<label class="control-label">Click to view original size</label>
<div class="center-all horizontal-scroll thumbnail-container" id="thumbnail-container">
{{ range $imgi, $imgv := $v.Game.Screenshots }}
<a href="javascript:embiggenScreenshot(this.getElementsByTagName('img')[0]);">
<img data-teamid="{{ $v.UUID }}" data-ssid="{{ $imgv.UUID }}" class="thumbnail" alt="{{ $imgv.Description }}" src="data:image/png;base64,{{ $imgv.Image }}" />
</a>
{{ end }}
</tbody>
</table>
</div>
<div class="content half">
<form action="/vote">
<input id="uservote" type="hidden" name="uservote" value="" />
<input id="timestamp" type="hidden" name="timestamp" value="{{.TemplateData.Timestamp}}" />
<button class="pure-button pure-button-primary space-vertical pull-right" type="submit">Submit Vote!</button>
</form>
</div>
</div>
</div>
{{ end }}
{{ end }}
<script>
var teamNames = { };
{{ range $i, $v := .TemplateData.Teams }}
teamNames[{{$v.UUID}}] = { "team-name": "{{$v.Name}}", "game-name": "{{$v.Game.Name}}" };
{{ end }}
function showScreenshots(tmuuid) {
var screenshots = document.getElementById('screenshots-'+tmuuid).cloneNode(true);
screenshots.style.display='';
showModal({
title: 'Screenshots',
subtitle: teamNames[tmuuid].game-name,
bodyNode: screenshots,
buttons: [{
title: 'Done',
position: 'right',
click: hideModal
}]
});
}
function embiggenScreenshot(img) {
}
function updateView() {
updateButtonStates();