Commit 08a24b6e authored by David Haynes's avatar David Haynes 🙆

Merge branch 'master' of git.gmu.edu:srct/weather

parents 9a9d8bae 53aa91e6
cd weather
meteor --settings config/settings.json
cd ..
......@@ -13,3 +13,4 @@ notices-for-facebook-graph-api-2
1.3.0-split-minifiers-package
1.4.0-remove-old-dev-bundle-link
1.4.1-add-shell-server-package
1.4.3-split-account-service-packages
......@@ -6,19 +6,19 @@
meteor-base@1.0.4 # Packages every Meteor app needs to have
mobile-experience@1.0.4 # Packages for a great mobile UX
mongo@1.1.14 # The database Meteor supports right now
mongo@1.1.17 # The database Meteor supports right now
blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views
session@1.1.7 # Client-side reactive dictionary for your app
jquery@1.11.10 # Helpful client-side library
tracker@1.1.1 # Meteor's client-side reactive programming library
tracker@1.1.3 # Meteor's client-side reactive programming library
es5-shim@4.6.15 # ECMAScript 5 compatibility for older browsers.
ecmascript@0.6.1 # Enable ECMAScript2015+ syntax in app code
ecmascript@0.7.3 # Enable ECMAScript2015+ syntax in app code
zodiase:mdl
mquandalle:bower
http@1.2.10
standard-minifier-css@1.3.2
standard-minifier-js@1.2.1
shell-server@0.2.1
http@1.2.12
standard-minifier-css@1.3.4
standard-minifier-js@2.0.0
shell-server@0.2.3
aldeed:simple-schema # Schema support for db
aldeed:simple-schema@1.5.3
allow-deny@1.0.5
autoupdate@1.3.12
babel-compiler@6.13.0
babel-compiler@6.18.2
babel-runtime@1.0.1
base64@1.0.10
binary-heap@1.0.10
blaze@2.3.0
blaze-html-templates@1.1.0
blaze@2.3.2
blaze-html-templates@1.1.2
blaze-tools@1.0.10
boilerplate-generator@1.0.11
caching-compiler@1.1.9
caching-html-compiler@1.1.0
caching-html-compiler@1.1.2
callback-hook@1.0.10
check@1.2.4
check@1.2.5
ddp@1.2.5
ddp-client@1.3.2
ddp-client@1.3.4
ddp-common@1.2.8
ddp-server@1.3.12
ddp-server@1.3.14
deps@1.0.12
diff-sequence@1.0.7
ecmascript@0.6.1
ecmascript@0.7.3
ecmascript-runtime@0.3.15
ejson@1.0.13
es5-shim@4.6.15
......@@ -29,27 +29,27 @@ geojson-utils@1.0.10
hot-code-push@1.0.4
html-tools@1.0.11
htmljs@1.0.11
http@1.2.10
http@1.2.12
id-map@1.0.9
jquery@1.11.10
launch-screen@1.1.0
launch-screen@1.1.1
livedata@1.0.18
logging@1.1.16
logging@1.1.17
mdg:validation-error@0.5.1
meteor@1.6.0
meteor@1.6.1
meteor-base@1.0.4
minifier-css@1.2.15
minifier-js@1.2.15
minimongo@1.0.19
minifier-css@1.2.16
minifier-js@2.0.0
minimongo@1.0.23
mobile-experience@1.0.4
mobile-status-bar@1.0.13
modules@0.7.7
modules-runtime@0.7.8
mongo@1.1.14
mobile-status-bar@1.0.14
modules@0.8.2
modules-runtime@0.7.10
mongo@1.1.17
mongo-id@1.0.6
mquandalle:bower@1.5.2_1
npm-mongo@2.2.16_1
observe-sequence@1.0.14
npm-mongo@2.2.24
observe-sequence@1.0.16
ordered-dict@1.0.9
promise@0.8.8
random@1.0.10
......@@ -59,20 +59,20 @@ reload@1.1.11
retry@1.0.9
routepolicy@1.0.12
session@1.1.7
shell-server@0.2.1
spacebars@1.0.13
spacebars-compiler@1.1.0
standard-minifier-css@1.3.2
standard-minifier-js@1.2.1
templating@1.3.0
templating-compiler@1.3.0
templating-runtime@1.3.0
templating-tools@1.1.0
tracker@1.1.1
ui@1.0.12
shell-server@0.2.3
spacebars@1.0.15
spacebars-compiler@1.1.2
standard-minifier-css@1.3.4
standard-minifier-js@2.0.0
templating@1.3.2
templating-compiler@1.3.2
templating-runtime@1.3.2
templating-tools@1.1.2
tracker@1.1.3
ui@1.0.13
underscore@1.0.10
url@1.0.11
webapp@1.3.12
url@1.1.0
webapp@1.3.15
webapp-hashing@1.0.9
zodiase:check@0.0.5
zodiase:material-design-icons-fonts@3.0.1
......
......@@ -9,39 +9,19 @@
</div>
<!-- Tab Bar Container , and Tab links -->
<div class="mdl-layout__tab-bar mdl-js-ripple-effect header-bg" style="background: #006633;">
<a id="fairfax-tab-button" href="#fairfax" class="mdl-layout__tab is-active">Fairfax</a>
<!--a href="#arlington" class="mdl-layout__tab">Arlington</a>
<a href="#scitech" class="mdl-layout__tab">SciTech</a>
<a href="#korea" class="mdl-layout__tab">Mason Korea</a -->
<a id="fairfax-tab-button" href="#weather" class="mdl-layout__tab is-active">Fairfax</a>
<a id="arlington-tab-button" href="#weather" class="mdl-layout__tab">Arlington</a>
<a id="scitech-tab-button" href="#weather" class="mdl-layout__tab">SciTech</a>
<a id="korea-tab-button" href="#weather" class="mdl-layout__tab">Mason Korea</a>
</div>
</header>
<!-- MDL Layout Header -->
<main class="mdl-layout__content">
<!-- "is-active" class to set the default active tab -->
<section class="mdl-layout__tab-panel is-active" id="fairfax">
<section class="mdl-layout__tab-panel is-active" id="weather">
<div class="page-content">
<div class="page-content">{{> weather}}</div>
</div>
</section>
<!--
<section class="mdl-layout__tab-panel" id="arlington">
<div class="page-content">
<div class="page-content">{{> weather}}</div>
</div>
</section>
<section class="mdl-layout__tab-panel" id="scitech">
<div class="page-content">
<div class="page-content">{{> weather}}</div>
</div>
</section>
<section class="mdl-layout__tab-panel" id="korea">
<div class="page-content">
<div class="page-content">{{> weather}}</div>
</div>
</section>
-->
{{> footer}}
</main>
</div>
......
Template.home.onRendered(function(){
// Add listeners to each tab to change the current location.
// When locationName changes, the weather data is obained for the new location.
//TODO: Use Meteor's built in event system (see below)
document.getElementById('fairfax-tab-button').addEventListener('click', function(){
Session.set('locationName', 'FAIRFAX');
});
document.getElementById('arlington-tab-button').addEventListener('click', function(){
Session.set('locationName', 'ARLINGTON');
});
document.getElementById('scitech-tab-button').addEventListener('click', function(){
Session.set('locationName', 'SCITECH');
});
document.getElementById('korea-tab-button').addEventListener('click', function(){
Session.set('locationName', 'KOREA');
});
});
/*
This is the proper way to handle event listeners in Meteor, but
for some reason the events don't fire this way. Can't find a fix, so I
implmented them using normal JavaScript + HTML seen above.
Template.home.events({
'click #fairfax-tab-button' (event) {
'click #fairfax-tab-button': function() {
Session.set('locationName', 'FAIRFAX');
},
'click a.mdl-layout__tab-bar' (event) {
console.log(event);
'click #arlington-tab-button': function() {
Session.set('locationName', 'ARLINGTON');
},
'click #scitech-tab-button': function() {
Session.set('locationName', 'SCITECH');
},
'click #korea-tab-button': function() {
Session.set('locationName', 'KOREA');
}
});
Template.home.onRendered(function() {
document.getElementById("#fairfax-tab-button").addEventListener("click", function(){
});
});
*/
......@@ -101,7 +101,7 @@ Template.weather.helpers({
},
getDayNameFromTime: function(timestamp) {
var given = new Date(timestamp * 1000);
console.log(given);
//console.log(given);
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
return days[ given.getDay() ];
},
......@@ -147,13 +147,16 @@ Template.weather.helpers({
var weatherData = {};
var weatherDataDependency = new Tracker.Dependency;
Template.weather.onCreated(function(){
// Set default location to fairfax
Session.set("locationName", "FAIRFAX");
// Function that is ran when any dependencies change
Tracker.autorun(function () {
var locName = Session.get("locationName");
var location = LOCATIONS[locName];
Meteor.call('getWeather', location.lat, location.long, function(error, result) {
// Get weather for current location
Meteor.call('getWeather', location, function(error, result) {
weatherData = result;
document.title = "SRCT Weather • "+Math.round(result.data.currently.temperature)+"° F"
weatherDataDependency.changed();
......
......@@ -6,8 +6,8 @@
* https://guide.meteor.com/methods.html
*/
Meteor.methods({
getWeather: function(latitude, longitude) {
return getWeather(latitude, longitude);
getWeather: function(location) {
return getWeather(location);
}
});
......@@ -15,21 +15,23 @@ Meteor.methods({
* Gets the most recent wether data based on the given Lat. and Long. and then
* returns it. Only gets new data if we have left the acceptable cache time.
*
* @param latitude - A long that represents the Lat. of the weather data we
* want.
* @param longitude - A long that represents the Long. of the weather data we
* want.
* @param location - A dictionary from locations.js containing latitude, longitude,
* and name of the campus we want to retrive the weather for.
*
* @return weatherData - An object holding the API call data and retrieval time.
*/
function getWeather(latitude, longitude) {
var curWeatherData = WeatherData.find({}, {sort: {retrievalTime: -1, limit: 1}}).fetch()[0];
function getWeather(location) {
// Query the database for the weather data at given location
var curWeatherData = WeatherData.find({ locationName: { $eq: location.name }}, {sort: {retrievalTime: -1, limit: 1}}).fetch()[0];
// Check if there is data at all
if(curWeatherData === undefined) {
console.log("Getting first time data.")
var weatherData = getWeatherFromAPI(latitude, longitude);
// If not, get data from API
var weatherData = getWeatherFromAPI(location.lat, location.long);
// Insert data into database
WeatherData.insert(weatherData);
return curWeatherData;
return weatherData;
}
// Get current time
......@@ -47,7 +49,7 @@ function getWeather(latitude, longitude) {
// Data is expired, retrieve again.
console.log("Data Age: " + timeDiff)
console.log("Cache expired. Retrieving...")
var weatherData = getWeatherFromAPI(latitude, longitude);
var weatherData = getWeatherFromAPI(location.lat, location.long);
// Check if there was an error in the API call.
if(weatherData === undefined) {
......@@ -93,9 +95,27 @@ function getWeatherFromAPI(latitude, longitude) {
var date = new Date();
var linuxTime = date.getTime(); // convert millis to seconds
// Find which location the data is for
var location = "undefined";
switch(latitude) {
case LOCATIONS.FAIRFAX.lat:
location = LOCATIONS.FAIRFAX.name;
break;
case LOCATIONS.ARLINGTON.lat:
location = LOCATIONS.ARLINGTON.name;
break;
case LOCATIONS.SCITECH.lat:
location = LOCATIONS.SCITECH.name;
break;
case LOCATIONS.KOREA.lat:
location = LOCATIONS.KOREA.name;
break;
}
// Store the retrieval time with the data. We shouldn't get the same data
// every time someone goes to the page.
var weatherData = {
locationName: location,
retrievalTime: linuxTime,
data: result.data,
error: false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment