Changeset - 98d80dfbd7e3
[Not reviewed]
Dennis Fink - 9 years ago 2015-10-22 17:25:15
dennis.fink@c3l.lu
Don't fail on calculation weights for relays

Relays don't have a 5_years subkey in their weights json.
We fix this by using a try clause and simply continue with the
next iteration if a key is missing
1 file changed with 5 insertions and 1 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/model.py
Show inline comments
 
@@ -33,13 +33,17 @@ validate = functools.partial(
 
def calculate_weight(data):
 

	
 
    obj = {}
 

	
 
    for subkey in ('1_week', '1_month', '3_months', '1_year', '5_years'):
 

	
 
        subdata = data[subkey]
 
        try:
 
            subdata = data[subkey]
 
        except KeyError:
 
            continue
 

	
 
        factor = subdata['factor']
 

	
 
        values = [x * factor for x in subdata['values'] if x is not None]
 

	
 
        if values:
 
            obj[subkey] = statistics.mean(values) * 100
0 comments (0 inline, 0 general)