Created
July 19, 2015 00:01
-
-
Save jake-sl/0e6ce2bbb13ad5f546f9 to your computer and use it in GitHub Desktop.
roomv2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Turnt</title> | |
<link href="index.css" rel="stylesheet" type="text/css"/> | |
<link href="http://fonts.googleapis.com/css?family=Roboto+Slab" rel="stylesheet" type="text/css"> | |
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script> | |
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script> | |
</head> | |
<body> | |
<section id="input"> | |
<div class="content"> | |
<header> | |
<h1>Room</h1> | |
<h2>Turn it up or down?</h2> | |
</header> | |
<div class="arrow-container"> | |
<svg id="up-arrow" width="160" height="100" viewBox="0 0 160 100"> | |
<polygon points="0,100 160,100 80,0"/> | |
</svg> | |
<div id="room-opinion"> | |
0 | |
</div> | |
<svg id="down-arrow" width="160" height="100" viewBox="0 0 160 100"> | |
<polygon points="0,0 160,0 80,100"/> | |
</svg> | |
</div> | |
</div> | |
</section> | |
<section id="graph"> | |
</section> | |
<footer> | |
<small> | |
Room is an app for hyperlocal upvoting blah blah blah. Fork us on | |
<a href="https://github.com/jake-sl/room" target="_blank">Github</a>. | |
</small> | |
</footer> | |
</body> | |
<script> | |
var time = jQuery.parseJSON( | |
jQuery.ajax({ | |
url: "http://currentmillis.com/api/millis-since-unix-epoch.php", | |
async: false, | |
dataType: 'json' | |
}).responseText | |
); | |
$(function(){ | |
setInterval(timeUpdateFunction, 200); | |
}); | |
function timeUpdateFunction() { | |
time=time+200; | |
} | |
var myDataRef = new Firebase('https://goodenoughroom.firebaseio.com/'); | |
var name = $('up').val(); | |
var name = $('down').val(); | |
document.getElementById('up-arrow').onclick = function() { | |
myDataRef.push({ 'vote': '1', 'time': time}); | |
}; | |
document.getElementById('down-arrow').onclick = function() { | |
myDataRef.push({ 'vote': '0', 'time': time}); | |
}; | |
var votes = [0] | |
, globalAverage = 0 | |
myDataRef | |
.orderByChild('time') | |
.startAt(time-180000) | |
.endAt(time) | |
.on('child_added', addNewData) | |
function addNewData(snapshot) { | |
var voteJSON = snapshot.val() | |
, voteScore = parseInt(voteJSON.vote, 10) | |
votes.push(voteScore) | |
recalculateGlobalScore() | |
} | |
function recalculateGlobalScore(newScore) { | |
var total = votes.reduce( function(a, b) { return a + b } ) | |
globalAverage = total / votes.length; | |
weightedAverage = globalAverage*100; | |
console.log(weightedAverage); | |
document.getElementById("room-opinion").innerHTML = weightedAverage; | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment