function getGraphSlices(arrMeas, arrAlarms) {
  var slices = {};
  slices.locked = [];
  slices.unlocked = [];

  var endTime = 999999999999; //i.e., never

  var measIdx;
  var alarmIdx;
  var lockedSliceIdx = 0;
  var unlockedSliceIdx = 0;
  var measSize = 0;

  var addUnlockedSlice = function () {
    slices.unlocked[unlockedSliceIdx] = [];

    var alarmEnds = arrMeas[measSize].x;

    if (arrAlarms[alarmIdx].epochEnd != undefined) {
      alarmEnds = arrAlarms[alarmIdx].epochEnd;
    }

    while (measIdx <= measSize && alarmEnds > arrMeas[measIdx].x) {
      slices.unlocked[unlockedSliceIdx].push(arrMeas[measIdx]);
      measIdx++;
    }

    //Add alarm End
    if (measIdx < measSize && arrMeas[measIdx].x <= endTime) {
      //We want the line to continue from the last point, only if monitorization hasn't ended
      slices.unlocked[unlockedSliceIdx].push(arrMeas[measIdx]);
    }

    unlockedSliceIdx++;
  };

  var addLockedSlice = function (alarmStarts) {
    slices.locked[lockedSliceIdx] = [];

    while (measIdx <= measSize && alarmStarts > arrMeas[measIdx].x) {
      slices.locked[lockedSliceIdx].push(arrMeas[measIdx]);
      measIdx++;
    }

    //Add end if alarm matches a measure
    if (measIdx < measSize && arrMeas[measIdx].x <= endTime) {
      //We want the line to continue from the last point if monitorization hasn't ended
      measIdx--;
    }

    lockedSliceIdx++;
  };

  var processAlarm = function () {
    if (arrAlarms == undefined || alarmIdx >= arrAlarms.length) {
      return;
    }

    //Save alarms y from meas array
    //arrAlarms[alarmIdx].y =  arrMeas[measIdx].y;

    //TODO: type should be obtained from an "enum" or so
    if (arrAlarms[alarmIdx].type == 'LOST') {
      addUnlockedSlice();
    } else if (arrAlarms[alarmIdx].type == 'MONSTART') {
      if (arrAlarms[alarmIdx].epochEnd != undefined) {
        endTime = arrAlarms[alarmIdx].epochEnd;
      } else {
        endTime = 999999999999; //i.e., never
      }
    } else if (arrAlarms[alarmIdx].type == 'POWUP') {
      endTime = arrAlarms[alarmIdx].x;
    }

    alarmIdx++;
  };

  if (arrAlarms != undefined) {
    alarmIdx = 0;
  }

  if (arrMeas != undefined) {
    measIdx = 0;
    measSize = arrMeas.length - 1;
  }

  while (measIdx < measSize) {
    var alarmStarts = arrMeas[measSize].x;

    if (arrAlarms != undefined && alarmIdx < arrAlarms.length) {
      alarmStarts = arrAlarms[alarmIdx].x;
    }

    if (alarmStarts > arrMeas[measIdx].x) {
      addLockedSlice(alarmStarts);
      processAlarm();
    } else {
      processAlarm();
    }
  }

  return slices;
}
