Get Month to Date Average Response Time

The name of the pictureThe name of the pictureThe name of the pictureClash 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









share|improve this question



























    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









    share|improve this question























      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









      share|improve this question













      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











      share|improve this question












      share|improve this question




      share|improve this question








      edited Feb 7 at 15:23









      200_success

      123k14143401




      123k14143401









      asked Feb 7 at 14:34









      wizloc

      1011




      1011

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?