http://facultypages.morris.umn.edu/~mcphee/Courses/CSci1251/47619/sol arPanelDat
ID: 3772522 • Letter: H
Question
http://facultypages.morris.umn.edu/~mcphee/Courses/CSci1251/47619/sol arPanelData/stats_2015_10_05.json
Aggregate the data into hours
This data has readings every five minutes, which makes it somewhat noisy. Let’s aggregate it
into hours, i.e., create one entry for each hour that has the sum of all the data from that hour.
T h a t ’ s e a s y t o d o w i t h a p i v o t t a b l e ex c e p t w e n e e d a n e w e n t r y f o r e a c h r o w t h a t i s a
combination of the date and hour so the pivot table will know how to group the data. There are a number of ways we could do this, and none of them are super pretty. I propose we create a new column in our energy data sheet called “Date-hour” that will have entries like “DH-07-13” that indicate that the data in that row was collected on the 7th (the “07” part) between 1pm and 2pm (the “13” part). We can get this by writing a JavaScript function that takes the date from column A and computes the “Date-hour” label. (See the target sheet for an example of where we’re heading.) In my solution I found it useful to write a little helper function padSingleDigits() that takes a number and returns a string that is either that number if it already has two digits, or is the given number with a “0” padded on the front if it’s a single digit. Thus if we had it 14 we’ll get the string “14” back, and if we hand it 9 we’ll get the string “09” back.
Problem 4 (10 points)Write a JavaScript function padSingleDigits()that pads single digit numbers as described above.
Now you can use padSingleDigits(),along with appropriate JavaScript date functions to extract the necessary parts from the date and build the desired label.
Explanation / Answer
Tee desired result will get with this below javascript function : function padSingleDigits(number){ if(number>=0 && numberRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.