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,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
}