Exemplo n.º 1
0
def PREDICT():
    json = request.get_json(force=True)
    if json["lang"] == "python":
        methods = parse_py(json['f'])
    else:
        methods = parse_clike(json['f'])
    m = []
    if json['model'] == "model1":  #dynamic analysis
        for i in methods:
            func_obj = i[0]
            original_func_name = func_obj.__name__
            func_source_code = i[1]
            m.append([original_func_name, mp1.predict(func_obj, json['lang'])])

    elif json['model'] == "model2":  #static analysis
        for i in methods:
            func_obj = i[0]
            original_func_name = func_obj.__name__
            func_source_code = i[1]
            m.append([
                original_func_name,
                mp2.predict(func_source_code, json['lang'])
            ])

    else:  #default is dynamic analysis
        for i in methods:
            func_obj = i[0]
            original_func_name = func_obj.__name__
            func_source_code = i[1]
            m.append([original_func_name, mp1.predict(func_obj, json['lang'])])

    return jsonify(m)
Exemplo n.º 2
0
def execute(func_str, label):
    cppyy.cppdef("using namespace std;")
    cppyy.cppdef(func_str)
    a = cp.Adaptor()
    #print(getattr(a,label))
    res = mp.predict(getattr(a, label), "C++")
    return res
Exemplo n.º 3
0
def test_performance():
    # labels = os.listdir('dataset_working')
    # # labels.remove(os.path.basename(__file__))
    # labels.remove('isAnagram')
    # labels.remove('myPow')
    # labels.remove('isPalindrome')
    # labels.remove('fib')
    

    map = json.load(open("mapping.json"))
    accuracy = json.load(open("label_accuracy.json"))
    labels = ["isAnagram","strStr"]
    # done = ["sortArray","rotate","fib","isPalindrome","myPow","isUgly","countPrimes","mySqrt","reverse","numTrees","isAnagram","strStr","canJump","coinChange","numIslands","canFinish","hasCycle","reverseList","inorderTraversal","isValidBST","maxDepth","maxPathSum","levelOrder","solveSudoku"]
    # print(map["canFinish"][0])
    total = 0
    correct = 0
    for label in labels:
        prgs = os.listdir('dataset'+'/'+label)
        prgs.sort()
        if '__pycache__' in prgs:
            prgs.remove('__pycache__')
        ltotal = 0
        lcorrect = 0
        frontend_label = map[label][0]
        for prg in prgs:
            total += 1
            ltotal += 1
            print("Evaluating " + prg)
            loader = importlib.machinery.SourceFileLoader('dataset'+'/'+label, 'dataset'+'/'+label+'/'+prg)
            handle = loader.load_module('dataset'+'/'+label)
            s = handle.Solution()
            a = Adaptor()
            global f
            f = getattr(s, label)
            res = mp.predict(getattr(a,label),"python")
            oplabel = res
            if(oplabel==map[label][0]):
                lcorrect += 1
            print(res,label)
            # print("Accuracy till "+ str(total)+" prgs: " + str((float(correct)/total)*100) )
        val = (float(lcorrect)*(accuracy[frontend_label]/100)/ltotal)*100
        correct += float(lcorrect)*(accuracy[frontend_label]/100)
        with open("results.txt",'a') as f:
            f.write("Accuracy of "+ frontend_label + " " + str(lcorrect)+"/"+str(ltotal)+" prgs: " + str(val)+"\n")
    
    with open("results.txt",'a') as f:
            f.write("Overall Accuracy: " + str((float(correct)/total)*100)+"\n")

    return  (float(correct)/total)*100
Exemplo n.º 4
0
import model1.predict as mp1
import model1.optimize as op1
import model1.dataset as g1


def bubbleSort(arr: list):
    n = len(arr)

    # Traverse through all array elements
    for i in range(n - 1):
        # range(n) also work but outer loop will repeat one time more than needed.

        # Last i elements are already in place
        for j in range(0, n - i - 1):

            # traverse the array from 0 to n-i-1
            # Swap if the element found is greater
            # than the next element
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
    return arr


def timSort(arr: list):
    return sorted(arr)


print(mp1.predict(bubbleSort))
#print(op1.optimize(bubbleSort,weights=[1,1,0,0]))
#print(op1.compare([timSort,bubbleSort]))
#print(op1.rank([timSort]))