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

Commit 1c59dc6

Browse files
author
James Cori
committed
Merge branch 'develop'
2 parents f87838d + 40d4464 commit 1c59dc6

File tree

5 files changed

+160
-8
lines changed

5 files changed

+160
-8
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* Populate the following properties on the challenges:
3+
* - metadata.effortHoursEstimate
4+
* - metadata.effortHoursOffshore
5+
* - metadata.effortHoursOnshore
6+
*/
7+
global.Promise = require('bluebird')
8+
9+
const config = require('config')
10+
const _ = require('lodash')
11+
const logger = require('../../util/logger')
12+
const challengeService = require('../../services/challengeService')
13+
const { getESClient } = require('../../util/helper')
14+
const { getEffortHoursFromIfx } = require('../../services/challengeInformixService')
15+
16+
const mapping = {
17+
effortHoursEstimate: 88,
18+
effortHoursOffshore: 89,
19+
effortHoursOnshore: 90
20+
}
21+
22+
const migrationFunction = {
23+
run: async () => {
24+
const perPage = config.get('MIGRATION_SCRIPT_BATCH_SIZE')
25+
let finish = false
26+
let page = 0
27+
let batch = 1
28+
29+
while (!finish) {
30+
logger.info(`Batch-${batch} - Loading challenges`)
31+
const challenges = await getChallengesMissingData(page, perPage)
32+
logger.info(`Found ${challenges.length} challenges`)
33+
if (challenges.length > 0) {
34+
for (const challenge of challenges) {
35+
challenge.legacy.migration = 10
36+
const legacyData = await getEffortHoursFromIfx(challenge.legacyId)
37+
if (legacyData.length > 0) {
38+
_.keys(mapping, (key) => {
39+
const v5Index = _.findIndex(challenge.metadata, meta => meta.name === key)
40+
const legacyIndex = _.findIndex(legacyData, entry => entry.project_info_type_id === mapping[key])
41+
if (v5Index === -1) {
42+
challenge.metadata.push({
43+
name: key,
44+
value: legacyData[legacyIndex].value
45+
})
46+
} else {
47+
challenge.metadata[v5Index].value = legacyData[legacyIndex].value
48+
}
49+
})
50+
await challengeService.save(challenge)
51+
}
52+
}
53+
} else {
54+
finish = true
55+
}
56+
page++
57+
batch++
58+
}
59+
}
60+
}
61+
62+
async function getChallengesMissingData (page = 0, perPage = 10) {
63+
const esQuery = {
64+
index: config.get('ES.CHALLENGE_ES_INDEX'),
65+
type: config.get('ES.CHALLENGE_ES_TYPE'),
66+
size: perPage,
67+
from: page * perPage,
68+
body: {
69+
query: {
70+
range: {
71+
'legacy.migration': {
72+
lt: 10
73+
}
74+
}
75+
}
76+
}
77+
}
78+
// logger.debug(`ES Query ${JSON.stringify(esQuery)}`)
79+
// Search with constructed query
80+
let docs
81+
try {
82+
docs = await getESClient().search(esQuery)
83+
} catch (e) {
84+
// Catch error when the ES is fresh and has no data
85+
docs = {
86+
hits: {
87+
total: 0,
88+
hits: []
89+
}
90+
}
91+
}
92+
// Extract data from hits
93+
return _.map(docs.hits.hits, item => (item._source))
94+
}
95+
96+
module.exports = migrationFunction

src/services/challengeInformixService.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@ const helper = require('../util/helper')
44
// const getErrorService = require('./errorService')
55
const { executeQueryAsync } = require('../util/informixWrapper')
66

7+
/**
8+
* Get effort hours for a legacyId
9+
* @param {Number} legacyId the legacy ID
10+
*/
11+
async function getEffortHoursFromIfx (legacyId) {
12+
const sql = `SELECT LIMIT 1
13+
project_info_type_id,
14+
value,
15+
FROM project_info
16+
WHERE project_id = ${legacyId} and project_info_type_id in (88, 89, 90)
17+
`
18+
return execQuery(sql)
19+
}
20+
721
/**
822
* Gets the copilot payment for a legacyId
923
* @param {Number} legacyId the legacy ID
1024
*/
1125
async function getCopilotPaymentFromIfx (legacyId) {
12-
const sql = `SELECT limit 1 * FROM project_info WHERE project_id = ${_.toInteger(legacyId)} AND project_info_type_id = 49`
13-
const result = await execQuery(sql)
14-
if (result && result[0]) return result[0]
15-
return false
26+
const getCopilotResourceRes = await execQuery(`SELECT limit 1 resource_id as resourceid FROM resource WHERE project_id = ${_.toInteger(legacyId)} AND resource_role_id = 14`)
27+
const copilotResourceId = _.get(getCopilotResourceRes, '[0].resourceid', null)
28+
if (!copilotResourceId) return null
29+
const result = await execQuery(`SELECT amount FROM project_payment where resource_id = ${_.toInteger(copilotResourceId)} AND project_payment_type_id = 4`)
30+
return _.get(result, '[0]', null)
1631
}
1732

