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

Commit f785f10

Browse files
committed
Add final fix
1 parent bd4226a commit f785f10

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

23462346
## Validate Handle [/users/validate/{handle}]
@@ -6437,6 +6437,110 @@ Request
64376437
"description":"Servers are up but overloaded. Try again later."
64386438
}
64396439

6440+
## Get SRM Rounds For Problem [/data/srm/problems/:problemId/rounds]
6441+
### Get SRM Rounds For Problem [GET]
6442+
6443+
+ Parameters
6444+
+ problemId (required, number, `12348765`) ... The problemId to get the rounds for.
6445+
6446+
+ Response 200 (application/json)
6447+
6448+
{
6449+
"rounds": [
6450+
{
6451+
"contestId": 3005,
6452+
"contestName": "Contest 3005",
6453+
"roundId": 6,
6454+
"roundName": "Past Srm Round",
6455+
"divisionDescription": "Unrated Division",
6456+
"levelDescription": "Level 2001"
6457+
},
6458+
{
6459+
"contestId": 3006,
6460+
"contestName": "Contest 3006",
6461+
"roundId": 7,
6462+
"roundName": "Past Tournament Round",
6463+
"divisionDescription": "Division-I",
6464+
"levelDescription": "Level 2001"
6465+
},
6466+
{
6467+
"contestId": 3007,
6468+
"contestName": "Contest 3007",
6469+
"roundId": 8,
6470+
"roundName": "Past Long Round",
6471+
"divisionDescription": "Division-II",
6472+
"levelDescription": "Level 2001"
6473+
},
6474+
{
6475+
"contestId": 3008,
6476+
"contestName": "Contest 3008",
6477+
"roundId": 9,
6478+
"roundName": "Past Event Round",
6479+
"divisionDescription": "No Division Applicable",
6480+
"levelDescription": "Level 2001"
6481+
}
6482+
]
6483+
}
6484+
6485+
+ Response 400 (application/json)
6486+
6487+
{
6488+
"error": {
6489+
"name": "Bad Request",
6490+
"value": 400,
6491+
"description": "The request was invalid. An accompanying message will explain why.",
6492+
"details": "problemId should be number."
6493+
}
6494+
}
6495+
6496+
+ Response 400 (application/json)
6497+
6498+
{
6499+
"error": {
6500+
"name": "Bad Request",
6501+
"value": 400,
6502+
"description": "The request was invalid. An accompanying message will explain why.",
6503+
"details": "problemId should be positive."
6504+
}
6505+
}
6506+
6507+
+ Response 400 (application/json)
6508+
6509+
{
6510+
"error": {
6511+
"name": "Bad Request",
6512+
"value": 400,
6513+
"description": "The request was invalid. An accompanying message will explain why.",
6514+
"details": "problemId should be less or equal to 2147483647."
6515+
}
6516+
}
6517+
6518+
+ Response 404 (application/json)
6519+
6520+
{
6521+
"error": {
6522+
"name": "Not Found",
6523+
"value": 404,
6524+
"description": "The URI requested is invalid or the requested resource does not exist.",
6525+
"details": "The problem doesn't exist."
6526+
}
6527+
}
6528+
6529+
+ Response 500 (application/json)
6530+
6531+
{
6532+
"name":"Internal Server Error",
6533+
"value":"500",
6534+
"description":"Unknown server error. Please contact support."
6535+
}
6536+
6537+
+ Response 503 (application/json)
6538+
6539+
{
6540+
"name":"Service Unavailable",
6541+
"value":"503",
6542+
"description":"Servers are up but overloaded. Try again later."
6543+
}
64406544

64416545
## View Algorithm SRM Challenges [/data/srm/challenges?listType={listType}&pageSize={pageSize}&pageIndex={pageIndex}&sortColumn={sortColumn}&sortOrder={sortOrder}]
64426546
### View Algorithm SRM Challenges [GET]
@@ -6954,7 +7058,7 @@ Request
69547058
"value":"503",
69557059
"description":"Servers are up but overloaded. Try again later."
69567060
}
6957-
7061+
69587062
## View Active Data Science Challenges [/dataScience/challenges/active?submissionEndFrom={submissionEndFrom}&submissionEndTo={submissionEndTo}]
69597063
### View Active Data Science Challenges [GET]
69607064

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.62
4+
* @version 1.63
55
* @author vangavroche, Sky_, muzehyun, kurtrips, Ghost_141, ecnu_haozi, hesibo, LazyChild, isv, flytoj2ee,
66
* @author panoptimum, bugbuka, Easyhard, TCASSEMBLER
77
*
@@ -144,6 +144,8 @@
144144
* - Added routes for modifying/deleting round question answers.
145145
* Changes in 1.62:
146146
* - Added route for src2image api.
147+
* Changes in 1.63:
148+
* - Added route for Rounds For Problem API
147149
*/
148150
/*jslint node:true, nomen: true */
149151
"use strict";
@@ -287,6 +289,7 @@ exports.routes = {
287289
{ path: "/:apiVersion/data/srm/roundAccess", action: "loadRoundAccess"},
288290
{ path: "/:apiVersion/data/srm/schedule", action: "getSRMSchedule"},
289291
{ path: "/:apiVersion/data/srm/practice/problems", action: "getPracticeProblems" },
292+
{ path: "/:apiVersion/data/srm/problems/:problemId/rounds", action: "getSrmRoundsForProblem" },
290293

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

0 commit comments

Comments
 (0)