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

Commit 0ac1e09

Browse files
committed
Get Rounds API Update
1 parent 29f032c commit 0ac1e09

16 files changed

+409
-48
lines changed

actions/rounds.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ var TIME_FILTER_COLUMNS = [
6565

6666
// the sort columns
6767
var SORT_COLUMNS = {
68+
"name": "name",
6869
"registrationPhaseStartTime": "start_time_1",
6970
"registrationPhaseEndTime": "end_time_1",
7071
"codingPhaseStartTime": "start_time_2",
@@ -274,7 +275,7 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
274275
filterCondition = ' r.round_id > 0 ';
275276
if (_.isDefined(params.name)) {
276277
// set name filter
277-
filterCondition = filterCondition + ' AND LOWER(name) LIKE LOWER("%' + decodeURIComponent(params.name) + '%")';
278+
filterCondition = filterCondition + ' AND LOWER(r.name) LIKE LOWER("%' + decodeURIComponent(params.name) + '%")';
278279
}
279280

280281
if (statusCondition !== '') {
@@ -344,7 +345,15 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
344345
"registrationLimit": rounds[i].registration_limit,
345346
"invitationalType": rounds[i].invitational ? rounds[i].invitational.trim() : rounds[i].invitational,
346347
"region": rounds[i].region_name,
347-
"roundSchedule": []
348+
"contestId": rounds[i].contest_id,
349+
"contestName": rounds[i].contest_name,
350+
"contestStatus": rounds[i].contest_status,
351+
"hasProblems": rounds[i].has_problems.trim() === 'true',
352+
"hasTerms": rounds[i].has_terms.trim() === 'true',
353+
"hasSchedule": rounds[i].has_schedule.trim() === 'true',
354+
"hasQuestions": rounds[i].has_questions.trim() === 'true',
355+
"roundSchedule": [],
356+
"languages": []
348357
};
349358

350359
for (j = 1; j <= 7; j++) {
@@ -364,26 +373,43 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
364373

365374
if (idStr !== '') {
366375
sqlParams.roundIdList = idStr;
367-
// get round terms
368-
api.dataAccess.executeQuery("get_round_terms_by_ids",
369-
sqlParams,
370-
dbConnectionMap,
371-
cb);
376+
async.parallel({
377+
languages: function (cbx) {
378+
api.dataAccess.executeQuery("get_round_language_by_ids",
379+
sqlParams,
380+
dbConnectionMap,
381+
cbx);
382+
},
383+
terms: function (cbx) {
384+
api.dataAccess.executeQuery("get_round_terms_by_ids",
385+
sqlParams,
386+
dbConnectionMap,
387+
cbx);
388+
}
389+
}, cb);
372390
} else {
373391
cb(null, null);
374392
}
375393
}, function (results, cb) {
376394
var j;
377395
if (results !== null) {
378-
for (i = 0; i < results.length; i++) {
396+
for (i = 0; i < results.terms.length; i++) {
379397
for (j = 0; j < data.length; j++) {
380398
// only return the first term
381-
if (results[i].round_id === data[j].id && !data[j]["roundTerms"]) {
382-
data[j]["roundTerms"] = results[i].terms_content;
399+
if (results.terms[i].round_id === data[j].id && !data[j]["roundTerms"]) {
400+
data[j]["roundTerms"] = results.terms[i].terms_content;
383401
break;
384402
}
385403
}
386404
}
405+
406+
for (i = 0; i < results.languages.length; i++) {
407+
for (j = 0; j < data.length; j++) {
408+
if (results.languages[i].round_id === data[j].id) {
409+
data[j]["languages"].push({"id": results.languages[i].language_id, "description": results.languages[i].language_name});
410+
}
411+
}
412+
}
387413
}
388414

389415
result.data = data;
@@ -408,7 +434,7 @@ exports.getRounds = {
408434
description: "Get Rounds",
409435
inputs: {
410436
required: [],
411-
optional: ["pageSize", "pageIndex", "sortColumn", "sortOrder"].concat(FILTER_COLUMNS).concat(TIME_FILTER_COLUMNS)
437+
optional: ["pageSize", "pageIndex", "sortColumn", "sortOrder", "name"].concat(FILTER_COLUMNS).concat(TIME_FILTER_COLUMNS)
412438
},
413439
blockedConnectionTypes: [],
414440
outputExample: {},

apiary.apib

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8297,7 +8297,7 @@ Request
82978297
},
82988298
"languages": {
82998299
"roundId": 40006,
8300-
languages [
8300+
"languages": [
83018301
{
83028302
"id": 1,
83038303
"description": "Java"
@@ -15783,7 +15783,7 @@ Source Code Image Generation APIs
1578315783
+ Parameters
1578415784
+ pageIndex (optional, number, `1`) ... The paging number, 1-based, -1 if no paging. It can be null.
1578515785
+ pageSize (optional, number, `50`) ... The max number of the results, should be set if pageIndex is set.
15786-
+ sortColumn (optional, string, `registrationPhaseStartTime`) ... The column name to sort, can be null. It should be one of registrationPhaseStartTime, registrationPhaseEndTime, codingPhaseStartTime, codingPhaseEndTime, intermissionPhaseStartTime, intermissionPhaseEndTime, challengePhaseStartTime, challengePhaseEndTime, systemTestPhaseStartTime, systemTestPhaseEndTime, roomAssignmentPhaseStartTime, roomAssignmentPhaseEndTime, moderatedChatPhaseStartTime, moderatedChatPhaseEndTime.
15786+
+ sortColumn (optional, string, `registrationPhaseStartTime`) ... The column name to sort, can be null. It should be one of name,registrationPhaseStartTime, registrationPhaseEndTime, codingPhaseStartTime, codingPhaseEndTime, intermissionPhaseStartTime, intermissionPhaseEndTime, challengePhaseStartTime, challengePhaseEndTime, systemTestPhaseStartTime, systemTestPhaseEndTime, roomAssignmentPhaseStartTime, roomAssignmentPhaseEndTime, moderatedChatPhaseStartTime, moderatedChatPhaseEndTime.
1578715787
+ sortOrder (optional, string, `desc`) ... The sort order, can be null. It should be one of desc or asc.
1578815788
+ name (optional, string, `test`) ... The name filter, can be null. It should be encoded in uri format. It's case insensitive and it could be only part of name to filter.
1578915789
+ type (optional, string, `Single%20Round%20Match`) ... The type filter, can be null. It should be encoded in uri format. It's case insensitive. It should be values in round_type_lu table description field. It could use ',' char to connect more than 1 value.
@@ -15838,6 +15838,13 @@ Source Code Image Generation APIs
1583815838
"Registration Limit": 1000,
1583915839
"Invitational Type": "Not",
1584015840
"Region": "Alpha",
15841+
"contestId": 12917,
15842+
"contestName": "Test SRM",
15843+
"contestStatus": "A",
15844+
"hasProblems": true,
15845+
"hasTerms": true,
15846+
"hasSchedule": true,
15847+
"hasQuestions": false,
1584115848
"Round Schedule": [
1584215849
{
1584315850
"Phase Name": "Registration Phase",
@@ -15881,7 +15888,17 @@ Source Code Image Generation APIs
1588115888
"End Time": "2013-12-15T05:50:51.000+05:00",
1588215889
"Status": "Draft"
1588315890
}
15884-
]
15891+
],
15892+
"languages": [
15893+
{
15894+
"id": 1,
15895+
"description": "Java"
15896+
},
15897+
{
15898+
"id": 2,
15899+
"description": "XML"
15900+
}
15901+
]
1588515902
}
1588615903
]
1588715904
}

queries/get_round_language_by_ids

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select rl.round_id as round_id, l.language_id as language_id, l.language_name as language_name from round_language rl, language l where rl.language_id = l.language_id and rl.round_id in (@roundIdList@)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name" : "get_round_language_by_ids",
3+
"db" : "informixoltp",
4+
"sqlfile" : "get_round_language_by_ids"
5+
}

queries/get_rounds

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ SELECT
55
r.name as name,
66
r.short_name as short_name,
77
rt.round_type_desc,
8+
c.contest_id as contest_id,
9+
c.name as contest_name,
10+
c.status as contest_status,
811
CASE WHEN (UPPER(r.status) = 'A') THEN
912
'Active'
1013
WHEN (UPPER(r.status) = 'P') THEN
@@ -99,12 +102,31 @@ SELECT
99102
'Draft'
100103
ELSE NULL
101104
END as status_7,
102-
(select segment_desc from segment where segment_id = 7) as name_7
105+
(select segment_desc from segment where segment_id = 7) as name_7,
106+
CASE WHEN ((select count(*) from round_component rc where rc.round_id = r.round_id) > 0) THEN
107+
'true'
108+
ELSE 'false'
109+
END AS has_problems,
110+
CASE WHEN ((select count(*) from round_terms rt where rt.round_id = r.round_id) > 0) THEN
111+
'true'
112+
ELSE 'false'
113+
END AS has_terms,
114+
CASE WHEN ((select count(*) from round_segment rs where rs.round_id = r.round_id) > 0) THEN
115+
'true'
116+
ELSE 'false'
117+
END AS has_schedule,
118+
CASE WHEN ((select count(*) from round_question rq where rq.round_id = r.round_id) > 0) THEN
119+
'true'
120+
ELSE 'false'
121+
END AS has_questions
122+
103123
FROM (round r
104124
LEFT OUTER JOIN round_type_lu rt
105125
ON r.round_type_id=rt.round_type_id
106126
LEFT OUTER JOIN region reg
107127
ON r.region_id=reg.region_id
128+
LEFT OUTER JOIN contest c
129+
ON r.contest_id=c.contest_id
108130
LEFT OUTER JOIN round_segment rs1
109131
ON r.round_id=rs1.round_id and rs1.segment_id = 1
110132
LEFT OUTER JOIN round_segment rs2
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
DELETE FROM round_terms WHERE round_id >= 12001 and round_id < 13000;
1+
DELETE FROM round_language WHERE round_id >= 12001 and round_id < 13000;
2+
DELETE FROM round_terms WHERE round_id >= 12001 and round_id < 13000;
23
DELETE FROM round_segment WHERE round_id >= 12001 and round_id < 13000;
34
DELETE FROM round WHERE round_id >= 12001 and round_id < 13000;
45
DELETE FROM contest WHERE contest_id = 12001;

test/sqls/rounds/informixoltp__insert_test_data

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VA
1010
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12001, 6, '2013-12-12 01:50:51', '2013-12-13 01:50:51', 'F');
1111
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12001, 7, '2013-12-14 01:50:51', '2013-12-15 01:50:51', 'F');
1212

13+
INSERT INTO round_language(round_id, language_id) VALUES(12001, 1);
14+
INSERT INTO round_language(round_id, language_id) VALUES(12001, 2);
15+
1316

1417
INSERT INTO round(round_id, contest_id, name, status, registration_limit, invitational, round_type_id, short_name, region_id) VALUES(12002, 12001, 'test round 12002', 'A', 1000, 0, 2, 'short name 12002', 1);
1518

test/test.rounds.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ describe('Get rounds api', function () {
201201
});
202202

203203
// sortColumn
204-
it("sortColumn should be an element of registrationphasestarttime,registrationphaseendtime," +
204+
it("sortColumn should be an element of name,registrationphasestarttime,registrationphaseendtime," +
205205
"codingphasestarttime,codingphaseendtime,intermissionphasestarttime,intermissionphaseendtime," +
206206
"challengephasestarttime,challengephaseendtime,systemtestphasestarttime,systemtestphaseendtime," +
207207
"roomassignmentphasestarttime,roomassignmentphaseendtime,moderatedchatphasestarttime,moderatedchatphaseendtime.", function (done) {
208208
assertError("/v2/data/rounds?sortColumn=dd", 'heffan', 400,
209-
"sortColumn should be an element of registrationphasestarttime,registrationphaseendtime," +
209+
"sortColumn should be an element of name,registrationphasestarttime,registrationphaseendtime," +
210210
"codingphasestarttime,codingphaseendtime,intermissionphasestarttime,intermissionphaseendtime," +
211211
"challengephasestarttime,challengephaseendtime,systemtestphasestarttime,systemtestphaseendtime," +
212212
"roomassignmentphasestarttime,roomassignmentphaseendtime,moderatedchatphasestarttime,moderatedchatphaseendtime.", done);

test/test_files/rounds/expected_default_parameters.json

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
"registrationLimit": 1000,
1313
"invitationalType": "Not",
1414
"region": "Alpha",
15+
"contestId": 12001,
16+
"contestName": "test contest 12001",
17+
"contestStatus": "I",
18+
"hasProblems": false,
19+
"hasTerms": false,
20+
"hasSchedule": true,
21+
"hasQuestions": false,
1522
"roundSchedule": [
1623
{
1724
"phaseName": "Registration Phase",
@@ -37,7 +44,8 @@
3744
"endTime": "2011-12-15T05:50:51.000+05:00",
3845
"status": "Draft"
3946
}
40-
]
47+
],
48+
"languages": []
4149
},
4250
{
4351
"id": 12004,
@@ -48,6 +56,13 @@
4856
"registrationLimit": 1000,
4957
"invitationalType": "Not",
5058
"region": "Alpha",
59+
"contestId": 12001,
60+
"contestName": "test contest 12001",
61+
"contestStatus": "I",
62+
"hasProblems": false,
63+
"hasTerms": false,
64+
"hasSchedule": true,
65+
"hasQuestions": false,
5166
"roundSchedule": [
5267
{
5368
"phaseName": "Registration Phase",
@@ -91,7 +106,8 @@
91106
"endTime": "2013-02-15T05:50:51.000+05:00",
92107
"status": "Draft"
93108
}
94-
]
109+
],
110+
"languages": []
95111
},
96112
{
97113
"id": 12003,
@@ -102,6 +118,13 @@
102118
"registrationLimit": 1000,
103119
"invitationalType": "Not",
104120
"region": "Alpha",
121+
"contestId": 12001,
122+
"contestName": "test contest 12001",
123+
"contestStatus": "I",
124+
"hasProblems": false,
125+
"hasTerms": false,
126+
"hasSchedule": true,
127+
"hasQuestions": false,
105128
"roundSchedule": [
106129
{
107130
"phaseName": "Registration Phase",
@@ -145,18 +168,26 @@
145168
"endTime": "2013-09-15T04:50:51.000+05:00",
146169
"status": "Draft"
147170
}
148-
]
171+
],
172+
"languages": []
149173
},
150174
{
151175
"id": 12001,
152176
"name": "test round 12001",
153177
"shortName": "short name 12001",
154178
"type": "Single Round Match",
155179
"status": "Active",
156-
"roundTerms": "term1",
157180
"registrationLimit": 1000,
158181
"invitationalType": "Not",
159182
"region": "Alpha",
183+
"contestId": 12001,
184+
"contestName": "test contest 12001",
185+
"contestStatus": "I",
186+
"roundTerms": "term1",
187+
"hasProblems": false,
188+
"hasTerms": true,
189+
"hasSchedule": true,
190+
"hasQuestions": false,
160191
"roundSchedule": [
161192
{
162193
"phaseName": "Registration Phase",
@@ -200,6 +231,16 @@
200231
"endTime": "2013-12-15T05:50:51.000+05:00",
201232
"status": "Draft"
202233
}
234+
],
235+
"languages": [
236+
{
237+
"id": 1,
238+
"description": "Java"
239+
},
240+
{
241+
"id": 2,
242+
"description": "XML"
243+
}
203244
]
204245
},
205246
{
@@ -211,6 +252,13 @@
211252
"registrationLimit": 1000,
212253
"invitationalType": "Not",
213254
"region": "Alpha",
255+
"contestId": 12001,
256+
"contestName": "test contest 12001",
257+
"contestStatus": "I",
258+
"hasProblems": false,
259+
"hasTerms": false,
260+
"hasSchedule": true,
261+
"hasQuestions": false,
214262
"roundSchedule": [
215263
{
216264
"phaseName": "Registration Phase",
@@ -254,7 +302,8 @@
254302
"endTime": "2014-12-15T05:50:51.000+05:00",
255303
"status": "Draft"
256304
}
257-
]
305+
],
306+
"languages": []
258307
},
259308
{
260309
"id": 12006,
@@ -265,6 +314,13 @@
265314
"registrationLimit": 1000,
266315
"invitationalType": "Not",
267316
"region": "Alpha",
317+
"contestId": 12001,
318+
"contestName": "test contest 12001",
319+
"contestStatus": "I",
320+
"hasProblems": false,
321+
"hasTerms": false,
322+
"hasSchedule": true,
323+
"hasQuestions": false,
268324
"roundSchedule": [
269325
{
270326
"phaseName": "Registration Phase",
@@ -302,7 +358,8 @@
302358
"endTime": "2015-12-15T05:50:51.000+05:00",
303359
"status": "Draft"
304360
}
305-
]
361+
],
362+
"languages": []
306363
}
307364
]
308365
}

0 commit comments

Comments
 (0)