Fix sorting of tagger fingerprint matches (#1369)

This commit is contained in:
InfiniteTF
2021-05-07 05:00:29 +02:00
committed by GitHub
parent bdac352250
commit 81cf3d3337
3 changed files with 29 additions and 10 deletions

View File

@@ -46,7 +46,10 @@ const getDurationStatus = (
</div> </div>
); );
const minDiff = Math.min(scene.duration, ...durations); const minDiff = Math.min(
Math.abs(scene.duration - stashDuration),
...durations
);
return <div>Duration off by at least {Math.floor(minDiff)}s</div>; return <div>Duration off by at least {Math.floor(minDiff)}s</div>;
}; };

View File

@@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from "react";
import { Button, Card, Form, InputGroup } from "react-bootstrap"; import { Button, Card, Form, InputGroup } from "react-bootstrap";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { HashLink } from "react-router-hash-link"; import { HashLink } from "react-router-hash-link";
import { uniqBy } from "lodash";
import { ScenePreview } from "src/components/Scenes/SceneCard"; import { ScenePreview } from "src/components/Scenes/SceneCard";
import { useLocalForage } from "src/hooks"; import { useLocalForage } from "src/hooks";
@@ -333,11 +334,17 @@ const TaggerList: React.FC<ITaggerListProps> = ({
config.mode, config.mode,
config.blacklist config.blacklist
); );
const fingerprintMatch =
fingerprints[scene.checksum ?? ""] ?? // Get all scenes matching one of the fingerprints, and return array of unique scenes
fingerprints[scene.oshash ?? ""] ?? const fingerprintMatches = uniqBy(
fingerprints[scene.phash ?? ""] ?? [
null; ...(fingerprints[scene.checksum ?? ""] ?? []),
...(fingerprints[scene.oshash ?? ""] ?? []),
...(fingerprints[scene.phash ?? ""] ?? []),
].flat(),
(f) => f.stash_id
);
const isTagged = taggedScenes[scene.id]; const isTagged = taggedScenes[scene.id];
const hasStashIDs = scene.stash_ids.length > 0; const hasStashIDs = scene.stash_ids.length > 0;
const width = scene.file.width ? scene.file.width : 0; const width = scene.file.width ? scene.file.width : 0;
@@ -432,9 +439,9 @@ const TaggerList: React.FC<ITaggerListProps> = ({
} }
let searchResult; let searchResult;
if (fingerprintMatch && !isTagged && !hasStashIDs) { if (fingerprintMatches.length > 0 && !isTagged && !hasStashIDs) {
searchResult = sortScenesByDuration( searchResult = sortScenesByDuration(
fingerprintMatch, fingerprintMatches,
scene.file.duration ?? 0 scene.file.duration ?? 0
).map((match, i) => ( ).map((match, i) => (
<StashSearchResult <StashSearchResult
@@ -460,7 +467,7 @@ const TaggerList: React.FC<ITaggerListProps> = ({
} else if ( } else if (
searchResults[scene.id]?.length > 0 && searchResults[scene.id]?.length > 0 &&
!isTagged && !isTagged &&
!fingerprintMatch fingerprintMatches.length === 0
) { ) {
searchResult = ( searchResult = (
<ul className="pl-0 mt-3 mb-0"> <ul className="pl-0 mt-3 mb-0">
@@ -495,7 +502,7 @@ const TaggerList: React.FC<ITaggerListProps> = ({
); );
} }
return hideUnmatched && !fingerprintMatch ? null : ( return hideUnmatched && fingerprintMatches.length === 0 ? null : (
<div key={scene.id} className="mt-3 search-item"> <div key={scene.id} className="mt-3 search-item">
<div className="row"> <div className="row">
<div className="col col-lg-6 overflow-hidden align-items-center d-flex flex-column flex-sm-row"> <div className="col col-lg-6 overflow-hidden align-items-center d-flex flex-column flex-sm-row">

View File

@@ -179,6 +179,15 @@ export const sortScenesByDuration = (
if (aDur.length > 0 && bDur.length === 0) return -1; if (aDur.length > 0 && bDur.length === 0) return -1;
if (aDur.length === 0 && bDur.length > 0) return 1; if (aDur.length === 0 && bDur.length > 0) return 1;
const aMatches = aDur.filter((match) => match <= 5);
const bMatches = bDur.filter((match) => match <= 5);
if (aMatches.length > 0 || bMatches.length > 0) {
if (aMatches.length > bMatches.length) return -1;
if (aMatches.length < bMatches.length) return 1;
return 0;
}
const aDiff = Math.min(...aDur); const aDiff = Math.min(...aDur);
const bDiff = Math.min(...bDur); const bDiff = Math.min(...bDur);