Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve scene tagger prioritization #4618

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions ui/v2.5/src/components/Tagger/scenes/SceneTagger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,20 @@ export const Tagger: React.FC<ITaggerProps> = ({ scenes, queue }) => {
const [nbPhashMatchSceneB, ratioPhashMatchSceneB] =
calculatePhashComparisonScore(stashScene, sceneB);

if (nbPhashMatchSceneA != nbPhashMatchSceneB) {
// If only one scene has matching phash, prefer that scene
if (
(nbPhashMatchSceneA != nbPhashMatchSceneB && nbPhashMatchSceneA === 0) ||
nbPhashMatchSceneB === 0
) {
return nbPhashMatchSceneB - nbPhashMatchSceneA;
}

// Same number of phash matches, check duration
// Prefer scene with highest ratio of phash matches
if (ratioPhashMatchSceneA !== ratioPhashMatchSceneB) {
return ratioPhashMatchSceneB - ratioPhashMatchSceneA;
}

// Same ratio of phash matches, check duration
const [
nbDurationMatchSceneA,
ratioDurationMatchSceneA,
Expand All @@ -213,11 +222,6 @@ export const Tagger: React.FC<ITaggerProps> = ({ scenes, queue }) => {
return ratioDurationMatchSceneB - ratioDurationMatchSceneA;
}

// Damn this is close... Check phash ratio
if (ratioPhashMatchSceneA !== ratioPhashMatchSceneB) {
return ratioPhashMatchSceneB - ratioPhashMatchSceneA;
}

// fall back to duration difference - less is better
return minDurationDiffSceneA - minDurationDiffSceneB;
}
Expand Down
31 changes: 27 additions & 4 deletions ui/v2.5/src/components/Tagger/scenes/StashSearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import { FormattedMessage, useIntl } from "react-intl";
import uniq from "lodash-es/uniq";
import { blobToBase64 } from "base64-blob";
import { distance } from "src/utils/hamming";
import { faCheckCircle } from "@fortawesome/free-regular-svg-icons";
import {
faPlus,
faTriangleExclamation,
faXmark,
} from "@fortawesome/free-solid-svg-icons";

import * as GQL from "src/core/generated-graphql";
import { HoverPopover } from "src/components/Shared/HoverPopover";
import { Icon } from "src/components/Shared/Icon";
import { LoadingIndicator } from "src/components/Shared/LoadingIndicator";
import { SuccessIcon } from "src/components/Shared/SuccessIcon";
import { LoadingIndicator } from "src/components/Shared/LoadingIndicator";
import { TagSelect } from "src/components/Shared/Select";
import { TruncatedText } from "src/components/Shared/TruncatedText";
import { OperationButton } from "src/components/Shared/OperationButton";
Expand All @@ -22,10 +28,25 @@ import { SceneTaggerModalsState } from "./sceneTaggerModals";
import PerformerResult from "./PerformerResult";
import StudioResult from "./StudioResult";
import { useInitialState } from "src/hooks/state";
import { faPlus } from "@fortawesome/free-solid-svg-icons";
import { getStashboxBase } from "src/utils/stashbox";
import { ExternalLink } from "src/components/Shared/ExternalLink";

const getDurationIcon = (matchPercentage: number) => {
if (matchPercentage > 65)
return (
<Icon className="SceneTaggerIcon text-success" icon={faCheckCircle} />
);
if (matchPercentage > 35)
return (
<Icon
className="SceneTaggerIcon text-warn"
icon={faTriangleExclamation}
/>
);

return <Icon className="SceneTaggerIcon text-danger" icon={faXmark} />;
};

const getDurationStatus = (
scene: IScrapedScene,
stashDuration: number | undefined | null
Expand All @@ -52,10 +73,12 @@ const getDurationStatus = (
else if (scene.duration && Math.abs(scene.duration - stashDuration) < 5)
match = <FormattedMessage id="component_tagger.results.fp_matches" />;

const matchPercentage = (matchCount / durations.length) * 100;

if (match)
return (
<div className="font-weight-bold">
<SuccessIcon className="mr-2" />
{getDurationIcon(matchPercentage)}
{match}
</div>
);
Expand Down Expand Up @@ -146,7 +169,7 @@ const getFingerprintStatus = (
<div>
{phashMatches.length > 0 && (
<div className="font-weight-bold">
<SuccessIcon className="mr-2" />
<SuccessIcon className="SceneTaggerIcon" />
<HoverPopover
placement="bottom"
content={phashList}
Expand Down
6 changes: 6 additions & 0 deletions ui/v2.5/src/components/Tagger/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
background-color: #137cbd;
}
}

.SceneTaggerIcon {
margin-left: 0.25em;
margin-right: 10px;
width: var(--fa-fw-width, 1.25em);
}
}

.selected-result {
Expand Down
Loading