Skip to content

Instantly share code, notes, and snippets.

@jake-sl
Created July 18, 2015 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jake-sl/a1ee800965d593e4eaaf to your computer and use it in GitHub Desktop.
Save jake-sl/a1ee800965d593e4eaaf to your computer and use it in GitHub Desktop.
<!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">
5
</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 = []
, globalAverage = 0
myDataRef
.orderByChild('time')
.startAt(time-180000)
.endAt(time)
.on('child_added', addNewData)
function addNewData(voteJSON) {
var 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;
console.log(total);
weightedAverage = globalAverage*100;
//console.log(weightedAverage);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment