Map App Store genres to categories

This commit is contained in:
Sam Carlton 2021-04-24 16:11:04 -05:00
parent 3faeaa7745
commit 848023788c
2 changed files with 64 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import axios from 'axios'
import statuses, { getStatusName } from './statuses'
import appStoreGenres from './app-store/genres.js'
import { findCategoryForTagsSet } from './categories.js'
import parseDate from './parse-date'
import { eitherMatches } from './matching.js'
import { getAppEndpoint } from './app-derived'
@ -110,7 +111,7 @@ async function fetchBundleGenres () {
function generateTagsSetFromGenres( bundleId, bundleGenres ) {
// If we don't have this bundleID
// then return empty
if ( !bundleGenres.has( bundleId ) ) return []
if ( !bundleGenres.has( bundleId ) ) return new Set()
const genres = new Set()
@ -188,6 +189,19 @@ export default async function () {
const tags = generateTagsSetFromGenres( appScan.bundleIdentifier, bundleGenres )
// Move productivity tag to the end since it's a more generic tag
if ( tags.has('Productivity') ) {
tags.delete('Productivity')
tags.add('Productivity')
}
const foundCategory = findCategoryForTagsSet( tags )
const category = {
label: foundCategory ? foundCategory.label : undefined,
slug: foundCategory ? foundCategory.slug : 'uncategorized'
}
// Add to scanned app list
scanListMap.set( appSlug, {
name: appName,
@ -204,9 +218,7 @@ export default async function () {
},
slug: appSlug
}),
category: {
slug: 'uncategorized'
},
category,
tags: Array.from(tags),
relatedLinks
})

View file

@ -5,6 +5,32 @@ export function makeCategorySlug ( categoryName ) {
return makeSlug( categoryName )
}
const categoryMap = new Map([
[ 'Business', 2 ],
[ 'Entertainment', 5 ],
[ 'Finance', 2 ],
[ 'Games', 100 ],
[ 'Music', 6 ],
[ 'Photo & Video', 7 ],
[ 'Productivity', 2 ],
[ 'Utilities', 12 ],
[ 'Graphics & Design', 7 ],
[ 'Developer Tools', 1 ],
// [ 'Name', 1 ],
])
// Maps App Store Genre to categort IDS
export function getCategoryIdForGenre ( genreName ) {
// If we don't have this genre mapped
// then return nothing
if ( !categoryMap.has(genreName) ) return null
// return this category id mapped to this genre
return categoryMap.get( genreName )
}
// Contains all types of properies to keep data consistent
export const categoryTemplate = {
@ -156,6 +182,8 @@ export const categories = {
}
export const categoriesById = Object.fromEntries( Object.entries( categories ).map( ([ key, category ]) => [category.id, { ...category, key } ] ) )
export function getAppCategory (app) {
if (typeof app.category === 'undefined') {
console.log('app', app)
@ -178,3 +206,23 @@ export function getAppCategory (app) {
return categories[app.category.slug]
}
export function findCategoryForTagsSet ( tags ) {
for ( const tag of tags ) {
const categoryIdForGenre = getCategoryIdForGenre( tag )
// Skip non-mapped genres
if ( categoryIdForGenre === null ) continue
// const foundCategory = categoriesById[ categoryIdForGenre ]
// category.label = foundCategory.label
// category.slug = foundCategory.slug
return categoriesById[ categoryIdForGenre ]
}
return null
}