Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(verbosity): better handling for verbosity #109

Merged
merged 27 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2a0252a
Merge pull request #35 from ubiquibot/development
gentlementlegen Jun 11, 2024
ebc6c7b
Merge pull request #47 from ubiquibot/development
gentlementlegen Jul 7, 2024
d0c3197
Merge pull request #53 from ubiquibot/development
gentlementlegen Jul 10, 2024
a68ad6b
Merge pull request #70 from ubiquibot/development
gentlementlegen Jul 25, 2024
3938625
Merge pull request #80 from ubiquibot/development
gentlementlegen Aug 13, 2024
2ade82a
chore(main): release 1.3.0
github-actions[bot] Aug 13, 2024
2ba580b
Merge pull request #71 from ubiquibot/release-please--branches--main
gentlementlegen Aug 13, 2024
21b54b2
Merge pull request #89 from ubiquibot/development
gentlementlegen Aug 20, 2024
59391f2
Merge pull request #90 from ubiquibot/development
gentlementlegen Aug 20, 2024
4be2fde
chore(main): release 1.3.1
github-actions[bot] Aug 20, 2024
a1ccb45
Merge pull request #91 from ubiquibot/release-please--branches--main
gentlementlegen Aug 23, 2024
dd3141c
Merge pull request #99 from ubiquibot/development
gentlementlegen Aug 26, 2024
75fa9a2
Merge pull request #105 from ubiquibot/development
gentlementlegen Aug 28, 2024
00d65b6
chore(main): release 1.4.0
github-actions[bot] Aug 28, 2024
7f49264
Merge pull request #100 from ubiquibot/release-please--branches--main
gentlementlegen Aug 28, 2024
4e19255
refactor(verbosity): better handling for verbosity
obeys Aug 31, 2024
1e30cd2
fix: fixed decimal issues with evaluation
obeys Sep 2, 2024
a0d007c
fix: edited the mock results to match new calculation module
obeys Sep 2, 2024
b171bb6
fix: include forgotten reward-split calculation changes
obeys Sep 2, 2024
834910e
fix: refactored extra calculation and fixed mock results
obeys Sep 7, 2024
0b6f245
fix: test permit related mock test result fixes
obeys Sep 10, 2024
3cee864
fix: fix github comment and reward split tests
obeys Sep 11, 2024
ff5c7ed
Merge branch 'development' into word-count
obeys Sep 11, 2024
35ea7a6
merge branch 'development' into word-count
obeys Sep 12, 2024
aa3affa
fix: fixed issues with permit generation and mock results
obeys Sep 12, 2024
4e24f40
fix: fix github comment and reward split tests
obeys Sep 12, 2024
9a1fd36
chore: fixed test results
gentlementlegen Sep 12, 2024
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
1 change: 1 addition & 0 deletions src/configuration/formatting-evaluator-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const formattingEvaluatorConfigurationType = Type.Object(
],
}
),
wordCountExponent: Type.Number({ default: 0.85 }),
},
{ default: {} }
);
Expand Down
45 changes: 30 additions & 15 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class FormattingEvaluatorModule implements Module {
configuration.incentives.formattingEvaluator;
private readonly _md = new MarkdownIt();
private readonly _multipliers: { [k: number]: Multiplier } = {};
private readonly _wordCountExponent: number;

_getEnumValue(key: CommentType) {
let res = 0;
Expand All @@ -46,6 +47,7 @@ export class FormattingEvaluatorModule implements Module {
};
}, {});
}
this._wordCountExponent = this._configuration?.wordCountExponent ?? 0.85;
}

