mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
misc fixes, GET user (with tests), more comments for preenHistory
This commit is contained in:
@@ -2,30 +2,47 @@ import moment from 'moment';
|
||||
import _ from 'lodash';
|
||||
|
||||
function _preen (newHistory, history, amount, groupBy) {
|
||||
let groups = _.chain(history)
|
||||
_.chain(history)
|
||||
.groupBy(h => moment(h.date).format(groupBy))
|
||||
.sortBy((h, k) => k)
|
||||
.slice(-amount)
|
||||
.pop()
|
||||
.each((group) => {
|
||||
newHistory.push({
|
||||
date: moment(group[0].date).toDate(),
|
||||
value: _.reduce(group, (m, obj) => m + obj.value, 0) / group.length,
|
||||
});
|
||||
})
|
||||
.value();
|
||||
|
||||
groups = groups.slice(-amount);
|
||||
groups.pop();
|
||||
|
||||
_.each(groups, (group) => {
|
||||
newHistory.push({
|
||||
date: moment(group[0].date).toDate(),
|
||||
value: _.reduce(group, (m, obj) => m + obj.value, 0) / group.length,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Free users:
|
||||
// Preen history for users with > 7 history entries
|
||||
// This takes an infinite array of single day entries [day day day day day...], and turns it into a condensed array
|
||||
// of averages, condensing more the further back in time we go. Eg, 7 entries each for last 7 days; 1 entry each week
|
||||
// of this month; 1 entry for each month of this year; 1 entry per previous year: [day*7 week*4 month*12 year*infinite]
|
||||
// Preen history for users with > 7 history entries
|
||||
// This takes an infinite array of single day entries [day day day day day...], and turns it into a condensed array
|
||||
// of averages, condensing more the further back in time we go. Eg, 7 entries each for last 7 days; 1 entry each week
|
||||
// of this month; 1 entry for each month of this year; 1 entry per previous year: [day*7 week*4 month*12 year*infinite]
|
||||
//
|
||||
// Subscribers:
|
||||
// TODO implement
|
||||
// TODO implement
|
||||
|
||||
// TODO Probably the description ^ is not too correct, this method actually takes 1 value each for the last 50 years,
|
||||
// then the X last months, where X is the month we're in (september = 8 starting from 0)
|
||||
// and all the days in this month
|
||||
// Allowing for multiple values in a single day for habits we probably want something different:
|
||||
// For free users:
|
||||
// - At max 30 values for today (max 30)
|
||||
// - 1 value each for the previous 61 days (2 months)
|
||||
// - 1 value each for the previous 10 months (max 10)
|
||||
// - 1 value each for the previous 50 years
|
||||
// - Total: 30+61+10+ a few years ~= 105
|
||||
//
|
||||
// For subscribed users
|
||||
// - At max 30 values for today (max 30)
|
||||
// - 1 value each for the previous 364 days (max 364)
|
||||
// - 1 value each for the previous 12 months (max 12)
|
||||
// - 1 value each for the previous 50 years
|
||||
// - Total: 30+364+12+ a few years ~= 410
|
||||
//
|
||||
export function preenHistory (history) {
|
||||
// TODO remember to add this to migration
|
||||
/* history = _.filter(history, function(h) {
|
||||
|
||||
Reference in New Issue
Block a user