def indicator_from_row(row): values = get_row_values(row) code = normalise_indicator_code(values[0]) category = values[1].split(':')[0] name = values[2] source_description = { **DEFAULT_SOURCE_DESCRIPTION, 'dataPublisherSource': values[13], 'additionalInfo': '\n'.join([ title + ': ' + content for (title, content) in [('Limitations and exceptions', values[10]), ('Notes from original source', values[11]), ('General comments', values[12]), ('Statistical concept and methodology', values[14]), ('Related source links', values[16]), ('Other web links', values[17])] if content ]) } # override dataPublishedBy if from the IEA if 'iea.org' in json.dumps(source_description).lower( ) or 'iea stat' in json.dumps(source_description).lower( ) or 'iea 2014' in json.dumps(source_description).lower(): source_description[ 'dataPublishedBy'] = 'International Energy Agency (IEA) via The World Bank' indicator = { 'variableId': None, 'datasetId': None, 'sourceId': None, 'code': code, 'category': category, 'datasetName': dataset_name_from_category(category), 'name': name, 'description': default(values[4], ''), 'unit': default(values[5], ''), 'shortUnit': None, # derived below 'source': { 'name': 'World Bank - WDI: ' + name, 'description': json.dumps(source_description) } } # if no unit is specified, try to derive it from the name if not indicator['unit'] and '(' in indicator['name'] and ')' in indicator[ 'name']: indicator['unit'] = indicator['name'][indicator['name'].rfind('(') + 1:indicator['name'].rfind(')')] # derive the short unit indicator['shortUnit'] = extract_short_unit(indicator['unit']) return indicator
def __init__(self, name, history_length=1, type="float", display_width=None, display_precision=None, display_priority=0, export_precision=None, display_postfix="", display_scale=1, display_name=None): assert type in ["int", "float", "stats", "str"] default_display_width = { "int": 6, "float": 8, "stats": 26, "str": 20 }[type] default_display_precision = { "int": 0, "float": 3, "stats": 0, "str": None }[type] default_export_precision = { "int": 1, "float": 6, "stats": 6, "str": None }[type] self._name = name self._display_name = display_name self.display_width = utils.default( display_width, max(default_display_width, len(self.display_name) + 1)) self.display_precision = utils.default(display_precision, default_display_precision) self.export_precision = utils.default(export_precision, default_export_precision) self.display_priority = display_priority self.display_postfix = display_postfix self.display_scale = display_scale self._history = deque(maxlen=history_length) self._history_length = history_length self._type = type
def add_datetime(data, column, prefix=None, with_time=True): data[column] = pd.to_datetime(data[column]) prefix = U.default(prefix, re.sub('[Dd]ate$', '', column)) attrs = ('Year', 'Month', 'Week', 'Day', 'Dayofweek') if with_time: attrs += ('Hour', 'Minute') for attr in attrs: data[f'{prefix}_{attr}'] = getattr(data[column].dt, attr.lower()) return data
class SYMBOLS(object): # internal use only init = '_init' callback = '_callback' slots = '_slots' metal = '_metal' include = '_include' macro = '_macro' out = '_out' tmp = '_tmp' write = '_write' mapping = '_mapping' result = '_result' marker = '_marker' domain = '_domain' i18n_context = '_i18n_context' attributes = '_attributes' negotiate = '_negotiate' translate = '_translate' validate = '_validate' msgid = '_msgid' re_amp = '_re_amp' raise_exc = '_raise_exc' lookup_attr = '_lookup_attr' # transient _slots = TRANSIENT_SYMBOL _translate = TRANSIENT_SYMBOL target_language = TRANSIENT_SYMBOL # markers default_marker = utils.default() default_marker_symbol = '_default' # advertised symbols repeat = 'repeat' language = 'target_language' xincludes = 'xincludes' default = 'default' scope = 'econtext' remote_scope = 'rcontext' def __new__(cls, **kwargs): class SYMBOLS(cls): pass for name, value in kwargs.items(): setattr(SYMBOLS, name, value) return SYMBOLS @classmethod def as_dict(cls): return dict((name, getattr(cls, name)) for name in dir(cls))
def get_asset_list(**kwargs): try: #指定输出的内容列表 output = [ 'id', 'sn', 'inner_ip', 'app_ip', 'remote_ip', 'mac', 'hostname', 'os', 'cpu', 'nu_ram', 'nu_disk', 'ram', 'disk', 'idc_id', 'model_id', 'raid_id', 'raid_type', 'admin', 'spec_id', 'type_id', 'business', 'remote_card', 'purchase_date', 'warranty', 'remark', 'nu_cpu', 'cabinet_seat_id', 'disk_type', 'slot_ram', 'slot_disk' ] #对传入的参数进行接收数据 data = request.get_json()['params'] #api可以指定输出字段,如果没有指定output,就按默认output输出 fields = data.get('output', output) # 前端传来的where条件 where = data.get('where', None) #如果没有传入where的值或者是空的情况 if not where: return json.dumps({'code': 1, 'errmsg': 'must need a condition'}) #进行操作查出数据的内容 result = app.config['cursor'].get_results('asset', fields, where) #写入日志 utils.write_log('api').info('View all assets') #如果结果没有的话 if not result: return json.dumps({'code': 1, 'errmsg': 'asset not exist'}) #进行对时间字符编码转换 for _result in result: _result['warranty'] = utils.default(_result['warranty']) _result['purchase_date'] = utils.default(_result['purchase_date']) return json.dumps({'code': 0, 'result': result}) except: #捕捉异常 utils.write_log('api').error("View asset error: %s" % traceback.format_exc()) return json.dumps({'code': 1, 'errmsg': 'View asset failed'})
def wandaV2(data, knownSkills, method): for skill in knownSkills: thingy = (e in data for e in skill[method]) if any(thingy): if skill['responseType']=='text': utils.speak(skill['response'][0]) else: args = list() for argument in skill['arguments']: if argument==None: break args.append(eval(argument)) utils.speak(getattr(utils , skill['response'][0])(args)) return if data != [None]: if method=='trigger': wandaV2(data,knownSkills, 'extendedTrigger') else: utils.speak(utils.default([data])) else: utils.stillStanding()
def initialize_default(): return utils.default()