async transform(data: Readonly<IssueActivity>, result: Result) {
Expand All @@ -54,23 +56,9 @@ export class FormattingEvaluatorModule implements Module {
const comments = currentElement.comments || [];
for (let i = 0; i < comments.length; i++) {
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] ?? { multiplier: 0 };
const formattingTotal = formatting
? Object.values(formatting).reduce((acc, curr) => {
let sum = new Decimal(0);
for (const symbol of Object.keys(curr.symbols)) {
sum = sum.add(
new Decimal(curr.symbols[symbol].count)
.mul(curr.symbols[symbol].multiplier)
.mul(multiplierFactor.multiplier)
.mul(curr.score)
);
}
return acc.add(sum);
}, new Decimal(0))
: new Decimal(0);
const formattingTotal = this._calculateFormattingTotal(formatting, multiplierFactor).toDecimalPlaces(2);
comment.score = {
...comment.score,
formatting: {
Expand All @@ -84,6 +72,33 @@ export class FormattingEvaluatorModule implements Module {
return result;
}

private _calculateFormattingTotal(
formatting: ReturnType<typeof this._getFormattingScore>["formatting"],
multiplierFactor: Multiplier
): Decimal {
if (!formatting) return new Decimal(0);

return Object.values(formatting).reduce((acc, curr) => {
let sum = new Decimal(0);

for (const symbol of Object.keys(curr.symbols)) {
const count = new Decimal(curr.symbols[symbol].count);
const symbolMultiplier = new Decimal(curr.symbols[symbol].multiplier);
const formattingElementScore = new Decimal(curr.score);
const exponent = this._wordCountExponent;

sum = sum.add(
count
.pow(exponent) // (count^exponent)
.mul(symbolMultiplier) // symbol multiplier
.mul(formattingElementScore) // comment type multiplier
.mul(multiplierFactor.multiplier) // formatting element score
);
}
return acc.add(sum);
}, new Decimal(0));
}

get enabled(): boolean {
if (!Value.Check(formattingEvaluatorConfigurationType, this._configuration)) {
console.warn("Invalid / missing configuration detected for FormattingEvaluatorModule, disabling.");
Expand Down
44 changes: 22 additions & 22 deletions tests/__mocks__/results/content-evaluator-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"multiplier": 1
},
"relevance": 0.8,
"reward": 3.36
"reward": 2.128
},
"type": "ISSUE_AUTHOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1948930217"
Expand All @@ -44,7 +44,7 @@
"multiplier": 1
},
"relevance": 0.8,
"reward": 2.56
"reward": 1.688
},
"type": "ISSUE_AUTHOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1949201722"
Expand Down Expand Up @@ -77,7 +77,7 @@
"multiplier": 1
},
"relevance": 0.8,
"reward": 11.68
"reward": 6.28
},
"type": "ISSUE_AUTHOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1949203681"
Expand All @@ -101,7 +101,7 @@
"multiplier": 1
},
"relevance": 0.8,
"reward": 1.44
"reward": 1.032
},
"type": "ISSUE_AUTHOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1949633751"
Expand All @@ -125,7 +125,7 @@
"multiplier": 1
},
"relevance": 0.8,
"reward": 1.28
"reward": 0.936
},
"type": "ISSUE_AUTHOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1949639054"
Expand All @@ -149,7 +149,7 @@
"multiplier": 1
},
"relevance": 0.8,
"reward": 8.16
"reward": 4.528
},
"type": "ISSUE_AUTHOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1949642845"
Expand Down Expand Up @@ -209,7 +209,7 @@
"multiplier": 1
},
"relevance": 1,
"reward": 5.7
"reward": 3.51
},
"type": "ISSUE_SPECIFICATION",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22"
Expand All @@ -233,7 +233,7 @@
"multiplier": 1
},
"relevance": 1,
"reward": 0.7
"reward": 0.52
},
"type": "PULL_COLLABORATOR",
"url": "https://github.com/ubiquibot/comment-incentives/pull/25#issuecomment-1949021356"
Expand All @@ -257,7 +257,7 @@
"multiplier": 1
},
"relevance": 1,
"reward": 1.2
"reward": 0.83
},
"type": "PULL_COLLABORATOR",
"url": "https://github.com/ubiquibot/comment-incentives/pull/25#issuecomment-1949196677"
Expand Down Expand Up @@ -317,13 +317,13 @@
"multiplier": 1
},
"relevance": 1,
"reward": 64.9
"reward": 25.02
},
"type": "PULL_COLLABORATOR",
"url": "https://github.com/ubiquibot/comment-incentives/pull/25#issuecomment-1949196678"
}
],
"total": 100.98,
"total": 46.472,
"userId": 4975670
},
"gitcoindev": {
Expand Down Expand Up @@ -395,7 +395,7 @@
"multiplier": 2
},
"relevance": 1,
"reward": 4
"reward": 2.83
},
"type": "PULL_AUTHOR",
"url": "https://github.com/ubiquibot/comment-incentives/pull/25#issuecomment-1949044575"
Expand All @@ -419,7 +419,7 @@
"multiplier": 2
},
"relevance": 1,
"reward": 6
"reward": 4
},
"type": "PULL_AUTHOR",
"url": "https://github.com/ubiquibot/comment-incentives/pull/25#issuecomment-1949046925"
Expand All @@ -429,7 +429,7 @@
"multiplier": 1,
"reward": 37.5
},
"total": 47.5,
"total": 44.33,
"userId": 88761781
},
"molecula451": {
Expand Down Expand Up @@ -462,7 +462,7 @@
"multiplier": 0.25
},
"relevance": 0.8,
"reward": 0.3
"reward": 0.2
},
"type": "ISSUE_CONTRIBUTOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1948916343"
Expand All @@ -486,7 +486,7 @@
"multiplier": 0.25
},
"relevance": 0.8,
"reward": 0.1
"reward": 0.08
},
"type": "ISSUE_CONTRIBUTOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1948989989"
Expand All @@ -510,7 +510,7 @@
"multiplier": 0.25
},
"relevance": 0.8,
"reward": 0.28
"reward": 0.192
},
"type": "ISSUE_CONTRIBUTOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1949195772"
Expand All @@ -534,7 +534,7 @@
"multiplier": 0.25
},
"relevance": 0.8,
"reward": 0.24
"reward": 0.168
},
"type": "ISSUE_CONTRIBUTOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1949564869"
Expand All @@ -558,7 +558,7 @@
"multiplier": 0.25
},
"relevance": 0.8,
"reward": 0.62
"reward": 0.368
},
"type": "ISSUE_CONTRIBUTOR",
"url": "https://github.com/ubiquibot/comment-incentives/issues/22#issuecomment-1949635137"
Expand Down Expand Up @@ -606,7 +606,7 @@
"multiplier": 0.25
},
"relevance": 1,
"reward": 0.025
"reward": 0.03
},
"type": "PULL_CONTRIBUTOR",
"url": "https://github.com/ubiquibot/comment-incentives/pull/25#issuecomment-1949038563"
Expand All @@ -630,13 +630,13 @@
"multiplier": 0.25
},
"relevance": 1,
"reward": 0.45
"reward": 0.29
},
"type": "PULL_CONTRIBUTOR",
"url": "https://github.com/ubiquibot/comment-incentives/pull/25#issuecomment-1949044855"
}
],
"total": 2.055,
"total": 1.368,
"userId": 41552663
}
}
Loading
Loading