Complexity Notebook

The complexity notebook experiments with code complexity analysis.


In [22]:
import understand
import sys, traceback

In [23]:
db = None
try:
    db = understand.open("/Users/ashapoch/Dropbox/_tsg/github-tsg-assessment-service/samples/tdsandbox/tdsandbox.udb")
except understand.UnderstandError:
    traceback.print_exc(file=sys.stdout)

In [24]:
def print_metrics(db):
    metrics = db.metric(db.metrics())
    for k,v in sorted(metrics.items()):
        print (k,"=",v)

In [25]:
def print_complexities(db):
    funcs = db.lookup("com.softserve.td.*", "function,method,procedure")
    for f in funcs:
        name = f.name()
        complexity = f.metric(["CyclomaticStrict"])
        print(f.longname(), "(", f.parameters(), ")", "CyclomaticStrict is", complexity["CyclomaticStrict"])

In [26]:
if db:
    print_complexities(db)


com.softserve.td.alg.rest.Parentheses.Parentheses ( String[] payload ) CyclomaticStrict is 1
com.softserve.td.alg.rest.Parentheses.getPayload (  ) CyclomaticStrict is 1
com.softserve.td.alg.services.impl.ParenthesesServiceImpl1.dfs ( ArrayList<String> result,String s,int left,int right ) CyclomaticStrict is 6
com.softserve.td.alg.services.impl.ParenthesesServiceImpl1.generateParentheses ( int n ) CyclomaticStrict is 1
com.softserve.td.alg.services.ParenthesesService.generateParentheses ( int n ) CyclomaticStrict is 1
com.softserve.td.TdsandboxApplication.main ( String[] args ) CyclomaticStrict is 1
com.softserve.td.alg.services.impl.ParenthesesServiceImpl2.generateParentheses ( int n ) CyclomaticStrict is 8
com.softserve.td.TdsandboxApplicationTests.contextLoads (  ) CyclomaticStrict is 1
com.softserve.td.alg.ParenthesesTests.impl1MaxNumberSupported (  ) CyclomaticStrict is 2
com.softserve.td.alg.ParenthesesTests.impl1Works (  ) CyclomaticStrict is 1
com.softserve.td.alg.ParenthesesTests.impl2Works (  ) CyclomaticStrict is 1
com.softserve.td.alg.ParenthesesTests.runTestSet ( ParenthesesService service ) CyclomaticStrict is 2
com.softserve.td.alg.rest.ParenthesesController.parentheses ( int n,String strategy ) CyclomaticStrict is 1

In [ ]: