Skip to content
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
12 changes: 6 additions & 6 deletions common/models/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export const QUESTION_RESPONSE_TYPES = {
}

export const LIKERT_7_AGREEMENT_OPTIONS = [
{value: 1, label: 'strongly disagree'},
{value: 2, label: 'disagree'},
{value: 3, label: 'somewhat disagree'},
{value: 4, label: 'neutral'},
{value: 5, label: 'somewhat agree'},
{value: 6, label: 'agree'},
{value: 7, label: 'strongly agree'},
{value: 6, label: 'agree'},
{value: 5, label: 'somewhat agree'},
{value: 4, label: 'neutral'},
{value: 3, label: 'somewhat disagree'},
{value: 2, label: 'disagree'},
{value: 1, label: 'strongly disagree'},
{value: 0, label: 'not enough information'},
]

Expand Down
2 changes: 1 addition & 1 deletion common/util/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function formFieldsForQuestionGroup(questionGroup) {
case QUESTION_RESPONSE_TYPES.LIKERT_7:
field.type = FORM_INPUT_TYPES.RADIO
field.options = LIKERT_7_AGREEMENT_OPTIONS
field.value = parseInt(responseValue, 10) || 0
field.value = parseInt(responseValue, 10) || null
break
default:
throw new Error(`Invalid user question response type: ${question.responseType}`)
Expand Down
84 changes: 84 additions & 0 deletions db/migrations/20160804122354-player-stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const config = require('../config')

config()

exports.up = async (r, conn) => {
const players = await r.table('players').run(conn)

const updates = players.map(player => {
const ecc = player.ecc
const projects = {}

const cycles = player.cycleProjectECC || {}
Object.keys(cycles).forEach(cycleId => {
const cycleProjects = cycles[cycleId] || {}

Object.keys(cycleProjects).forEach(projectId => {
const cycleProjectStats = cycleProjects[projectId] || {}

if (!projects[projectId]) {
projects[projectId] = {cycles: {}}
}
if (!projects[projectId].cycles[cycleId]) {
projects[projectId].cycles[cycleId] = {}
}

projects[projectId].cycles[cycleId].abc = cycleProjectStats.abc || 0
projects[projectId].cycles[cycleId].rc = cycleProjectStats.rc || 0
projects[projectId].cycles[cycleId].ecc = cycleProjectStats.ecc || 0
})
})

return r.table('players')
.get(player.id)
.replace(
r.row
.merge({stats: {ecc, projects}})
.without('ecc', 'cycleProjectECC')
)
.run(conn)
})

return Promise.all(updates)
}

exports.down = async (r, conn) => {
const players = await r.table('players').run(conn)

const updates = players.map(player => {
const stats = player.stats || {}
const ecc = stats.ecc || 0
const cycleProjectECC = {}

const projects = stats.projects || {}
Object.keys(projects).forEach(projectId => {
const projectCycles = (projects[projectId] || {}).cycles || {}

Object.keys(projectCycles).forEach(cycleId => {
const projectCycleStats = projectCycles[cycleId] || {}

if (!cycleProjectECC[cycleId]) {
cycleProjectECC[cycleId] = {}
}
if (!cycleProjectECC[cycleId][projectId]) {
cycleProjectECC[cycleId][projectId] = {}
}

cycleProjectECC[cycleId][projectId].abc = projectCycleStats.abc
cycleProjectECC[cycleId][projectId].rc = projectCycleStats.rc
cycleProjectECC[cycleId][projectId].ecc = projectCycleStats.ecc
})
})

return r.table('players')
.get(player.id)
.replace(
r.row
.merge({ecc, cycleProjectECC})
.without('stats')
)
.run(conn)
})

return Promise.all(updates)
}
11 changes: 11 additions & 0 deletions db/migrations/20160804151238-responsesIndexSurveyId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.up = function (r, conn) {
return r.table('responses')
.indexCreate('surveyId')
.run(conn)
}

exports.down = function (r, conn) {
return r.table('responses')
.indexDrop('surveyId')
.run(conn)
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"data:github-goals": "./node_modules/.bin/babel-node test/generateTestGoals",
"db:create": "./node_modules/.bin/babel-node ./db/create.js",
"db:drop": "./node_modules/.bin/babel-node ./db/drop.js",
"db:migrate:configure": "node ./db/config.js > ./db/database.json",
"db:migrate": "npm run db:migrate:configure && node ./node_modules/.bin/rethink-migrate -r db",
"db:migrate:up": "npm run db:migrate:configure && node ./node_modules/.bin/rethink-migrate -r db up",
"db:migrate:down": "npm run db:migrate:configure && node ./node_modules/.bin/rethink-migrate -r db down",
"db:migrate:configure": "./node_modules/.bin/babel-node ./db/config.js > ./db/database.json",
"db:migrate": "npm run db:migrate:configure && ./node_modules/.bin/babel-node ./node_modules/.bin/rethink-migrate -r db",
"db:migrate:up": "npm run db:migrate:configure && ./node_modules/.bin/babel-node ./node_modules/.bin/rethink-migrate -r db up",
"db:migrate:down": "npm run db:migrate:configure && ./node_modules/.bin/babel-node ./node_modules/.bin/rethink-migrate -r db down",
"start": "npm run icons:fetch && node server",
"workers": "./node_modules/.bin/babel-node ./server/workers",
"postinstall": "npm run build",
Expand Down
2 changes: 1 addition & 1 deletion server/actions/__tests__/formProjects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async function _generatePlayers(chapterId, options = {}) {
const numAdvanced = options.advanced || 0
return {
regular: await factory.createMany('player', {chapterId}, numTotal - numAdvanced),
advanced: await factory.createMany('player', {chapterId, ecc: TEST_ADVANCED_PLAYER_ECC}, numAdvanced)
advanced: await factory.createMany('player', {chapterId, stats: {ecc: TEST_ADVANCED_PLAYER_ECC}}, numAdvanced)
}
}

Expand Down
117 changes: 117 additions & 0 deletions server/actions/__tests__/updateProjectStats.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* eslint-env mocha */
/* global expect, testContext */
/* eslint-disable prefer-arrow-callback, no-unused-expressions */

import factory from '../../../test/factories'
import {withDBCleanup, useFixture} from '../../../test/helpers'
import {getPlayerById} from '../../../server/db/player'

import updateProjectStats from '../updateProjectStats'

describe(testContext(__filename), function () {
describe('updateProjectStats', function () {
withDBCleanup()
useFixture.buildSurvey()

beforeEach('Setup Survey Data', async function () {
const learningSupportQuestion = await factory.create('question', {
responseType: 'likert7Agreement',
subjectType: 'player',
body: 'so-and-so supported me in learning my craft.',
})

const cultureContributionQuestion = await factory.create('question', {
responseType: 'likert7Agreement',
subjectType: 'player',
body: 'so-and-so contributed positively to our team culture.',
})

const projectHoursQuestion = await factory.create('question', {
responseType: 'text',
subjectType: 'project',
body: 'During this past cycle, how many hours did you dedicate to this project?'
})

const relativeContributionQuestion = await factory.create('question', {
responseType: 'relativeContribution',
subjectType: 'team'
})

await this.buildSurvey([
{questionId: learningSupportQuestion.id, subjectIds: () => this.teamPlayerIds},
{questionId: cultureContributionQuestion.id, subjectIds: () => this.teamPlayerIds},
{questionId: relativeContributionQuestion.id, subjectIds: () => this.teamPlayerIds},
{questionId: projectHoursQuestion.id, subjectIds: () => this.project.id},
])

const responseData = []
this.teamPlayerIds.forEach(respondentId => {
this.teamPlayerIds.forEach(subjectId => {
responseData.push({
questionId: relativeContributionQuestion.id,
surveyId: this.survey.id,
respondentId,
subjectId,
value: 20,
})

responseData.push({
questionId: learningSupportQuestion.id,
surveyId: this.survey.id,
respondentId,
subjectId,
value: 5,
})

responseData.push({
questionId: cultureContributionQuestion.id,
surveyId: this.survey.id,
respondentId,
subjectId,
value: 7,
})
})

responseData.push({
questionId: projectHoursQuestion.id,
surveyId: this.survey.id,
respondentId,
subjectId: this.project.id,
value: '35',
})
})

await factory.createMany('response', responseData)
})

it('updates the players\' stats based on the survey responses', async function() {
const expectedECC = 20 * this.teamPlayerIds.length
await updateProjectStats(this.project, this.cycleId)

const updatedPlayer = await getPlayerById(this.teamPlayerIds[0])

expect(updatedPlayer.stats).to.deep.eq({
ecc: expectedECC,
projects: {
[this.project.id]: {
cycles: {
[this.cycleId]: {
ls: 67,
cc: 100,
ec: 25,
ecd: -5,
abc: 4,
rc: 20,
rcSelf: 20,
rcOther: 20,
ecc: expectedECC,
hours: 35,
teamHours: 140,
},
},
},
},
})
})
})
})
73 changes: 0 additions & 73 deletions server/actions/__tests__/updateTeamECCStats.test.js

This file was deleted.

4 changes: 3 additions & 1 deletion server/actions/formProjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ function _formGoalGroups(players, playerVotes) {
const regularPlayers = new Map()

players.forEach(player => {
if (parseInt(player.ecc, 10) >= MIN_ADVANCED_PLAYER_ECC) {
const playerECC = parseInt((player.stats || {}).ecc, 10) || 0

if (playerECC >= MIN_ADVANCED_PLAYER_ECC) {
advancedPlayers.set(player.id, player)
} else {
regularPlayers.set(player.id, player)
Expand Down
8 changes: 8 additions & 0 deletions server/actions/getPlayerInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {graphQLFetcher} from '../util'

export default function getPlayerInfo(playerIds) {
return graphQLFetcher(process.env.IDM_BASE_URL)({
query: 'query ($playerIds: [ID]!) { getUsersByIds(ids: $playerIds) { id handle name } }',
variables: {playerIds},
}).then(result => result.data.getUsersByIds)
}
Loading