@@ -647,6 +647,8 @@ export class FlowService {
647647
648648 starSubcategories . null = nullProjects . length ;
649649
650+ // console.log('dist', starSubcategories);
651+
650652 let total = 0 ;
651653 for ( const key in starSubcategories ) {
652654 if ( key === '1' ) continue ;
@@ -661,9 +663,79 @@ export class FlowService {
661663 getStarsById ( vote . project1Id ) !== 1 ,
662664 ) ;
663665
666+ // console.log('effectiveVotes', effectiveVotes);
667+ // console.log('total:', total);
668+
669+ if ( total === 0 ) {
670+ return allVotes . length / combinations ( allProjects . length , 2 ) ;
671+ }
672+
664673 return effectiveVotes . length / total ;
665674 } ;
666675
676+ test = async ( ) => {
677+ const userId = 13 ;
678+ const parentCollection = 1 ;
679+
680+ const [ collection , votes , projects , allStars , projectCoIs ] =
681+ await Promise . all ( [
682+ this . prismaService . project . findUnique ( {
683+ where : {
684+ id : parentCollection || - 1 ,
685+ type : ProjectType . collection ,
686+ } ,
687+ select : { name : true , id : true } ,
688+ } ) ,
689+ this . prismaService . vote . findMany ( {
690+ where : {
691+ userId : userId ,
692+ project1 : { parentId : parentCollection } ,
693+ project2 : { parentId : parentCollection } ,
694+ } ,
695+ } ) ,
696+ this . prismaService . project . findMany ( {
697+ where : {
698+ parentId : parentCollection || - 1 ,
699+ } ,
700+ } ) ,
701+ this . getUserProjectStars ( userId , parentCollection || - 1 ) ,
702+ this . prismaService . projectCoI . findMany ( {
703+ where : {
704+ project : { parentId : parentCollection } ,
705+ userId,
706+ } ,
707+ } ) ,
708+ ] ) ;
709+
710+ // projects except those with conflict of interest
711+ const allProjects = projects
712+ . filter ( ( item ) => ! projectCoIs . find ( ( el ) => el . projectId === item . id ) )
713+ . sort ( ( a , b ) =>
714+ ( a . implicitCategory || '' ) . localeCompare ( b . implicitCategory || '' ) ,
715+ ) ;
716+
717+ const projectStars = allStars . filter (
718+ ( item ) => ! projectCoIs . find ( ( el ) => el . projectId === item . projectId ) ,
719+ ) ;
720+
721+ const allVotes = votes . filter (
722+ ( item ) =>
723+ ! projectCoIs . find (
724+ ( el ) =>
725+ el . projectId === item . project1Id ||
726+ el . projectId === item . project2Id ,
727+ ) ,
728+ ) ;
729+
730+ const realProgress = this . calculateProgress (
731+ allVotes ,
732+ projectStars ,
733+ allProjects ,
734+ ) ;
735+
736+ console . log ( realProgress ) ;
737+ } ;
738+
667739 // if projectId is provided, the returend pair must include that project if possible
668740 getPairs = async (
669741 userId : number ,
@@ -727,7 +799,7 @@ export class FlowService {
727799 allProjects ,
728800 ) ;
729801
730- const progress = Math . min ( 1 , realProgress * 3 ) ;
802+ const progress = Math . min ( 1 , realProgress * 10 ) ;
731803
732804 if ( progress === 1 ) {
733805 if ( collection ) {
@@ -998,7 +1070,7 @@ export class FlowService {
9981070
9991071 console . log ( 'summation' , summation ) ;
10001072 // console.log("to fn3 summation", summation)
1001- if ( Math . abs ( 1 - toFixedNumber ( summation , 5 ) ) > 0.00001 )
1073+ if ( Math . abs ( 1 - toFixedNumber ( summation , 3 ) ) > 0.001 )
10021074 throw new BadRequestException ( 'Sumamtion of shares must equal 1' ) ;
10031075 } ;
10041076
0 commit comments