col to rows

    /**
     * 计算驻留时长返回的记录
     * col to  rows 
     * 2011-11-4
     * @param list
     * @param mulColF   需要转换的列
     * @param groupKeyF 分组的字段
     * @param calcValueF需计算结果的字段
     * @return  返回最终需要展示的结果集
     * List<HashMap<String,Object>>
     * Yang,Hualong
     */
	public static List<HashMap<String,Object>> calcZzbbZl(List<HashMap<String,Object>> list,String mulColF,String[] groupKeyF,String[] calcValueF){
		LinkedHashMap<String,HashMap<String,Object>> tempMap = new LinkedHashMap(100); 
		LinkedHashSet<String> prefixKeys = new LinkedHashSet<String>();
		LinkedHashSet<String> suffixKeys = new LinkedHashSet<String>();
		String suffix = "H";
		for(int i = 0 ;i < list.size();i++){
			HashMap<String,Object> record = list.get(i);
			String key = record.get(mulColF).toString();
			String others = "";
			for(int j = 0 ;j < groupKeyF.length;j++){
				others+= record.get(groupKeyF[j]).toString()+suffix;
				//System.out.println(others);
			}
			prefixKeys.add(others);//sid Key
			suffixKeys.add(key);//statykey
			tempMap.put(others+key, record);//
		}
		List<HashMap<String,Object>> retrunList = new ArrayList<HashMap<String,Object>>();
//		System.out.println("otherKeys:"+otherKeys);//sidKey 
//		System.out.println("mainKeys:"+mainKeys);//hourKey
//		System.out.println("map:"+map);
		for(String row:prefixKeys){//sid
			Double sumtotal=0d;//获取每个小区下面的合计值
			HashMap<String,Object> newRecord = new HashMap<String,Object>(100);
			HashMap<String,Object> containValueRecord = new HashMap<String,Object>(100);
			for(String col: suffixKeys){//stathours
				String key = (row+col);
				HashMap<String,Object> temp = tempMap.get(key); 
				if(temp==null){
					continue;
				}
				for(int i = 0 ;i < groupKeyF.length;i++){//sid
					newRecord.put(groupKeyF[i], temp.get(groupKeyF[i]));
				}
				for(int i = 0 ;i < calcValueF.length;i++){//total
					for (int j = 1; j < MAX_STATHOURS; j++) {
						if(j==new Integer(col)){//如果当前
							//System.out.println(col+suffix+":"+temp.get(calcValueF[i]));
							containValueRecord.put(col+suffix,temp.get(calcValueF[i]));
							sumtotal+=(Double)temp.get(calcValueF[i]);
						}else{
							newRecord.put(j+suffix,0);
							//System.out.println(j+suffix+":"+0);
						}
					}
				}
			}
			System.out.println("newRecord2:"+containValueRecord);
			System.out.println("size:"+newRecord.size());
			newRecord.putAll(containValueRecord);
			newRecord.put("stotal", sumtotal);//合计值
			retrunList.add(newRecord);
		}
		return  retrunList;
	}
 
def compare_table(self, block_name, old_table, new_table, belong_to): logger.info(f"start compare table, old_data_id: {old_table.data_id}, new_data_id: {new_table.data_id}") # 使表格内列数一致 self.align_table_col(old_table, new_table) # 表格中存在大量视觉上merge但是实际未合并的空格,需要将空格赋值为正确的文本,防止影响相似度匹配 self.fill_visual_merged_cells(old_table) self.fill_visual_merged_cells(new_table) if old_table.head_type == new_table.head_type == 'horizontal': old_col_table, new_col_table = self.transpose_table(old_table, new_table) else: if old_table.head_type == 'vertical': new_table.head_list = old_table.head_list new_table.head_type = 'vertical' elif new_table.head_type == 'vertical': old_table.head_list = new_table.head_list old_table.head_type = 'vertical' old_col_table, new_col_table = old_table, new_table # 列匹配 del_cols, add_cols = old_col_table.rows, new_col_table.rows col_matched = CustomTableStrategyMiddleware(self._path_base).match_row(del_cols, add_cols,is_col=True, head_indexes=[old_table.head_list,new_table.head_list]) if col_matched: matched_old_cols, matched_new_cols = list(zip(*list(col_matched))) del_cols = [old_col for old_col in old_col_table.rows if old_col not in matched_old_cols] add_cols = [new_col for new_col in new_col_table.rows if new_col not in matched_new_cols] sub_type = 'col' if old_table.head_type == 'horizontal' else 'row' ls_col_delete, ls_col_add = self.process_delete_add_diff(block_name, sub_type, del_cols, add_cols, belong_to=belong_to, head_type=old_table.head_type) # 根据matched的列组合新的表,得到列一致的两个表 if col_matched: old_col_indexes,new_col_indexes =[],[] for old_col, new_col in col_matched: old_col_indexes.append(old_col_table.rows.index(old_col)) new_col_indexes.append(new_col_table.rows.index(new_col)) old_equal_col_table = self.choice_cols(old_table, old_col_indexes) new_equal_col_table = self.choice_cols(new_table, new_col_indexes) else: return ls_col_delete, ls_col_add, [] # 行匹配 del_rows, add_rows = old_equal_col_table.rows, new_equal_col_table.rows row_matched = CustomTableStrategyMiddleware(self._path_base).match_row(del_rows, add_rows, is_col=False) if row_matched: matched_old_rows, matched_new_rows = list(zip(*list(row_matched))) del_rows_indexes = [idx for idx, old_row in enumerate(old_equal_col_table.rows) if old_row not in matched_old_rows] add_rows_indexes = [idx for idx, new_row in enumerate(new_equal_col_table.rows) if new_row not in matched_new_rows] # 使用没有重组前的表,横表头直接处理,竖表头需要转置 if old_table.head_type == new_table.head_type == 'horizontal': del_rows = [old_table.rows[idx] for idx in del_rows_indexes] add_rows = [new_table.rows[idx] for idx in add_rows_indexes] else: old_transpose_table = self.choice_cols(old_table, list(range(len(old_table.rows)))) new_transpose_table = self.choice_cols(new_table, list(range(len(new_table.rows)))) del_rows = [old_transpose_table.rows[idx] for idx in del_rows_indexes] add_rows = [new_transpose_table.rows[idx] for idx in add_rows_indexes] sub_type = 'row' if old_table.head_type == 'horizontal' else 'col' ls_row_delete, ls_row_add = self.process_delete_add_diff(block_name, sub_type, del_rows, add_rows, belong_to=belong_to, head_type=old_table.head_type) # 根据matched的行组合新的表,得到行一致的两个表 if row_matched: old_equal_row_table, new_equal_row_table = TableObject(), TableObject() old_equal_row_table.rows = list(matched_old_rows) old_equal_row_table.head_type = old_table.head_type self.copy_table_attrs(old_equal_row_table, old_table) new_equal_row_table.rows = list(matched_new_rows) new_equal_row_table.head_type = new_table.head_type self.copy_table_attrs(new_equal_row_table, new_table) # 查找行变更、列变更、单元格变更 ls_row_update, ls_col_update, ls_cell_update = self.compare_ordered_tables(block_name,old_equal_row_table, new_equal_row_table,belong_to=belong_to) else: ls_row_update, ls_col_update, ls_cell_update = [], [], [] part_delete = ls_row_delete + ls_col_delete part_add = ls_row_add + ls_col_add part_update = ls_row_update + ls_col_update + ls_cell_update logger.info(f"finish compare table, old_data_id: {old_table.data_id}, new_data_id: {new_table.data_id}") return part_delete, part_add, part_update 详细解析一下
最新发布
09-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值