Skip to content

Commit

Permalink
Merge pull request #53 from ubiquibot/development
Browse files Browse the repository at this point in the history
feat: split reward between multiple assignees
  • Loading branch information
gentlementlegen committed Jul 10, 2024
2 parents ebc6c7b + 28a6e40 commit d0c3197
Show file tree
Hide file tree
Showing 19 changed files with 9,337 additions and 12,215 deletions.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "**/tests/__mocks__"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox", "supabase", "wxdai", "noopener", "knip", "hellip"],
"words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox", "supabase", "wxdai", "noopener", "knip", "hellip", "mswjs"],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [1.1.0](https://github.com/ubiquibot/conversation-rewards/compare/v1.0.0...v1.1.0) (2024-07-07)


### Features

* add erc20RewardToken config param ([2b53e68](https://github.com/ubiquibot/conversation-rewards/commit/2b53e6875178d8f4ead54a620dc13e0e5f8c2322))
* pass token address on permit generation ([6fd15dd](https://github.com/ubiquibot/conversation-rewards/commit/6fd15ddcdf71062f905a14ddf4c4dd5fe8051e38))
* set default erc20 reward param to WXDAI ([f7ad975](https://github.com/ubiquibot/conversation-rewards/commit/f7ad97538c7a5da1dfee37f309be4a2885847574))


### Bug Fixes

* resolve conflicts ([f8159e1](https://github.com/ubiquibot/conversation-rewards/commit/f8159e16d7988ba7346208fba8d18b25115fe4bb))
* updated test suite to match the new schema, fixed the async test to not run after tear down ([ca6e472](https://github.com/ubiquibot/conversation-rewards/commit/ca6e472511cbecad9a7b3ce7ba137e9c6b3ce3ff))

## 1.0.0 (2024-06-11)


Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Be sure to review all `*.test.*` files for implementation details.
"userName": {
"total": 40.5,
"task": {
"reward": 37.5
"reward": 37.5,
"multiplier": 1
},
"comments": [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@sinclair/typebox": "0.32.23",
"@supabase/supabase-js": "2.42.0",
"@ubiquibot/permit-generation": "1.3.1",
"@ubiquity-dao/rpc-handler": "^1.1.0",
"@ubiquity-dao/rpc-handler": "1.1.0",
"decimal.js": "10.4.3",
"dotenv": "16.4.5",
"ethers": "^6.13.0",
Expand Down
7 changes: 4 additions & 3 deletions src/parser/github-comment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export class GithubCommentModule implements Module {
_createContributionRows(result: Result[0], sortedTasks: SortedTasks | undefined) {
const content: string[] = [];

if (result.task?.reward) {
content.push(buildContributionRow("Issue", "Task", result.task.multiplier, result.task.reward));
}

if (!sortedTasks) {
return content.join("");
}
Expand All @@ -83,9 +87,6 @@ export class GithubCommentModule implements Module {
</tr>`;
}

if (result.task?.reward) {
content.push(buildContributionRow("Issue", "Task", 1, result.task.reward));
}
if (sortedTasks.issues.specification) {
content.push(buildContributionRow("Issue", "Specification", 1, sortedTasks.issues.specification.score?.reward));
}
Expand Down
1 change: 1 addition & 0 deletions src/parser/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export interface Result {
total: number;
task?: {
reward: number;
multiplier: number;
};
permitUrl?: string;
userId: number;
Expand Down
27 changes: 20 additions & 7 deletions src/parser/user-extractor-module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Value } from "@sinclair/typebox/value";
import Decimal from "decimal.js";
import configuration from "../configuration/config-reader";
import { UserExtractorConfiguration, userExtractorConfigurationType } from "../configuration/user-extractor-config";
import { GitHubIssue } from "../github-types";
Expand Down Expand Up @@ -42,19 +43,31 @@ export class UserExtractorModule implements Module {
return sortedPriceLabels[0];
}

_getTaskMultiplier(issue: GitHubIssue) {
return new Decimal(1).div(issue.assignees?.length || 1);
}

async transform(data: Readonly<IssueActivity>, result: Result): Promise<Result> {
// First, try to add all assignees as they didn't necessarily add a comment but should receive a reward
data.self?.assignees?.forEach((assignee) => {
const task = data.self
? {
reward: new Decimal(this._extractTaskPrice(data.self)).mul(this._getTaskMultiplier(data.self)).toNumber(),
multiplier: this._getTaskMultiplier(data.self).toNumber(),
}
: undefined;
result[assignee.login] = {
...result[assignee.login],
userId: assignee.id,
total: 0,
task,
};
});
for (const comment of data.allComments) {
if (comment.user && comment.body && this._checkEntryValidity(comment)) {
const task =
data.self?.assignee?.id === comment.user.id
? {
reward: this._extractTaskPrice(data.self),
}
: undefined;
result[comment.user.login] = {
...result[comment.user.login],
total: 0,
task,
userId: comment.user.id,
};
}
Expand Down
3 changes: 2 additions & 1 deletion tests/__mocks__/results/content-evaluator-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@
"gitcoindev": {
"total": 45.5,
"task": {
"reward": 37.5
"reward": 37.5,
"multiplier": 1
},
"userId": 88761781,
"comments": [
Expand Down
3 changes: 2 additions & 1 deletion tests/__mocks__/results/data-purge-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"gitcoindev": {
"total": 37.5,
"task": {
"reward": 37.5
"reward": 37.5,
"multiplier": 1
},
"userId": 88761781,
"comments": [
Expand Down
3 changes: 2 additions & 1 deletion tests/__mocks__/results/formatting-evaluator-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@
"gitcoindev": {
"total": 47.5,
"task": {
"reward": 37.5
"reward": 37.5,
"multiplier": 1
},
"userId": 88761781,
"comments": [
Expand Down
3 changes: 2 additions & 1 deletion tests/__mocks__/results/github-comment-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@
"gitcoindev": {
"total": 45.5,
"task": {
"reward": 37.5
"reward": 37.5,
"multiplier": 1
},
"userId": 88761781,
"comments": [
Expand Down
1 change: 1 addition & 0 deletions tests/__mocks__/results/output-reward-split.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<details> <summary> <b> <h3> <a href="https://pay.ubq.fi?claim=W3sidHlwZSI6ImVyYzIwLXBlcm1pdCIsInBlcm1pdCI6eyJwZXJtaXR0ZWQiOnsidG9rZW4iOiIweGU5MUQxNTNFMGI0MTUxOEEyQ2U4RGQzRDc5NDRGYTg2MzQ2M2E5N2QiLCJhbW91bnQiOiIzNDEyMDAwMDAwMDAwMDAwMDAwMCJ9LCJub25jZSI6IjI0MzI1Mzc3MDIzMTc5NjEwOTcxMzU1NjgzOTQ2OTU1MjU5OTg3OTgyMTUxMzM5NDUwMzE0NjAwNzc3OTM3ODU5Mzk3OTYyODgzODA4IiwiZGVhZGxpbmUiOiI1Nzg5NjA0NDYxODY1ODA5NzcxMTc4NTQ5MjUwNDM0Mzk1MzkyNjYzNDk5MjMzMjgyMDI4MjAxOTcyODc5MjAwMzk1NjU2NDgxOTk2NyJ9LCJ0cmFuc2ZlckRldGFpbHMiOnsidG8iOiIweDREMDcwNGY0MDBENTdCYTkzZUVhODg3NjVDM0ZjREJEODI2ZENGYzQiLCJyZXF1ZXN0ZWRBbW91bnQiOiIzNDEyMDAwMDAwMDAwMDAwMDAwMCJ9LCJvd25lciI6IjB4ZDk1MzBGM2ZiQkVhMTFiZUQwMURDMDlFNzkzMThmMmYyMDIyMzcxNiIsInNpZ25hdHVyZSI6IjB4YjRhMTg4Y2Y3MDg1N2FmYzc4MThiZjMwM2MzN2RmNGRlZjJkN2JjNDUyNDdhMDdjNTQwODc3YzA2NWMyYjU2NjJiZGJlZDU3YTIxYzE2NzA2OGExYjQ2YzAwYzc0YjVlZDBmMWJjOWI2YzAyMzVhMzY1Mzk2MjE5ZmI3Y2QxZjQxYyIsIm5ldHdvcmtJZCI6MTAwfV0=" target="_blank" rel="noopener"> [ 34.12 WXDAI ] </a> </h3> <h6> @0x4007 </h6> </b> </summary> <h6>Contributions Overview</h6> <table> <thead> <tr> <th>View</th> <th>Contribution</th> <th>Count</th> <th>Reward</th> </tr> </thead> <tbody> <tr> <td>Issue</td> <td>Task</td> <td>0.5</td> <td>25</td> </tr> <tr> <td>Issue</td> <td>Specification</td> <td>1</td> <td>3.84</td> </tr> <tr> <td>Issue</td> <td>Comment</td> <td>2</td> <td>5.28</td> </tr> </tbody> </table> <h6>Conversation Incentives</h6> <table> <thead> <tr> <th>Comment</th> <th>Formatting</th> <th>Relevance</th> <th>Reward</th> </tr> </thead> <tbody> <tr> <td> <h6> <a href="https://github.com/ubiquity/work.ubq.fi/issues/69" target="_blank" rel="noopener">Looks like the filters are barely useable now that we have the s&hellip;</a> </h6> </td> <td> <details> <summary> 4.8 </summary> <pre>content:&#13; p:&#13; count: 48&#13; score: 1&#13; img:&#13; count: 1&#13; score: 0&#13;wordValue: 0.1&#13;formattingMultiplier: 1&#13;</pre> </details> </td> <td>0.8</td> <td>3.84</td> </tr> <tr> <td> <h6> <a href="https://github.com/ubiquity/work.ubq.fi/issues/69#issuecomment-2186802545" target="_blank" rel="noopener">Okay both bots are broken @gentlementlegen We should have split&hellip;</a> </h6> </td> <td> <details> <summary> 2.6 </summary> <pre>content:&#13; p:&#13; count: 13&#13; score: 1&#13;wordValue: 0.2&#13;formattingMultiplier: 1&#13;</pre> </details> </td> <td>0.8</td> <td>2.08</td> </tr> <tr> <td> <h6> <a href="https://github.com/ubiquity/work.ubq.fi/issues/69#issuecomment-2186807999" target="_blank" rel="noopener">Actually, looks like it did the right thing for your reward on v&hellip;</a> </h6> </td> <td> <details> <summary> 4 </summary> <pre>content:&#13; p:&#13; count: 20&#13; score: 1&#13;wordValue: 0.2&#13;formattingMultiplier: 1&#13;</pre> </details> </td> <td>0.8</td> <td>3.2</td> </tr> </tbody> </table> </details><details> <summary> <b> <h3> <a href="undefined" target="_blank" rel="noopener"> [ 25.82 WXDAI ] </a> </h3> <h6> @gentlementlegen </h6> </b> </summary> <h6>Contributions Overview</h6> <table> <thead> <tr> <th>View</th> <th>Contribution</th> <th>Count</th> <th>Reward</th> </tr> </thead> <tbody> <tr> <td>Issue</td> <td>Task</td> <td>0.5</td> <td>25</td> </tr> <tr> <td>Issue</td> <td>Comment</td> <td>2</td> <td>0.82</td> </tr> </tbody> </table> <h6>Conversation Incentives</h6> <table> <thead> <tr> <th>Comment</th> <th>Formatting</th> <th>Relevance</th> <th>Reward</th> </tr> </thead> <tbody> <tr> <td> <h6> <a href="https://github.com/ubiquity/work.ubq.fi/issues/69#issuecomment-2186805818" target="_blank" rel="noopener">@0x4007 So it should be 25 each? I can confirm this is not handl&hellip;</a> </h6> </td> <td> <details> <summary> 0.6 </summary> <pre>content:&#13; p:&#13; count: 24&#13; score: 1&#13;wordValue: 0.1&#13;formattingMultiplier: 0.25&#13;</pre> </details> </td> <td>0.8</td> <td>0.48</td> </tr> <tr> <td> <h6> <a href="https://github.com/ubiquity/work.ubq.fi/issues/69#issuecomment-2186813200" target="_blank" rel="noopener">Ah yes because it doesn't apply the &#96;0.5&#96; multiplier I s&hellip;</a> </h6> </td> <td> <details> <summary> 0.425 </summary> <pre>content:&#13; p:&#13; count: 16&#13; score: 1&#13; code:&#13; count: 1&#13; score: 1&#13;wordValue: 0.1&#13;formattingMultiplier: 0.25&#13;</pre> </details> </td> <td>0.8</td> <td>0.34</td> </tr> </tbody> </table> </details>
2 changes: 1 addition & 1 deletion tests/__mocks__/results/output.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/__mocks__/results/permit-generation-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@
"gitcoindev": {
"total": 45.5,
"task": {
"reward": 37.5
"reward": 37.5,
"multiplier": 1
},
"userId": 88761781,
"comments": [
Expand Down
Loading

0 comments on commit d0c3197

Please sign in to comment.