Skip to content

Commit d990e45

Browse files
Merge pull request #29 from hurricanemark/Phase2-BaselineToSeriousWorks
Phase2 baseline to serious works
2 parents d4d487a + a84c108 commit d990e45

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

public/README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,59 @@ Partial files are pieces of reusable code segment that typically appear again an
179179
</html>
180180
```
181181

182-
6. Create ejs template file `index.ejs`, and inject partial files as follow.
182+
183+
6. Create ejs file `utils.ejs` containing client-side functions. Notice the ejs tags <% ... %>
184+
185+
```c
186+
<%
187+
188+
// Convert Unix_TimeStamp to Local DateTime.
189+
unixTsToLocalTime = (unix_ts) => {
190+
// Create a new JavaScript Date object based on the timestamp
191+
// multiplied by 1000 so that the argument is in milliseconds, not seconds.
192+
var date = new Date(unix_ts * 1000);
193+
// Hours part from the timestamp
194+
var hours = date.getHours();
195+
// Minutes part from the timestamp
196+
var minutes = "0" + date.getMinutes();
197+
// Seconds part from the timestamp
198+
var seconds = "0" + date.getSeconds();
199+
200+
// Will display time in 10:30:23 format
201+
return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
202+
}
203+
204+
// Return verbish based on temperature trending.
205+
trendingTemperature = (dataArr) => {
206+
var sum = 0;
207+
for (var item of dataArr) {
208+
sum += item.temp;
209+
}
210+
let average = sum / dataArr.length;
211+
let diff = average - dataArr[0].temp;
212+
if ( diff > 0 ) {
213+
if (diff <= 3){ return "Slight warming trend ahead."; }
214+
else if (diff > 3 && diff <= 10) { return "Moderate warming trend ahead."; }
215+
else { return "Considerable warming trend ahead."; }
216+
} else {
217+
if (diff >= -3){ return "Slight cooling trend ahead."; }
218+
else if (diff < -3 && diff <= -10) { return "Moderate cooling trend ahead."; }
219+
else { return "Considerable warming trend ahead."; }
220+
}
221+
}
222+
%>
223+
```
224+
225+
226+
7. Create ejs template file `index.ejs`, and inject partial files as follow.
183227
184228
```c
185229
<!DOCTYPE html>
186230
<html lang="en">
187231
188232
<head>
189-
<%- include('./partials/head'); %>
233+
<%- include('./partials/head'); %>
234+
<%- include('./pages/utils'); %>
190235
</head>
191236
192237
<body class="container">
@@ -205,6 +250,8 @@ Partial files are pieces of reusable code segment that typically appear again an
205250
</html>
206251
```
207252

253+
<br />
254+
208255
<strong>Implement server-side routings </strong>
209256

210257
1. Add routing for the `about` page

views/pages/utils.ejs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ trendingTemperature = (dataArr) => {
2323
let average = sum / dataArr.length;
2424
let diff = average - dataArr[0].temp;
2525
if ( diff > 0 ) {
26-
return "Warming trend ahead.";
26+
if (diff <= 3){ return "Slight warming trend ahead."; }
27+
else if (diff > 3 && diff <= 10) { return "Moderate warming trend ahead."; }
28+
else { return "Considerable warming trend ahead."; }
2729
} else {
28-
return "Cooling trend ahead.";
30+
if (diff >= -3){ return "Slight cooling trend ahead."; }
31+
else if (diff < -3 && diff <= -10) { return "Moderate cooling trend ahead."; }
32+
else { return "Considerable warming trend ahead."; }
2933
}
3034
}
3135
%>

0 commit comments

Comments
 (0)