commit
dc1602b6e8
24 changed files with 1164 additions and 4358 deletions
@ -0,0 +1,15 @@ |
||||
{ |
||||
"name": "Postgraphile Schema", |
||||
"schemaPath": "postgraphile-schema.graphql", |
||||
"extensions": { |
||||
"endpoints": { |
||||
"Remote SWAPI GraphQL Endpoint": { |
||||
"url": "http://localhost:5433/graphql", |
||||
"headers": { |
||||
"user-agent": "JS GraphQL" |
||||
}, |
||||
"introspect": true |
||||
} |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,109 @@ |
||||
import gql from 'graphql-tag' |
||||
import possiblePositions from '@/app/euromat/possiblePositions' |
||||
|
||||
export function getPositionById (id) { |
||||
return possiblePositions.find(option => option.id === id).position |
||||
} |
||||
|
||||
export const apolloThesesQuery = gql`{
|
||||
allQuestions(orderBy: ROW_ID_ASC) { |
||||
nodes { |
||||
category: categoryByCategoryRowId { |
||||
id |
||||
title |
||||
} |
||||
title |
||||
rowId |
||||
id |
||||
} |
||||
} |
||||
}` |
||||
|
||||
export const apolloThesesUpdate = data => data.allQuestions.nodes.map(node => ({ |
||||
id: node.rowId, |
||||
thesis: { |
||||
de: node.title |
||||
}, |
||||
category: { |
||||
de: node.category ? node.category.title : '' |
||||
} |
||||
})) |
||||
|
||||
export const apolloThesesCountQuery = gql`{
|
||||
allQuestions { |
||||
totalCount |
||||
} |
||||
}` |
||||
|
||||
export const apolloThesesCountUpdate = data => data.allQuestions.totalCount |
||||
|
||||
export const apolloPersonsForResultsQuery = gql`{
|
||||
allPeople(condition: {role: KANDIMAT_CANDIDATE}) { |
||||
nodes { |
||||
id |
||||
firstName |
||||
lastName |
||||
rowId |
||||
answers: answersByPersonRowId { |
||||
nodes { |
||||
id |
||||
position |
||||
questionRowId |
||||
text |
||||
} |
||||
} |
||||
} |
||||
} |
||||
}` |
||||
|
||||
export const apolloPersonsForResultsUpdate = data => data.allPeople.nodes.map(person => ({ |
||||
id: person.rowId, |
||||
name: `${person.firstName} ${person.lastName}`, |
||||
token: person.firstName.charAt(0) + person.lastName.charAt(0), |
||||
positions: person.answers.nodes.map(answer => ({ |
||||
thesis: answer.questionRowId, |
||||
position: getPositionById(answer.position), |
||||
statement: { |
||||
de: answer.text |
||||
} |
||||
})) |
||||
})) |
||||
|
||||
export const apolloPersonPositionsQuery = gql` |
||||
query Person($partyId: Int!) { |
||||
personByRowId(rowId: $partyId) { |
||||
id |
||||
firstName |
||||
lastName |
||||
answers: answersByPersonRowId { |
||||
nodes { |
||||
id |
||||
position |
||||
personRowId |
||||
text |
||||
question: questionByQuestionRowId { |
||||
id |
||||
rowId |
||||
} |
||||
} |
||||
} |
||||
} |
||||
}` |
||||
|
||||
export const apolloPersonPositionsUpdate = data => { |
||||
const person = data.personByRowId |
||||
return { |
||||
id: person.rowId, |
||||
name: `${person.firstName} ${person.lastName}`, |
||||
token: person.firstName.charAt(0) + person.lastName.charAt(0), |
||||
theses: person.answers ? person.answers.nodes.map(answer => { |
||||
const question = answer.question |
||||
return question ? { |
||||
id: question.rowId, |
||||
position: getPositionById(answer.position), |
||||
statement: answer.text, |
||||
showStatement: false |
||||
} : null |
||||
}) : [] |
||||
} |
||||
} |
@ -0,0 +1,115 @@ |
||||
import { evalPointsPerThesisPerParty, getPartiesWithScores, getTotalMaxPoints } from '@/app/euromat/scoring' |
||||
|
||||
const positionDef = ['positive', 'neutral', 'negative', 'skipped'] |
||||
// See offficial Rechenmodell of bpb from 2019
|
||||
const rechenmodellGrid = [ |
||||
[0, 0, 0, 0, 0, false], |
||||
[0, 0, 2, 0, 1, false], |
||||
[0, 2, 2, 0, 0, false], |
||||
[0, 0, 0, 0, 2, false], |
||||
[1, 1, 0, 2, 2, true], |
||||
[0, 0, 2, 0, 0, false], |
||||
[0, 2, 2, 1, 0, false], |
||||
[0, 0, 0, 2, 2, false], |
||||
[2, 0, 2, 2, 1, false], |
||||
[1, 2, 2, 2, 1, false], |
||||
[2, 2, 0, 0, 2, false], |
||||
[0, 2, 2, 2, 2, false], |
||||
[0, 2, 0, 0, 3, false], |
||||
[0, 2, 1, 2, 2, false], |
||||
[2, 0, 0, 1, 2, false], |
||||
[2, 0, 0, 0, 2, true], |
||||
[2, 0, 0, 2, 3, false], |
||||
[0, 0, 0, 0, 2, false], |
||||
[2, 0, 0, 0, 1, false], |
||||
[2, 0, 0, 0, 1, false], |
||||
[0, 0, 2, 2, 2, true], |
||||
[2, 2, 1, 2, 2, false], |
||||
[2, 2, 0, 2, 2, false], |
||||
[2, 2, 2, 0, 2, false], |
||||
[0, 2, 0, 2, 1, false], |
||||
[1, 2, 2, 0, 0, false], |
||||
[2, 0, 2, 0, 0, false], |
||||
[2, 0, 0, 2, 2, false], |
||||
[0, 2, 0, 2, 1, false], |
||||
[1, 2, 0, 2, 2, false], |
||||
[0, 1, 2, 0, 0, false], |
||||
[1, 2, 2, 0, 1, false], |
||||
[2, 0, 2, 2, 1, false], |
||||
[0, 2, 2, 2, 2, false], |
||||
[0, 2, 0, 0, 0, false], |
||||
[0, 2, 0, 0, 1, false], |
||||
[2, 2, 2, 2, 0, false], |
||||
[2, 0, 0, 2, 0, false] |
||||
] |
||||
|
||||
const rechenmodellExpectedTotalScorePerParty = [44, 37, 28, 50] |
||||
const rechenmodellExpectedMaxScore = 78 |
||||
|
||||
const testParties = [1, 2, 3, 4].map(partyId => ({ |
||||
id: partyId, |
||||
token: 'idontcare', |
||||
positions: rechenmodellGrid.map((thesis, index) => ({ |
||||
thesis: index, |
||||
position: positionDef[thesis[partyId - 1]] |
||||
})) |
||||
})) |
||||
|
||||
const testAnswers = rechenmodellGrid.map((thesis, index) => ({ |
||||
position: positionDef[thesis[4]], |
||||
thesis: index |
||||
})) |
||||
|
||||
const testEmphasis = rechenmodellGrid |
||||
.map((thesis, index) => ({ |
||||
...thesis, |
||||
thesis: index |
||||
})) |
||||
.filter((thesis, index) => thesis[5]) |
||||
.map(thesis => ({ thesis: thesis.thesis })) |
||||
|
||||
describe('The getPartiesWithScores function', () => { |
||||
it('returns the correct total scores according to the Rechenmodell example of bpb', () => { |
||||
const resultPartiesWithScores = getPartiesWithScores(testAnswers, testEmphasis, testParties) |
||||
|
||||
expect(resultPartiesWithScores.map(party => party.score)).toEqual(rechenmodellExpectedTotalScorePerParty) |
||||
}) |
||||
}) |
||||
|
||||
describe('The getTotalMaxPoints function', () => { |
||||
it('returns the correct maximum score points according to the Rechenmodell example of bpb', () => { |
||||
const resultTotalMaxPoints = getTotalMaxPoints(testAnswers, testEmphasis) |
||||
|
||||
expect(resultTotalMaxPoints).toEqual(rechenmodellExpectedMaxScore) |
||||
}) |
||||
}) |
||||
|
||||
describe('The evalPointsPerThesisPerParty fucntion', () => { |
||||
test.each` |
||||
partyPosition | userPosition | expectedScore | expectedScoreWithEmphasis |
||||
${'negative'} | ${'negative'} | ${2} | ${4} |
||||
${'negative'} | ${'neutral'} | ${1} | ${2} |
||||
${'negative'} | ${'positive'} | ${0} | ${0} |
||||
${'negative'} | ${'skipped'} | ${0} | ${0} |
||||
${'neutral'} | ${'negative'} | ${1} | ${2} |
||||
${'neutral'} | ${'neutral'} | ${2} | ${4} |
||||
${'neutral'} | ${'positive'} | ${1} | ${2} |
||||
${'neutral'} | ${'skipped'} | ${0} | ${0} |
||||
${'positive'} | ${'negative'} | ${0} | ${0} |
||||
${'positive'} | ${'neutral'} | ${1} | ${2} |
||||
${'positive'} | ${'positive'} | ${2} | ${4} |
||||
${'positive'} | ${'skipped'} | ${0} | ${0} |
||||
${'skipped'} | ${'negative'} | ${0} | ${0} |
||||
${'skipped'} | ${'neutral'} | ${0} | ${0} |
||||
${'skipped'} | ${'positive'} | ${0} | ${0} |
||||
${'skipped'} | ${'skipped'} | ${0} | ${0} |
||||
`('returns the correct score (according to the Rechenmodell of the bpb' +
|
||||
' if the party position is $partyPosition and the user\'s position is $userPosition', |
||||
({ partyPosition, userPosition, expectedScore, expectedScoreWithEmphasis }) => { |
||||
const resultScore = evalPointsPerThesisPerParty(partyPosition, userPosition, false) |
||||
const resultScoreWithEmphasis = evalPointsPerThesisPerParty(partyPosition, userPosition, true) |
||||
|
||||
expect(resultScore).toEqual(expectedScore) |
||||
expect(resultScoreWithEmphasis).toEqual(expectedScoreWithEmphasis) |
||||
}) |
||||
}) |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
@ -1 +0,0 @@ |
||||
export const IPDATA_URL = 'https://api.ipdata.co/?api-key=test' |
@ -1,7 +1,4 @@ |
||||
import { loadContent } from '@/helper/content' |
||||
import options from './options' |
||||
import theses from ' |