javascript - Generating json object with specific format from a collection -
i'm trying use jquery bracket plugin (http://www.aropupu.fi/bracket/).
as can see, plugin asks specific format in json object. example here:
var minimaldata = { teams : [ ["team 1", "team 2"], /* first matchup */ ["team 3", "team 4"] /* second matchup */ ], results : [ [[1,2], [3,4]], /* first round */ [[4,6], [2,1]] /* second round */ ] }
i have collection of games scores, players names (home , away), round, etc. i'm pulling server side; games json pretty "raw data".
as can see, jquery bracket json needs property "teams" going used on first round , here, making bracket depending on scores. results property divided rounds , has follow same order teams property.
i've been trying create object raw data. main point here, know results, i'm using plugin print tournament bracket.
my raw data object is:
[{"id":"160058","round":"4","score1":"2","score2":"0","player1":"nameplayer1","id1":"1152","player2":"nameplayer2","id2":"5509"},{"id":"160059","round":"4","score1":"1","score2":"2","player1":"nameplayer1","id1":"5509","player2":"nameplayer2","id2":"1152"},{"id":"160060","round":"4","score1":"2","score2":"1","player1":"nameplayer1","id1":"41","player2":"nameplayer2","id2":"138"},{"id":"160061","round":"4","score1":"1","score2":"0","player1":"nameplayer1","id1":"138","player2":"nameplayer2","id2":"41"},{"id":"160062","round":"4","score1":"2","score2":"0","player1":"nameplayer1","id1":"4003","player2":"nameplayer2","id2":"1318"},{"id":"160063","round":"4","score1":"2","score2":"2","player1":"nameplayer1","id1":"1318","player2":"nameplayer2","id2":"4003"},{"id":"160064","round":"4","score1":"0","score2":"0","player1":"nameplayer1","id1":"157","player2":"nameplayer2","id2":"6296"},{"id":"160065","round":"4","score1":"0","score2":"2","player1":"nameplayer1","id1":"6296","player2":"nameplayer2","id2":"157"},{"id":"161886","round":"5","score1":"0","score2":"0","player1":"nameplayer1","id1":"138","player2":"nameplayer2","id2":"157"},{"id":"161887","round":"5","score1":"0","score2":"1","player1":"nameplayer1","id1":"157","player2":"nameplayer2","id2":"138"},{"id":"161888","round":"5","score1":"1","score2":"2","player1":"nameplayer1","id1":"1152","player2":"nameplayer2","id2":"4003"},{"id":"161889","round":"5","score1":"2","score2":"1","player1":"nameplayer1","id1":"4003","player2":"nameplayer2","id2":"1152"},{"id":"167278","round":"6","score1":"0","score2":"0","player1":"nameplayer1","id1":"4003","player2":"nameplayer2","id2":"138"},{"id":"167279","round":"6","score1":"3","score2":"0","player1":"nameplayer1","id1":"138","player2":"nameplayer2","id2":"4003"}]
the example data starting round 4, either way, going bigger paste here.
i thinking in doing recursive , backwards (starting last round, till first one), creating tree (which should tournament brackets), i've not been able desired results. figured out how print whole tournament bracket, order of scores wrong, printing wrong players in final game.
any idea point me on right direction?
i'm not posting code, because it's useless far.
thanks
Comments
Post a Comment