99import { PrismaService } from 'src/prisma.service' ;
1010import {
1111 getPairwiseCombinations ,
12+ shuffleArraySeeded ,
1213 sortCombinationsByImplicitCategoryAndOccurance ,
1314} from 'src/utils' ;
1415import {
@@ -699,8 +700,6 @@ export class FlowService {
699700 ( a . implicitCategory || '' ) . localeCompare ( b . implicitCategory || '' ) ,
700701 ) ;
701702
702- console . log ( allProjects . slice ( 0 , 10 ) . map ( ( item ) => item . implicitCategory ) ) ;
703-
704703 const projectStars = allStars . filter (
705704 ( item ) => ! projectCoIs . find ( ( el ) => el . projectId === item . projectId ) ,
706705 ) ;
@@ -751,24 +750,36 @@ export class FlowService {
751750
752751 const allIds = allProjects . map ( ( child ) => child . id ) ;
753752
754- const projectIdOccurencesRanking = this . determineIdRanking ( votedIds ) ;
755-
756- // ascending id rankings (i.e., the last element has been voted the most)
757- let idRanking : number [ ] = [ ] ;
753+ let idRanking = this . determineIdRanking ( votedIds ) ;
758754
759755 for ( let i = 0 ; i < allIds . length ; i ++ ) {
760756 const value = allIds [ i ] ;
761- if ( ! projectIdOccurencesRanking . includes ( value ) ) idRanking . push ( value ) ;
757+ if ( ! ( value in idRanking ) ) idRanking = { ... idRanking , [ value ] : 0 } ;
762758 }
763759
764- idRanking = [ ...idRanking , ...projectIdOccurencesRanking ] ;
760+ const getProjectOccurances = ( id : number ) =>
761+ id in idRanking ? idRanking [ id ] : 0 ;
762+
763+ // idRanking = [...idRanking, ...projectIdOccurencesRanking];
765764
766765 const combinations = getPairwiseCombinations ( allIds ) ;
767766
767+ const implicitCategoryPriorities = Array . from (
768+ new Set ( allProjects . map ( ( item ) => item . implicitCategory ) ) ,
769+ ) . map ( ( cat , index ) => ( { name : cat , priority : index * 2 } ) ) ;
770+
771+ console . log ( shuffleArraySeeded ( implicitCategoryPriorities , userId ) ) ;
772+
773+ const getImplicitCatScore = ( cat : string ) =>
774+ shuffleArraySeeded ( implicitCategoryPriorities , userId ) . find (
775+ ( el ) => el . name === cat ,
776+ ) ?. priority || 0 ;
777+
768778 const sortedCombinations = sortCombinationsByImplicitCategoryAndOccurance (
769779 combinations ,
770- idRanking ,
780+ getProjectOccurances ,
771781 getProjectImplicitCatById ,
782+ getImplicitCatScore ,
772783 ) ;
773784
774785 const result = [ ] ;
@@ -1090,7 +1101,7 @@ export class FlowService {
10901101
10911102 private determineIdRanking = (
10921103 ids : number [ ] ,
1093- order : 'ASC' | 'DSC' = 'ASC' ,
1104+ // order: 'ASC' | 'DSC' = 'ASC',
10941105 ) => {
10951106 // Function to count the occurrences of an element in an array
10961107 const countOccurrences = ( arr : number [ ] , val : number ) =>
@@ -1100,17 +1111,19 @@ export class FlowService {
11001111 const frequencyMap : Record < number , number > = { } ;
11011112 ids . forEach ( ( i ) => ( frequencyMap [ i ] = countOccurrences ( ids , i ) ) ) ;
11021113
1103- // Create an array of unique elements
1104- const uniqueElements = [ ...new Set ( ids ) ] ;
1114+ return frequencyMap ;
11051115
1106- // Sort the unique elements array based on the frequency of each element
1107- uniqueElements . sort ( ( a , b ) =>
1108- order === 'ASC'
1109- ? frequencyMap [ a ] - frequencyMap [ b ]
1110- : frequencyMap [ b ] - frequencyMap [ a ] ,
1111- ) ;
1116+ // // Create an array of unique elements
1117+ // const uniqueElements = [...new Set(ids)];
1118+
1119+ // // Sort the unique elements array based on the frequency of each element
1120+ // uniqueElements.sort((a, b) =>
1121+ // order === 'ASC'
1122+ // ? frequencyMap[a] - frequencyMap[b]
1123+ // : frequencyMap[b] - frequencyMap[a],
1124+ // );
11121125
1113- return uniqueElements ;
1126+ // return uniqueElements;
11141127 } ;
11151128
11161129 private validateVote = async (
0 commit comments