请求分析各clientId的新旧映射差异(附新映射文件示例)
To spot the differences between old and new primary/secondary mappings for each clientId, we’ll break this down into tracking additions, removals, and unchanged values in both primary and secondary lists for every client. Since you’ve shared the new mappings but not the old ones, I’ll use sample old mappings to walk through the process clearly.
Sample Old Mappings (for demonstration)
Let’s assume these are your existing old mapping files:
old_primary_mapping.txt:{1=[343, 0, 686, 1372, 882, 456], 2=[687, 1, 1373, 883, 197], 3=[1374, 2, 884, 737, 198]}old_secondary_mapping.txt:{1=[1152, 816, 1488, 336, 789], 2=[1153, 817, 337, 1489, 1009], 3=[1154, 1490, 338]}
Step-by-Step Difference Breakdown per ClientId
ClientId 1
- Primary Mapping Differences:
- Removed:
456 - Added:
196 - Unchanged:
343, 0, 686, 1372, 882
- Removed:
- Secondary Mapping Differences:
- Removed:
789 - Added:
1008 - Unchanged:
1152, 816, 1488, 336
- Removed:
ClientId 2
- Primary Mapping Differences:
- Added:
736, 1030, 1569 - Unchanged:
687, 1, 1373, 883, 197
- Added:
- Secondary Mapping Differences:
- Added:
0, 1297 - Unchanged:
1153, 817, 337, 1489, 1009
- Added:
ClientId 3
- Primary Mapping Differences:
- Added:
1570 - Unchanged:
1374, 2, 884, 737, 198
- Added:
- Secondary Mapping Differences:
- Added:
1 - Unchanged:
1154, 1490, 338
- Added:
Automate the Comparison (Python Code Example)
If you want to compute these differences programmatically, here’s a straightforward script that takes old and new mappings as dictionaries and outputs structured results:
def calculate_mapping_changes(old_list, new_list): old_values = set(old_list) new_values = set(new_list) return { "removed": sorted(old_values - new_values), "added": sorted(new_values - old_values), "unchanged": sorted(old_values & new_values) } # Your provided new mappings new_primary = {1:[343, 0, 686, 1372, 882, 196], 2:[687, 1, 1373, 883, 197, 736, 1030, 1569], 3:[1374, 2, 884, 737, 198, 1570]} new_secondary = {1:[1152, 816, 1488, 336, 1008], 2:[1153, 0, 817, 337, 1489, 1009, 1297], 3:[1, 1154, 1490, 338]} # Sample old mappings (replace with your actual old data) old_primary = {1:[343, 0, 686, 1372, 882, 456], 2:[687, 1, 1373, 883, 197], 3:[1374, 2, 884, 737, 198]} old_secondary = {1:[1152, 816, 1488, 336, 789], 2:[1153, 817, 337, 1489, 1009], 3:[1154, 1490, 338]} # Generate and print results for each clientId for client_id in new_primary.keys(): print(f"=== ClientId {client_id} ===") print("Primary Mapping Changes:") print(calculate_mapping_changes(old_primary[client_id], new_primary[client_id])) print("Secondary Mapping Changes:") print(calculate_mapping_changes(old_secondary[client_id], new_secondary[client_id])) print()
Just replace the sample old mappings with your actual old data, and this script will output clean, organized differences for every client’s mappings.
内容的提问来源于stack exchange,提问作者user1950349

