Rounds and games parsers written.

master
Ben Burlingham 9 years ago
parent 4030198e64
commit 60b5c18add
  1. 1
      .gitignore
  2. 94
      games.hs
  3. 1
      games.json
  4. 40
      rounds.hs
  5. 1
      rounds.json
  6. 8
      worldcup.html

1
.gitignore vendored

@ -0,0 +1 @@
data

@ -0,0 +1,94 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
import Data.Aeson as AE
import Data.Aeson.Types as AET
import Data.ByteString.Lazy as BL
import Data.ByteString.Lazy.Char8 as BL8
import Prelude as P
-- "id":1
-- "key":null CHECKED, NULL
-- THIS "round_id":1 round title join
-- "pos":1 RANKING? NOT USING
-- "group_id":null
-- THIS "team1_id":45
-- THIS "team2_id":30
-- THIS "play_at":"2011-11-11 12:00:00.000000"
-- "postponed":"f" CHECKED, NULL
-- "play_at_v2":null CHECKED, NULL
-- "play_at_v3":null CHECKED, NULL
-- "ground_id":null CHECKED, NULL
-- "city_id":null CHECKED, NULL
-- "knockout":"f"
-- "home":"t"
-- THIS "score1":1 regular time
-- THIS "score2":0 regular time
-- THIS "score1et":null extended time
-- THIS "score2et":null extended time
-- THIS "score1p":null penalty time
-- THIS "score2p":null penalty time
--
-- "score1i":null CHECKED, NULL
-- "score2i":null CHECKED, NULL
-- "score1ii":null CHECKED, NULL
-- "score2ii":null CHECKED, NULL
-- "next_game_id":null CHECKED, NULL
-- "prev_game_id":null CHECKED, NULL
-- "winner":1
-- "winner90":1
-- "created_at":"2016-09-28 03:35:02.277055"
-- "updated_at":"2016-09-28 03:35:02.277055"
data Game = Game {
team1_id :: Value,
team2_id :: Value,
play_at :: Value,
score1 :: Value,
score2 :: Value,
score1et :: Value,
score2et :: Value,
score1p :: Value,
score2p :: Value } deriving (Show)
instance ToJSON Game where
toJSON Game{..} = object [
"t1" .= team1_id,
"t2" .= team2_id,
"ts" .= play_at,
"s1" .= score1,
"s2" .= score2,
"s1e" .= score1et,
"s2e" .= score2et,
"s1p" .= score1p,
"s2p" .= score2p ]
instance FromJSON Game where
parseJSON = withObject "game" $ \o -> do
team1_id <- o .: "team1_id"
team2_id <- o .: "team2_id"
play_at <- o .: "play_at"
score1 <- o .: "score1"
score2 <- o .: "score2"
score1et <- o .: "score1et"
score2et <- o .: "score2et"
score1p <- o .: "score1p"
score2p <- o .: "score2p"
return Game{..}
reduce :: [Game] -> Value -> [Game]
reduce acc x = case (parseEither parseJSON x :: Either String Game) of
(Left s) -> error s
(Right v) -> v : acc
parseGames :: Either String [Value] -> [Game]
parseGames (Left x) = error x
parseGames (Right xs) = P.foldl reduce [] xs
main :: IO ()
main = do
src <- BL.readFile "./data/games.json"
let games = parseGames (AE.eitherDecode src :: Either String [Value])
let encoded = encode games
BL8.putStrLn encoded
BL.writeFile "games.json" encoded

File diff suppressed because one or more lines are too long

@ -0,0 +1,40 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
import Data.Aeson as AE
import Data.Aeson.Types as AET
import Data.ByteString.Lazy as BL
import Data.ByteString.Lazy.Char8 as BL8
import Data.HashMap.Strict as HM
import Prelude as P
data Round = Round { _id :: Value, title :: Value } deriving (Show)
instance ToJSON Round where
toJSON Round{..} = object [ "i" .= _id, "t" .= title ]
instance FromJSON Round where
parseJSON = withObject "round" $ \o -> do
_id <- o .: "id"
title <- o .: "title"
return Round{..}
reduce :: [Round] -> Value -> [Round]
reduce acc x = case (parseEither parseJSON x :: Either String Round) of
(Left s) -> error s
(Right v) -> v : acc
parseRounds :: Either String [Value] -> [Round]
parseRounds (Left x) = error x
parseRounds (Right xs) = P.foldl reduce [] xs
parseResult :: [Round] -> [(String, Value)]
parseResult = P.foldl (\acc x -> (extractId x, title x) : acc) []
where
extractId = BL8.unpack . encode . _id
main :: IO ()
main = do
src <- BL.readFile "./data/rounds.json"
let teams = parseRounds (AE.eitherDecode src :: Either String [Value])
BL.writeFile "rounds.json" $ encode $ HM.fromList $ parseResult teams

