-
-
Save anonymous/354693058ecc00d27a73ba5802e5a09a to your computer and use it in GitHub Desktop.
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
'use strict'; | |
//Require Packages | |
const express = require('express'); | |
//Models | |
const tweets = require('./models/tweets.js'); | |
const events = require('./models/events.js'); | |
const achievements = require('./models/achievements.js'); | |
const housepoints = require('./models/housepoints.js'); | |
const organiser = require('./organiser.js'); | |
const renderer = require('./renderer.js'); | |
//Setup Application | |
const app = express(); | |
const port = 1993; | |
//Setup Static Server | |
app.use('/static', express.static(__dirname + '/public')); | |
//Setup View Engine | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'pug'); | |
//Routes | |
app.get('/reception', function (request, response) { | |
Promise.all([ | |
//events.getPromise(), | |
tweets.getPromise('xx'), | |
tweets.getPromise('xx'), | |
tweets.getPromise('xx'), | |
tweets.getPromise('xx'), | |
tweets.getPromise('xx'), | |
tweets.getPromise('xx'), | |
achievements.getPromise(), | |
//housepoints.getPromise() | |
]) | |
.then(function (data) { | |
return organiser.shuffle(data); | |
}) | |
.then(function (shuffledData) { | |
//response.send(shuffledData); | |
response.render('layout', { | |
title: 'Visual Display', | |
slides: shuffledData | |
}); | |
}) | |
.catch(function (reason) { | |
console.log(reason); | |
}); | |
}); | |
//Start Server | |
app.listen(port, function () { | |
console.log(`Visual Display server started on port ${port}.`); | |
}); |
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
html | |
head | |
title= title | |
body | |
each slide in slides | |
p= slide.type |
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
function shuffle(data) { | |
return new Promise(function (resolve, reject) { | |
let shuffledData = []; | |
//Combine data of the same type | |
let tweets = []; | |
let achievements = []; | |
for (var i in data) { | |
switch (data[i].type) { | |
case "tweets": | |
for (var j in data[i].data) { | |
tweets.push(data[i].data[j]); | |
} | |
randomiseOrder(tweets); | |
break; | |
case "achievements": | |
for (var j in data[i].data) { | |
achievements.push(data[i].data[j]); | |
} | |
randomiseOrder(achievements); | |
break; | |
} | |
} | |
//Shuffle Data into 3 achievements then a tweet; | |
let achievementCount = 0; | |
let tweetCount = 0; | |
for (var i in achievements) { | |
shuffledData.push(achievements[i]); | |
achievementCount++; | |
//If 3 achievments put in a tweet | |
if (achievementCount == 2) { | |
shuffledData.push(tweets[tweetCount]); | |
achievementCount = 0; | |
if (tweetCount < tweets.length){ | |
tweetCount++; | |
}else{ | |
tweetCount = 0; | |
} | |
} | |
} | |
resolve(shuffledData); | |
}); | |
} | |
//Helper Functions | |
//http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array | |
function randomiseOrder(array) { | |
var currentIndex = array.length, | |
temporaryValue, randomIndex; | |
// While there remain elements to shuffle... | |
while (0 !== currentIndex) { | |
// Pick a remaining element... | |
randomIndex = Math.floor(Math.random() * currentIndex); | |
currentIndex -= 1; | |
// And swap it with the current element. | |
temporaryValue = array[currentIndex]; | |
array[currentIndex] = array[randomIndex]; | |
array[randomIndex] = temporaryValue; | |
} | |
return array; | |
} | |
module.exports.shuffle = shuffle; | |
/*Takes in the collection of data and will shuffle them to something like this: | |
Student Achievment | |
Student Achievment | |
Student Achievment | |
Tweet | |
Student Achievment | |
Student Achievment | |
Student Achievment | |
Events | |
Student Achievment | |
Student Achievment | |
Student Achievment | |
House Points | |
--(Repeat) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let's share the screen, do you have team viewer