Skip to content

Commit

Permalink
Add bsKit.isSynched() and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
lucka-me committed May 28, 2020
1 parent 4079f03 commit 79e307e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
19 changes: 19 additions & 0 deletions lib/bsKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,23 @@ const bsKit = {

loadReference: () => bsKit.reference = firebase.database().ref(value.string.path.bsReference),
getId: (imgUrl) => imgUrl.replace(/[^a-zA-Z0-9]/g, '').slice(- 10).toLowerCase(),
isSynched: (stars, status) => {
const reason = value.data.reason;
if (stars === 'D' && status === reason.duplicated.code) {
return true;
}
const general = parseFloat(stars);
if (isNaN(general)) return false;
const type = value.data.type;
if (general < 3 && status === reason.undeclared.code) {
return true;
}
if (general > 3 && status === type.accepted.code) {
return true;
}
if (general > 3 && status === reason.tooClose.code) {
return true;
}
return false;
},
};
1 change: 0 additions & 1 deletion lib/dashboard/bs/synch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dashboard.card.bs.card.synch = {
init: () => { },
update: (stats) => {
const card = dashboard.card.bs.card.synch;
//const rate = stats.synch.matched / stats.synch.total;
const rate = stats.synched / stats.review;
card.textSynch.innerHTML = `${(rate * 100).toFixed(1)}`;
},
Expand Down
37 changes: 1 addition & 36 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const process = {
review: 0, portal: 0,
rate: { },
reviewTimes: [],
//synch: { total: 0, matched: 0, },
synched: 0,
};
const rateKeys = Object.keys(value.string.bs.rate);
Expand Down Expand Up @@ -100,46 +99,12 @@ const process = {
}
stats.reviewTimes.push(review.Timestamp);
// Synch
if (review.stars === 'D' && portal.status === value.data.reason.duplicated.code) {
if (bsKit.isSynched(review.stars, portal.status)) {
stats.synched += 1;
} else {
const general = parseFloat(review.stars);
if (!isNaN(general)) {
if (general < 3 && portal.status === value.data.reason.undeclared.code) {
stats.synched += 1;
} else if (general > 3 && portal.status === value.data.type.accepted.code) {
stats.synched += 1;
} else if (general > 3 && portal.status === value.data.reason.tooClose.code) {
stats.synched += 1;
}
}
}
}
if (generals.length < 1) continue;
stats.portal += 1;
// Synch
// let mostCode = value.data.type.pending.code;
// let mostCount = 0;
// generals.map((general) => {
// if (general === 'D') return value.data.reason.duplicated.code;
// if (general < 3) return value.data.reason.undeclared.code;
// return value.data.type.accepted.code;
// }).reduce((map, code) => {
// const count = (map.has(code) ? map.get(code) : 0) + 1;
// map.set(code, count);
// if (count > mostCount) {
// mostCode = code;
// mostCount = count;
// }
// return map;
// }, new Map());
// if (mostCode === value.data.type.pending.code) continue;
// stats.synch.total += 1;
// if (mostCode === portal.status) {
// stats.synch.matched += 1;
// } else if (mostCode === value.data.type.accepted.code && portal.status === value.data.reason.tooClose.code) {
// stats.synch.matched += 1;
// }
}
return stats;
},
Expand Down

0 comments on commit 79e307e

Please sign in to comment.