Skip to content

Commit

Permalink
Merge pull request #2662 from ff137/feat/min_max_mmr_pubmatches
Browse files Browse the repository at this point in the history
Add `minRank` and `maxRank` query parameters to `/publicMatches`
  • Loading branch information
howardchung committed Jun 25, 2023
2 parents 16e4f89 + b0d3000 commit 7936584
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opendota-core",
"description": "Open source Dota data platform",
"version": "21.0.0",
"version": "21.0.1",
"license": "MIT",
"main": "index.js",
"scripts": {
Expand Down
38 changes: 29 additions & 9 deletions routes/requests/queryParams/matchParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,48 @@ module.exports = {
},
},
// for /publicMatches:
mmrAscendingParam: {
name: "mmr_ascending",
lessThanMatchIdParam: {
name: "less_than_match_id",
in: "query",
description: "Order by MMR ascending",
description: "Get matches with a match ID lower than this value",
required: false,
schema: {
type: "integer",
},
},
mmrDescendingParam: {
name: "mmr_descending",
minRankParam: {
name: "min_rank",
in: "query",
description: "Order by MMR descending",
description:
"Minimum rank for the matches. Ranks are represented by integers (10-15: Herald, 20-25: Guardian, 30-35: Crusader, 40-45: Archon, 50-55: Legend, 60-65: Ancient, 70-75: Divine, 80-85: Immortal). Each increment represents an additional star.",
required: false,
schema: {
type: "integer",
},
},
lessThanMatchIdParam: {
name: "less_than_match_id",
maxRankParam: {
name: "max_rank",
in: "query",
description: "Get matches with a match ID lower than this value",
description:
"Maximum rank for the matches. Ranks are represented by integers (10-15: Herald, 20-25: Guardian, 30-35: Crusader, 40-45: Archon, 50-55: Legend, 60-65: Ancient, 70-75: Divine, 80-85: Immortal). Each increment represents an additional star.",
required: false,
schema: {
type: "integer",
},
},
mmrAscendingParam: {
name: "mmr_ascending",
in: "query",
description: "Order by MMR ascending",
required: false,
schema: {
type: "integer",
},
},
mmrDescendingParam: {
name: "mmr_descending",
in: "query",
description: "Order by MMR descending",
required: false,
schema: {
type: "integer",
Expand Down
23 changes: 17 additions & 6 deletions routes/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ const spec = {
info: {
title: "OpenDota API",
description: `# Introduction
The OpenDota API provides Dota 2 related data including advanced match data extracted from match replays.
You can find data that can be used to convert hero and ability IDs and other information provided by the API from the [dotaconstants](https://github.com/odota/dotaconstants) repository.
The OpenDota API offers 50,000 free calls per month and a rate limit of 60 requests/minute. We also offer a Premium Tier with unlimited API calls and higher rate limits. Check out the [API page](https://www.opendota.com/api-keys) to learn more.
The OpenDota API provides Dota 2 related data including advanced match data extracted from match replays.
You can find data that can be used to convert hero and ability IDs and other information provided by the API from the [dotaconstants](https://github.com/odota/dotaconstants) repository.
The OpenDota API offers 50,000 free calls per month and a rate limit of 60 requests/minute. We also offer a Premium Tier with unlimited API calls and higher rate limits. Check out the [API page](https://www.opendota.com/api-keys) to learn more.
`,
version: packageJson.version,
},
Expand Down Expand Up @@ -1153,9 +1153,11 @@ const spec = {
description: "Get list of randomly sampled public matches",
tags: ["public matches"],
parameters: [
{ $ref: "#/components/parameters/lessThanMatchIdParam" },
{ $ref: "#/components/parameters/minRankParam" },
{ $ref: "#/components/parameters/maxRankParam" },
{ $ref: "#/components/parameters/mmrAscendingParam" },
{ $ref: "#/components/parameters/mmrDescendingParam" },
{ $ref: "#/components/parameters/lessThanMatchIdParam" },
],
responses: {
200: {
Expand Down Expand Up @@ -1187,12 +1189,21 @@ const spec = {
order = "ORDER BY match_id DESC";
moreThan = 0;
}
let minRank = req.query.min_rank
? `AND avg_rank_tier >= ${req.query.min_rank}`
: "";
let maxRank = req.query.max_rank
? `AND avg_rank_tier <= ${req.query.max_rank}`
: "";

db.raw(
`
WITH match_ids AS (SELECT match_id FROM public_matches
WHERE TRUE
AND match_id > ?
AND match_id < ?
${minRank}
${maxRank}
${order}
LIMIT 100)
SELECT * FROM
Expand Down
52 changes: 38 additions & 14 deletions spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"openapi": "3.0.3",
"info": {
"title": "OpenDota API",
"description": "# Introduction\n The OpenDota API provides Dota 2 related data including advanced match data extracted from match replays.\n \n You can find data that can be used to convert hero and ability IDs and other information provided by the API from the [dotaconstants](https://github.com/odota/dotaconstants) repository.\n \n The OpenDota API offers 50,000 free calls per month and a rate limit of 60 requests/minute. We also offer a Premium Tier with unlimited API calls and higher rate limits. Check out the [API page](https://www.opendota.com/api-keys) to learn more.\n ",
"version": "21.0.0"
"description": "# Introduction\nThe OpenDota API provides Dota 2 related data including advanced match data extracted from match replays.\n\nYou can find data that can be used to convert hero and ability IDs and other information provided by the API from the [dotaconstants](https://github.com/odota/dotaconstants) repository.\n\nThe OpenDota API offers 50,000 free calls per month and a rate limit of 60 requests/minute. We also offer a Premium Tier with unlimited API calls and higher rate limits. Check out the [API page](https://www.opendota.com/api-keys) to learn more.\n ",
"version": "21.0.1"
},
"servers": [
{
Expand Down Expand Up @@ -3145,28 +3145,46 @@
"type": "integer"
}
},
"mmrAscendingParam": {
"name": "mmr_ascending",
"lessThanMatchIdParam": {
"name": "less_than_match_id",
"in": "query",
"description": "Order by MMR ascending",
"description": "Get matches with a match ID lower than this value",
"required": false,
"schema": {
"type": "integer"
}
},
"mmrDescendingParam": {
"name": "mmr_descending",
"minRankParam": {
"name": "min_rank",
"in": "query",
"description": "Order by MMR descending",
"description": "Minimum rank for the matches. Ranks are represented by integers (10-15: Herald, 20-25: Guardian, 30-35: Crusader, 40-45: Archon, 50-55: Legend, 60-65: Ancient, 70-75: Divine, 80-85: Immortal). Each increment represents an additional star.",
"required": false,
"schema": {
"type": "integer"
}
},
"lessThanMatchIdParam": {
"name": "less_than_match_id",
"maxRankParam": {
"name": "max_rank",
"in": "query",
"description": "Get matches with a match ID lower than this value",
"description": "Maximum rank for the matches. Ranks are represented by integers (10-15: Herald, 20-25: Guardian, 30-35: Crusader, 40-45: Archon, 50-55: Legend, 60-65: Ancient, 70-75: Divine, 80-85: Immortal). Each increment represents an additional star.",
"required": false,
"schema": {
"type": "integer"
}
},
"mmrAscendingParam": {
"name": "mmr_ascending",
"in": "query",
"description": "Order by MMR ascending",
"required": false,
"schema": {
"type": "integer"
}
},
"mmrDescendingParam": {
"name": "mmr_descending",
"in": "query",
"description": "Order by MMR descending",
"required": false,
"schema": {
"type": "integer"
Expand Down Expand Up @@ -4439,13 +4457,19 @@
"tags": ["public matches"],
"parameters": [
{
"$ref": "#/components/parameters/mmrAscendingParam"
"$ref": "#/components/parameters/lessThanMatchIdParam"
},
{
"$ref": "#/components/parameters/mmrDescendingParam"
"$ref": "#/components/parameters/minRankParam"
},
{
"$ref": "#/components/parameters/lessThanMatchIdParam"
"$ref": "#/components/parameters/maxRankParam"
},
{
"$ref": "#/components/parameters/mmrAscendingParam"
},
{
"$ref": "#/components/parameters/mmrDescendingParam"
}
],
"responses": {
Expand Down

0 comments on commit 7936584

Please sign in to comment.