Skip to content

Commit 9390331

Browse files
Merge pull request #27 from hurricanemark/Phase2-BaselineToSeriousWorks
Phase2 baseline to serious works
2 parents 90293f1 + 27a129d commit 9390331

File tree

6 files changed

+26
-65
lines changed

6 files changed

+26
-65
lines changed

index.js

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ app.get('/weatherbit', (req, res) => {
3131
// console.log('render get weatherbit:');
3232
// console.dir(req.params)
3333
// console.dir(req.body);
34-
let apikey = encrypt(process.env.WEATHERBIT_KEY);
35-
res.render('pages/weatherbit', { key: apikey });
34+
res.render('pages/weatherbit');
3635
})
3736

3837
// Posting data to the client-side requires two API calls.
@@ -181,7 +180,6 @@ function getWeatherBitAirQuality(city) {
181180
}
182181

183182

184-
185183
/*
186184
* Return multiple promises consists of currentConditions and dailyForecast data.
187185
*/
@@ -204,56 +202,12 @@ async function gatherWeatheBits(city) {
204202
}
205203
}
206204

207-
// post weather data to the client-side
208-
app.post('/', (req, res) => {
209-
// currentLoc();
210-
// console.log(currentLoc);
211-
// console.log("Lng: " + longitude + ", Lat: " + latitude);
212-
console.dir(req.params);
213-
console.dir(req.body);
214-
215-
return;
216-
// call weatherAPI for data
217-
let apiKey = process.env.WEATHER_VISUALCROSSING_API_KEY;
218-
let city = req.body.locale;
219-
let url = process.env.WEATHER_VISUALCROSSING_API_BASE_URI;
220-
221-
/*VISUALCROSSING_URI=https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/${city}?unitGroup=us&contentType=json&key=${apiKey} */
222-
let uriStr = `${url}${city}?unitGroup=us&contentType=json&key=${apiKey}`;
223-
// console.log(uriStr);
224-
try {
225-
request(uriStr, async function (err, response, body) {
226-
console.log(response.statusCode);
227-
228-
if (response.statusCode == 429) {
229-
console.log("You have exceeded your API call limit with visualcrossing.com!");
230-
res.render('index', { locale: city, status: response.statusCode, data: null, error: "Visualcrossing API call limit exceeded." });
231-
}
232-
if (response.statusCode == 400) {
233-
res.render('index', { locale: city, status: response.statusCode, data: null, error: "Please check your input." });
234-
}
235-
if (response.statusCode === 200) {
236-
237-
let weather = await JSON.parse(body);
238-
res.render('index', { locale: city, status: response.statusCode, data: weather, error: null });
239-
} else {
240-
res.render('index', { locale: city, status: response.statusCode, data: null, error: 'Error, please check your input.'});
241-
}
242-
243-
});
244-
245-
} catch (err) {
246-
res.render('index', { locale: city, data: null, forecast: null, error: err.message });
247-
}
248-
});
249-
250-
251205
// about page
252206
app.get('/about', function(req, res) {
253207
res.render('pages/about');
254208
});
255209

256-
let port = process.env.PORT || 3210;
210+
let port = process.env.PORT || 3000;
257211

258212
// creating a server that is listening on ${port} for connections.
259213
app.listen(port, () => {

public/Runtime.JPG

93.4 KB
Loading

public/Runtime.PNG

-33.6 KB
Loading

views/pages/utils.ejs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,17 @@ unixTsToLocalTime = (unix_ts) => {
1515
return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
1616
}
1717
18+
trendingTemperature = (dataArr) => {
19+
var sum = 0;
20+
for (var item of dataArr) {
21+
sum += item.temp;
22+
}
23+
let average = sum / dataArr.length;
24+
let diff = average - dataArr[0].temp;
25+
if ( diff > 0 ) {
26+
return "Warming trend ahead.";
27+
} else {
28+
return "Cooling trend ahead.";
29+
}
30+
}
1831
%>

views/pages/weatherbit.ejs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<header>
1111
<%- include('./../partials/header'); %>
1212
</header>
13-
<main onload="">
13+
<main>
1414
<br />
1515
<div>
1616
<fieldset>
@@ -36,23 +36,19 @@
3636
<br />
3737
<strong>Geolocation</strong>: <%= curData.lat %>, <%= curData.lon %>
3838
<br />
39-
<strong>Time zone: </strong>
40-
<%= curData.timezone %>
39+
<strong>Datetime</strong>: <%= curData.ob_time %>
40+
<br />
41+
<strong>Time zone</strong>: <%= curData.timezone %>
4142
<br />
4243
<hr />
4344
</p>
4445
<table class="styled-table">
4546
<tr class="active-row">
46-
<th>Datetime: </th>
47+
<th>Cloud cover(%): </th>
4748
<td>
48-
<%= curData.ob_time %>
49+
<%= curData.clouds %>
4950
</td>
5051
</tr>
51-
<th>Cloud cover(%): </th>
52-
<td>
53-
<%= curData.clouds %>
54-
</td>
55-
</tr>
5652
<th>Temperature(F): </th>
5753
<td>
5854
<%= curData.temp %>
@@ -197,11 +193,13 @@
197193
<div class="row">
198194
<div class="col-sm-12">
199195
<h5>Extended Forecast</h5>
196+
200197
<div class="jumbotron jumbotron-fluid" style="padding:10px 5px 15px 20px;">
201198
<% if( typeof(error)==="undefined" || foreStatus===400 ){ %>
202199
<p style="color:gray"> Waiting for data.</p>
203200
<% } else { %>
204-
<table class="styled-table">
201+
<div style="color:rgb(18, 83, 175);"><%= trendingTemperature(foreData.data) %></div>
202+
<table class="styled-table" style="overflow-x: auto;">
205203
<thead>
206204
<tr class="w-35">
207205
<th style="color:black;"> Date</th>
@@ -210,8 +208,7 @@
210208
<th style="color:rgb(27, 119, 223);"> TemperatureF) </th>
211209
<th style="color:rgba(20, 15, 177, 0.474);"> Pressure(㎧)</th>
212210
<th style="color:green;"> Humidity</th>
213-
<th style="color:rgb(198, 73, 15);"> Wind Speed</th>
214-
<th style="color:rgb(198, 15, 195);"> Wind Gust</th>
211+
<th style="color:rgb(198, 15, 195);"> Wind</th>
215212
<th style="color:rgb(15, 22, 207);"> Cloud Cover(%)</th>
216213
<th style="color:rgb(30, 140, 224);"> Visibility</th>
217214
<th style="color:rgb(78, 122, 80);"> UV Index</th>
@@ -242,9 +239,6 @@
242239
<td style="color:green;">
243240
<%= forecast[i].rh %>
244241
</td>
245-
<td style="color:rgb(198, 73, 15);">
246-
<%= forecast[i].wind_gust_spd %>
247-
</td>
248242
<td style="color:rgb(198, 15, 195);">
249243
<%= forecast[i].wind_gust_spd %> <%= forecast[i].wind_cdir %>
250244
</td>

views/partials/footer.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- This code contains copyright information and uses several classes from Bootstrap for styling. -->
22
<p class="text-center text-muted" style="
3-
position:fixed;
3+
44
bottom:0;
55
left:20px;
66
">&copy; Copyright 2022 by The Awesome TechRolEmi</p>

0 commit comments

Comments
 (0)