@ -0,0 +1 @@
{"112":"Matchday 1","105":"Matchday 12","17":"Matchday III.3","71":"Matchday HEX.6","48":"Play-off 2nd Leg","113":"Matchday 2","104":"Matchday 11","16":"Matchday III.2","70":"Matchday HEX.5","49":"First Round Play-offs / First Leg","28":"Matchday IV.8","110":"Matchday 17","59":"Matchday II.9","107":"Matchday 14","15":"Matchday III.1","73":"Matchday HEX.8","29":"Matchday IV.9","111":"Matchday 18","58":"Matchday II.8","106":"Matchday 13","14":"Second Round Play-offs / 2nd leg","72":"Matchday HEX.7","8":"Matchday 6","116":"Matchday 5","88":"Matchday","101":"Matchday 8","13":"Second Round Play-offs / 1st leg","75":"Matchday HEX.10","39":"Matchday 6","9":"Play-off 1st Leg","117":"Matchday 6","89":"Matchday","100":"Matchday 7","12":"First Round Play-offs / 2nd leg","74":"Matchday HEX.9","38":"Matchday 5","114":"Matchday 3","99":"Matchday 6","103":"Matchday 10","11":"First Round Play-offs / 1st leg","77":"Matchday 1","129":"Semi-finals","68":"Matchday HEX.3","115":"Matchday 4","98":"Matchday 5","102":"Matchday 9","10":"Play-off 2nd Leg","76":"Matchday HEX.11","128":"Quarter-finals","69":"Matchday HEX.4","22":"Matchday IV.2","4":"Matchday 2","97":"Matchday 4","84":"Matchday 5","53":"Matchday II.3","79":"Matchday 3","127":"Round of 16","66":"Matchday HEX.1","35":"Matchday 3","40":"Matchday 7","23":"Matchday IV.3","5":"Matchday 3","96":"Matchday 3","85":"Matchday 6","52":"Matchday II.2","78":"Matchday 2","126":"Matchday 15","67":"Matchday HEX.2","34":"Matchday 2","41":"Matchday 8","20":"Matchday III.6","6":"Matchday 4","118":"Matchday 7","95":"Matchday 2","86":"Matchday","51":"Matchday II.1","125":"Matchday 14","64":"Matchday III.5","37":"Matchday","42":"Matchday","21":"Matchday IV.1","7":"Matchday 5","119":"Matchday 8","94":"Matchday 1","87":"Matchday","50":"First Round Play-offs / Second Leg","124":"Matchday 13","65":"Matchday III.6","36":"Matchday 4","43":"Matchday 9","26":"Matchday IV.6","93":"Play-off 2nd Leg","80":"Matchday 1","57":"Matchday II.7","109":"Matchday 16","123":"Matchday 12","130":"Match for third place","62":"Matchday III.3","31":"Fifth place playoff / 1st leg","44":"Matchday 10","27":"Matchday IV.7","1":"First Round Play-offs / 1st leg","92":"Play-off 1st Leg","81":"Matchday 2","56":"Matchday II.6","108":"Matchday 15","122":"Matchday 11","131":"Final","63":"Matchday III.4","30":"Matchday IV.10","45":"Matchday 11","24":"Matchday IV.4","2":"First Round Play-offs / 2nd leg","91":"Matchday","82":"Matchday 3","55":"Matchday II.5","19":"Matchday III.5","121":"Matchday 10","60":"Matchday III.1","33":"Matchday 1","46":"Matchday 12","25":"Matchday IV.5","3":"Matchday 1","90":"Matchday","83":"Matchday 4","54":"Matchday II.4","18":"Matchday III.4","120":"Matchday 9","61":"Matchday III.2","32":"Fifth place playoff / 2nd leg","47":"Play-off 1st Leg"}

@ -23,6 +23,9 @@ body {
<svg width="500" height="500"></svg>
<script src="http://d3js.org/d3.v4.0.0-alpha.50.min.js"></script>
<script src="http://d3js.org/d3-chord.v0.0.min.js"></script>
<script src="teams.json"></script>
<script src="rounds.json"></script>
<script src="games.json"></script>
<script>
// use lookup table to build this array:
@ -120,6 +123,11 @@ function groupTicks(d, step) {
<a href="https://github.com/d3/d3-scale-chromatic">https://github.com/d3/d3-scale-chromatic</a>
https://github.com/jokecamp/sportdb-build-scripts
https://groups.google.com/forum/#!topic/opensport/593H1O7yIdE
https://github.com/openfootball/datafile/blob/master/worldcup.rb
https://openfootball.github.io/questions.html
<h5>TODO</h5>
add team name to each arc
build dataset

Loading…
Cancel
Save