Get Month to Date Average Response Time
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
Problem: Given an array of objects where the object structure is
...
call_received: timestamp in utc,
call_logs: [
...
created_date: timestamp in utc
]
write a function to find and return the month to date average response time for all objects where response time is equal to the difference between the call received and the created date of the first entered call log. There can be multiple call logs, so must use the one with the earliest timestamp.
Additional criteria: If the call was entered before work hours (7am), the created date in the equation should be rounded to 7am. If the call was made after work hours (4:30pm), the created date should be rounded to 7am the following day. If made on the weekend (Friday 4:30pm to Monday at 7am), round to Monday at 7am.
export function getResponseTime(dispatches)
// If the array is empty, return 0
if (_.size(dispatches) === 0)
return 0
else
// Otherwise, filter to dispatches within the last month
dispatches = _.filter(dispatches, dispatch => moment.utc().diff(moment(dispatch.call_received), 'months', true) < 1)
if (_.size(dispatches) == 0)
// If no dispatches within last month, return 0
return 0
else
const responseTimes =
let responseTime = null
dispatches.map(dispatch =>
// Dispatch will only have call logs key if one has been entered
if (dispatch.call_logs)
)
// Return the mean of the response times (rounding to nearest hundredth decimal)
return _.size(responseTimes) > 0 ? Math.ceil(_.mean(responseTimes) * 100) / 100 : 0
javascript datetime statistics lodash.js
add a comment |Â
up vote
0
down vote
favorite
Problem: Given an array of objects where the object structure is
...
call_received: timestamp in utc,
call_logs: [
...
created_date: timestamp in utc
]
write a function to find and return the month to date average response time for all objects where response time is equal to the difference between the call received and the created date of the first entered call log. There can be multiple call logs, so must use the one with the earliest timestamp.
Additional criteria: If the call was entered before work hours (7am), the created date in the equation should be rounded to 7am. If the call was made after work hours (4:30pm), the created date should be rounded to 7am the following day. If made on the weekend (Friday 4:30pm to Monday at 7am), round to Monday at 7am.
export function getResponseTime(dispatches)
// If the array is empty, return 0
if (_.size(dispatches) === 0)
return 0
else
// Otherwise, filter to dispatches within the last month
dispatches = _.filter(dispatches, dispatch => moment.utc().diff(moment(dispatch.call_received), 'months', true) < 1)
if (_.size(dispatches) == 0)
// If no dispatches within last month, return 0
return 0
else
const responseTimes =
let responseTime = null
dispatches.map(dispatch =>
// Dispatch will only have call logs key if one has been entered
if (dispatch.call_logs)
)
// Return the mean of the response times (rounding to nearest hundredth decimal)
return _.size(responseTimes) > 0 ? Math.ceil(_.mean(responseTimes) * 100) / 100 : 0
javascript datetime statistics lodash.js
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Problem: Given an array of objects where the object structure is
...
call_received: timestamp in utc,
call_logs: [
...
created_date: timestamp in utc
]
write a function to find and return the month to date average response time for all objects where response time is equal to the difference between the call received and the created date of the first entered call log. There can be multiple call logs, so must use the one with the earliest timestamp.
Additional criteria: If the call was entered before work hours (7am), the created date in the equation should be rounded to 7am. If the call was made after work hours (4:30pm), the created date should be rounded to 7am the following day. If made on the weekend (Friday 4:30pm to Monday at 7am), round to Monday at 7am.
export function getResponseTime(dispatches)
// If the array is empty, return 0
if (_.size(dispatches) === 0)
return 0
else
// Otherwise, filter to dispatches within the last month
dispatches = _.filter(dispatches, dispatch => moment.utc().diff(moment(dispatch.call_received), 'months', true) < 1)
if (_.size(dispatches) == 0)
// If no dispatches within last month, return 0
return 0
else
const responseTimes =
let responseTime = null
dispatches.map(dispatch =>
// Dispatch will only have call logs key if one has been entered
if (dispatch.call_logs)
)
// Return the mean of the response times (rounding to nearest hundredth decimal)
return _.size(responseTimes) > 0 ? Math.ceil(_.mean(responseTimes) * 100) / 100 : 0
javascript datetime statistics lodash.js
Problem: Given an array of objects where the object structure is
...
call_received: timestamp in utc,
call_logs: [
...
created_date: timestamp in utc
]
write a function to find and return the month to date average response time for all objects where response time is equal to the difference between the call received and the created date of the first entered call log. There can be multiple call logs, so must use the one with the earliest timestamp.
Additional criteria: If the call was entered before work hours (7am), the created date in the equation should be rounded to 7am. If the call was made after work hours (4:30pm), the created date should be rounded to 7am the following day. If made on the weekend (Friday 4:30pm to Monday at 7am), round to Monday at 7am.
export function getResponseTime(dispatches)
// If the array is empty, return 0
if (_.size(dispatches) === 0)
return 0
else
// Otherwise, filter to dispatches within the last month
dispatches = _.filter(dispatches, dispatch => moment.utc().diff(moment(dispatch.call_received), 'months', true) < 1)
if (_.size(dispatches) == 0)
// If no dispatches within last month, return 0
return 0
else
const responseTimes =
let responseTime = null
dispatches.map(dispatch =>
// Dispatch will only have call logs key if one has been entered
if (dispatch.call_logs)
)
// Return the mean of the response times (rounding to nearest hundredth decimal)
return _.size(responseTimes) > 0 ? Math.ceil(_.mean(responseTimes) * 100) / 100 : 0
javascript datetime statistics lodash.js
edited Feb 7 at 15:23
200_success
123k14143401
123k14143401
asked Feb 7 at 14:34
wizloc
1011
1011
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187011%2fget-month-to-date-average-response-time%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password