Skip to content

Commit

Permalink
Next stage
Browse files Browse the repository at this point in the history
  • Loading branch information
jthrilly committed Jan 8, 2013
1 parent 2313544 commit 2e514d1
Show file tree
Hide file tree
Showing 8 changed files with 647 additions and 30 deletions.
1 change: 1 addition & 0 deletions data/area_codes.geojson

Large diffs are not rendered by default.

185 changes: 185 additions & 0 deletions data/areas_tweets.csv

Large diffs are not rendered by default.

185 changes: 185 additions & 0 deletions data/areas_user.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/uk_post_areas.geojson

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions data_massage.php
@@ -0,0 +1,63 @@
<?php

// Author: Joshua Melville
//
// Take the post code shapefile geojson and the csv twitter data the merge the two, so that
// each geojson feature contains the twitter numbers for every team
//

// ini_set("precision", "50");
header('Content-Type: application/json');

function csvtogeojson($file) {

$row = 1;
$array = array();
$feature = array();
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row == 1) {
$fields = $data;
} else {
foreach ($fields as $key => $value) {
if (is_numeric($data[$key])) { $data[$key] = $data[$key]* 10000; }
$feature['properties'][$value] = $data[$key];
// echo "key =".$key." value not found: ".$value." for data point: ".$data[2]."<br>";

}


}
$feature['shortcode'] = $data[2];
$array[] = $feature;
$row++;

unset($feature);

}
fclose($handle);
}

return $array;
}

$area_codes = json_decode(file_get_contents("data/uk_post_areas.geojson"), true);

// $fields = array("id","OBJECTID","post_2","Shape_Leng","Shape_Area","arsenal","astonvilla","chelsea","everton","fulham","liverpool","manchestercity","manchesterunited","newcastleunited","norwichcity","queensparkrangers","random","reading","southampton","stokecity","sunderland","swanseacity","tottenhamhotspur","westbromwichalbion","westhamunited","wiganathletic","arsenal_lq","arsenal_norm","astonvilla_lq","astonvilla_norm","chelsea_lq","chelsea_norm","everton_lq","everton_norm","fulham_lq","fulham_norm","liverpool_lq","liverpool_norm","manchestercity_lq","manchestercity_norm","manchesterunited_lq","manchesterunited_norm","newcastleunited_lq","newcastleunited_norm","norwichcity_lq","norwichcity_norm","queensparkrangers_lq","queensparkrangers_norm","random_lq","random_norm","reading_lq","reading_norm","southampton_lq","southampton_norm","stokecity_lq","stokecity_norm","sunderland_lq","sunderland_norm","swanseacity_lq","swanseacity_norm","tottenhamhotspur_lq","tottenhamhotspur_norm","westbromwichalbion_lq","westbromwichalbion_norm","westhamunited_lq","westhamunited_norm","wiganathletic_lq","wiganathletic_norm");
$twitter_data = csvtogeojson('data/areas_user.csv');

foreach ($area_codes['features'] as $key => $value) {

$current_code = $area_codes['features'][$key]['properties']['post_2'];

foreach($twitter_data as $data_key => $data_value) {
if ($twitter_data[$data_key]['shortcode'] == $current_code) {
$area_codes['features'][$key]['twitter_data'] = $twitter_data[$data_key]['properties'];
}

}

}

echo "var area_codes = ".json_encode($area_codes);
?>
200 changes: 183 additions & 17 deletions index_rivalries.html
Expand Up @@ -8,7 +8,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1.0 user-scaleable=no">

<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

Expand All @@ -21,20 +21,73 @@
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.5/leaflet.ie.css" />
<![endif]-->
<script src="js/rivalries.js"></script>
<script src="data/uk_post_areas.geojson" type="text/javascript"></script>
<script src="data/area_codes.geojson" type="text/javascript"></script>
<style type="text/css">
html, body {
padding:0;
margin:0;
width:100%;
height:100%;

body {
padding: 0;
margin: 0;
}

html, body, #map {
height: 100%;
}

#map {
width:100%;
height:100%;
opacity:1;
}

.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;
background: white;
background: rgba(0,0,0,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
width:200px;
position:relative;
top:100px;
color:#fff;
}
.info h4 {
margin: 0 0 5px;
color: #777;
}

