WIP
This commit is contained in:
parent
c057fe3df8
commit
259b527214
6 changed files with 68 additions and 81 deletions
|
|
@ -1,8 +1,9 @@
|
|||
var pgp = require('pg-promise')()
|
||||
var psqlUrl = require('../lib/options').postgres
|
||||
var psqlUrl = require('../lib/options').postgresql
|
||||
var R = require('ramda')
|
||||
|
||||
function connect () {
|
||||
console.log(psqlUrl)
|
||||
return pgp(psqlUrl)
|
||||
}
|
||||
exports.connect = connect
|
||||
|
|
@ -37,8 +38,8 @@ module.exports = {
|
|||
}
|
||||
|
||||
function matchesValue (crypto, machine, instance) {
|
||||
instance.fieldScope.crypto === crypto &&
|
||||
instance.fieldScope.machine === machine
|
||||
return instance.fieldLocator.fieldScope.crypto === crypto &&
|
||||
instance.fieldLocator.fieldScope.machine === machine
|
||||
}
|
||||
|
||||
function permutations (crypto, machine) {
|
||||
|
|
@ -50,37 +51,43 @@ function permutations (crypto, machine) {
|
|||
])
|
||||
}
|
||||
|
||||
function fallbackValue (arr, instances) {
|
||||
const crypto = arr[0]
|
||||
const machine = arr[1]
|
||||
function fallbackValue (crypto, machine, instances) {
|
||||
const notNil = R.pipe(R.isNil, R.not)
|
||||
const pickValue = (crypto, machine) => R.find(matchesValue, instances)
|
||||
|
||||
console.log('DEBUG10: %j', instances)
|
||||
const pickValue = arr => R.find(instance => matchesValue(arr[0], arr[1], instance), instances)
|
||||
console.log('DEBUG11: %j', permutations(crypto, machine))
|
||||
console.log('DEBUG14: %j', R.map(pickValue, permutations(crypto, machine)))
|
||||
return R.find(notNil, R.map(pickValue, permutations(crypto, machine)))
|
||||
}
|
||||
|
||||
function generalScoped (crypto, machine, config) {
|
||||
const machineScopedCluster = fieldCluster =>
|
||||
[fieldCluster.code, fallbackValue(crypto, machine, fieldCluster.fieldInstances)]
|
||||
const scopedValue = (key, instances) =>
|
||||
[key, fallbackValue(crypto, machine, keyedValues(key, instances))]
|
||||
|
||||
const scopedGroups = group =>
|
||||
[group.code, R.fromPairs(group.fieldClusters.map(machineScopedCluster))]
|
||||
const keyedValues = (key, instances) => R.filter(r => r.fieldLocator.code === key, instances)
|
||||
const keys = instances => R.uniq(R.map(r => r.fieldLocator.code, instances))
|
||||
|
||||
const scopedGroups = group => {
|
||||
const instances = group.values
|
||||
console.log('DEBUG66: %j', keys(instances))
|
||||
return [group.code, R.fromPairs(keys(instances).map(key => scopedValue(key, instances)))]
|
||||
}
|
||||
|
||||
return R.fromPairs(config.groups.map(scopedGroups))
|
||||
}
|
||||
|
||||
function machineScoped (machine, config) {
|
||||
generalScoped('global', machine, config)
|
||||
return generalScoped('global', machine, config)
|
||||
}
|
||||
|
||||
function unscoped (config) {
|
||||
generalScoped('global', 'global', config)
|
||||
return generalScoped('global', 'global', config)
|
||||
}
|
||||
|
||||
function cryptoScoped (crypto, config) {
|
||||
generalScoped(crypto, 'global', config)
|
||||
return generalScoped(crypto, 'global', config)
|
||||
}
|
||||
|
||||
function scoped (crypto, machine, config) {
|
||||
generalScoped(crypto, machine, config)
|
||||
return generalScoped(crypto, machine, config)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue