@yrpri/api 9.0.231 → 9.0.233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/managers/subscriptionManager.js +2 -2
- package/controllers/allOurIdeas.js +1 -1
- package/controllers/communities.cjs +282 -91
- package/controllers/domains.cjs +54 -8
- package/controllers/groups.cjs +51 -6
- package/controllers/points.cjs +4 -9
- package/controllers/posts.cjs +7 -9
- package/controllers/ratings.cjs +3 -6
- package/models/point.cjs +31 -3
- package/models/post.cjs +2 -3
- package/package.json +32 -67
- package/services/engine/allOurIdeas/aiHelper.d.ts +7 -4
- package/services/engine/allOurIdeas/aiHelper.js +34 -19
- package/services/engine/allOurIdeas/explainAnswersAssistant.d.ts +1 -1
- package/services/engine/allOurIdeas/explainAnswersAssistant.js +3 -9
- package/services/engine/moderation/fraud/CreateFraudAuditReport.cjs +35 -11
- package/services/engine/moderation/fraud/CreateFraudAuditReport.d.cts +21 -0
- package/services/engine/moderation/fraud/FraudBase.cjs +38 -18
- package/services/engine/moderation/fraud/FraudBase.d.cts +2 -0
- package/services/engine/moderation/fraud/FraudDeleteBase.cjs +48 -29
- package/services/engine/moderation/fraud/FraudDeleteBase.d.cts +8 -6
- package/services/engine/moderation/fraud/FraudDeleteEndorsements.cjs +5 -4
- package/services/engine/moderation/fraud/FraudDeleteEndorsements.d.cts +2 -2
- package/services/engine/moderation/fraud/FraudDeletePointQualities.cjs +3 -2
- package/services/engine/moderation/fraud/FraudDeletePointQualities.d.cts +1 -1
- package/services/engine/moderation/fraud/FraudDeletePoints.cjs +3 -2
- package/services/engine/moderation/fraud/FraudDeletePoints.d.cts +1 -1
- package/services/engine/moderation/fraud/FraudDeletePosts.cjs +3 -2
- package/services/engine/moderation/fraud/FraudDeleteRatings.cjs +61 -4
- package/services/engine/moderation/fraud/FraudGetBase.cjs +44 -20
- package/services/engine/moderation/fraud/FraudGetBase.d.cts +5 -0
- package/services/engine/moderation/fraud/FraudGetEndorsements.cjs +4 -13
- package/services/engine/moderation/fraud/FraudGetEndorsements.d.cts +1 -1
- package/services/engine/moderation/fraud/FraudGetPointQualities.cjs +3 -0
- package/services/engine/moderation/fraud/FraudGetPointQualities.d.cts +1 -1
- package/services/engine/moderation/fraud/FraudGetPoints.cjs +3 -0
- package/services/engine/moderation/fraud/FraudGetPoints.d.cts +1 -1
- package/services/engine/moderation/fraud/FraudGetPosts.cjs +17 -16
- package/services/engine/moderation/fraud/FraudGetPosts.d.cts +3 -3
- package/services/engine/moderation/fraud/FraudGetRatings.cjs +62 -30
- package/services/engine/moderation/fraud/FraudGetRatings.d.cts +4 -1
- package/services/engine/moderation/fraud/FraudRequestValidation.cjs +143 -0
- package/services/engine/moderation/fraud/FraudRequestValidation.d.cts +21 -0
- package/services/engine/moderation/fraud/FraudScannerNotifier.cjs +59 -35
- package/services/engine/moderation/fraud/FraudScannerNotifier.d.cts +20 -1
- package/services/llms/baseChatBot.d.ts +2 -0
- package/services/llms/baseChatBot.js +25 -9
- package/services/llms/imageGeneration/chatGptImageGenerator.d.ts +2 -2
- package/services/llms/imageGeneration/chatGptImageGenerator.js +13 -10
- package/services/llms/imageGeneration/collectionImageGenerator.js +31 -13
- package/services/llms/imageGeneration/dalleImageGenerator.d.ts +2 -2
- package/services/llms/imageGeneration/dalleImageGenerator.js +28 -16
- package/services/llms/imageGeneration/fluxImageGenerator.d.ts +2 -2
- package/services/llms/imageGeneration/fluxImageGenerator.js +9 -3
- package/services/llms/imageGeneration/iImageGenerator.d.ts +8 -1
- package/services/llms/imageGeneration/imageModelConfig.cjs +319 -0
- package/services/llms/imageGeneration/imageModelConfig.d.cts +79 -0
- package/services/llms/imageGeneration/imagenImageGenerator.d.ts +2 -3
- package/services/llms/imageGeneration/imagenImageGenerator.js +10 -10
- package/tests/fraudManagement.test.cjs +470 -0
- package/tests/fraudManagement.test.d.cts +1 -0
- package/tests/imageModelConfig.test.cjs +144 -0
- package/tests/imageModelConfig.test.d.cts +1 -0
- package/utils/ai_image_generation_guard.cjs +268 -0
- package/utils/ai_image_generation_guard.d.cts +34 -0
- package/utils/fingerprint_data.cjs +32 -0
- package/utils/fingerprint_data.d.cts +6 -0
- package/utils/recount_utils.cjs +53 -37
- package/utils/recount_utils.d.cts +7 -7
|
@@ -4,12 +4,69 @@ const FraudDeleteEndorsements = require('./FraudDeleteEndorsements.cjs');
|
|
|
4
4
|
const models = require("../../../../models/index.cjs");
|
|
5
5
|
//TODO: Change to native JS instead of lodash
|
|
6
6
|
class FraudDeleteRatings extends FraudDeleteEndorsements {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
getAllItemsExceptOne(items) {
|
|
8
|
+
if (items.length === 1 && this.getAllowedSingleDelete()) {
|
|
9
|
+
return items;
|
|
10
|
+
}
|
|
11
|
+
const itemsByTypeIndex = _.groupBy(items, item => {
|
|
12
|
+
return item.type_index === undefined || item.type_index === null
|
|
13
|
+
? "default"
|
|
14
|
+
: item.type_index;
|
|
15
|
+
});
|
|
16
|
+
let itemsToDelete = [];
|
|
17
|
+
_.each(itemsByTypeIndex, innerItems => {
|
|
18
|
+
itemsToDelete = itemsToDelete.concat(super.getAllItemsExceptOne(innerItems));
|
|
19
|
+
});
|
|
20
|
+
return itemsToDelete;
|
|
21
|
+
}
|
|
22
|
+
async destroyChunkItems(items, transaction) {
|
|
23
|
+
return this.destroyChunkItemsByModel(models.Rating, items, transaction);
|
|
9
24
|
}
|
|
10
25
|
async getItemsById() {
|
|
11
|
-
|
|
12
|
-
|
|
26
|
+
return await new Promise(async (resolve, reject) => {
|
|
27
|
+
try {
|
|
28
|
+
const items = await models.Rating.findAll({
|
|
29
|
+
where: {
|
|
30
|
+
id: {
|
|
31
|
+
$in: this.job.internal_data.idsToDelete
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
attributes: ["id", "created_at", "value", "type_index", "post_id", "user_id", "user_agent", "ip_address", "data"],
|
|
35
|
+
include: [
|
|
36
|
+
{
|
|
37
|
+
model: models.User,
|
|
38
|
+
attributes: ['id', 'email'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
model: models.Post,
|
|
42
|
+
attributes: ['id', 'name'],
|
|
43
|
+
include: [
|
|
44
|
+
{
|
|
45
|
+
model: models.Group,
|
|
46
|
+
attributes: ['id'],
|
|
47
|
+
include: [
|
|
48
|
+
{
|
|
49
|
+
model: models.Community,
|
|
50
|
+
attributes: [],
|
|
51
|
+
where: {
|
|
52
|
+
id: this.workPackage.communityId
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
const itemsToAnalyse = _.sortBy(items, function (item) {
|
|
62
|
+
return [item.post_id, item.type_index, item.user_agent];
|
|
63
|
+
});
|
|
64
|
+
resolve(itemsToAnalyse);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
reject(error);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
13
70
|
}
|
|
14
71
|
}
|
|
15
72
|
module.exports = FraudDeleteRatings;
|
|
@@ -26,6 +26,21 @@ class FraudGetBase extends FraudBase {
|
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
getUserEmail(item) {
|
|
30
|
+
return item.User && item.User.email ? item.User.email : "";
|
|
31
|
+
}
|
|
32
|
+
getUserName(item) {
|
|
33
|
+
return item.User && item.User.name ? item.User.name : "";
|
|
34
|
+
}
|
|
35
|
+
getPostName(item) {
|
|
36
|
+
return item.Post && item.Post.name ? item.Post.name : "";
|
|
37
|
+
}
|
|
38
|
+
getPointQualityPostName(item) {
|
|
39
|
+
return item.Point && item.Point.Post && item.Point.Post.name ? item.Point.Post.name : "";
|
|
40
|
+
}
|
|
41
|
+
getItemName(item) {
|
|
42
|
+
return item && item.name ? item.name : "";
|
|
43
|
+
}
|
|
29
44
|
customCompress() {
|
|
30
45
|
const flatData = [];
|
|
31
46
|
_.forEach(this.dataToProcess, item => {
|
|
@@ -71,43 +86,52 @@ class FraudGetBase extends FraudBase {
|
|
|
71
86
|
cDoneUserAgents[item.user_agent] = true;
|
|
72
87
|
outData.cUserAgents.push(item.user_agent);
|
|
73
88
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
const userEmail = this.getUserEmail(item);
|
|
90
|
+
const userName = this.getUserName(item);
|
|
91
|
+
item.User = item.User || {};
|
|
92
|
+
if (!cDoneEmails[userEmail]) {
|
|
93
|
+
cDoneEmails[userEmail] = true;
|
|
94
|
+
outData.cEmails.push(userEmail);
|
|
77
95
|
}
|
|
78
|
-
if (!cDoneNames[
|
|
79
|
-
cDoneNames[
|
|
80
|
-
outData.cNames.push(
|
|
96
|
+
if (!cDoneNames[userName]) {
|
|
97
|
+
cDoneNames[userName] = true;
|
|
98
|
+
outData.cNames.push(userName);
|
|
81
99
|
}
|
|
82
100
|
if (this.workPackage.collectionType === "endorsements" ||
|
|
83
101
|
this.workPackage.collectionType === "ratings" ||
|
|
84
102
|
this.workPackage.collectionType === "points") {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
103
|
+
const postName = this.getPostName(item);
|
|
104
|
+
item.Post = item.Post || {};
|
|
105
|
+
if (!cDonePostNames[postName]) {
|
|
106
|
+
cDonePostNames[postName] = true;
|
|
107
|
+
outData.cPostNames.push(postName);
|
|
88
108
|
}
|
|
89
|
-
item.Post.name = outData.cPostNames.indexOf(
|
|
109
|
+
item.Post.name = outData.cPostNames.indexOf(postName);
|
|
90
110
|
}
|
|
91
111
|
if (this.workPackage.collectionType === "posts") {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
112
|
+
const postName = this.getItemName(item);
|
|
113
|
+
if (!cDonePostNames[postName]) {
|
|
114
|
+
cDonePostNames[postName] = true;
|
|
115
|
+
outData.cPostNames.push(postName);
|
|
95
116
|
}
|
|
96
|
-
item.name = outData.cPostNames.indexOf(
|
|
117
|
+
item.name = outData.cPostNames.indexOf(postName);
|
|
97
118
|
}
|
|
98
119
|
if (this.workPackage.collectionType === "pointQualities") {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
120
|
+
const postName = this.getPointQualityPostName(item);
|
|
121
|
+
item.Point = item.Point || {};
|
|
122
|
+
item.Point.Post = item.Point.Post || {};
|
|
123
|
+
if (!cDonePostNames[postName]) {
|
|
124
|
+
cDonePostNames[postName] = true;
|
|
125
|
+
outData.cPostNames.push(postName);
|
|
102
126
|
}
|
|
103
|
-
item.Point.Post.name = outData.cPostNames.indexOf(
|
|
127
|
+
item.Point.Post.name = outData.cPostNames.indexOf(postName);
|
|
104
128
|
}
|
|
105
129
|
item.dataValues.backgroundColor = outData.cBackgroundColors.indexOf(item.dataValues.backgroundColor);
|
|
106
130
|
item.dataValues.confidenceScoreSort = parseInt(item.dataValues.confidenceScore.replace("%", ''));
|
|
107
131
|
item.ip_address = outData.cIpAddresses.indexOf(item.ip_address);
|
|
108
132
|
item.user_agent = outData.cUserAgents.indexOf(item.user_agent);
|
|
109
|
-
item.User.email = outData.cEmails.indexOf(
|
|
110
|
-
item.User.name = outData.
|
|
133
|
+
item.User.email = outData.cEmails.indexOf(userEmail);
|
|
134
|
+
item.User.name = outData.cNames.indexOf(userName);
|
|
111
135
|
outData.items.push(item);
|
|
112
136
|
});
|
|
113
137
|
this.dataToProcess = outData;
|
|
@@ -2,6 +2,11 @@ export = FraudGetBase;
|
|
|
2
2
|
declare class FraudGetBase extends FraudBase {
|
|
3
3
|
formatTime(): void;
|
|
4
4
|
setBackgroundColorsFromKey(): void;
|
|
5
|
+
getUserEmail(item: any): any;
|
|
6
|
+
getUserName(item: any): any;
|
|
7
|
+
getPostName(item: any): any;
|
|
8
|
+
getPointQualityPostName(item: any): any;
|
|
9
|
+
getItemName(item: any): any;
|
|
5
10
|
customCompress(): void;
|
|
6
11
|
processAndGetFraudItems(): Promise<any>;
|
|
7
12
|
}
|
|
@@ -39,19 +39,7 @@ class FraudGetEndorsements extends FraudGetBase {
|
|
|
39
39
|
const itemsToAnalyse = _.sortBy(items, function (item) {
|
|
40
40
|
return [item.post_id, item.user_agent];
|
|
41
41
|
});
|
|
42
|
-
|
|
43
|
-
if (getGroup && items.length > 0) {
|
|
44
|
-
const group = await models.Group.findOne({
|
|
45
|
-
where: {
|
|
46
|
-
id: itemsToAnalyse[0].Post.Group.id
|
|
47
|
-
},
|
|
48
|
-
attributes: ['configuration']
|
|
49
|
-
});
|
|
50
|
-
if (group) {
|
|
51
|
-
groupConfiguration = group.configuration;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
resolve({ itemsToAnalyse, groupConfiguration });
|
|
42
|
+
resolve({ itemsToAnalyse });
|
|
55
43
|
}
|
|
56
44
|
catch (error) {
|
|
57
45
|
reject(error);
|
|
@@ -66,6 +54,9 @@ class FraudGetEndorsements extends FraudGetBase {
|
|
|
66
54
|
let topItems = this.setupTopItems(items);
|
|
67
55
|
const postIds = this.getPostIdsFromItems(topItems);
|
|
68
56
|
const postCount = _.uniq(postIds).length;
|
|
57
|
+
if (this.isDebugFraudDetectionCountAll()) {
|
|
58
|
+
return this.getDebugTopItems(topItems);
|
|
59
|
+
}
|
|
69
60
|
if (type === "byIpUserAgentPostId") {
|
|
70
61
|
let out = [];
|
|
71
62
|
_.each(topItems, function (item) {
|
|
@@ -2,6 +2,6 @@ export = FraudGetEndorsements;
|
|
|
2
2
|
declare class FraudGetEndorsements extends FraudGetBase {
|
|
3
3
|
getAllModelItems(model: any, getGroup: any): Promise<any>;
|
|
4
4
|
getAllItems(): Promise<any>;
|
|
5
|
-
getTopItems(items: any, type: any): any
|
|
5
|
+
getTopItems(items: any, type: any): any;
|
|
6
6
|
}
|
|
7
7
|
import FraudGetBase = require("./FraudGetBase.cjs");
|
|
@@ -65,6 +65,9 @@ class FraudGetPointQualities extends FraudGetBase {
|
|
|
65
65
|
let topItems = this.setupTopItems(items);
|
|
66
66
|
const pointIds = this.getPointIdsFromItems(topItems);
|
|
67
67
|
const pointCount = _.uniq(pointIds).length;
|
|
68
|
+
if (this.isDebugFraudDetectionCountAll()) {
|
|
69
|
+
return this.getDebugTopItems(topItems);
|
|
70
|
+
}
|
|
68
71
|
if (type === "byIpUserAgentPointId") {
|
|
69
72
|
let out = [];
|
|
70
73
|
_.each(topItems, function (item) {
|
|
@@ -2,6 +2,6 @@ export = FraudGetPointQualities;
|
|
|
2
2
|
declare class FraudGetPointQualities extends FraudGetBase {
|
|
3
3
|
getAllItems(): Promise<any>;
|
|
4
4
|
getPointIdsFromItems(topItems: any): any[];
|
|
5
|
-
getTopItems(items: any, type: any): any
|
|
5
|
+
getTopItems(items: any, type: any): any;
|
|
6
6
|
}
|
|
7
7
|
import FraudGetBase = require("./FraudGetBase.cjs");
|
|
@@ -51,6 +51,9 @@ class FraudGetPointQualities extends FraudGetBase {
|
|
|
51
51
|
const postIds = this.getPostIdsFromItems(topItems);
|
|
52
52
|
const postCount = _.uniq(postIds).length;
|
|
53
53
|
const pointMultiplier = 10;
|
|
54
|
+
if (this.isDebugFraudDetectionCountAll()) {
|
|
55
|
+
return this.getDebugTopItems(topItems);
|
|
56
|
+
}
|
|
54
57
|
if (type === "byIpUserAgentPostId") {
|
|
55
58
|
let out = [];
|
|
56
59
|
_.each(topItems, function (item) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export = FraudGetPointQualities;
|
|
2
2
|
declare class FraudGetPointQualities extends FraudGetBase {
|
|
3
3
|
getAllItems(): Promise<any>;
|
|
4
|
-
getTopItems(items: any, type: any): any
|
|
4
|
+
getTopItems(items: any, type: any): any;
|
|
5
5
|
}
|
|
6
6
|
import FraudGetBase = require("./FraudGetBase.cjs");
|
|
@@ -3,7 +3,7 @@ const _ = require("lodash");
|
|
|
3
3
|
const FraudGetBase = require('./FraudGetBase.cjs');
|
|
4
4
|
const models = require("../../../../models/index.cjs");
|
|
5
5
|
const log = require("../../../../utils/logger.cjs");
|
|
6
|
-
class
|
|
6
|
+
class FraudGetPosts extends FraudGetBase {
|
|
7
7
|
async getAllItems() {
|
|
8
8
|
return await new Promise(async (resolve, reject) => {
|
|
9
9
|
try {
|
|
@@ -41,23 +41,24 @@ class FraudGetPoints extends FraudGetBase {
|
|
|
41
41
|
}
|
|
42
42
|
getTopItems(items, type) {
|
|
43
43
|
let topItems = this.setupTopItems(items);
|
|
44
|
-
const postIds = this.getPostIdsFromItems(topItems);
|
|
45
|
-
const postCount = _.uniq(postIds).length;
|
|
46
44
|
const pointMultiplier = 10;
|
|
45
|
+
if (this.isDebugFraudDetectionCountAll()) {
|
|
46
|
+
return this.getDebugTopItems(topItems);
|
|
47
|
+
}
|
|
47
48
|
if (type === "byIpFingerprint") {
|
|
48
49
|
let out = [];
|
|
49
50
|
_.each(topItems, function (item) {
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
51
|
+
if (item.count > pointMultiplier) {
|
|
52
|
+
if (item.count > 5 * pointMultiplier) {
|
|
52
53
|
this.setWeightedConfidenceScore(item.items, 70);
|
|
53
54
|
}
|
|
54
|
-
else if (
|
|
55
|
+
else if (item.count > 4 * pointMultiplier) {
|
|
55
56
|
this.setWeightedConfidenceScore(item.items, 60);
|
|
56
57
|
}
|
|
57
|
-
else if (
|
|
58
|
+
else if (item.count > 3 * pointMultiplier) {
|
|
58
59
|
this.setWeightedConfidenceScore(item.items, 40);
|
|
59
60
|
}
|
|
60
|
-
else if (
|
|
61
|
+
else if (item.count > 2 * pointMultiplier) {
|
|
61
62
|
this.setWeightedConfidenceScore(item.items, 20);
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
@@ -74,23 +75,23 @@ class FraudGetPoints extends FraudGetBase {
|
|
|
74
75
|
else if (type === "byIpAddress") {
|
|
75
76
|
let out = [];
|
|
76
77
|
_.each(topItems, function (item) {
|
|
77
|
-
if (
|
|
78
|
-
if (
|
|
78
|
+
if (item.count > pointMultiplier) {
|
|
79
|
+
if (item.count > 100 * pointMultiplier) {
|
|
79
80
|
this.setWeightedConfidenceScore(item.items, 70);
|
|
80
81
|
}
|
|
81
|
-
else if (
|
|
82
|
+
else if (item.count > 50 * pointMultiplier) {
|
|
82
83
|
this.setWeightedConfidenceScore(item.items, 65);
|
|
83
84
|
}
|
|
84
|
-
else if (
|
|
85
|
+
else if (item.count > 25 * pointMultiplier) {
|
|
85
86
|
this.setWeightedConfidenceScore(item.items, 40);
|
|
86
87
|
}
|
|
87
|
-
else if (
|
|
88
|
+
else if (item.count > 10 * pointMultiplier) {
|
|
88
89
|
this.setWeightedConfidenceScore(item.items, 35);
|
|
89
90
|
}
|
|
90
|
-
else if (
|
|
91
|
+
else if (item.count > 5 * pointMultiplier) {
|
|
91
92
|
this.setWeightedConfidenceScore(item.items, 20);
|
|
92
93
|
}
|
|
93
|
-
else if (
|
|
94
|
+
else if (item.count > 2 * pointMultiplier) {
|
|
94
95
|
this.setWeightedConfidenceScore(item.items, 15);
|
|
95
96
|
}
|
|
96
97
|
else {
|
|
@@ -107,4 +108,4 @@ class FraudGetPoints extends FraudGetBase {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
|
-
module.exports =
|
|
111
|
+
module.exports = FraudGetPosts;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export =
|
|
2
|
-
declare class
|
|
1
|
+
export = FraudGetPosts;
|
|
2
|
+
declare class FraudGetPosts extends FraudGetBase {
|
|
3
3
|
getAllItems(): Promise<any>;
|
|
4
|
-
getTopItems(items: any, type: any): any
|
|
4
|
+
getTopItems(items: any, type: any): any;
|
|
5
5
|
}
|
|
6
6
|
import FraudGetBase = require("./FraudGetBase.cjs");
|
|
@@ -6,38 +6,67 @@ const log = require("../../../../utils/logger.cjs");
|
|
|
6
6
|
class FraudGetRatings extends FraudGetEndorsements {
|
|
7
7
|
constructor(workPackage) {
|
|
8
8
|
super(workPackage);
|
|
9
|
-
this.
|
|
9
|
+
this.ratingDimensionCountsByGroupId = {};
|
|
10
10
|
}
|
|
11
11
|
async getAllItems() {
|
|
12
12
|
const itemsContainer = await this.getAllModelItems(models.Rating, true);
|
|
13
|
-
this.
|
|
13
|
+
this.ratingDimensionCountsByGroupId = await this.getRatingDimensionCountsByGroupId(itemsContainer.itemsToAnalyse);
|
|
14
14
|
return itemsContainer.itemsToAnalyse;
|
|
15
15
|
}
|
|
16
|
+
async getRatingDimensionCountsByGroupId(items) {
|
|
17
|
+
const groupIds = _.uniq(items.map(item => {
|
|
18
|
+
return item.Post && item.Post.Group && item.Post.Group.id;
|
|
19
|
+
}).filter(groupId => groupId));
|
|
20
|
+
if (groupIds.length === 0) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
const groups = await models.Group.findAll({
|
|
24
|
+
where: {
|
|
25
|
+
id: groupIds
|
|
26
|
+
},
|
|
27
|
+
attributes: ['id', 'configuration']
|
|
28
|
+
});
|
|
29
|
+
return groups.reduce((countsByGroupId, group) => {
|
|
30
|
+
const customRatings = group.configuration && group.configuration.customRatings;
|
|
31
|
+
countsByGroupId[group.id] =
|
|
32
|
+
customRatings && typeof customRatings === "object"
|
|
33
|
+
? Math.max(Object.keys(customRatings).length, 1)
|
|
34
|
+
: 1;
|
|
35
|
+
return countsByGroupId;
|
|
36
|
+
}, {});
|
|
37
|
+
}
|
|
38
|
+
getRatingDimensionsForItem(item) {
|
|
39
|
+
const groupId = item.Post && item.Post.Group && item.Post.Group.id;
|
|
40
|
+
return this.ratingDimensionCountsByGroupId[groupId] || 1;
|
|
41
|
+
}
|
|
42
|
+
getNormalizedRatingCount(items) {
|
|
43
|
+
return _.sumBy(items, item => 1 / this.getRatingDimensionsForItem(item));
|
|
44
|
+
}
|
|
16
45
|
getTopItems(items, type) {
|
|
17
46
|
let topItems = this.setupTopItems(items);
|
|
18
47
|
const postIds = this.getPostIdsFromItems(topItems);
|
|
19
|
-
const postCount = _.uniq(postIds).length;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ratingsCount = Object.keys(this.groupConfiguration.customRatings).length;
|
|
48
|
+
const postCount = Math.max(_.uniq(postIds).length, 1);
|
|
49
|
+
if (this.isDebugFraudDetectionCountAll()) {
|
|
50
|
+
return this.getDebugTopItems(topItems);
|
|
23
51
|
}
|
|
24
52
|
if (type === "byIpUserAgentPostId") {
|
|
25
53
|
let out = [];
|
|
26
54
|
_.each(topItems, function (item) {
|
|
27
|
-
|
|
28
|
-
|
|
55
|
+
const ratingRatio = this.getNormalizedRatingCount(item.items);
|
|
56
|
+
if (ratingRatio > 1) {
|
|
57
|
+
if (ratingRatio > 10) {
|
|
29
58
|
this.setWeightedConfidenceScore(item.items, 95);
|
|
30
59
|
}
|
|
31
|
-
else if (
|
|
60
|
+
else if (ratingRatio > 5) {
|
|
32
61
|
this.setWeightedConfidenceScore(item.items, 90);
|
|
33
62
|
}
|
|
34
|
-
else if (
|
|
63
|
+
else if (ratingRatio > 4) {
|
|
35
64
|
this.setWeightedConfidenceScore(item.items, 85);
|
|
36
65
|
}
|
|
37
|
-
else if (
|
|
66
|
+
else if (ratingRatio > 3) {
|
|
38
67
|
this.setWeightedConfidenceScore(item.items, 80);
|
|
39
68
|
}
|
|
40
|
-
else if (
|
|
69
|
+
else if (ratingRatio > 2) {
|
|
41
70
|
this.setWeightedConfidenceScore(item.items, 75);
|
|
42
71
|
}
|
|
43
72
|
else {
|
|
@@ -51,17 +80,18 @@ class FraudGetRatings extends FraudGetEndorsements {
|
|
|
51
80
|
else if (type === "byIpFingerprint") {
|
|
52
81
|
let out = [];
|
|
53
82
|
_.each(topItems, function (item) {
|
|
54
|
-
|
|
55
|
-
|
|
83
|
+
const ratingRatio = this.getNormalizedRatingCount(item.items) / postCount;
|
|
84
|
+
if (ratingRatio > 1) {
|
|
85
|
+
if (ratingRatio > 5) {
|
|
56
86
|
this.setWeightedConfidenceScore(item.items, 99);
|
|
57
87
|
}
|
|
58
|
-
else if (
|
|
88
|
+
else if (ratingRatio > 4) {
|
|
59
89
|
this.setWeightedConfidenceScore(item.items, 95);
|
|
60
90
|
}
|
|
61
|
-
else if (
|
|
91
|
+
else if (ratingRatio > 3) {
|
|
62
92
|
this.setWeightedConfidenceScore(item.items, 90);
|
|
63
93
|
}
|
|
64
|
-
else if (
|
|
94
|
+
else if (ratingRatio > 2) {
|
|
65
95
|
this.setWeightedConfidenceScore(item.items, 85);
|
|
66
96
|
}
|
|
67
97
|
else {
|
|
@@ -78,20 +108,21 @@ class FraudGetRatings extends FraudGetEndorsements {
|
|
|
78
108
|
else if (type === "byIpFingerprintPostId") {
|
|
79
109
|
let out = [];
|
|
80
110
|
_.each(topItems, function (item) {
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
const ratingRatio = this.getNormalizedRatingCount(item.items);
|
|
112
|
+
if (ratingRatio > 1) {
|
|
113
|
+
if (ratingRatio > 10) {
|
|
83
114
|
this.setWeightedConfidenceScore(item.items, 100);
|
|
84
115
|
}
|
|
85
|
-
else if (
|
|
116
|
+
else if (ratingRatio > 5) {
|
|
86
117
|
this.setWeightedConfidenceScore(item.items, 98);
|
|
87
118
|
}
|
|
88
|
-
else if (
|
|
119
|
+
else if (ratingRatio > 4) {
|
|
89
120
|
this.setWeightedConfidenceScore(item.items, 95);
|
|
90
121
|
}
|
|
91
|
-
else if (
|
|
122
|
+
else if (ratingRatio > 3) {
|
|
92
123
|
this.setWeightedConfidenceScore(item.items, 90);
|
|
93
124
|
}
|
|
94
|
-
else if (
|
|
125
|
+
else if (ratingRatio > 2) {
|
|
95
126
|
this.setWeightedConfidenceScore(item.items, 85);
|
|
96
127
|
}
|
|
97
128
|
else {
|
|
@@ -105,23 +136,24 @@ class FraudGetRatings extends FraudGetEndorsements {
|
|
|
105
136
|
else if (type === "byIpAddress") {
|
|
106
137
|
let out = [];
|
|
107
138
|
_.each(topItems, function (item) {
|
|
108
|
-
|
|
109
|
-
|
|
139
|
+
const ratingRatio = this.getNormalizedRatingCount(item.items) / postCount;
|
|
140
|
+
if (ratingRatio > 1) {
|
|
141
|
+
if (ratingRatio > 100) {
|
|
110
142
|
this.setWeightedConfidenceScore(item.items, 90);
|
|
111
143
|
}
|
|
112
|
-
else if (
|
|
144
|
+
else if (ratingRatio > 50) {
|
|
113
145
|
this.setWeightedConfidenceScore(item.items, 85);
|
|
114
146
|
}
|
|
115
|
-
else if (
|
|
147
|
+
else if (ratingRatio > 25) {
|
|
116
148
|
this.setWeightedConfidenceScore(item.items, 80);
|
|
117
149
|
}
|
|
118
|
-
else if (
|
|
150
|
+
else if (ratingRatio > 10) {
|
|
119
151
|
this.setWeightedConfidenceScore(item.items, 75);
|
|
120
152
|
}
|
|
121
|
-
else if (
|
|
153
|
+
else if (ratingRatio > 5) {
|
|
122
154
|
this.setWeightedConfidenceScore(item.items, 70);
|
|
123
155
|
}
|
|
124
|
-
else if (
|
|
156
|
+
else if (ratingRatio > 2) {
|
|
125
157
|
this.setWeightedConfidenceScore(item.items, 65);
|
|
126
158
|
}
|
|
127
159
|
else {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export = FraudGetRatings;
|
|
2
2
|
declare class FraudGetRatings extends FraudGetEndorsements {
|
|
3
|
-
|
|
3
|
+
ratingDimensionCountsByGroupId: {};
|
|
4
|
+
getRatingDimensionCountsByGroupId(items: any): Promise<{}>;
|
|
5
|
+
getRatingDimensionsForItem(item: any): any;
|
|
6
|
+
getNormalizedRatingCount(items: any): number;
|
|
4
7
|
}
|
|
5
8
|
import FraudGetEndorsements = require("./FraudGetEndorsements.cjs");
|