Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clusternetwork.js refactoring #143

Closed
wants to merge 10 commits into from
12 changes: 5 additions & 7 deletions html/network.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
</li>
</ul>

<form class="navbar-form navbar-right">
<div class="form-group" id="network_status_string"></div>
</form>
<div class="navbar-form navbar-right" id="network_status_string"></div>
</div>
<!-- /.navbar-collapse -->
</div>
Expand Down Expand Up @@ -614,19 +612,19 @@ <h4 class="modal-title">Listing nodes in cluster X</h4>
d3.select(d3.select(this).attr("href")).style("display", null);
});

hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#cluster-table-export",
cluster_table
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#subcluster-table-export",
subcluster_table
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#node-table-export",
node_table
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#priority-table-export",
priority_set_table
);
Expand Down
8 changes: 3 additions & 5 deletions html/plain.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
</li>
</ul>

<form class="navbar-form navbar-right">
<div class="form-group" id="network_status_string"></div>
</form>
<div class="navbar-form navbar-right" id="network_status_string"></div>
</div>
<!-- /.navbar-collapse -->
</div>
Expand Down Expand Up @@ -571,11 +569,11 @@ <h4 class="modal-title">Listing nodes in cluster X</h4>
d3.select(d3.select(this).attr("href")).style("display", null);
});

hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#cluster-table-export",
cluster_table
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#node-table-export",
node_table
);
Expand Down
10 changes: 4 additions & 6 deletions html/priority-sets-args.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
</li>
</ul>

<form class="navbar-form navbar-right">
<div class="form-group" id="network_status_string"></div>
</form>
<div class="navbar-form navbar-right" id="network_status_string"></div>
</div>
<!-- /.navbar-collapse -->
</div>
Expand Down Expand Up @@ -673,17 +671,17 @@ <h5 class="modal-desc">Select CoI from the list</h5>
d3.select(d3.select(this).attr("href")).style("display", null);
});

hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#cluster-table-export",
cluster_table,
true
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#subcluster-table-export",
subcluster_table,
true
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#node-table-export",
node_table,
true
Expand Down
10 changes: 4 additions & 6 deletions html/social.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@
</li>
</ul>

<form class="navbar-form navbar-right">
<div class="form-group" id="network_status_string"></div>
</form>
<div class="navbar-form navbar-right" id="network_status_string"></div>
</div>
<!-- /.navbar-collapse -->
</div>
Expand Down Expand Up @@ -591,15 +589,15 @@ <h4 class="modal-title">Listing nodes in cluster X</h4>
d3.select(d3.select(this).attr("href")).style("display", null);
});

hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#cluster-table-export",
cluster_table
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#subcluster-table-export",
subcluster_table
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#node-table-export",
node_table
);
Expand Down
10 changes: 4 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
</li>
</ul>

<form class="navbar-form navbar-right">
<div class="form-group" id="network_status_string"></div>
</form>
<div class="navbar-form navbar-right" id="network_status_string"></div>
</div>
<!-- /.navbar-collapse -->
</div>
Expand Down Expand Up @@ -593,15 +591,15 @@ <h4 class="modal-title">Listing nodes in cluster X</h4>
d3.select(d3.select(this).attr("href")).style("display", null);
});

hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#cluster-table-export",
cluster_table
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#subcluster-table-export",
subcluster_table
);
hivtrace.misc.export_table_to_text(
hivtrace.helpers.render_button_export_table_to_text(
"#node-table-export",
node_table
);
Expand Down
7 changes: 7 additions & 0 deletions refactor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Some scripts to assist / automate the refactoring process.

`function-usages.py`:
Provide a regex expression (optional) and files to search within. The script returns all instances of the regex expression that are used only in one file (and is useful since a function that is only used in one file can just be moved to that file).

For example, finding `clusternetwork.js` `self` functions that can be refactored from `clusterOI.js`, run:
`python3 refactor/function-usages.py src/clusternetwork.js src/clustersOI/clusterOI.js`
59 changes: 59 additions & 0 deletions refactor/function-usages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import sys
import os
import re
import argparse

# Define the regex pattern
regex = re.escape("self.") + "[a-zA-Z0-9_]+" + re.escape("(")

parser = argparse.ArgumentParser(description='Find function usages in a list of files')
# optional regex pattern
parser.add_argument('--pattern', type=str, help='a regex pattern to search for. expects last character to be an open parenthesis')
parser.add_argument('--no-paranthesis', action='store_true', help='if set, will not expect the last character of the pattern to be an open paranthesis')
parser.add_argument('files', metavar='files', type=str, nargs='+',
help='a list of files to search for function usages')

# Parse the arguments
args = parser.parse_args()
if args.pattern:
regex = args.pattern

# records where a function is used, and which functions are used in a file
function_to_files = {}
files_to_functions = {}

# Iterate over the provided file list
for file in args.files:
# Check if the file exists
if os.path.isfile(file):
# Open the file and search for the regex pattern
with open(file, 'r') as f:
content = f.read()
functions = re.findall(regex, content)
if not args.no_paranthesis:
functions = [function[:-1] for function in functions]

for function in functions:
if function not in function_to_files:
function_to_files[function] = {}
if file not in function_to_files[function]:
function_to_files[function][file] = 1
else:
function_to_files[function][file] += 1

if file not in files_to_functions:
files_to_functions[file] = {}
if function not in files_to_functions[file]:
files_to_functions[file][function] = 1
else:
files_to_functions[file][function] += 1
else:
print(f"File not found: {file}")
sys.exit(1)

for file in files_to_functions:
print(f"File {file} exclusively uses: ")
for function in files_to_functions[file]:
files_used_in = function_to_files[function].keys()
if len(files_used_in) == 1:
print(f" {function} ({files_to_functions[file][function]} times)")
Loading
Loading