@@ -44,6 +44,7 @@ exports.groupUsersCounter = functions.database.ref('/v2/results/{projectId}/{gro
4444 const totalGroupContributionCountRef = userRef . child ( 'groupContributionCount' )
4545 const userContributionRef = userRef . child ( 'contributions/' + context . params . projectId )
4646 const taskContributionCountRef = userRef . child ( 'contributions/' + context . params . projectId + '/taskContributionCount' )
47+ const thisResultRef = admin . database ( ) . ref ( '/v2/results/' + context . params . projectId + '/' + context . params . groupId + '/' + context . params . userId )
4748
4849 // if result ref does not contain all required attributes we don't updated counters
4950 // e.g. due to some error when uploading from client
@@ -61,6 +62,30 @@ exports.groupUsersCounter = functions.database.ref('/v2/results/{projectId}/{gro
6162 return null
6263 }
6364
65+ // Check for specific user ids which have been identified as problematic.
66+ // These users have repeatedly uploaded harmful results.
67+ // Add new user ids to this list if needed.
68+ const userIds = [ ]
69+ if ( userIds . includes ( context . params . userId ) ) {
70+ console . log ( 'suspicious user: ' + context . params . userId )
71+ console . log ( 'will remove this result and not update counters' )
72+ return Promise . all ( [ thisResultRef . remove ( ) ] )
73+ }
74+
75+ // check if these results are likely to be vandalism
76+ // mapping speed is defined by the average time needed per task in seconds
77+ const numberOfTasks = Object . keys ( result [ 'results' ] ) . length
78+ const startTime = Date . parse ( result [ 'startTime' ] ) / 1000
79+ const endTime = Date . parse ( result [ 'endTime' ] ) / 1000
80+ const mappingSpeed = ( endTime - startTime ) / numberOfTasks
81+
82+ if ( mappingSpeed < 0.125 ) {
83+ // this about 8-times faster than the average time needed per task
84+ console . log ( 'unlikely high mapping speed: ' + mappingSpeed )
85+ console . log ( 'will remove this result and not update counters' )
86+ return Promise . all ( [ thisResultRef . remove ( ) ] )
87+ }
88+
6489 /*
6590 Check if this user has submitted a results for this group already.
6691 If no result has been submitted yet, set userId in v2/groupsUsers.
0 commit comments