@@ -620,6 +620,124 @@ app.post('/generate_client_urls', function (req, res) {
620620 } ) ;
621621} ) ;
622622
623+ app . post ( '/get_analytics_masks' , function ( req , res ) {
624+ console . log ( 'GET to get_analytics_masks.' ) ;
625+ console . log ( req . body ) ;
626+
627+ var schema = {
628+ session : joi . string ( ) . alphanum ( ) . required ( ) ,
629+ password : joi . string ( ) . alphanum ( ) . required ( )
630+ } ;
631+
632+ joi . validate ( req . body , schema , function ( valErr , body ) {
633+ if ( valErr ) {
634+ console . log ( valErr ) ;
635+ res . status ( 500 ) . send ( 'Invalid or missing fields.' ) ;
636+ return ;
637+ }
638+
639+ var fail = function ( err ) {
640+ console . log ( err ) ;
641+ res . status ( 500 ) . send ( err ) ;
642+ } ;
643+ var success = function ( ) {
644+ AnalyticsMask . where ( { session : body . session } ) . find ( function ( err , data ) {
645+ if ( err ) {
646+ console . log ( err ) ;
647+ res . status ( 500 ) . send ( 'Error getting analytics masks.' ) ;
648+ return ;
649+ }
650+ if ( ! data || data . length === 0 ) {
651+ res . status ( 500 ) . send ( 'No submissions yet. Please come back later.' ) ;
652+ return ;
653+ }
654+ else {
655+ console . log ( data ) ;
656+ res . send ( { data : JSON . stringify ( data ) } ) ;
657+ return ;
658+ }
659+ } ) ;
660+ } ;
661+
662+ verify_password ( body . session , body . password , function ( ) {
663+ verify_status ( body . session , "STOP" , success , fail ) ;
664+ } , fail ) ;
665+ } ) ;
666+
667+ } ) ;
668+
669+ // endpoint for getting all of the cubes for a specific session
670+ app . post ( '/get_cubes' , function ( req , res ) {
671+ console . log ( 'POST to get_cubes.' ) ;
672+ console . log ( req . body ) ;
673+
674+ var schema = {
675+ session : joi . string ( ) . alphanum ( ) . required ( ) ,
676+ password : joi . string ( ) . alphanum ( ) . required ( )
677+ } ;
678+
679+ joi . validate ( req . body , schema , function ( valErr , body ) {
680+ if ( valErr ) {
681+ console . log ( valErr ) ;
682+ res . status ( 500 ) . send ( 'Invalid or missing fields.' ) ;
683+ return ;
684+ }
685+
686+ var fail = function ( err ) {
687+ console . log ( err ) ;
688+ res . status ( 500 ) . send ( err ) ;
689+ } ;
690+ var success = function ( ) {
691+ Cube . where ( { session : body . session } ) . find ( function ( err , data ) {
692+ if ( err ) {
693+ console . log ( err ) ;
694+ res . status ( 500 ) . send ( 'Error getting cubes.' ) ;
695+ return ;
696+ }
697+ if ( ! data || data . length === 0 ) {
698+ res . status ( 500 ) . send ( 'No submissions yet. Please come back later.' ) ;
699+ return ;
700+ }
701+ else {
702+ console . log ( data . length ) ;
703+ var result = { } ;
704+ for ( var i = 0 ; i < 5 ; i ++ ) {
705+ for ( var j = i + 1 ; j < 5 ; j ++ ) {
706+ result [ i + ":" + j ] = [ ] ;
707+ }
708+ }
709+
710+ for ( var d = 0 ; d < data . length ; d ++ ) {
711+ var one_submission = data [ d ] . fields ;
712+ for ( var i = 0 ; i < 5 ; i ++ ) {
713+ for ( var j = i + 1 ; j < 5 ; j ++ ) {
714+ result [ i + ":" + j ] . push ( one_submission [ i + ":" + j ] ) ;
715+ }
716+ }
717+ }
718+
719+ // Sort (to shuffle/remove order) pairs
720+ // now it cannot be inferred which pairs are from the same submission.
721+ for ( var i = 0 ; i < 5 ; i ++ ) {
722+ for ( var j = i + 1 ; j < 5 ; j ++ ) {
723+ result [ i + ":" + j ] = result [ i + ":" + j ] . sort ( ) ;
724+ }
725+ }
726+
727+ res . send ( result ) ;
728+ return ;
729+ }
730+ } ) ;
731+ } ;
732+
733+ verify_password ( body . session , body . password , function ( ) {
734+ verify_status ( body . session , "STOP" , success , fail ) ;
735+ } , fail ) ;
736+ } ) ;
737+
738+ } ) ;
739+
740+
623741// endpoint for getting already generated client unique urls
624742app . post ( '/get_client_urls' , function ( req , res ) {
625743 console . log ( 'POST /get_client_urls' ) ;
@@ -830,6 +948,66 @@ app.post('/get_cubes', function (req, res) {
830948
831949} ) ;
832950
951+
952+ // endpoint for getting the service share of the result of the aggregation
953+ app . post ( '/get_analytics' , function ( req , res ) {
954+ console . log ( 'POST /get_analytics' ) ;
955+ console . log ( req . body ) ;
956+
957+ var schema = {
958+ session : joi . string ( ) . alphanum ( ) . required ( ) ,
959+ password : joi . string ( ) . alphanum ( ) . required ( )
960+ } ;
961+
962+ joi . validate ( req . body , schema , function ( valErr , body ) {
963+ if ( valErr ) {
964+ console . log ( valErr ) ;
965+ res . status ( 500 ) . send ( 'Invalid or missing fields.' ) ;
966+ return ;
967+ }
968+
969+ var fail = function ( err ) {
970+ console . log ( err ) ;
971+ res . status ( 500 ) . send ( err ) ;
972+ } ;
973+ var success = function ( ) {
974+ Analytics . where ( { session : body . session } ) . find ( function ( err , data ) {
975+ if ( err ) {
976+ console . log ( err ) ;
977+ res . status ( 500 ) . send ( 'Error computing aggregate.' ) ;
978+ return ;
979+ }
980+
981+ // make sure query result is not empty
982+ if ( data . length >= 1 ) {
983+ console . log ( 'Computing share of aggregate.' ) ;
984+
985+ var invalidShareCount = mpc . countInvalidShares ( data , true ) ,
986+ serviceShare = mpc . aggregateShares ( data , true ) ;
987+
988+ // TODO: we should set a threshold and abort if there are too
989+ // many invalid shares
990+ console . log ( 'Invalid share count:' , invalidShareCount ) ;
991+
992+ console . log ( 'Sending aggregate.' ) ;
993+ console . log ( 'SERVICE SHARE' , serviceShare ) ;
994+ res . json ( serviceShare ) ;
995+
996+ return ;
997+ }
998+ else {
999+ res . status ( 500 ) . send ( 'No submissions yet. Please come back later.' ) ;
1000+ return ;
1001+ }
1002+ } ) ;
1003+ } ;
1004+
1005+ verify_password ( body . session , body . password , function ( ) {
1006+ verify_status ( body . session , "STOP" , success , fail ) ;
1007+ } , fail ) ;
1008+ } ) ;
1009+ } ) ;
1010+
8331011// endpoint for getting the service share of the result of the aggregation
8341012app . post ( '/get_aggregate' , function ( req , res ) {
8351013 console . log ( 'POST /get_aggregate' ) ;
0 commit comments