1
1
"use strict"
2
2
3
+ var BAN_UID = new Set ( ) ;
4
+ var SPAM_UID = new Set ( ) ;
5
+
3
6
/**
4
7
* @template T
5
8
* @template R
@@ -211,21 +214,32 @@ class Analyse
211
214
const uid1 = new Set ( uid0 ) ;
212
215
uid1 . delete ( "" ) ; //except anonymous user
213
216
const uids = uid1 . toArray ( ) ;
214
- console . log ( "here [" + uids . length + "] uids" ) ;
217
+ console . log ( "Analyse Similarity here [" + uids . length + "] uids" ) ;
215
218
219
+ /**@type {[Promise<Zan[]>, Promise<Zan[]>] }*/
216
220
const zanquerys = [ db . zans . where ( "from" ) . anyOf ( uids ) . toArray ( ) , db . zanarts . where ( "from" ) . anyOf ( uids ) . toArray ( ) ] ;
217
- /**@type {[Zan[], Zan[]] }*/
218
221
const [ anszan , artzan ] = await Promise . all ( zanquerys ) ;
219
- console . log ( "get [" + anszan . length + "] answer records" , "get [" + artzan . length + "] article records" ) ;
222
+ console . log ( `get [${ anszan . length } ] answer records` , `get [${ artzan . length } ] article records` ) ;
223
+
224
+ const zancounter = new SimpleBag ( anszan . mapToProp ( "from" ) ) ;
225
+ zancounter . adds ( artzan . mapToProp ( "from" ) ) ;
220
226
221
- const voterbag0 = new SimpleBag ( anszan . mapToProp ( "from" ) ) ;
222
- voterbag0 . adds ( artzan . mapToProp ( "from" ) ) ;
227
+ const zancounter2 = new SimpleBag ( ) ;
228
+ {
229
+ /**@type {Set<string> }*/
230
+ const banusers = zancounter . toSet ( ) . intersection ( BAN_UID ) ;
231
+ const involvedAnss = new Set ( anszan . filter ( zan => banusers . has ( zan . from ) ) . mapToProp ( "to" ) ) ;
232
+ anszan . filter ( zan => involvedAnss . has ( zan . to ) ) . forEach ( zan => zancounter2 . add ( zan . from ) ) ;
233
+ const involvedArts = new Set ( artzan . filter ( zan => banusers . has ( zan . from ) ) . mapToProp ( "to" ) ) ;
234
+ artzan . filter ( zan => involvedArts . has ( zan . to ) ) . forEach ( zan => zancounter2 . add ( zan . from ) ) ;
235
+ console . log ( `find [${ banusers . size } ] banned users` , `involve [${ involvedAnss . size + involvedArts . size } ] objects` ) ;
236
+ }
223
237
224
238
/**@type {number } ln(1~(zan-80)) => [1,9]*/
225
239
const minrepeat = Math . minmax ( Math . floor ( Math . log ( Math . max ( uids . length - 80 , 1 ) ) ) , 1 , 9 ) ;
226
- const ansbag = new SimpleBag ( anszan . mapToProp ( "to" ) ) . above ( minrepeat ) , artbag = new SimpleBag ( artzan . mapToProp ( "to" ) ) . above ( minrepeat ) ;
227
- const ansset = ansbag . toSet ( ) , artset = artbag . toSet ( ) ;
228
- console . log ( " reduce to [" + ansset . size + " ] answer records" , "get [" + artset . size + " ] article records" ) ;
240
+ const ansset = new SimpleBag ( anszan . mapToProp ( "to" ) ) . above ( minrepeat ) . toSet ( ) ;
241
+ const artset = new SimpleBag ( artzan . mapToProp ( "to" ) ) . above ( minrepeat ) . toSet ( ) ;
242
+ console . log ( ` reduce to [${ ansset . size } ] answer records` , `reduce to [ ${ artset . size } ] article records` ) ;
229
243
230
244
const voterbag = new SimpleBag ( ) ;
231
245
for ( let i = 0 ; i < anszan . length ; ++ i )
@@ -241,8 +255,9 @@ class Analyse
241
255
voterbag . add ( zan . from ) ;
242
256
}
243
257
244
- /**@type {[string, [number, number]][] }*/
245
- const result = voterbag . map ( ( uid , count ) => [ uid , [ count , voterbag0 . count ( uid ) ] ] ) ;
258
+ /**@type {[string, [number, number, number]][] }*/
259
+ const result = voterbag . map ( ( uid , count ) => [ uid , [ count , zancounter2 . count ( uid ) , zancounter . count ( uid ) ] ] ) ;
260
+ console . log ( `Analyse Similarity finished, threshold [${ minrepeat } ]` ) ;
246
261
return { data : result , limit : minrepeat } ;
247
262
}
248
263
}
0 commit comments