1833
/**
@@ -682,5 +697,6 @@ module.exports = {
682697
getCopilotPaymentFromIfx,
683698
createCopilotPaymentInIfx,
684699
updateCopilotPaymentInIfx,
685-
deleteCopilotPaymentFromIfx
700+
deleteCopilotPaymentFromIfx,
701+
getEffortHoursFromIfx
686702
}

src/services/challengeService.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,19 @@ async function buildV5Challenge (legacyId, challengeListing, challengeDetails) {
714714
} else {
715715
newPhase.isOpen = false
716716
}
717+
logger.debug(`Challenge ${legacyId} Phase ${phase.type} id ${newPhase.phaseId} Duration ${v5duration} = ${(v5duration / 60 / 60)} hrs or ${(v5duration / 60 / 60 / 24)} days`)
717718
return newPhase
718719
})
719720
newChallenge.endDate = challengeEndDate
721+
logger.debug(`Final Phase Array ${JSON.stringify(phases)}`)
720722

721723
if (phases.length > 0) {
722724
const registrationPhase = _.find(phases, p => p.name === 'Registration')
723725
const submissionPhase = _.find(phases, p => p.name === 'Submission')
726+
727+
logger.debug(`Registration Phase ${JSON.stringify(registrationPhase)}`)
728+
logger.debug(`Submission Phase ${JSON.stringify(submissionPhase)}`)
729+
724730
newChallenge.currentPhaseNames = _.map(_.filter(phases, p => p.isOpen === true), 'name')
725731
if (registrationPhase) {
726732
newChallenge.registrationStartDate = registrationPhase.actualStartDate || registrationPhase.scheduledStartDate
@@ -741,10 +747,32 @@ async function buildV5Challenge (legacyId, challengeListing, challengeDetails) {
741747

742748
const metadataList = ['allowStockArt', 'drPoints', 'submissionViewable', 'submissionLimit', 'codeRepo', 'environment']
743749
const allMetadata = _.map(metadataList, item => {
744-
if (challengeListing[item]) return { name: item, value: _.toString(challengeListing[item]) }
750+
if (challengeListing[item]) {
751+
if (item === 'submissionLimit') {
752+
return { name: item, value: _.toString(_.get(challengeListing[item], 'count', 0)) }
753+
}
754+
return { name: item, value: _.toString(challengeListing[item]) }
755+
}
745756
})
746757
metadata.push(..._.compact(allMetadata))
747758

759+
const effortHoursMapping = {
760+
effortHoursEstimate: 88,
761+
effortHoursOffshore: 89,
762+
effortHoursOnshore: 90
763+
}
764+
765+
const legacyEffortHoursData = await challengeInformixService.getEffortHoursFromIfx(legacyId)
766+
if (legacyEffortHoursData.length > 0) {
767+
_.keys(effortHoursMapping, (key) => {
768+
const legacyIndex = _.findIndex(legacyEffortHoursData, entry => entry.project_info_type_id === effortHoursMapping[key])
769+
metadata.push({
770+
name: key,
771+
value: legacyEffortHoursData[legacyIndex].value
772+
})
773+
})
774+
}
775+
748776
const events = []
749777
if (challengeListing.events && challengeListing.events.length > 0) {
750778
for (const event of challengeListing.events) {

src/services/syncService.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,21 @@ async function syncLegacyId (legacyId, force) {
4545
* @param {Number} legacyId
4646
*/
4747
async function processChallenge (legacyId, challengeListing, challengeDetails) {
48+
const timelineScheduleFields = ['phases', 'startDate', 'endDate', 'currentPhaseNames', 'registrationStartDate', 'registrationEndDate', 'submissionStartDate', 'submissionEndDate']
4849
const v5ChallengeObjectFromV4 = await challengeService.buildV5Challenge(legacyId, challengeListing, challengeDetails)
4950
const [v5ChallengeFromAPI] = await challengeService.getChallengeFromV5API(legacyId)
5051

52+
// Timeline fields are managed by the V5 Scheduler instead of the legacy autopilot
53+
if (_.get(v5ChallengeFromAPI, 'legacy.useSchedulingAPI') === true) {
54+
_.set(v5ChallengeObjectFromV4, 'legacy.useSchedulingAPI', true)
55+
_.each(timelineScheduleFields, (prop) => {
56+
_.unset(v5ChallengeObjectFromV4, prop)
57+
})
58+
}
59+
60+
// logger.debug(`V5 Object Built from V4: ${JSON.stringify(v5ChallengeObjectFromV4)}`)
61+
// logger.debug(`V5 Object from API: ${JSON.stringify(v5ChallengeFromAPI)}`)
62+
5163
const v4StatusNumber = challengeStatusOrders[_.toLower(v5ChallengeObjectFromV4.status)] || challengeStatusOrders.cancelled
5264
const v5StatusNumber = challengeStatusOrders[_.toLower(v5ChallengeFromAPI.status)] || challengeStatusOrders.cancelled
5365

@@ -112,7 +124,7 @@ async function processChallenge (legacyId, challengeListing, challengeDetails) {
112124
prizes: [
113125
{
114126
type: 'USD',
115-
value: copilotPayment.value
127+
value: copilotPayment.amount
116128
}
117129
],
118130
type: config.COPILOT_PAYMENT_TYPE

src/util/conversionMappings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module.exports = {
135135
[V5_TYPE_IDS.TASK]: () => buildV4Data(V4_TRACKS.DEVELOP, V4_SUBTRACKS.FIRST_2_FINISH, true)
136136
},
137137
[V5_TRACK_IDS.QA]: {
138-
[V5_TYPE_IDS.CHALLENGE]: () => buildV4Data(V4_TRACKS.DEVELOP, V4_SUBTRACKS.TEST_SUITES, false),
138+
[V5_TYPE_IDS.CHALLENGE]: () => buildV4Data(V4_TRACKS.DEVELOP, V4_SUBTRACKS.BUG_HUNT, false),
139139
[V5_TYPE_IDS.FIRST_2_FINISH]: () => buildV4Data(V4_TRACKS.DEVELOP, V4_SUBTRACKS.FIRST_2_FINISH, false),
140140
[V5_TYPE_IDS.TASK]: () => buildV4Data(V4_TRACKS.DEVELOP, V4_SUBTRACKS.FIRST_2_FINISH, true)
141141
}

0 commit comments

Comments
 (0)