@@ -1096,6 +1096,7 @@ export const databaseService = {
10961096 } ;
10971097 birthPlaces : { place : string ; count : number } [ ] ;
10981098 birthCountries : { country : string ; count : number } [ ] ;
1099+ occupations : { occupation : string ; count : number } [ ] ;
10991100 } > {
11001101 if ( ! useSqlite ) {
11011102 throw new Error ( 'SQLite is required for tree stats' ) ;
@@ -1302,6 +1303,18 @@ export const databaseService = {
13021303 . sort ( ( a , b ) => b . count - a . count )
13031304 . slice ( 0 , 20 ) ;
13041305
1306+ // Top occupations from claims table
1307+ const occupationRows = sqliteService . queryAll < { occupation : string ; count : number } > (
1308+ `SELECT c.value_text as occupation, COUNT(DISTINCT c.person_id) as count
1309+ FROM claim c
1310+ JOIN database_membership dm ON c.person_id = dm.person_id AND dm.db_id = @dbId
1311+ WHERE c.predicate = 'occupation' AND c.value_text IS NOT NULL AND c.value_text != ''
1312+ GROUP BY c.value_text
1313+ ORDER BY count DESC
1314+ LIMIT 30` ,
1315+ { dbId }
1316+ ) ;
1317+
13051318 const lifespanByCentury = sqliteService . queryAll < { century : number ; avgAge : number ; count : number } > (
13061319 `SELECT CAST((b.date_year / 100) AS INTEGER) as century,
13071320 ROUND(AVG(d.date_year - b.date_year), 1) as avgAge,
@@ -1339,6 +1352,7 @@ export const databaseService = {
13391352 } ,
13401353 birthPlaces : birthPlaceRows . map ( r => ( { place : r . place , count : r . count } ) ) ,
13411354 birthCountries : birthCountryRows . map ( r => ( { country : r . country , count : r . count } ) ) ,
1355+ occupations : occupationRows . map ( r => ( { occupation : r . occupation , count : r . count } ) ) ,
13421356 } ;
13431357 } ,
13441358} ;
0 commit comments