Skip to content

Commit

Permalink
Merge pull request #11 from Graham42/statistics_performance
Browse files Browse the repository at this point in the history
Limit number of events used to assess level
  • Loading branch information
philippotto authored Apr 18, 2017
2 parents 19cb671 + 763cc95 commit 9d33745
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions app/scripts/services/level_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,22 @@ const LevelService = {
// average time of < Y s
// success rate > Z

// only consider the last 1500 events for performance reasons
// 1500 picked for 12 semitones in an octave * 100 success events / 0.8 for 80% success rate
let eventsToAssess = events.slice(-1500);

const thresholdSettings = AppFreezer.get().settings.pitchReading.automaticDifficulty;

optThresholds = optThresholds || {
amount: thresholdSettings.amount,
accuracy: thresholdSettings.accuracyGoal,
time: thresholdSettings.timeGoal
};
const unfoldedEvents = _.flatMap(events, (event) => {

const filteredEvents = eventsToAssess.filter((event) =>
event.keys.some(this.levelContainsKey.bind(this, level))
);
const unfoldedEvents = _.flatMap(filteredEvents, (event) => {
return event.keys.map((key) => {
const subEvent = {
...event,
Expand All @@ -113,19 +121,15 @@ const LevelService = {
return subEvent;
});
});
const filteredEvents = unfoldedEvents.filter((event) =>
this.levelContainsKey(level, event.key)
);

const eventsByKey = _.groupBy(filteredEvents, "key");
const eventsByKey = _.groupBy(unfoldedEvents, "key");
if (_.size(eventsByKey) < this.getNotesOfLevel(level)) {
return false;
}
const evaluation = _.map(eventsByKey, (events, key) => {
const successPartition = _.partition(events, "success")[0];
const successPartition = _.partition(eventsToAssess, "success")[0];

const eventsLength = events.length;
const accuracy = successPartition.length / events.length;
const eventsLength = eventsToAssess.length;
const accuracy = successPartition.length / eventsToAssess.length;
const time = _.sum(successPartition.map((el) => el.time)) / successPartition.length;

const meetsLength = eventsLength >= optThresholds.amount;
Expand Down

0 comments on commit 9d33745

Please sign in to comment.