Something went wrong. Try again.
Your trusty automation assistant in TLE Community misadventures!
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import _ from 'lodash'import Table from 'cli-table3'
import { getAllBuildings, log, util } from '@tlecommunity/super-core'
class BuildingTypes { constructor(options) { this.options = options }
validateOptions() { return new Promise((resolve, reject) => { resolve(true) }) }
run() { return getAllBuildings().then((buildings) => { let table = new Table({ head: ['Quantity', 'Type', 'Average Level'], })
_.chain(buildings) .thru((buildings) => { let obj = {}
_.each(buildings, (b) => { if (!obj[b.name]) { obj[b.name] = [] }
obj[b.name] = obj[b.name].concat([util.int(b.level)]) })
return obj }) .mapValues((levels, name) => { return [levels.length, name, util.mean(levels)] }) .values() .sortBy((arr) => arr[1]) .sortBy((arr) => arr[0]) .each((b) => table.push(b)) .value()
log.newline() log.info(table.toString()) }) }}
export default BuildingTypes