-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add challenge DF tables, routes, parsers #57
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9080863
Update table structure and add new tables
trizin f84e6b4
Export new tables
trizin 2dc33a9
Read challenge csvs
trizin 4c01db9
Update challenge tables with parsed data
trizin 7fde832
Update cron to process challenge datas
trizin f60350b
Add challenge route
trizin 4d4e2ef
Update rewards summary table
trizin 83cb97b
Update dir tests
trizin c14ca3c
Fix test
trizin f7d7d8d
Fix last
trizin 39d634d
Fix hashsum
trizin e53d94e
Fix
trizin d9ef3ba
Merge branch 'main' into issue55-add-challenge-df-tables
trizin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,25 +33,27 @@ async function updateDb(data, dbname, round) { | |
} | ||
} | ||
} | ||
|
||
async function updateRewardsSummary(round) { | ||
// Aggregates the sum of "passive," "curating," and "predictoor" rewards for each "LP_addr" for a given "round" by getting the sum of `amt` from `rewards_info`, `passive_rewards_info`, and `predictoor_rewards` tables | ||
// Aggregates the sum of "passive," "curating," "predictoor" and "challenge" rewards for each "LP_addr" for a given "round" by getting the sum of `amt` from `rewards_info`, `passive_rewards_info`, `predictoor_rewards` and `challenge_rewards` tables | ||
await db.promise().query( | ||
` | ||
INSERT INTO rewards_summary(LP_addr, passive_amt, curating_amt, predictoor_amt, round) | ||
SELECT LP_addr, SUM(passive) AS passive_amt, SUM(curating) AS curating_amt, SUM(OCEAN_amt) AS predictoor_amt, ? FROM | ||
( | ||
SELECT LP_addr, SUM(reward) AS passive, 0 AS curating, 0 AS OCEAN_amt FROM passive_rewards_info WHERE round = ? GROUP BY LP_addr | ||
UNION | ||
SELECT LP_addr, 0 AS passive, SUM(amt) AS curating, 0 AS OCEAN_amt FROM rewards_info WHERE round = ? GROUP BY LP_addr | ||
UNION | ||
SELECT predictoor_addr AS LP_addr, 0 AS passive, 0 AS curating, OCEAN_amt FROM predictoor_rewards WHERE round = ? | ||
) AS foo GROUP BY LP_addr`, | ||
[round, round, round, round] | ||
INSERT INTO rewards_summary(LP_addr, passive_amt, curating_amt, predictoor_amt, challenge_amt, round) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||
SELECT LP_addr, SUM(passive) AS passive_amt, SUM(curating) AS curating_amt, SUM(predictoor) AS predictoor_amt, SUM(challenge) AS challenge_amt, ? FROM | ||
( | ||
SELECT LP_addr, SUM(reward) AS passive, 0 AS curating, 0 AS predictoor, 0 AS challenge FROM passive_rewards_info WHERE round = ? GROUP BY LP_addr | ||
UNION | ||
SELECT LP_addr, 0 AS passive, SUM(amt) AS curating, 0 AS predictoor, 0 AS challenge FROM rewards_info WHERE round = ? GROUP BY LP_addr | ||
UNION | ||
SELECT predictoor_addr AS LP_addr, 0 AS passive, 0 AS curating, OCEAN_amt AS predictoor, 0 AS challenge FROM predictoor_rewards WHERE round = ? | ||
UNION | ||
SELECT winner_addr AS LP_addr, 0 AS passive, 0 AS curating, 0 AS predictoor, SUM(OCEAN_amt) AS challenge FROM challenge_rewards WHERE round = ? GROUP BY winner_addr | ||
) AS foo GROUP BY LP_addr`, | ||
[round, round, round, round, round] | ||
); | ||
} | ||
|
||
|
||
|
||
module.exports = { | ||
updateDb, | ||
dropTable, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const express = require("express") | ||
const { getChallengeData, getChallengeRewards } = require("../../services/challenge") | ||
const router = express.Router() | ||
|
||
router.post("/data", async (req, res) => { | ||
let data = await getChallengeData(req.body) | ||
res.json(data) | ||
}) | ||
|
||
router.post("/rewards", async (req, res) => { | ||
let data = await getChallengeRewards(req.body) | ||
res.json(data) | ||
}) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { selectQuery } = require("../querier") | ||
|
||
const getChallengeData = ({ query, sort, limit, offset, group, fields, join }) => { | ||
return selectQuery( | ||
query, | ||
sort, | ||
limit, | ||
offset, | ||
"challenge_data", | ||
group, | ||
fields, | ||
join | ||
) | ||
} | ||
|
||
const getChallengeRewards = ({ query, sort, limit, offset, group, fields, join }) => { | ||
return selectQuery( | ||
query, | ||
sort, | ||
limit, | ||
offset, | ||
"challenge_rewards", | ||
group, | ||
fields, | ||
join | ||
) | ||
} | ||
|
||
module.exports = { | ||
getChallengeData, | ||
getChallengeRewards | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,11 @@ describe("Testing readDataDir function", () => { | |
"passive.csv", | ||
"nftinfo.csv", | ||
"rate-sample.csv", | ||
"symbols-sample.csv" | ||
"symbols-sample.csv", | ||
"predictoor_rewards.csv", | ||
"predictoor_data.csv", | ||
"challenge_rewards.csv", | ||
"challenge_data.csv" | ||
]) | ||
|
||
// Mock readFileSync to return a predefined string | ||
|
@@ -47,11 +51,11 @@ describe("Testing readDataDir function", () => { | |
const result = readDataDir(dataDir) | ||
|
||
expect(fs.readdirSync).toHaveBeenCalledWith(dataDir) | ||
expect(fs.readFileSync).toHaveBeenCalledTimes(10) | ||
expect(parseCsv).toHaveBeenCalledTimes(10) | ||
expect(crypto.createHash).toHaveBeenCalledTimes(10) | ||
expect(mockHash.update).toHaveBeenCalledTimes(10) | ||
expect(mockHash.digest).toHaveBeenCalledTimes(10) | ||
expect(fs.readFileSync).toHaveBeenCalledTimes(14) | ||
expect(parseCsv).toHaveBeenCalledTimes(14) | ||
expect(crypto.createHash).toHaveBeenCalledTimes(14) | ||
expect(mockHash.update).toHaveBeenCalledTimes(14) | ||
expect(mockHash.digest).toHaveBeenCalledTimes(14) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
||
|
||
expect(result).toEqual({ | ||
allocations: parseCsv(), | ||
|
@@ -64,8 +68,12 @@ describe("Testing readDataDir function", () => { | |
nftinfo: parseCsv(), | ||
rates: parseCsv(), | ||
symbols: parseCsv(), | ||
predictoor_rewards: parseCsv(), | ||
predictoor_data: parseCsv(), | ||
challenge_rewards: parseCsv(), | ||
challenge_data: parseCsv(), | ||
hashsum: | ||
"123456123456123456123456123456123456123456123456123456123456" | ||
"123456123456123456123456123456123456123456123456123456123456123456123456123456123456" | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!