A little bit of cleanups and modifications on profiles

This commit is contained in:
Zaid Abdulla committed 2013-01-07 11:32:15 +03:00
1 parent 7eed5cd4d0
commit 2b5a1b2ff0
1 file changed
+7 -28
+7 -28
View File
@@ -45,25 +45,13 @@ calculateProfilesHash = (profiles) ->
return hash return hash
getProfilesVaraibles = (profiles) ->
vars = []
for p in profiles
for c in p.configurations
vars.push(c[0])
return vars
exports.findDeviceConfigurationDiscrepancy = (deviceId, profilesHash, callback) -> exports.findDeviceConfigurationDiscrepancy = (deviceId, profilesHash, callback) ->
getProfiles((profiles) -> getProfiles((profiles) ->
params = {'_tags' : 1} params = {'_tags' : 1}
for p of profiles for p of profiles
profile = profiles[p] profile = profiles[p]
for c in profile.configurations for c in profile.configurations
switch c.type params[c.name] = 1
when 'value'
params[c.param] = 1
else
throw 'Unknown configuration type'
db.devicesCollection.findOne({'_id' : deviceId}, params, (err, device) -> db.devicesCollection.findOne({'_id' : deviceId}, params, (err, device) ->
tags = device['_tags'] or [] tags = device['_tags'] or []
@@ -78,12 +66,9 @@ exports.findDeviceConfigurationDiscrepancy = (deviceId, profilesHash, callback)
discrepency = {} discrepency = {}
for c in combinedConfigurations for c in combinedConfigurations
switch c.type if c.value != getDeviceParamFromPath(device, "#{c.name}._value")
when 'value' discrepency[c.name] = c.value
if c.value != getDeviceParamFromPath(device, "#{c.param}._value")
discrepency[c.param] = c.value
else
throw 'Unknown configuration type'
if not profilesHash if not profilesHash
profilesHash = calculateProfilesHash(profiles) profilesHash = calculateProfilesHash(profiles)
db.memcached.set('profiles_hash', profilesHash, config.PROFILES_CACHE_DURATION, (err, res) -> db.memcached.set('profiles_hash', profilesHash, config.PROFILES_CACHE_DURATION, (err, res) ->
@@ -101,15 +86,9 @@ combineProfileConfigurations = (profiles) ->
configurations = {} configurations = {}
for p in profiles for p in profiles
for c in p.configurations for c in p.configurations
type = c.type if not maxWeights[c.name]? or p.weight > maxWeights[c.name]
switch type configurations[c.name] = c
when 'value' maxWeights[c.name] = p.weight
paramName = c.param
if not maxWeights["#{type}_#{paramName}"]? or p.weight > maxWeights["#{type}_#{paramName}"]
configurations["#{type}_#{paramName}"] = c
maxWeights["#{type}_#{paramName}"] = p.weight
else
throw 'Unknown configuration type'
configurationsList = (configurations[c] for c of configurations) configurationsList = (configurations[c] for c of configurations)
return configurationsList return configurationsList