add debugging logs

This commit is contained in:
Bilal Catic
2019-12-05 09:27:39 +01:00
parent 166e2a0a9f
commit f9694570a5

View File

@@ -533,92 +533,123 @@ const getIncidentData = (reservation) => {
getEntriesBetween(fromTimestamp, toTimestamp, resourceId) getEntriesBetween(fromTimestamp, toTimestamp, resourceId)
.then((entriesBetween) => { .then((entriesBetween) => {
// const reservationMoment = moment.tz(currentReservation.start, currentReservation.timezone);
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-11-23 00:00:16+00')) {
// console.log('\r\n\r\n==== ANALYSE RESERVATION [GET INCIDENT DATA] ==== ');
// console.log('\tStart : ', reservationMoment.format('DD.MM, HH:mm'));
// console.log('\tEnd : ', moment.tz(currentReservation.end, currentReservation.timezone).format('DD.MM, HH:mm'));
// console.log('\t----------------------------------');
// console.log('\tFirst previous reservation : is back to back [', previousReservationIsBackToBack ? 'T' : 'F', ']');
// if (previousReservation) {
// console.log('\t\tStart : ', moment.tz(previousReservation.start, previousReservation.timezone).format('DD.MM, HH:mm'));
// console.log('\t\tEnd : ', moment.tz(previousReservation.end, previousReservation.timezone).format('DD.MM, HH:mm'));
// } else {
// console.log('\t\tNO PREVIOUS RESERVATION');
// }
//
// console.log('\tFirst next reservation : is back to back [', nextReservationIsBackToBack ? 'T' : 'F', ']');
// if (nextReservation) {
// console.log('\t\tStart : ', moment.tz(nextReservation.start, nextReservation.timezone).format('DD.MM, HH:mm'));
// console.log('\t\tEnd : ', moment.tz(nextReservation.end, nextReservation.timezone).format('DD.MM, HH:mm'));
// } else {
// console.log('\t\tNO NEXT RESERVATION');
// }
//
// console.log('\t--------------------');
//
// console.log('\tFrom timestamp : ', fromTimestamp ? moment.tz(fromTimestamp, UI_TIMEZONE).format('DD.MM, HH:mm') : '-');
// console.log('\tTo timestamp : ', toTimestamp ? moment.tz(toTimestamp, UI_TIMEZONE).format('DD.MM, HH:mm') : '-');
// console.log('\t--------------------');
// }
let pairUnlockEntry = null; let pairUnlockEntry = null;
let pairLockEntry = null; let pairLockEntry = null;
//Inspect all entries and insert detected incidents //Inspect all entries and insert detected incidents
entriesBetween.forEach((entry) => { entriesBetween.forEach((entry) => {
if (entry && entry.event){ // console.log('\tEvent : ', entry.event);
switch(entry.event){ // console.log('\tEvent : ', entry.timestamp ? moment.tz(entry.timestamp, UI_TIMEZONE).format('DD.MM, HH:mm') : '-');
case doorLockEvents.USER_UNLOCKED: if (entry && entry.event){
if (!pairUnlockEntry){ switch(entry.event){
pairUnlockEntry = entry; case doorLockEvents.USER_UNLOCKED:
}else{ if (!pairUnlockEntry){
const emptyReservation = { pairUnlockEntry = entry;
reservationId: null, }else{
start: null, const emptyReservation = {
end: null, reservationId: null,
}; start: null,
end: null,
};
incidents.push({
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
reservation: emptyReservation,
unlockTimestamp: pairUnlockEntry.timestamp,
memberId: pairUnlockEntry.memberId,
resourceId,
});
pairLockEntry = null;
pairUnlockEntry = entry;
}
break;
case doorLockEvents.USER_LOCKED:
if (pairUnlockEntry && !pairLockEntry){
pairLockEntry = entry;
const emptyReservation = {
reservationId: null,
start: null,
end: null,
};
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
const lockMoment = moment.utc(pairLockEntry.timestamp);
if (lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day')){
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
if (timeIntervalsToCharge > 0){
incidents.push({ incidents.push({
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE, incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
reservation: emptyReservation, reservation: emptyReservation,
unlockTimestamp: pairUnlockEntry.timestamp, unlockTimestamp: pairUnlockEntry.timestamp,
lockTimestamp: pairLockEntry.timestamp,
memberId: pairUnlockEntry.memberId, memberId: pairUnlockEntry.memberId,
resourceId, resourceId,
chargePrice: UNSCHEDULED_CHARGE_PRICE,
timeIntervalsToCharge,
totalChargeFee,
}); });
pairLockEntry = null;
pairUnlockEntry = entry;
} }
break; }else{
case doorLockEvents.USER_LOCKED: const emptyReservation = {
if (pairUnlockEntry && !pairLockEntry){ reservationId: null,
pairLockEntry = entry; start: null,
const emptyReservation = { end: null,
reservationId: null, };
start: null,
end: null,
};
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
const lockMoment = moment.utc(pairLockEntry.timestamp);
if (lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day')){ incidents.push({
const timeDifference = lockMoment.diff(unlockMoment, 'minutes'); incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION); reservation: emptyReservation,
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE; unlockTimestamp: pairUnlockEntry.timestamp,
if (timeIntervalsToCharge > 0){ memberId: pairUnlockEntry.memberId,
incidents.push({ resourceId,
incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE, });
reservation: emptyReservation, }
unlockTimestamp: pairUnlockEntry.timestamp,
lockTimestamp: pairLockEntry.timestamp,
memberId: pairUnlockEntry.memberId,
resourceId,
chargePrice: UNSCHEDULED_CHARGE_PRICE,
timeIntervalsToCharge,
totalChargeFee,
});
}
}else{
const emptyReservation = {
reservationId: null,
start: null,
end: null,
};
incidents.push({ pairUnlockEntry = null;
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE, pairLockEntry = null;
reservation: emptyReservation, }else{
unlockTimestamp: pairUnlockEntry.timestamp, if (!pairUnlockEntry){
memberId: pairUnlockEntry.memberId, pairLockEntry = entry;
resourceId, //Only lock entry, ignore now
}); }
} pairLockEntry = null;
pairUnlockEntry = null;
pairUnlockEntry = null;
pairLockEntry = null;
}else{
if (!pairUnlockEntry){
pairLockEntry = entry;
//Only lock entry, ignore now
}
pairLockEntry = null;
pairUnlockEntry = null;
}
} }
} }
}); }
});
//Now wait also for "forgotToLockAsyncCheck" to finish //Now wait also for "forgotToLockAsyncCheck" to finish