From 8778ea1275643b359d2903c0b7719aadcb5d5f7c Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Tue, 22 Oct 2024 03:13:41 +0200 Subject: [PATCH] Removed old profile interpolation code. --- src/actors.js | 208 -------------------------------------------------- 1 file changed, 208 deletions(-) diff --git a/src/actors.js b/src/actors.js index 20fdc389..185a4613 100755 --- a/src/actors.js +++ b/src/actors.js @@ -360,65 +360,6 @@ async function fetchProfiles(actorIdsOrNames) { .leftJoin('media', 'actors_profiles.avatar_media_id', 'media.id'); } -/* -function getMostFrequent(items) { - const { mostFrequent } = items.reduce((acc, item) => { - if (item === undefined || item === null) { - return acc; - } - - const slug = slugify(item); - - acc.counts[slug] = (acc.counts[slug] || 0) + 1; - - if (!acc.mostFrequent || acc.counts[slug] > acc.counts[slugify(acc.mostFrequent)]) { - acc.mostFrequent = item; - } - - return acc; - }, { - counts: {}, - mostFrequent: null, - }); - - return mostFrequent; -} - -function getMostFrequentDate(dates) { - const year = getMostFrequent(dates.map((dateX) => dateX.getFullYear())); - const month = getMostFrequent(dates.map((dateX) => dateX.getMonth())); - const date = getMostFrequent(dates.map((dateX) => dateX.getDate())); - - if (year === null || month === null || date === null) { - return null; - } - - return moment({ year, month, date }).toDate(); -} - -function getHighest(items) { - return items.reduce((prevItem, item) => (item > prevItem ? item : prevItem), null); -} - -function getLongest(items) { - return items.sort((itemA, itemB) => itemB.length - itemA.length)[0] || null; -} - -function getAverage(items) { - return Math.round(items.reduce((acc, item) => acc + item, 0) / items.length) || null; -} - -function mergeMainProfile(profile, mainProfile) { - const preservedKeys = ['id']; - - const mergedProfile = Object.fromEntries(Object.entries(profile).map(([key, value]) => [key, mainProfile[key] === null || preservedKeys.includes(key) - ? value - : mainProfile[key]])); - - return mergedProfile; -} -*/ - async function interpolateProfiles(actorIdsOrNames) { const { interpolateProfiles: interpolateProfilesUtil } = await actorsCommon; @@ -433,155 +374,6 @@ async function interpolateProfiles(actorIdsOrNames) { } catch (error) { console.log(error); } - /* - const profiles = await fetchProfiles(actorIdsOrNames); - - const profilesByActorId = profiles.reduce((acc, profile) => ({ - ...acc, - [profile.actor_id]: [ - ...(acc[profile.actor_id] || []), - profile, - ], - }), {}); - - logger.info(`Interpolating ${profiles.length} profiles from ${Object.keys(profilesByActorId).length} actors`); - - const interpolatedProfiles = Object.entries(profilesByActorId).map(([actorId, actorProfiles]) => { - // group values from each profile - const valuesByProperty = actorProfiles - .filter((profile) => profile.entity_id !== null) // main profile is interpolated separately at the end - .reduce((acc, profile) => Object - .entries(profile) - .reduce((profileAcc, [property, value]) => ({ - ...profileAcc, - [property]: [ - ...(acc[property] || []), - ...(value === null ? [] : Array.from({ length: profile.priority }, () => value)), // multiply by priority, increasing the odds of being the most frequent value - ], - }), { - // bundle location values so they can be assessed together, to ensure the most frequent city is in the most frequent state is in most frequent country - origin: [...acc.origin || [], { - ...(profile.birth_country_alpha2 && { country: profile.birth_country_alpha2 }), - ...(profile.birth_state && { state: profile.birth_state }), - ...(profile.birth_city && { city: profile.birth_city }), - }].filter((location) => Object.keys(location).length > 0), - residence: [...acc.residence || [], { - ...(profile.residence_country_alpha2 && { country: profile.residence_country_alpha2 }), - ...(profile.residence_state && { state: profile.residence_state }), - ...(profile.residence_city && { city: profile.residence_city }), - }].filter((location) => Object.keys(location).length > 0), - }), {}); - - const mostFrequentValues = [ - 'gender', - 'orientation', - 'ethnicity', - 'cup', - 'bust', - 'waist', - 'hip', - 'leg', - 'thigh', - 'foot', - 'shoe_size', - 'penis_length', - 'penis_girth', - 'circumcised', - 'hair_color', - 'eyes', - 'has_tattoos', - 'has_piercings', - 'blood_type', - ].reduce((acc, property) => ({ - ...acc, - [property]: getMostFrequent(valuesByProperty[property]), - }), {}); - - const profile = { - id: actorId, - ...mostFrequentValues, - }; - - profile.height = getMostFrequent(valuesByProperty.height.filter((height) => height > 50 && height < 300)); // remove unlikely values - - profile.date_of_birth = getMostFrequentDate(valuesByProperty.date_of_birth); - profile.date_of_death = getMostFrequentDate(valuesByProperty.date_of_death); - profile.age = getHighest(valuesByProperty.age); - - profile.natural_boobs = profile.gender === 'male' ? null : getMostFrequent(valuesByProperty.natural_boobs); - - // ensure most frequent country, city and state match up - profile.birth_country_alpha2 = getMostFrequent(valuesByProperty.origin.map((location) => location.country)); - const remainingOriginCountries = valuesByProperty.origin.filter((location) => location.country === profile.birth_country_alpha2); - - profile.birth_state = getMostFrequent(remainingOriginCountries.map((location) => location.state)); - const remainingOriginStates = remainingOriginCountries.filter((location) => !profile.birth_state || location.state === profile.birth_state); - - profile.birth_city = getMostFrequent(remainingOriginStates.map((location) => location.city)); - - profile.residence_country_alpha2 = getMostFrequent(valuesByProperty.residence.map((location) => location.country)); - const remainingResidenceCountries = valuesByProperty.residence.filter((location) => location.country === profile.residence_country_alpha2); - - profile.residence_state = getMostFrequent(remainingResidenceCountries.map((location) => location.state)); - const remainingResidenceStates = remainingResidenceCountries.filter((location) => !profile.residence_state || location.state === profile.residence_state); - - profile.residence_city = getMostFrequent(remainingResidenceStates.map((location) => location.city)); - - profile.weight = getAverage(valuesByProperty.weight); - - profile.tattoos = getLongest(valuesByProperty.tattoos); - profile.piercings = getLongest(valuesByProperty.piercings); - - profile.avatar_media_id = actorProfiles - .map((actorProfile) => actorProfile.avatar) - .filter((avatar) => avatar && (avatar.entropy === null || avatar.entropy > 5.5)) - .sort((avatarA, avatarB) => avatarB.height - avatarA.height)[0]?.id || null; - - if (!profile.avatar_media_id) { - // try to settle for low quality avatar - profile.avatar_media_id = actorProfiles - .map((actorProfile) => actorProfile.avatar) - .filter((avatar) => avatar) - .sort((avatarA, avatarB) => avatarB.height - avatarA.height)[0]?.id || null; - } - - const mainProfile = actorProfiles.find((actorProfile) => actorProfile.entity_id === null); - - return mergeMainProfile(profile, mainProfile); - }); - - const transaction = await knex.transaction(); - - // clear existing interpolated data - const emptyProfile = Object - .keys(omit(curateProfileEntry({ id: 1 }), ['id', 'actor_id', 'entity_id', 'url', 'description_hash'])) - .reduce((acc, key) => ({ ...acc, [key]: null }), {}); - - await knex('actors') - .modify((modifyBuilder) => { - if (actorIdsOrNames) { - modifyBuilder - .whereIn('id', actorIdsOrNames.filter((idOrName) => typeof idOrName === 'number')) - .orWhere((whereBuilder) => { - whereBuilder - .whereIn('name', actorIdsOrNames.filter((idOrName) => typeof idOrName === 'string')) - .whereNull('entity_id'); - }); - } - }) - .update(emptyProfile) - .transacting(transaction); - - // insert new interpolated data - const queries = interpolatedProfiles.map((profile) => knex('actors') - .where('id', profile.id) - .update(profile) - .transacting(transaction)); - - await Promise.all(queries) - .then(transaction.commit) - .catch(transaction.rollback); - */ } async function curateProfile(profile, actor) {