-
Notifications
You must be signed in to change notification settings - Fork 3
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
7e91150
commit 12a1aed
Showing
218 changed files
with
210,971 additions
and
279,115 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+6 KB
...data/advisors-detection-results/.DS_Store → ...rn_detection/advisors/detection/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+34.9 MB
...ssets/frameworks/PtidejSmellDetection.jar → .../detection/Decor/PtidejSmellDetection.jar
Binary file not shown.
468 changes: 468 additions & 0 deletions
468
historical_anti-pattern_detection/advisors/detection/Decor/PtidejSmellDetection.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
195 changes: 195 additions & 0 deletions
195
historical_anti-pattern_detection/advisors/detection/Hist/hist3.py
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,195 @@ | ||
from __future__ import print_function | ||
from __future__ import division | ||
from sklearn.preprocessing import StandardScaler | ||
|
||
from reader import * | ||
|
||
import math | ||
import dataConstruction.systems as systems | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
def precision(detected, true): | ||
truePos = 0 | ||
for className in detected: | ||
if className in true: | ||
truePos += 1 | ||
|
||
if len(true) == 0: | ||
return 0 | ||
|
||
return truePos / len(true) | ||
|
||
def recall(detected, true): | ||
truePos = 0 | ||
for className in detected: | ||
if className in true: | ||
truePos += 1 | ||
|
||
if len(detected) == 0: | ||
return 0 | ||
|
||
return truePos / len(detected) | ||
|
||
def f_mesure(detected, true, alpha): | ||
pre = precision(detected, true) | ||
rec = recall(detected, true) | ||
|
||
if (pre + rec) ==0: | ||
return 0 | ||
|
||
return pre*rec/(alpha*rec + (1-alpha)*pre) | ||
|
||
#return 2*pre*rec/(pre+rec) | ||
|
||
def getRescaledOccurences(systemName): | ||
historyFile = './data/history/class_changes/' + systemName + '.csv' | ||
systemClassesFile = './data/instances/classes/' + systemName + '.csv' | ||
|
||
classes = [] | ||
with open(systemClassesFile, 'rb') as csvfile: | ||
reader = csv.reader(csvfile, delimiter=';') | ||
|
||
for row in reader: | ||
classes.append(row[0]) | ||
|
||
reverseDictionnary = {classes[i]: i for i in range(len(classes))} | ||
changes = readHistory2(historyFile) | ||
|
||
|
||
data = [] | ||
#totalClasses = [] | ||
commit = [] | ||
commitNumber = changes[0]['Snapshot'] | ||
for i, change in enumerate(changes): | ||
if commitNumber != change['Snapshot']: | ||
data.append(set(commit)) | ||
#totalClasses = totalClasses + list(set(commit)) | ||
commit = [] | ||
commitNumber = change['Snapshot'] | ||
|
||
commit.append(change['Class']) | ||
|
||
if i == len(changes)-1: | ||
data.append(set(commit)) | ||
#totalClasses = totalClasses + list(set(commit)) | ||
|
||
#totalClasses = list(set(totalClasses)) | ||
#totalReverseDictionnary = {totalClasses[i]: i for i in xrange(len(totalClasses))} | ||
|
||
nbCommit = len(data) | ||
occurences = [0 for _ in range(len(classes))] | ||
#totalOccurences = [0 for _ in xrange(len(totalClasses))] | ||
for commit in data: | ||
for className in commit: | ||
#tidx = totalReverseDictionnary[className] | ||
#totalOccurences[tidx] = totalOccurences[tidx] + 1 | ||
if className in classes: | ||
idx = reverseDictionnary[className] | ||
occurences[idx] = occurences[idx] + 1 | ||
|
||
|
||
scaler = StandardScaler() | ||
scaler.fit(np.array(occurences).reshape(-1, 1)) | ||
rescaledOcc = scaler.transform(np.array(occurences).reshape(-1, 1)) | ||
|
||
return {classes[i]:rescaledOcc.reshape(-1)[i] for i in range(len(classes))} | ||
|
||
|
||
def blob(systemName, alpha): | ||
roDictionnary = getRescaledOccurences(systemName) | ||
|
||
smells = [] | ||
for className in roDictionnary: | ||
if roDictionnary[className] > alpha: | ||
smells.append(className) | ||
|
||
return smells | ||
|
||
|
||
|
||
def test(systemName, alpha): | ||
#print(systemName, alpha) | ||
trueFile = './data/labels/Blob/test/' + systemName + '.csv' | ||
systemClassesFile = './data/instances/classes/' + systemName + '.csv' | ||
|
||
#Get Smells occurences | ||
true = [] | ||
with open(trueFile, 'rb') as csvfile: | ||
reader = csv.reader(csvfile, delimiter=';') | ||
|
||
for row in reader: | ||
true.append(row[0]) | ||
|
||
detected = blob(systemName, alpha) | ||
|
||
pre = precision(detected, true) | ||
rec = recall(detected, true) | ||
f_m = f_mesure(detected, true, 0.5) | ||
|
||
#print('Precision :', "{0:.3f}".format(pre)) | ||
#print('Recall :', "{0:.3f}".format(rec)) | ||
#print('F-Mesure :', "{0:.3f}".format(f_m)) | ||
|
||
return f_m | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
||
'''for system in systems.hist: | ||
f_m = test(system['name'], 2.3) | ||
print(system['name'] + " : " + str(f_m))''' | ||
|
||
|
||
'''alphas = 0.4 + 0.1*np.array(range(50)) | ||
f_m = [] | ||
std = [] | ||
i = 0 | ||
for alpha in alphas: | ||
i = i + 1 | ||
print (str(i)) | ||
s = [] | ||
for system in systems.test: | ||
s.append(test(system['name'], alpha)) | ||
f_m.append(np.mean(s)) | ||
std.append(np.std(s)) | ||
plt.plot(alphas, f_m, 'ro', alphas, std) | ||
plt.show()''' | ||
|
||
|
||
''' | ||
s = 0 | ||
alphas = 1 + 0.1*np.array(range(60)) | ||
for system in systems.test: | ||
print(system['name']) | ||
bestAL = 0 | ||
bestFM = 0 | ||
f_m = 0 | ||
for alpha in alphas: | ||
f_m = test(system['name'], alpha) | ||
#print(f_m) | ||
if f_m == None: | ||
f_m = 0 | ||
if f_m > bestFM: | ||
bestFM = f_m | ||
bestAL = alpha | ||
f_m = test(system['name'], bestAL) | ||
print(f_m) | ||
print(bestAL) | ||
if f_m == None: | ||
f_m = 0 | ||
s = s + f_m | ||
print(s/len(systems.test))''' | ||
|
||
for system in systems.systems_git: | ||
roDictionnary = getRescaledOccurences(system['name']) | ||
|
||
print(roDictionnary) |
Binary file not shown.
Binary file renamed
BIN
+6 KB
...visors-detection-results/Ptidej/.DS_Store → ...etection/advisors/results/Decor/.DS_Store
Binary file not shown.
File renamed without changes.
Oops, something went wrong.