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

Dev Merge Rounds for Problem API #393

Merged
merged 2 commits into from
Dec 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 112 additions & 1 deletion actions/srmChallenges.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2013-2014 TopCoder Inc., All Rights Reserved.
*
* @version 1.8
* @version 1.9
* @author Sky_, freegod, panoptimum, Ghost_141
* changes in 1.1:
* - implement srm API
Expand All @@ -26,6 +26,8 @@
* - Update search srm challenges api. Add challengeName filter.
* Changes in 1.8:
* - Implement get srm practice problems api.
* Changes in 1.9:
* - Implement Rounds For Problem API
*/
/*jslint node: true, nomen: true */
"use strict";
Expand Down Expand Up @@ -2137,3 +2139,112 @@ exports.getPracticeProblems = {
}
}
};

/**
* getSrmRoundsForProblem implements the rounds for problem api.
*
* @param {Object} api - The api object.
* @param {Object} connection - The connection object.
* @param {Function} next - The callback function.
*/
function getSrmRoundsForProblem(api, connection, next) {
// control flow designators
var problemId = 'problemId',
checkProblem = 'checkProblem',
// shortcuts
helper = api.helper,
dbConnectionMap = connection.dbConnectionMap,
dataAccess = _.bind(api.dataAccess.executeQuery, api.dataAccess);
return async.waterfall(
[
function (cb) {
var id = parseInt(connection.params.problemId, 10),
error = helper.checkIdParameter(id, problemId),
results = {};
if (error) {
return cb(error);
}
results[problemId] = id;
return cb(null, results);
},
function (results, cb) {
var id = results[problemId];
dataAccess(
'check_problem_exists',
{problem_id: id},
dbConnectionMap,
function (error, result) {
if (error) {
return cb(error);
}
results[checkProblem] = result;
return cb(null, results);
}
);
},
function (results, cb) {
if (results[checkProblem][0].is_there) {
return cb(null, results);
}
return cb(new NotFoundError("The problem doesn't exist."));
},
function (results, cb) {
var id = results[problemId];
return dataAccess(
'get_rounds_for_problem',
{problem_id: id},
dbConnectionMap,
function (error, result) {
if (error) {
return cb(error);
}
return cb(
null,
{
rounds: helper.transferDBResults2Response(result)
}
);
}
);
}
],
function (error, results) {
if (error) {
helper.handleError(api, connection, error);
return next(connection, true);
}
connection.response = results;
return next(connection, true);
}
);
}

/**
* Rounds For Problem API
*
* This api returns the rounds that used the given problem (identified by problem id).
* This api will exclude the practice rounds.
* This api includes only finished rounds
*
* @since 1.9
*/
exports.getSrmRoundsForProblem = {
name: "getSrmRoundsForProblem",
description: "SRM Rounds For Problem API",
inputs: {
required: ['problemId'],
optional: []
},
blockedConnectionTypes: [],
outputExample: {},
version: 'v2',
transaction: 'read', // this action is read-only
databases: ["topcoder_dw"],
run: function (api, connection, next) {
if (connection.dbConnectionMap) {
api.log("Execute getSrmRoundsForProblem", 'debug');
return getSrmRoundsForProblem(api, connection, next);
}
return api.helper.handleNoConnection(api, connection, next);
}
};
112 changes: 108 additions & 4 deletions apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ Register a new user.
"value":"503",
"description":"Servers are up but overloaded. Try again later."
}

## My Profile [/user/activation-email]
### My Profile [GET]
+ Request
Expand Down Expand Up @@ -2299,7 +2299,7 @@ Register a new user.
"name":"Service Unavailable",
"value":"503",
"description":"Servers are up but overloaded. Try again later."
}
}

## get User Identity Information [/user/identity]
### Search My Challenges [GET]
Expand Down Expand Up @@ -2340,7 +2340,7 @@ Request
"name":"Service Unavailable",
"value":"503",
"description":"Servers are up but overloaded. Try again later."
}
}

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

## Get SRM Rounds For Problem [/data/srm/problems/:problemId/rounds]
### Get SRM Rounds For Problem [GET]

+ Parameters
+ problemId (required, number, `12348765`) ... The problemId to get the rounds for.

+ Response 200 (application/json)

{
"rounds": [
{
"contestId": 3005,
"contestName": "Contest 3005",
"roundId": 6,
"roundName": "Past Srm Round",
"divisionDescription": "Unrated Division",
"levelDescription": "Level 2001"
},
{
"contestId": 3006,
"contestName": "Contest 3006",
"roundId": 7,
"roundName": "Past Tournament Round",
"divisionDescription": "Division-I",
"levelDescription": "Level 2001"
},
{
"contestId": 3007,
"contestName": "Contest 3007",
"roundId": 8,
"roundName": "Past Long Round",
"divisionDescription": "Division-II",
"levelDescription": "Level 2001"
},
{
"contestId": 3008,
"contestName": "Contest 3008",
"roundId": 9,
"roundName": "Past Event Round",
"divisionDescription": "No Division Applicable",
"levelDescription": "Level 2001"
}
]
}