.legend {
text-align: left;
line-height: 18px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
.overlay {
position:absolute;
background: rgba(0,0,0,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
}
.title {
top:10px;
right:10px;
}
.header {
top:0px;
left:0%;
right:0%;
text-align:center;
}
.box {
bottom:90px;
left:30%;
right:30%;
}



</style>
</head>
<body>
Expand All @@ -49,21 +102,134 @@
<!-- Add your site or application content here -->

<div id="map"></div>

<div class="overlay header">
<div style="width:400px;display:block;text-align:center;margin:0 auto;height:75px;padding-top:10px;color:white">
<div id="team1" style="float:left;">
<image id="team1logo" src="" style="width:50px;height:50px" />
<br/><span id="team1name"></span>
</div>

<div id="team2" style="float:right">
<image id="team2logo" src="" style="width:50px;height:50px" />
<br/><span id="team2name"></span>
</div>
<div id="vs" style="height:200px;line-height:60px;font-size:38px">Vs.</div>
</div>
</div>

<script>
var map = L.map('map').setView([54.6342, -0.2], 6);

var current_rivalry = 0; // this is what we will change with our drop down select box
var team1_variable = rivalries[current_rivalry]['teams'][0]['variable'];
var team2_variable = rivalries[current_rivalry]['teams'][1]['variable'];

var team1_statistic = team1_variable+'_norm';
var team2_statistic = team2_variable+'_norm';
var value1,value2;


// this will be refactored into some sort of changeRivalry() function
$('#team1logo').attr("src", rivalries[current_rivalry]['teams'][0]['crest']);
$('#team1name').text(rivalries[current_rivalry]['teams'][0]['name']);

$('#team2logo').attr("src", rivalries[current_rivalry]['teams'][1]['crest']);
$('#team2name').text(rivalries[current_rivalry]['teams'][1]['name']);

var map = L.map('map').setView([54.6342, -3.2], 6);

L.tileLayer('http://{s}.tile.cloudmade.com/{key}/22677/256/{z}/{x}/{y}.png', {
attribution: 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2012 CloudMade',
key: 'BC9A493B41014CAABB98F0471D759707'
}).addTo(map);

L.geoJson(area_codes, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng);
}
}).addTo(map);
// control that shows state info on hover
var info = L.control();

info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};

info.update = function (props, twitter_data) {
this._div.innerHTML = '<h4>Twitter Support</h4> Postcode region:' + (props ?
'<b>' + props.post_2 + '</b><br />'+rivalries[current_rivalry]['teams'][0]['name']+': '+ twitter_data[team1_statistic] + '<br>'+rivalries[current_rivalry]['teams'][1]['name']+': '+ twitter_data[team2_statistic]
: 'Hover over a postcode region');

};

info.addTo(map);

function highlightFeature(e) {
var layer = e.target;

layer.setStyle({
weight: 2,
color: '#666666',
fillOpacity: 0.3
});

if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}

info.update(layer.feature.properties, layer.feature.twitter_data);
}

function resetHighlight(e) {
geojson.resetStyle(e.target);
info.update();
}

function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}

function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}

function style(feature) {

var value1,value2; //temp variables for storing statistics

$.each(feature.twitter_data, function( key, value ) {
if (key == team1_statistic) {
value1 = value;
} else if (key == team2_statistic) {
value2 = value;
}
});

polygoncolor = value1 > value2 ? rivalries[current_rivalry]['teams'][0]['color'] : rivalries[current_rivalry]['teams'][1]['color'];

return {
weight: 1,
opacity: 1,
color: '#ffffff',
fillOpacity: 0.5,
fillColor: polygoncolor,

};
}

function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}

geojson = L.geoJson(area_codes, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);

</script>


Expand Down
26 changes: 14 additions & 12 deletions js/rivalries.js
@@ -1,16 +1,18 @@
rivalries=[
{
"team1": "Manchester United",
"team1_crest": "img/crests/Manchester_United_FC.png",
"team2": "Manchester City",
"team2_crest": "img/crests/Manchester_City.png",
"rivalry_info": "The Manchester derby."
},
{
"team1": "Arsenal",
"team1_crest": "img/crests/Arsenal_FC.png",
"team2": "Tottenham Hotspur",
"team2_crest": "img/crests/Tottenham_Hotspur.png",
"rivalry_info": "The north London derby."
"teams": [{
"name": "Manchester United",
"crest": "img/crests/Manchester_United_FC.png",
"color": "#d02d3e",
"variable": "manchesterunited"
},
{
"name": "Manchester City",
"crest": "img/crests/Manchester_City.png",
"color": "#8CBED6",
"variable": "manchestercity"
}],
"rivalry_info": "The Manchester derby.",
"centre_map": [54.2323,-01,2345]
}
]
15 changes: 15 additions & 0 deletions test.php
@@ -0,0 +1,15 @@
<?php

// $number = filter_var("4.39239E-05", FILTER_VALIDATE_FLOAT);
$num = 4.39239E-05;
// $n = 4.39518e+7;
$num = $num*100000; //YOUR NUMBER
printf("SCINO = '%e'\n", $num);
//%e specifies sci-notation


printf("FLOAT = '%d'\n", $num);
// %d specifies decimal


?>

0 comments on commit 2e514d1

Please sign in to comment.