Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit aa78525

Browse files
committed
Merge branch 'rounds_for_problem' into dev
Conflicts: routes.js
2 parents aebd7d2 + f785f10 commit aa78525

12 files changed

+712
-7
lines changed

actions/srmChallenges.js

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (C) 2013-2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.8
4+
* @version 1.9
55
* @author Sky_, freegod, panoptimum, Ghost_141
66
* changes in 1.1:
77
* - implement srm API
@@ -26,6 +26,8 @@
2626
* - Update search srm challenges api. Add challengeName filter.
2727
* Changes in 1.8:
2828
* - Implement get srm practice problems api.
29+
* Changes in 1.9:
30+
* - Implement Rounds For Problem API
2931
*/
3032
/*jslint node: true, nomen: true */
3133
"use strict";
@@ -2137,3 +2139,112 @@ exports.getPracticeProblems = {
21372139
}
21382140
}
21392141
};
2142+
2143+
/**
2144+
* getSrmRoundsForProblem implements the rounds for problem api.
2145+
*
2146+
* @param {Object} api - The api object.
2147+
* @param {Object} connection - The connection object.
2148+
* @param {Function} next - The callback function.
2149+
*/
2150+
function getSrmRoundsForProblem(api, connection, next) {
2151+
// control flow designators
2152+
var problemId = 'problemId',
2153+
checkProblem = 'checkProblem',
2154+
// shortcuts
2155+
helper = api.helper,
2156+
dbConnectionMap = connection.dbConnectionMap,
2157+
dataAccess = _.bind(api.dataAccess.executeQuery, api.dataAccess);
2158+
return async.waterfall(
2159+
[
2160+
function (cb) {
2161+
var id = parseInt(connection.params.problemId, 10),
2162+
error = helper.checkIdParameter(id, problemId),
2163+
results = {};
2164+
if (error) {
2165+
return cb(error);
2166+
}
2167+
results[problemId] = id;
2168+
return cb(null, results);
2169+
},
2170+
function (results, cb) {
2171+
var id = results[problemId];
2172+
dataAccess(
2173+
'check_problem_exists',
2174+
{problem_id: id},
2175+
dbConnectionMap,
2176+
function (error, result) {
2177+
if (error) {
2178+
return cb(error);
2179+
}
2180+
results[checkProblem] = result;
2181+
return cb(null, results);
2182+
}
2183+
);
2184+
},
2185+
function (results, cb) {
2186+
if (results[checkProblem][0].is_there) {
2187+
return cb(null, results);
2188+
}
2189+
return cb(new NotFoundError("The problem doesn't exist."));
2190+
},
2191+
function (results, cb) {
2192+
var id = results[problemId];
2193+
return dataAccess(
2194+
'get_rounds_for_problem',
2195+
{problem_id: id},
2196+
dbConnectionMap,
2197+
function (error, result) {
2198+
if (error) {
2199+
return cb(error);
2200+
}
2201+
return cb(
2202+
null,
2203+
{
2204+
rounds: helper.transferDBResults2Response(result)
2205+
}
2206+
);
2207+
}
2208+
);
2209+
}
2210+
],
2211+
function (error, results) {
2212+
if (error) {
2213+
helper.handleError(api, connection, error);
2214+
return next(connection, true);
2215+
}
2216+
connection.response = results;
2217+
return next(connection, true);
2218+
}
2219+
);
2220+
}
2221+
2222+
/**
2223+
* Rounds For Problem API
2224+
*
2225+
* This api returns the rounds that used the given problem (identified by problem id).
2226+
* This api will exclude the practice rounds.
2227+
* This api includes only finished rounds
2228+
*
2229+
* @since 1.9
2230+
*/
2231+
exports.getSrmRoundsForProblem = {
2232+
name: "getSrmRoundsForProblem",
2233+
description: "SRM Rounds For Problem API",
2234+
inputs: {
2235+
required: ['problemId'],
2236+
optional: []
2237+
},
2238+
blockedConnectionTypes: [],
2239+
outputExample: {},
2240+
version: 'v2',
2241+
transaction: 'read', // this action is read-only
2242+
databases: ["topcoder_dw"],
2243+
run: function (api, connection, next) {
2244+
if (connection.dbConnectionMap) {
2245+
api.log("Execute getSrmRoundsForProblem", 'debug');
2246+
return getSrmRoundsForProblem(api, connection, next);
2247+
}
2248+
return api.helper.handleNoConnection(api, connection, next);
2249+
}
2250+
};

