Skip to content

Commit

Permalink
chore: fix tests for split reward
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Aug 15, 2024
1 parent 5117a4f commit 90bc3a8
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 171 deletions.
141 changes: 76 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Be sure to review all `*.test.*` files for implementation details.
}
},
"wordValue": 0.1,
"formattingMultiplier": 1
"multiplier": 1
},
"reward": 0.8,
"relevance": 0.5
Expand All @@ -42,7 +42,7 @@ Be sure to review all `*.test.*` files for implementation details.
}
```

Reward formula: `((count * wordValue) * (score * formattingMultiplier) * n) * relevance + task.reward = total`
Reward formula: `((count * wordValue) * (score * multiplier) * n) * relevance + task.reward = total`

## Plugin configuration

Expand All @@ -61,79 +61,90 @@ with:
requirePriceLabel: true
contentEvaluator:
multipliers:
- select: [ISSUE_SPECIFICATION]
- role: [ISSUE_SPECIFICATION]
relevance: 1
- select: [PULL_AUTHOR]
- role: [PULL_AUTHOR]
relevance: 1
- select: [PULL_ASSIGNEE]
- role: [PULL_ASSIGNEE]
relevance: 1
- select: [PULL_COLLABORATOR]
- role: [PULL_COLLABORATOR]
relevance: 1
- select: [PULL_CONTRIBUTOR]
- role: [PULL_CONTRIBUTOR]
relevance: 1
userExtractor:
redeemTask: true
dataPurge:
formattingEvaluator:
multipliers:
- select: [ ISSUE_SPECIFICATION ]
formattingMultiplier: 1
symbols:
"\\b\\w+\\b": 0.1
scores: # Scores can be set for each item differently
br: 0
code: 1
p: 1
em: 0
img: 0
strong: 0
blockquote: 0
h1: 1
h2: 1
h3: 1
h4: 1
h5: 1
h6: 1
a: 1
li: 1
td: 1
hr: 0
- select: [ISSUE_AUTHOR]
formattingMultiplier: 1
symbols:
"\\b\\w+\\b": 0.2
- select: [ISSUE_ASSIGNEE]
formattingMultiplier: 0
symbols:
"\\b\\w+\\b": 0
- select: [ISSUE_COLLABORATOR]
formattingMultiplier: 1
symbols:
"\\b\\w+\\b": 0.1
- select: [ISSUE_CONTRIBUTOR]
formattingMultiplier: 0.25
symbols:
"\\b\\w+\\b": 0.1
- select: [PULL_SPECIFICATION]
formattingMultiplier: 0
symbols:
"\\b\\w+\\b": 0
- select: [PULL_AUTHOR]
formattingMultiplier: 2
symbols:
"\\b\\w+\\b": 0.2
- select: [PULL_ASSIGNEE]
formattingMultiplier: 1
symbols:
"\\b\\w+\\b": 0.1
- select: [PULL_COLLABORATOR]
formattingMultiplier: 1
symbols:
"\\b\\w+\\b": 0.1
- select: [PULL_CONTRIBUTOR]
formattingMultiplier: 0.25
symbols:
"\\b\\w+\\b": 0.1
- role: [ ISSUE_SPECIFICATION ]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.1
scores: # Scores can be set for each item differently
br: 0
code: 1
p: 1
em: 0
img: 0
strong: 0
blockquote: 0
h1: 1
h2: 1
h3: 1
h4: 1
h5: 1
h6: 1
a: 1
li: 1
ul: 1
td: 1
hr: 0
- role: [ISSUE_AUTHOR]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.2
- role: [ISSUE_ASSIGNEE]
multiplier: 0
rewards:
regex:
"\\b\\w+\\b": 0
- role: [ISSUE_COLLABORATOR]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.1
- role: [ISSUE_CONTRIBUTOR]
multiplier: 0.25
rewards:
regex:
"\\b\\w+\\b": 0.1
- role: [PULL_SPECIFICATION]
multiplier: 0
rewards:
regex:
"\\b\\w+\\b": 0
- role: [PULL_AUTHOR]
multiplier: 2
rewards:
regex:
"\\b\\w+\\b": 0.2
- role: [PULL_ASSIGNEE]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.1
- role: [PULL_COLLABORATOR]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.1
- role: [PULL_CONTRIBUTOR]
multiplier: 0.25
rewards:
regex:
"\\b\\w+\\b": 0.1
permitGeneration:
githubComment:
post: true
Expand Down
1 change: 1 addition & 0 deletions src/configuration/formatting-evaluator-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const htmlType = Type.Record(Type.String(), Type.Number(), {
h6: 1,
a: 1,
li: 1,
ul: 1,
td: 1,
hr: 0,
},
Expand Down
14 changes: 7 additions & 7 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IssueActivity } from "../issue-activity";
import { GithubCommentScore, Module, Result } from "./processor";

interface Multiplier {
formattingMultiplier: number;
multiplier: number;
html: FormattingEvaluatorConfiguration["multipliers"][0]["rewards"]["html"];
regex: FormattingEvaluatorConfiguration["multipliers"][0]["rewards"]["regex"];
}
Expand All @@ -40,7 +40,7 @@ export class FormattingEvaluatorModule implements Module {
...acc,
[curr.role.reduce((a, b) => this._getEnumValue(b) | a, 0)]: {
html: curr.rewards.html,
formattingMultiplier: curr.multiplier,
multiplier: curr.multiplier,
regex: curr.rewards.regex,
},
};
Expand All @@ -56,7 +56,7 @@ export class FormattingEvaluatorModule implements Module {
const comment = comments[i];
// Count with html elements if any, otherwise just treat it as plain text
const { formatting } = this._getFormattingScore(comment);
const multiplierFactor = this._multipliers?.[comment.type] ?? { wordValue: 0, multiplier: 0 };
const multiplierFactor = this._multipliers?.[comment.type] ?? { multiplier: 0 };
const formattingTotal = formatting
? Object.values(formatting).reduce((acc, curr) => {
let sum = new Decimal(0);
Expand All @@ -75,7 +75,7 @@ export class FormattingEvaluatorModule implements Module {
...comment.score,
formatting: {
content: formatting,
formattingMultiplier: multiplierFactor.multiplier,
multiplier: multiplierFactor.multiplier,
},
reward: (comment.score?.reward ? formattingTotal.add(comment.score.reward) : formattingTotal).toNumber(),
};
Expand Down Expand Up @@ -103,9 +103,9 @@ export class FormattingEvaluatorModule implements Module {
}
}

_countWords(symbols: FormattingEvaluatorConfiguration["multipliers"][0]["symbols"], text: string) {
_countWords(regexes: FormattingEvaluatorConfiguration["multipliers"][0]["rewards"]["regex"], text: string) {
const counts: { [p: string]: { count: number; multiplier: number } } = {};
for (const [regex, multiplier] of Object.entries(symbols)) {
for (const [regex, multiplier] of Object.entries(regexes)) {
const match = text.trim().match(new RegExp(regex, "g"));
counts[regex] = {
count: match?.length || 1,
Expand All @@ -124,7 +124,7 @@ export class FormattingEvaluatorModule implements Module {

for (const element of elements) {
const tagName = element.tagName.toLowerCase();
const wordCount = this._countWords(this._multipliers[commentType].html, element.textContent || "");
const wordCount = this._countWords(this._multipliers[commentType].regex, element.textContent || "");
let score = 0;
if (this._multipliers[commentType]?.html[tagName] !== undefined) {
score = this._multipliers[commentType].html[tagName];
Expand Down
2 changes: 1 addition & 1 deletion src/parser/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface GithubCommentScore {
score?: {
formatting?: {
content: Record<string, { symbols: { [p: string]: { count: number; multiplier: number } }; score: number }>;
formattingMultiplier: number;
multiplier: number;
};
relevance?: number;
clarity?: number;
Expand Down
148 changes: 105 additions & 43 deletions tests/__mocks__/results/output-reward-split.html

Large diffs are not rendered by default.

Loading

0 comments on commit 90bc3a8

Please sign in to comment.