🔧 Got issue matches after getting volume filters

This commit is contained in:
2021-12-29 16:30:47 -08:00
parent da1965bad9
commit 7a92c1fddf
2 changed files with 44 additions and 11 deletions

View File

@@ -154,12 +154,15 @@ export default class ComicVineService extends Service {
offset: number; offset: number;
resources: string; resources: string;
scorerConfiguration?: { scorerConfiguration?: {
searchQuery: { searchParams: {
issue: object; searchTerms: {
series: object; name: string;
number: string;
year: string;
};
}; };
rawFileDetails: object;
}; };
rawFileDetails: object;
}> }>
) => { ) => {
const results: any = []; const results: any = [];
@@ -167,10 +170,39 @@ export default class ComicVineService extends Service {
ctx.params, ctx.params,
results, results,
); );
console.log("total volumes", volumes.length); // 1. Run the current batch of volumes through the matcher
// 1a. Run the current batch of volumes through the matcher const potentialVolumeMatches = rankVolumes(volumes, ctx.params.scorerConfiguration);
// Check for: issue year falling in the range of the volume run // 2. Construct the filter string
return rankVolumes(volumes, ctx.params.scorerConfiguration); // 2a. volume: 1111|2222|3333
let volumeIdString = "volume:";
potentialVolumeMatches.map((volumeId: string, idx: number) => {
if(idx >= potentialVolumeMatches.length - 1) {
volumeIdString += `${volumeId}`;
return volumeIdString;
}
volumeIdString += `${volumeId}|`;
});
const issueYear = parseInt(ctx.params.scorerConfiguration.searchParams.searchTerms.year, 10);
// 2b. cover_date:2014-01-01|2016-12-31 for the issue year 2015
const coverDateFilter = `cover_date:${issueYear - 1}-01-01|${issueYear + 1}-12-31`;
const filterString = `issue_number:${ctx.params.scorerConfiguration.searchParams.searchTerms.number},${volumeIdString},${coverDateFilter}`;
console.log(filterString);
const foo = await axios({
url: `https://comicvine.gamespot.com/api/issues?api_key=${process.env.COMICVINE_API_KEY}`,
params: {
resources: "issues",
limit: "100",
format: "json",
filter: filterString,
query: ctx.params.scorerConfiguration.searchParams.searchTerms.name,
},
headers: {"User-Agent": "ThreeTwo"},
});
console.log(foo.data);
return foo.data;
}, },
}, },
}, },
@@ -191,7 +223,6 @@ export default class ComicVineService extends Service {
parseInt(params.limit, 10) parseInt(params.limit, 10)
); );
if(parseInt(data.number_of_total_results, 10) <= 100 ) { if(parseInt(data.number_of_total_results, 10) <= 100 ) {
console.log("dari")
return [...data.results]; return [...data.results];
} }
if (currentPage < totalPages) { if (currentPage < totalPages) {

View File

@@ -112,12 +112,14 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
scorerConfiguration.searchParams.searchTerms.name, scorerConfiguration.searchParams.searchTerms.name,
volume.name volume.name
); );
// 1. If issue year starts after the candidate volume's start year or is the same year, +2 to volumeMatchScore
if (!isNil(volumeStartYear)) { if (!isNil(volumeStartYear)) {
if (isSameYear(issueYear, volumeStartYear) || if (isSameYear(issueYear, volumeStartYear) ||
isAfter(issueYear, volumeStartYear)) { isAfter(issueYear, volumeStartYear)) {
volumeMatchScore += 2; volumeMatchScore += 2;
} }
} }
// 2. If issue number falls in the range of candidate volume's first issue # and last issue #, +3 to volumeMatchScore
if(!isNil(firstIssueNumber) && !isNil(lastIssueNumber)) { if(!isNil(firstIssueNumber) && !isNil(lastIssueNumber)) {
if(firstIssueNumber <= issueNumber || issueNumber <= lastIssueNumber) { if(firstIssueNumber <= issueNumber || issueNumber <= lastIssueNumber) {
volumeMatchScore += 3; volumeMatchScore += 3;
@@ -125,7 +127,7 @@ export const rankVolumes = (volumes: any, scorerConfiguration: any) => {
} }
if(issueNameMatchScore > 0.5 && volumeMatchScore > 2) { if(issueNameMatchScore > 0.5 && volumeMatchScore > 2) {
console.log("VOLUME SCORE: ", volumeMatchScore); console.log("VOLUME SCORE: ", volumeMatchScore);
return volume; return volume.id;
} }
}); });
return foo.filter((item: any) => !isNil(item)); return foo.filter((item: any) => !isNil(item));