+ Response 400 (application/json)

{
"error": {
"name": "Bad Request",
"value": 400,
"description": "The request was invalid. An accompanying message will explain why.",
"details": "problemId should be number."
}
}

+ Response 400 (application/json)

{
"error": {
"name": "Bad Request",
"value": 400,
"description": "The request was invalid. An accompanying message will explain why.",
"details": "problemId should be positive."
}
}

+ Response 400 (application/json)

{
"error": {
"name": "Bad Request",
"value": 400,
"description": "The request was invalid. An accompanying message will explain why.",
"details": "problemId should be less or equal to 2147483647."
}
}

+ Response 404 (application/json)

{
"error": {
"name": "Not Found",
"value": 404,
"description": "The URI requested is invalid or the requested resource does not exist.",
"details": "The problem doesn't exist."
}
}

+ Response 500 (application/json)

{
"name":"Internal Server Error",
"value":"500",
"description":"Unknown server error. Please contact support."
}

+ Response 503 (application/json)

{
"name":"Service Unavailable",
"value":"503",
"description":"Servers are up but overloaded. Try again later."
}

## View Algorithm SRM Challenges [/data/srm/challenges?listType={listType}&pageSize={pageSize}&pageIndex={pageIndex}&sortColumn={sortColumn}&sortOrder={sortOrder}]
### View Algorithm SRM Challenges [GET]
Expand Down Expand Up @@ -7281,7 +7385,7 @@ Request
"value":"503",
"description":"Servers are up but overloaded. Try again later."
}

## View Active Data Science Challenges [/dataScience/challenges/active?submissionEndFrom={submissionEndFrom}&submissionEndTo={submissionEndTo}]
### View Active Data Science Challenges [GET]

Expand Down
Binary file added docs/TC API - Rounds For Problem API 1.0.doc
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"bigdecimal": "0.6.x",
"bignum": "0.6.x",
"java": "0.3.x",
"informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git#dee39dbda53f91081825f829325ed43566059d3d",
"informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git#46d1c91c3a8e164f888e88627b8da712e9ceb855",
"forums-wrapper": "git://github.com/cloudspokes/forums-wrapper.git#12b57be495c2e10431173522bc9eff60e0575959",
"asn1": "*",
"crypto": "0.0.x",
Expand Down
1 change: 1 addition & 0 deletions queries/check_problem_exists
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT count(*) AS is_there FROM problem WHERE problem_id = @problem_id@;
5 changes: 5 additions & 0 deletions queries/check_problem_exists.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "check_problem_exists",
"db" : "topcoder_dw",
"sqlfile" : "check_problem_exists"
}
16 changes: 16 additions & 0 deletions queries/get_rounds_for_problem
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT
r.round_id,
r.name AS round_name,
r.contest_id,
(SELECT name FROM contest c WHERE c.contest_id = r.contest_id) AS contest_name,
(SELECT division_desc FROM division_lu d WHERE p.division_id = d.division_id) AS division_description,
p.level_desc AS level_description
FROM
problem p,
round r
WHERE
p.problem_id = @problem_id@ AND
p.round_id = r.round_id AND
r.round_type_id IN (1,2,10,20) AND
r.status = 'P'
ORDER BY r.round_id ASC;
5 changes: 5 additions & 0 deletions queries/get_rounds_for_problem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "get_rounds_for_problem",
"db" : "topcoder_dw",
"sqlfile" : "get_rounds_for_problem"
}
5 changes: 4 additions & 1 deletion routes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved.
*
* @version 1.64
* @version 1.65
* @author vangavroche, Sky_, muzehyun, kurtrips, Ghost_141, ecnu_haozi, hesibo, LazyChild, isv, flytoj2ee,
* @author panoptimum, bugbuka, Easyhard, TCASSEMBLER
*
Expand Down Expand Up @@ -148,6 +148,8 @@
* - Add route for get user marathon matches api.
* Changes in 1.64:
* - Add route for get user algorithm challenges api.
* Changes in 1.65:
* - Added route for Rounds For Problem API
*/
/*jslint node:true, nomen: true */
"use strict";
Expand Down Expand Up @@ -293,6 +295,7 @@ exports.routes = {
{ path: "/:apiVersion/data/srm/roundAccess", action: "loadRoundAccess"},
{ path: "/:apiVersion/data/srm/schedule", action: "getSRMSchedule"},
{ path: "/:apiVersion/data/srm/practice/problems", action: "getPracticeProblems" },
{ path: "/:apiVersion/data/srm/problems/:problemId/rounds", action: "getSrmRoundsForProblem" },

{ path: "/:apiVersion/data/marathon/challenges/:roundId/regInfo", action: "getMarathonChallengeRegInfo" },
{ path: "/:apiVersion/data/marathon/challenges/:id", action: "getMarathonChallenge" },
Expand Down
Loading