Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions safety-label-user-agg/postToUserLabelRules.strato
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ def matchesPostLabelSelector(
hasConfiguredLabels && validAnyOf && validAllOf && matchesAnyOf && matchesAllOf
}

def requiredMatchingPosts(condition: PostLabelCountCondition): Int = {
if (condition.windowSize > 0 && condition.minimumMatchingPosts > condition.windowSize) {
condition.windowSize
} else {
condition.minimumMatchingPosts
}
}

def matchesPostLabelCount(
condition: PostLabelCountCondition,
posts: Seq[PostLabelData]
Expand All @@ -273,14 +281,14 @@ def matchesPostLabelCount(
posts
}
condition.windowSize > 0 &&
condition.minimumMatchingPosts > 0 &&
requiredMatchingPosts(condition) > 0 &&
windowPosts
.take(condition.windowSize)
.filter { post =>
isRecentPost(post.tweetId, condition.maxPostAgeDays) &&
matchesPostLabelSelector(post.labels, condition.postLabels)
}
.size >= condition.minimumMatchingPosts
.size >= requiredMatchingPosts(condition)
}

def matchesRule(rule: UserLabelRule, posts: Seq[PostLabelData]): Boolean = {
Expand Down Expand Up @@ -371,7 +379,7 @@ val defaultRulesJson =
"allOf": [
{
"windowSize": 10,
"minimumMatchingPosts": 11,
"minimumMatchingPosts": 10,
"maxPostAgeDays": 60,
"mediaOnly": false,
"postLabels": {
Expand Down Expand Up @@ -440,6 +448,7 @@ val export = {
needsMediaLookup = needsMediaLookup,
matchingOutputs = matchingOutputs,
validRules = validRules,
requiredMatchingPosts = requiredMatchingPosts,
evaluateForTest = evaluateForTest,
maxScanSizeForTest = maxScanSizeForTest,
defaultRulesJson = defaultRulesJson,
Expand Down