def reducer(acc, cur): obj = objects.clone(acc) if (cur[0] < len(query_set)): return objects.assign( obj, {keys_arr[cur[0]]: parse_census_numbers(cur[1])}) # or allows the accumulator to be returned first (don't ask me why that's not the default) else: return objects.assign(obj, {keys_arr[cur[0]]: cur[1]})
def update_report(data): """ Updates a report and returns the report's information. :param data: New report data :type data: dict """ report = fetch_report(data['user_id'], data['report_name']) if report is None: raise DBValidationException(f'The report is invalid.', 'report_name') current_data = { 'user_id': data['user_id'], 'report_name': report['report_name'], 'report_descrip': report['report_descrip'], 'share_dttm': report['share_dttm'], 'columns': [] } new_data = assign({}, current_data, pick(data, 'report_name', 'report_descrip', 'share_dttm', 'columns')) if len(new_data['columns']) < 1: raise DBException(f'"columns" are required.') execute_sp_with_required_in_args( 'MWH_FILES.MANAGE_CollegeScorecard_Console', 'SAVE USER SELECTION', new_data['user_id'], new_data['report_name'].upper(), new_data['report_descrip'], new_data['share_dttm'], get_columns_xml(new_data['columns'])) return fetch_report(new_data['user_id'], new_data['report_name'])
def create_report(data): """ Creates a report and returns the report's information. :param data: Report data :type data: dict """ if not is_blank(data['report_name']) and report_exists( data['user_id'], data['report_name']): raise DBValidationException( f"The report \"{data['report_name']}\" already exists.", 'report_name') required_data = { 'user_id': data['user_id'], 'report_name': '', 'report_descrip': '', 'share_dttm': '', 'columns': [] } new_data = assign( required_data, pick(data, 'report_name', 'report_descrip', 'share_dttm', 'columns')) if len(new_data['columns']) < 1: raise DBException(f'"columns" are required.') execute_sp_with_required_in_args( 'MWH_FILES.MANAGE_CollegeScorecard_Console', 'SAVE USER SELECTION', new_data['user_id'], new_data['report_name'].upper(), new_data['report_descrip'], new_data['share_dttm'], get_columns_xml(new_data['columns'])) return fetch_report(new_data['user_id'], new_data['report_name'])
def buildChild(data, tags): ''' 构建child接口组 :param data: 原始数据 :param tasg: buildTop构建的tags组 :return: 带有child信息的tags组 ''' try: dataObj = json.loads(data) tagsObj = objects.clone_deep(tags) # 遍历 tags ,嵌套遍历paths将对应的连接挂在到tags下的child中 paths = objects.get(dataObj, 'paths') for tag in tagsObj: for path in paths: if tag['name'] == getTagsFromPath(paths[path]): childItem = objects.clone_deep(paths[path]) tag['child'].append( objects.assign(childItem, {'path': path})) return tagsObj except: sysLog.warn('JSON处理失败,请确认地址是否正确') return []
def create_user(data): """ Creates a user and returns the new user information. :param data: New user data :type data: dict """ required_data = { 'employee_last_name': '', 'employee_first_name': '', 'employee_email': '', 'employee_phone': '', 'employee_cellphone': '', 'employee_password': '' } new_data = assign( required_data, pick( data, 'employee_last_name', 'employee_first_name', 'employee_email', 'employee_phone', 'employee_cellphone', 'employee_password' ) ) if is_blank(new_data['employee_email']): raise DBException(f'"employee_email" is required.') existing_user = fetch_user_by_email(new_data['employee_email']) if existing_user: raise DBException(f"{new_data['employee_email']} already exists.") result = execute_admin_console_sp( 'MWH.UMA_WAREHOUSE_ADMIN_CONSOLE', 'SAVE ADMIN CONSOLE USER', '', new_data['employee_last_name'], new_data['employee_first_name'], new_data['employee_email'], new_data['employee_phone'], new_data['employee_cellphone'], '', generate_password_hash(new_data['employee_password']) ) if len(result) < 1: raise DBException("The new user account could not be created.") return fetch_user_by_id(result[0]['id'])
def update_user(id_, data): """ Updates a user and returns the new user information. :param id_: User ID :type id_: int :param data: New user data :type data: dict """ user = fetch_user_by_id(id_) if user is None: raise DBException(f'{id_} is and invalid user ID.') current_data = { 'employee_last_name': user['employee_last_name'], 'employee_first_name': user['employee_first_name'], 'employee_email': user['employee_email'], 'employee_phone': user['employee_phone'], 'employee_cellphone': user['employee_cellphone'], 'employee_password': user['employee_password'] } new_data = assign( {}, current_data, pick( data, 'employee_last_name', 'employee_first_name', 'employee_email', 'employee_phone', 'employee_cellphone', 'employee_password' ) ) execute_admin_console_sp( 'MWH.UMA_WAREHOUSE_ADMIN_CONSOLE', 'SAVE ADMIN CONSOLE USER', id_, new_data['employee_last_name'], new_data['employee_first_name'], new_data['employee_email'], new_data['employee_phone'], new_data['employee_cellphone'], user['employee_password'], new_data['employee_password'] if is_blank(new_data['employee_password']) else '' ) return fetch_user_by_id(id_)
def buildTop(data): ''' 构建swagger顶层目录结构 :param data: swagger原始返回的信息 :return:返回顶层元组信息 ''' try: dataObj = json.loads(data) tags = objects.get(dataObj, 'tags', []) tops = arrays.compact(tags) tops = arrays.mapcat( tops, lambda item: objects.assign(objects.clone(item), {'child': []})) return tops except: sysLog.warn('JSON处理失败,请确认地址是否正确') return []
def buildListData(tags, keyWord=''): listData = [] for row in range(len(tags)): for childIndex in range(len(tags[row]['child'])): rowData = tags[row]['child'][childIndex] path = rowData['path'] methodTypes = DataUtils.getValidMethod(rowData) for methodType in methodTypes: itemData = objects.clone_deep( tags[row]['child'][childIndex][methodType]) itemData = objects.assign(itemData, { 'path': path, 'type': methodType }) listData.append(itemData) return listData