[offers][fix] Fix user's offers appearing in own top relevant offers during analysis

pull/508/head
Bryann Yeap Kok Keong 2 years ago
parent fec915cffa
commit cd4ed504df

@ -251,6 +251,8 @@ export const generateAnalysis = async (params: {
}, },
}); });
const offerIds = offers.map((offer) => offer.id);
// COMPANY ANALYSIS // COMPANY ANALYSIS
const companyMap = new Map<string, Offer>(); const companyMap = new Map<string, Offer>();
offers.forEach((offer) => { offers.forEach((offer) => {
@ -275,9 +277,9 @@ export const generateAnalysis = async (params: {
? 100 ? 100
: 100 - (100 * companyIndex) / (similarCompanyOffers.length - 1); : 100 - (100 * companyIndex) / (similarCompanyOffers.length - 1);
// Get top offers (excluding user's offer) // Get top offers (excluding user's offers)
similarCompanyOffers = similarCompanyOffers.filter( similarCompanyOffers = similarCompanyOffers.filter(
(offer) => offer.id !== companyOffer.id, (offer) => !offerIds.includes(offer.id),
); );
const noOfSimilarCompanyOffers = similarCompanyOffers.length; const noOfSimilarCompanyOffers = similarCompanyOffers.length;
@ -311,9 +313,7 @@ export const generateAnalysis = async (params: {
? 100 ? 100
: 100 - (100 * overallIndex) / (similarOffers.length - 1); : 100 - (100 * overallIndex) / (similarOffers.length - 1);
similarOffers = similarOffers.filter( similarOffers = similarOffers.filter((offer) => !offerIds.includes(offer.id));
(offer) => offer.id !== overallHighestOffer.id,
);
const noOfSimilarOffers = similarOffers.length; const noOfSimilarOffers = similarOffers.length;
const similarOffers90PercentileIndex = Math.ceil(noOfSimilarOffers * 0.1); const similarOffers90PercentileIndex = Math.ceil(noOfSimilarOffers * 0.1);

Loading…
Cancel
Save