apiary.apib

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ Register a new user.
20822082
"value":"503",
20832083
"description":"Servers are up but overloaded. Try again later."
20842084
}
2085-
2085+
20862086
## My Profile [/user/activation-email]
20872087
### My Profile [GET]
20882088
+ Request
@@ -2299,7 +2299,7 @@ Register a new user.
22992299
"name":"Service Unavailable",
23002300
"value":"503",
23012301
"description":"Servers are up but overloaded. Try again later."
2302-
}
2302+
}
23032303

23042304
## get User Identity Information [/user/identity]
23052305
### Search My Challenges [GET]
@@ -2340,7 +2340,7 @@ Request
23402340
"name":"Service Unavailable",
23412341
"value":"503",
23422342
"description":"Servers are up but overloaded. Try again later."
2343-
}
2343+
}
23442344

23452345
## Get User Algo Challenges [/user/{handle}/challenges/algo?pageIndex={pageIndex}&pageSize={pageSize}&sortOrder={sortOrder}&sortColumn={sortColumn}]
23462346
### Get User Algo Challenges [GET]
@@ -6764,6 +6764,110 @@ Request
67646764
"description":"Servers are up but overloaded. Try again later."
67656765
}
67666766

6767+
## Get SRM Rounds For Problem [/data/srm/problems/:problemId/rounds]
6768+
### Get SRM Rounds For Problem [GET]
6769+
6770+
+ Parameters
6771+
+ problemId (required, number, `12348765`) ... The problemId to get the rounds for.
6772+
6773+
+ Response 200 (application/json)
6774+
6775+
{
6776+
"rounds": [
6777+
{
6778+
"contestId": 3005,
6779+
"contestName": "Contest 3005",
6780+
"roundId": 6,
6781+
"roundName": "Past Srm Round",
6782+
"divisionDescription": "Unrated Division",
6783+
"levelDescription": "Level 2001"
6784+
},
6785+
{
6786+
"contestId": 3006,
6787+
"contestName": "Contest 3006",
6788+
"roundId": 7,
6789+
"roundName": "Past Tournament Round",
6790+
"divisionDescription": "Division-I",
6791+
"levelDescription": "Level 2001"
6792+
},
6793+
{
6794+
"contestId": 3007,
6795+
"contestName": "Contest 3007",
6796+
"roundId": 8,
6797+
"roundName": "Past Long Round",
6798+
"divisionDescription": "Division-II",
6799+
"levelDescription": "Level 2001"
6800+
},
6801+
{
6802+
"contestId": 3008,
6803+
"contestName": "Contest 3008",
6804+
"roundId": 9,
6805+
"roundName": "Past Event Round",
6806+
"divisionDescription": "No Division Applicable",
6807+
"levelDescription": "Level 2001"
6808+
}
6809+
]
6810+
}
6811+
6812+
+ Response 400 (application/json)
6813+
6814+
{
6815+
"error": {
6816+
"name": "Bad Request",
6817+
"value": 400,
6818+
"description": "The request was invalid. An accompanying message will explain why.",
6819+
"details": "problemId should be number."
6820+
}
6821+
}
6822+
6823+
+ Response 400 (application/json)
6824+
6825+
{
6826+
"error": {
6827+
"name": "Bad Request",
6828+
"value": 400,
6829+
"description": "The request was invalid. An accompanying message will explain why.",
6830+
"details": "problemId should be positive."
6831+
}
6832+
}
6833+
6834+
+ Response 400 (application/json)
6835+
6836+
{
6837+
"error": {
6838+
"name": "Bad Request",
6839+
"value": 400,
6840+
"description": "The request was invalid. An accompanying message will explain why.",
6841+
"details": "problemId should be less or equal to 2147483647."
6842+
}
6843+
}
6844+
6845+
+ Response 404 (application/json)
6846+
6847+
{
6848+
"error": {
6849+
"name": "Not Found",
6850+
"value": 404,
6851+
"description": "The URI requested is invalid or the requested resource does not exist.",
6852+
"details": "The problem doesn't exist."
6853+
}
6854+
}
6855+
6856+
+ Response 500 (application/json)
6857+
6858+
{
6859+
"name":"Internal Server Error",
6860+
"value":"500",
6861+
"description":"Unknown server error. Please contact support."
6862+
}
6863+
6864+
+ Response 503 (application/json)
6865+
6866+
{
6867+
"name":"Service Unavailable",
6868+
"value":"503",
6869+
"description":"Servers are up but overloaded. Try again later."
6870+
}
67676871

