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

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