commit 4030198e649e30617b59c37f17fde9152bc2a4c3 Author: Ben Burlingham Date: Mon Oct 10 06:54:03 2016 -0700 Worldcup data pulled. Teams parsed. diff --git a/Datafile b/Datafile new file mode 100644 index 0000000..b40f708 --- /dev/null +++ b/Datafile @@ -0,0 +1,13 @@ +#################################### +# Datafile for World Cups +# +# use +# $ sportdb new worldcup + + +world 'world.db', setup: 'countries' + + +football 'national-teams' +football 'world-cup' + diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d3ae169 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'http://rubygems.org' + +gem "activerecord", "= 4.2.7.1" +gem "sportdb" diff --git a/teams.hs b/teams.hs new file mode 100644 index 0000000..702a987 --- /dev/null +++ b/teams.hs @@ -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 Team = Team { _id :: Value, country :: Value } deriving (Show) + +instance ToJSON Team where + toJSON Team{..} = object [ "i" .= _id, "c" .= country ] + +instance FromJSON Team where + parseJSON = withObject "team" $ \o -> do + _id <- o .: "id" + country <- o .: "title" + return Team{..} + +reduce :: [Team] -> Value -> [Team] +reduce acc x = case (parseEither parseJSON x :: Either String Team) of + (Left s) -> error s + (Right v) -> v : acc + +parseTeams :: Either String [Value] -> [Team] +parseTeams (Left x) = error x +parseTeams (Right xs) = P.foldl reduce [] xs + +parseResult :: [Team] -> [(String, Value)] +parseResult = P.foldl (\acc x -> (extractId x, country x) : acc) [] + where + extractId = BL8.unpack . encode . _id + +main :: IO () +main = do + src <- BL.readFile "./data/teams.json" + let teams = parseTeams (AE.eitherDecode src :: Either String [Value]) + BL.writeFile "teams.json" $ encode $ HM.fromList $ parseResult teams diff --git a/teams.json b/teams.json new file mode 100644 index 0000000..c7753a9 --- /dev/null +++ b/teams.json @@ -0,0 +1 @@ +{"112":"Bonaire","149":"Hungary","211":"Brazil","163":"Liechtenstein","105":"Puerto Rico","170":"England","17":"Côte d'Ivoire","71":"Hong Kong","156":"Russia","48":"Malawi","113":"Guadeloupe","148":"Czech Republic","210":"Argentina","162":"Bosnia-Herzegovina","104":"Montserrat","171":"Scotland","16":"Burkina Faso","70":"China","157":"Turkey","49":"Mozambique","28":"Gabon","110":"Turks and Caicos Islands","213":"Paraguay","59":"Bangladesh","161":"Iceland","198":"Fiji","107":"Saint Lucia","172":"Wales","15":"Benin","73":"North Korea","154":"Croatia","29":"São Tomé and Príncipe","111":"United States Virgin Islands","212":"Chile","58":"Afghanistan","160":"Norway","199":"New Caledonia","106":"Saint Kitts and Nevis","173":"Northern Ireland","14":"Sierra Leone","72":"Japan","155":"Serbia","8":"Guinea","116":"Sint Maarten","88":"Vietnam","215":"Colombia","189":"Yemen","167":"Georgia","101":"Grenada","174":"Faroe Islands","13":"Senegal","75":"Macau","138":"Portugal","152":"Belarus","39":"Tanzania","9":"Guinea-Bissau","117":"Honduras","89":"Anguilla","214":"Uruguay","188":"United Arab Emirates","166":"San Marino","100":"Dominican Republic","175":"Gibraltar","12":"Mauritania","74":"South Korea","139":"Slovakia","153":"Switzerland","38":"Sudan","114":"Martinique","99":"Dominica","217":"Peru","165":"Moldova","103":"Jamaica","176":"Israel","208":"Niue","11":"Mali","77":"Taiwan","129":"Spain","68":"Turkmenistan","150":"Andorra","115":"Saint Martin","98":"Curaçao","216":"Ecuador","164":"Montenegro","102":"Haiti","177":"Bahrain","209":"Tuvalu","10":"Liberia","76":"Mongolia","128":"Estonia","69":"Uzbekistan","151":"Albania","22":"Cameroon","4":"Libya","97":"Cuba","84":"Philippines","141":"Bulgaria","219":"Bolivia","53":"Swaziland","185":"Qatar","192":"Canada","178":"Iran","206":"Vanuatu","220":"Guyana","79":"Cambodia","127":"Germany","134":"Italy","66":"Sri Lanka","35":"Rwanda","40":"Uganda","23":"Central African Republic","5":"Tunisia","96":"Cayman Islands","85":"Singapore","140":"Slovenia","218":"Venezuela","52":"South Africa","184":"Palestine","193":"Australia","179":"Iraq","207":"Kiribati","221":"Suriname","78":"Brunei","126":"Cyprus","135":"Luxembourg","67":"Tajikistan","34":"Kenya","41":"Zanzibar","20":"Nigeria","6":"Cape Verde","118":"Costa Rica","95":"British Virgin Islands","86":"Thailand","143":"Latvija","51":"Seychelles","187":"Syria","169":"Azerbaijan","190":"Mexico","204":"Tahiti","222":"French Guiana","125":"Belgium","136":"Malta","64":"Nepal","37":"South Sudan","42":"Angola","21":"Togo","7":"Gambia","119":"El Salvador","94":"Bermuda","87":"Timor-Leste","142":"Denmark","50":"Namibia","186":"Saudi Arabia","168":"Armenia","191":"United States","205":"Tonga","124":"Austria","137":"Netherlands","65":"Pakistan","36":"Somalia","43":"Botswana","26":"Congo DR","93":"Barbados","80":"Indonesia","145":"Poland","57":"Kazakhstan","181":"Kuwait","196":"American Samoa","109":"Trinidad and Tobago","202":"Samoa","123":"Nicaragua","130":"Finland","62":"Kyrgyzstan","31":"Djibouti","44":"Comoros","27":"Equatorial Guinea","1":"Algeria","92":"Bahamas","81":"Laos","144":"Lithuania","56":"Réunion","180":"Jordan","197":"Cook Islands","108":"Saint Vincent and the Grenadines","203":"Solomon Islands","122":"Belize","131":"France","63":"Maldives","30":"Burundi","45":"Lesotho","24":"Chad","2":"Egypt","91":"Aruba","82":"Malaysia","147":"Sweden","55":"Zimbabwe","183":"Oman","194":"Guam","200":"New Zealand","19":"Niger","121":"Guatemala","132":"Greece","60":"Bhutan","158":"Ukraine","33":"Ethiopia","46":"Mauritius","25":"Congo","3":"Morocco","90":"Antigua and Barbuda","83":"Myanmar","146":"Romania","54":"Zambia","182":"Lebanon","195":"Northern Mariana Islands","201":"Papua New Guinea","18":"Ghana","120":"Panama","133":"Ireland","61":"India","159":"Macedonia","32":"Eritrea","47":"Madagascar"} \ No newline at end of file diff --git a/worldcup.db b/worldcup.db new file mode 100644 index 0000000..f912f2e Binary files /dev/null and b/worldcup.db differ diff --git a/worldcup.html b/worldcup.html new file mode 100644 index 0000000..2613ad8 --- /dev/null +++ b/worldcup.html @@ -0,0 +1,126 @@ + + + + + + + + +
+
Lessons learned
+ scaleOrdinal vs scaleLinear (only 2 colors!) vs interpolateCool vs d3.schemeColor20c
+ ribbon source vs index (change fill them differently) + + https://github.com/d3/d3-scale-chromatic + +
TODO
+ add team name to each arc + build dataset +
diff --git a/worldcup.js b/worldcup.js new file mode 100644 index 0000000..560ee2f --- /dev/null +++ b/worldcup.js @@ -0,0 +1,17 @@ +const SqliteToJson = require('sqlite-to-json'); +const sqlite3 = require('sqlite3'); +const exporter = new SqliteToJson({ + client: new sqlite3.Database('./worldcup.db') +}); + +exporter.tables((err, tables) => { + errorHandler("Listing all tables.", err); + + tables.forEach((table) => { + exporter.save(table, `./data/${table}.json`, errorHandler.bind(null,`Saving ${table}.`)); + }); +}); + +function errorHandler(msg, err) { + err ? console.error(`ERROR ${msg}:\n ${err}`) : console.log(msg); +}