67686872
## View Algorithm SRM Challenges [/data/srm/challenges?listType={listType}&pageSize={pageSize}&pageIndex={pageIndex}&sortColumn={sortColumn}&sortOrder={sortOrder}]
67696873
### View Algorithm SRM Challenges [GET]
@@ -7281,7 +7385,7 @@ Request
72817385
"value":"503",
72827386
"description":"Servers are up but overloaded. Try again later."
72837387
}
7284-
7388+
72857389
## View Active Data Science Challenges [/dataScience/challenges/active?submissionEndFrom={submissionEndFrom}&submissionEndTo={submissionEndTo}]
72867390
### View Active Data Science Challenges [GET]
72877391

445 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"bigdecimal": "0.6.x",
2727
"bignum": "0.6.x",
2828
"java": "0.3.x",
29-
"informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git#dee39dbda53f91081825f829325ed43566059d3d",
29+
"informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git#46d1c91c3a8e164f888e88627b8da712e9ceb855",
3030
"forums-wrapper": "git://github.com/cloudspokes/forums-wrapper.git#12b57be495c2e10431173522bc9eff60e0575959",
3131
"asn1": "*",
3232
"crypto": "0.0.x",

queries/check_problem_exists

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT count(*) AS is_there FROM problem WHERE problem_id = @problem_id@;

queries/check_problem_exists.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name" : "check_problem_exists",
3+
"db" : "topcoder_dw",
4+
"sqlfile" : "check_problem_exists"
5+
}

queries/get_rounds_for_problem

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SELECT
2+
r.round_id,
3+
r.name AS round_name,
4+
r.contest_id,
5+
(SELECT name FROM contest c WHERE c.contest_id = r.contest_id) AS contest_name,
6+
(SELECT division_desc FROM division_lu d WHERE p.division_id = d.division_id) AS division_description,
7+
p.level_desc AS level_description
8+
FROM
9+
problem p,
10+
round r
11+
WHERE
12+
p.problem_id = @problem_id@ AND
13+
p.round_id = r.round_id AND
14+
r.round_type_id IN (1,2,10,20) AND
15+
r.status = 'P'
16+
ORDER BY r.round_id ASC;

queries/get_rounds_for_problem.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name" : "get_rounds_for_problem",
3+
"db" : "topcoder_dw",
4+
"sqlfile" : "get_rounds_for_problem"
5+
}

routes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.64
4+
* @version 1.65
55
* @author vangavroche, Sky_, muzehyun, kurtrips, Ghost_141, ecnu_haozi, hesibo, LazyChild, isv, flytoj2ee,
66
* @author panoptimum, bugbuka, Easyhard, TCASSEMBLER
77
*
@@ -148,6 +148,8 @@
148148
* - Add route for get user marathon matches api.
149149
* Changes in 1.64:
150150
* - Add route for get user algorithm challenges api.
151+
* Changes in 1.65:
152+
* - Added route for Rounds For Problem API
151153
*/
152154
/*jslint node:true, nomen: true */
153155
"use strict";
@@ -293,6 +295,7 @@ exports.routes = {
293295
{ path: "/:apiVersion/data/srm/roundAccess", action: "loadRoundAccess"},
294296
{ path: "/:apiVersion/data/srm/schedule", action: "getSRMSchedule"},
295297
{ path: "/:apiVersion/data/srm/practice/problems", action: "getPracticeProblems" },
298+
{ path: "/:apiVersion/data/srm/problems/:problemId/rounds", action: "getSrmRoundsForProblem" },
296299

297300
{ path: "/:apiVersion/data/marathon/challenges/:roundId/regInfo", action: "getMarathonChallengeRegInfo" },
298301
{ path: "/:apiVersion/data/marathon/challenges/:id", action: "getMarathonChallenge" },

0 commit comments

Comments
 (0)