New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help individuals learn multiple things #31
Merged
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a37ae8e
Refactor boilDownIndividualScore to pass scenario id through
Widdershin 9d67bdc
Multiply individual score by scenario importance
Widdershin 7ad804a
Added createScenarioImportance function and test
Widdershin 2c30468
boilDownIndividualScore now returns score and weightedScore
Widdershin 8275392
And now most of the tests even pass
Widdershin 69c4c57
Fixed a few bugs to make the core helix test run
Widdershin 1a7bc04
And now we have fitnesses working again
Widdershin 7053ac8
Refactor as much as possible out of helix.js#run
Widdershin 145c5df
Improve readability of long lines
Widdershin 9af13bb
Refactor all scenario importance logic into calculate-scenario-import…
Widdershin caa6109
Embarassingly, I was exporting the wrong function
Widdershin 70e0035
I wouldn't question this...
Widdershin 38fbfa3
Extract map extensions out of fitness-checking
Widdershin c87463e
Indent a set of chained calls for clarity
Widdershin
Jump to file or symbol
Failed to load files and symbols.
Diff settings
| @@ -0,0 +1,80 @@ | ||
| const reduceIntoObject = require('./reduce-into-object'); | ||
| const _ = require('lodash'); | ||
| // TODO - DUPLICATION OMG | ||
| const MAX_FITNESS = 1000; | ||
| function mean (numbers) { | ||
| const result = _.sum(numbers) / numbers.length; | ||
| if (result === Infinity) { | ||
| return 0; | ||
| } | ||
| return result; | ||
| } | ||
| function highestFitnessForScenario (fitnessesForScenario) { | ||
| return _.max( | ||
| fitnessesForScenario | ||
| .valuesArray() | ||
| .map(fitnesses => mean(fitnesses)) | ||
| ); | ||
| } | ||
| function highestFitnessForParticipantPerScenario (participant, fitnesses) { | ||
| return reduceIntoObject( | ||
| fitnesses.map((scenarioFitnesses, scenario) => { | ||
| if (scenarioFitnesses[participant] === undefined) { | ||
| return {[scenario.id]: 0}; | ||
| } | ||
| return { | ||
| [scenario.id]: highestFitnessForScenario(scenarioFitnesses[participant]) | ||
| }; | ||
| }).valuesArray() | ||
| ); | ||
| }; | ||
| function getHighestFitnessesForScenarioForParticipant (participants, fitnesses) { | ||
| return reduceIntoObject(participants.map(participant => { | ||
| return { | ||
| [participant]: highestFitnessForParticipantPerScenario( | ||
| participant, | ||
| fitnesses | ||
| ) | ||
| }; | ||
| })); | ||
| }; | ||
| function createScenarioImportances (fitnessForParticipantPerScenario) { | ||
| return Object.keys(fitnessForParticipantPerScenario) | ||
| .map(participant => ({participant, fitnesses: fitnessForParticipantPerScenario[participant]})) | ||
| .map(({participant, fitnesses}) => ({[participant]: calculateImportance(fitnesses)})) | ||
| .reduce((importances, importance) => Object.assign(importances, importance), {}); | ||
| }; | ||
| function replaceInfinityWithZero (number) { | ||
| if (number === Infinity) { | ||
| return 0; | ||
| } | ||
| return number; | ||
| } | ||
| function calculateImportance (fitnesses) { | ||
| return Object.keys(fitnesses) | ||
| .map(scenarioId => ({scenarioId, fitness: fitnesses[scenarioId]})) | ||
| .map(({scenarioId, fitness}) => ({[scenarioId]: replaceInfinityWithZero(MAX_FITNESS / fitness)})) | ||
| .reduce((importance, scenarioImportance) => Object.assign(importance, scenarioImportance), {}); | ||
| }; | ||
| function calculateScenarioImportances (participants, fitnesses) { | ||
| return createScenarioImportances( | ||
| getHighestFitnessesForScenarioForParticipant(participants, fitnesses) | ||
| ); | ||
| } | ||
| module.exports = calculateScenarioImportances; | ||
| @@ -0,0 +1,9 @@ | ||
| function reduceIntoObject (keyValues) { | ||
| return keyValues.reduce( | ||
| (object, keyValue) => Object.assign(object, keyValue), | ||
| {} | ||
| ); | ||
| }; | ||
| module.exports = reduceIntoObject; |
| @@ -0,0 +1,53 @@ | ||
| Map.prototype.map = function (f) { | ||
| const resultingMap = new Map(); | ||
| this.forEach((value, key) => { | ||
| resultingMap.set(key, f(value, key)); | ||
| }); | ||
| return resultingMap; | ||
| }; | ||
| Map.prototype.filter = function (f) { | ||
| const resultingMap = new Map(); | ||
| this.forEach((value, key) => { | ||
| if (f(value, key)) { | ||
| resultingMap.set(key, value); | ||
| }; | ||
| }); | ||
| return resultingMap; | ||
| }; | ||
| Map.prototype.valuesArray = function () { | ||
| const values = []; | ||
| for (let value of this.values()) { | ||
| values.push(value); | ||
| } | ||
| return values; | ||
| }; | ||
| Map.prototype.keysArray = function () { | ||
| const keys = []; | ||
| for (let key of this.keys()) { | ||
| keys.push(key); | ||
| } | ||
| return keys; | ||
| }; | ||
| Map.prototype.log = function () { | ||
| const entries = {}; | ||
| for (let [key, value] of this.entries()) { | ||
| entries[key] = value; | ||
| }; | ||
| console.log(entries); | ||
| return this; | ||
| }; |
Oops, something went wrong.