-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a606032
commit 2290887
Showing
10 changed files
with
410 additions
and
44 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Check for inconsistent results between merge tools and output them to a CSV. | ||
usage: python3 check_inconsistencies.py --result_csv <path_to_result_csv> --output_csv <path_to_output_csv> | ||
This script reads a result CSV file, checks for inconsistencies between merge tools based on fingerprints, | ||
and writes the inconsistent results to a new CSV file. | ||
Arguments: | ||
- result_csv: path to the result CSV file | ||
- output_csv: path to the output CSV file where inconsistent results will be saved | ||
""" | ||
|
||
import argparse | ||
import pandas as pd | ||
from typing import List | ||
|
||
|
||
def check_fingerprint_consistency( | ||
result_df: pd.DataFrame, merge_tools: List[str] | ||
) -> pd.DataFrame: | ||
"""Check if the fingerprints are consistent and return inconsistent results. | ||
Args: | ||
result_df: DataFrame containing the results of the merge tools | ||
merge_tools: list of merge tools | ||
Returns: | ||
DataFrame with inconsistent results | ||
""" | ||
inconsistencies = [] | ||
|
||
for merge_tool1 in merge_tools: | ||
for merge_tool2 in merge_tools: | ||
if merge_tool1 == "gitmerge_resolve" or merge_tool2 == "gitmerge_resolve": | ||
continue | ||
# ignore adjacent | ||
if ( | ||
merge_tool1 == "gitmerge_ort_adjacent" | ||
or merge_tool2 == "gitmerge_ort_adjacent" | ||
): | ||
continue | ||
if merge_tool1 != merge_tool2: | ||
# Check if fingerprints are the same | ||
same_fingerprint_mask = ( | ||
result_df[merge_tool1 + "_merge_fingerprint"] | ||
== result_df[merge_tool2 + "_merge_fingerprint"] | ||
) | ||
|
||
# Check if results are the same | ||
same_result_mask = result_df[merge_tool1] == result_df[merge_tool2] | ||
|
||
# Check if the fingerprints are the same but the results are different | ||
inconsistent_mask = same_fingerprint_mask & ~same_result_mask | ||
if inconsistent_mask.sum() > 0: | ||
inconsistent_results = result_df[inconsistent_mask].copy() | ||
inconsistent_results["tool1"] = merge_tool1 | ||
inconsistent_results["tool2"] = merge_tool2 | ||
inconsistencies.append(result_df[inconsistent_mask]) | ||
|
||
if inconsistencies: | ||
return pd.concat(inconsistencies).drop_duplicates() | ||
else: | ||
return pd.DataFrame() | ||
|
||
|
||
def main(): | ||
"""Main function""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--result_csv", | ||
type=str, | ||
help="Path to the result CSV file", | ||
default="results/combined/result.csv", | ||
) | ||
parser.add_argument( | ||
"--output_csv", | ||
type=str, | ||
help="Path to the output CSV file for inconsistent results", | ||
default="results/combined/inconsistent_results.csv", | ||
) | ||
args = parser.parse_args() | ||
|
||
# Read the result CSV file | ||
result_df = pd.read_csv(args.result_csv, index_col="idx") | ||
|
||
# List of merge tools | ||
merge_tools = [ | ||
col.split("_merge_fingerprint")[0] | ||
for col in result_df.columns | ||
if col.endswith("_merge_fingerprint") | ||
] | ||
|
||
# Check for inconsistencies | ||
inconsistent_results = check_fingerprint_consistency(result_df, merge_tools) | ||
|
||
if not inconsistent_results.empty: | ||
# Write the inconsistent results to the output CSV file | ||
inconsistent_results.to_csv(args.output_csv, index_label="idx") | ||
print(f"Inconsistent results have been saved to {args.output_csv}") | ||
print("Number of inconsistencies found:", len(inconsistent_results)) | ||
else: | ||
print("No inconsistencies found.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Delete the keys containing 'imports' in the JSON files in the given directory.""" | ||
|
||
import os | ||
import json | ||
|
||
|
||
def count_import_keys(directory): | ||
"""Count the number of keys containing 'imports' in the JSON files in the given directory.""" | ||
count = 0 | ||
for root, _, files in os.walk(directory): | ||
json_files = [f for f in files if f.endswith(".json")] | ||
for json_file in json_files: | ||
file_path = os.path.join(root, json_file) | ||
with open(file_path, "r", encoding="utf-8") as file: | ||
data = json.load(file) | ||
|
||
# Count keys containing 'adjacent' | ||
keys_to_delete = [key for key in data if "intellimerge" in key] | ||
count += len(keys_to_delete) | ||
return count | ||
|
||
|
||
def delete_import_keys(directory): | ||
"""Delete the keys containing 'imports' in the JSON files in the given directory.""" | ||
total_deleted = 0 | ||
for root, _, files in os.walk(directory): | ||
json_files = [f for f in files if f.endswith(".json")] | ||
for json_file in json_files: | ||
file_path = os.path.join(root, json_file) | ||
with open(file_path, "r", encoding="utf-8") as file: | ||
data = json.load(file) | ||
|
||
# Record keys to delete | ||
keys_to_delete = [key for key in data.keys() if "intellimerge" in key] | ||
if keys_to_delete: | ||
for key in keys_to_delete: | ||
del data[key] | ||
total_deleted += 1 | ||
|
||
# Save the modified data back to file | ||
with open(file_path, "w", encoding="utf-8") as file: | ||
json.dump(data, file, indent=4) | ||
|
||
return total_deleted | ||
|
||
|
||
def main(): | ||
"""Main function.""" | ||
directory = "cache" | ||
potential_deletions = count_import_keys(directory) | ||
print(f"Potential deletions: {potential_deletions}") | ||
confirm = input("Do you want to proceed with deleting these keys? (yes/no): ") | ||
if confirm.lower() == "yes": | ||
total_deleted = delete_import_keys(directory) | ||
print(f"Total keys deleted: {total_deleted}") | ||
else: | ||
print("Operation cancelled.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.