async function syncInitialValues(playerId: number, latest: Snapshot) { // Find or create (if doesn't exist) the player's initial values const [initial] = await InitialValues.findOrCreate({ where: { playerId } }); mapValues(latest, (value, key) => { if (value > -1 && initial[key] === -1) { initial[key] = value; } }); await initial.save(); return initial; }
const mapDispatchToProps = (dispatch, ownProps) => { const bindTable = actionCreator => actionCreator.bind(null, ownProps.table); // Bind the first parameter on `ownProps.table` const tableACs = mapValues(bindTable, tableActions); // Wrap action creators with `dispatch` const boundTableACs = bindActionCreators(tableACs, dispatch); const computedActions = { ...boundTableACs, dispatch, }; return () => computedActions; }
const transformResponse = (res) => { /* eslint-disable no-param-reassign */ if (res && res.file) { const tracks = Array.isArray(res.file.track) ? res.file.track : [res.file.track]; res.file.track = tracks.map(track => mapValues(track, mapValue)); } return res; }
function toProps(propTypes, controller) { return mapValues(propTypes, (val, key) => { return controller[key]; }); }
/** * Gets the available process managers (if any) from this extension * By default it checks the package.json for any listed ones, but subclasses * can override this method to do it a different way. * * @property processManagers * @type Object * @public */ get processManagers() { if (!this.pkg || !this.pkg['ghost-cli'] || !this.pkg['ghost-cli']['process-managers']) { return {}; } return mapValues(this.pkg['ghost-cli']['process-managers'], relPath => path.join(this.dir, relPath)); }
export default function getMajorLanguage(languages) { const sumLinesOfCode = reduce((sum, linesOfCode) => sum + linesOfCode, 0)( languages, ) const highUsageLanguages = flow( pickBy((value, key) => (value > 10000 ? key : null)), keys, )(languages) const mostPopularLanguage = flow( mapValues((value, key) => value / sumLinesOfCode), obj => [keys(obj).reduce((a, b) => (obj[a] > obj[b] ? a : b), null)], filter(value => value), )(languages) return union([...highUsageLanguages, ...mostPopularLanguage]) }
/** * Gets the all the player deltas (gains), for every period. */ async function getPlayerDeltas(playerId: number) { const initial = await InitialValues.findOne({ where: { playerId } }); const latest = await snapshotService.findLatest(playerId); const periodDeltas = await Promise.all( PERIODS.map(async period => { const deltas = await getPlayerPeriodDeltas(playerId, period, latest, initial); return { period, deltas }; }) ); // Turn an array of deltas, into an object, using the period as a key, // then include only the deltas array in the final object, not the period fields return mapValues(keyBy(periodDeltas, 'period'), p => p.deltas); }
async function updateArchive({ timestamp, data }, archive) { const preppedData = archive ? { timestamp, data: mapValues(data, (projectData, name) => { const projectArchive = removeOutdated(archive.data[name] || [], 30) return [...projectData, ...projectArchive] }), } : { timestamp, data } const content = JSON.stringify(preppedData) if (archive) { await editGist(content, archive.id) } else { await createGist(content) } return preppedData }
/** * Finds all player snapshots, grouped by period. * * Ex: * { * day: [...], * week: [...], * etc * } */ async function getAllGrouped(playerId) { if (!playerId) { throw new BadRequestError(`Invalid player id.`); } const partials = await Promise.all( PERIODS.map(async period => { const list = await getAllInPeriod(playerId, period); return { period, snapshots: list }; }) ); // Turn an array of snapshots, into an object, using the period as a key, // then include only the snapshots array in the final object, not the period fields return mapValues(keyBy(partials, 'period'), p => p.snapshots); }
const createEventsBindingSelector = (ownEvents = {}) => { const ownEventEntries = Object.entries(ownEvents); return createSelector( // Bind args of all event callbacks to given input (events, arg) => { const customEvents = mapValues(events, fn => () => fn(arg)); return ownEventEntries.reduce( (events, [name, ownCallback]) => { const customCallback = events[name]; const callback = customCallback ? composeCallback(customCallback, ownCallback) : ownCallback; return { ...events, [name]: callback }; }, customEvents ); }, // [events, {change, side}] (prev, next) => shallowEquals(prev[0], next[0]) && shallowEquals(prev[1], next[1]) ); }
const countMap = mapValues( keyBy( participantCount.map((c: any) => ({
private _parseQuery(data) { return mapValues(data, value => { if (value === 'true' || value === 'false') { value = value === 'true' } if (value === '%00' || value === 'null') { value = null } const parseValue = parseFloat(value) if (!isNaN(parseValue) && isFinite(value)) { value = parseValue } return value }) }
mapValues( ac => ac(table), { getOptions, getInitial, getData, isTriggerFetch, isFetching, isError, })
mapValues(metaModels, defineModel => defineModel(db))
function toBindings(propTypes) { return mapValues(propTypes, () => '<'); }