Exemplo n.º 1
0
def itemize(s, label=None):
    """
    converts dictionary to string
    """
    if s:
        if label:
            st = ''
            params = PARAMS_ORDER.get(str(label))
            
            if params:
                params = params[0] + params[1]
                for param in params[1:]:
                    if param in s and not param in ['label', 'model', 'type']:
                        if ',' in str(s[param]):
                            if len(s[param]) < 20:
                                st += '%s: %s, ' %(param, s[param])
                            else:
                                st += '%s: %s.., ' %(param, s[param][:20])
                        else:
                            if str(s[param]).isdigit():
                                st += '%s: %d, ' %(param, int(s[param]))
                            else:
                                try:
                                    st += '%s: %.2f, ' %(param, float(s[param]))
                                except:
                                    st += '%s: %s, ' %(param, s[param])
                st = st[:-2]
                return st   
        l = s.items()
        l.sort()
        l = ["%s: %s" %(str(i[0]),str(i[1])) for i in l]
        return ', '.join(l)
    return None
Exemplo n.º 2
0
# -*- coding: utf-8 -*-
#from reversion import revision

import numpy as np
from network.network_settings import PARAMS_ORDER

params_order = {}
for key, val in PARAMS_ORDER.items():
    params_order[key] = val[0] + val[1]

def dict_to_JSON(valDict):
    params_order = PARAMS_ORDER[valDict['model']][0] + PARAMS_ORDER[valDict['model']][1]
    valList = []
    
    for keyJSON in params_order:
        if keyJSON in valDict:
            if valDict[keyJSON]:
                valList.append('"%s":"%s"' %(keyJSON, valDict[keyJSON]))
                continue
        valList.append('"%s":""' %keyJSON)
        
    return '{' + ', '.join(valList) + '}'
    
def csv_to_dict(csv):
    csvList = csv.split('\r\n')
    devList = []
    for device in csvList:
        statusList = device.split(';')
        statusList = [status.lstrip() for status in statusList]
        statusList[1] = int(statusList[1])
        if statusList[0] in params_order: