Skip to content

Commit

Permalink
Major restructuring in the main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
m-zakeri committed May 26, 2022
1 parent c355a31 commit 3d5c51a
Show file tree
Hide file tree
Showing 177 changed files with 1,236 additions and 1,260 deletions.
7 changes: 3 additions & 4 deletions codart/codart_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
# from gen.java9.Java9_v2Parser import Java9_v2Parser # Old slow grammar parser
# from java9speedy.parser import sa_java9_v2 # Old slow grammar enhanced by CPP backend

from gen.javaLabeled.JavaLexer import JavaLexer # Java8 grammar efficient lexer
from gen.javaLabeled.JavaParserLabeled import JavaParserLabeled # Java8 grammar efficient parser labeled
from codart.gen.javaLabeled.JavaLexer import JavaLexer # Java8 grammar efficient lexer
from codart.gen.javaLabeled.JavaParserLabeled import JavaParserLabeled # Java8 grammar efficient parser labeled

# Import refactorings listeners
from refactorings.encapsulate_field import EncapsulateFiledRefactoringListener # CodART first refactoring :)
from refactorings.extract_class import ExtractClassRefactoringListener
from codart.refactorings.encapsulate_field import EncapsulateFiledRefactoringListener # CodART first refactoring :)


def main(args):
Expand Down
24 changes: 23 additions & 1 deletion sbse/config.py → codart/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'jvlt-1.3.2', # 10
'tabula-java', # 11
'JHotDraw-7.0.6', # 12
'jhotdraw-6.0b1', # 13
],

# Understand DB Path
Expand Down Expand Up @@ -82,6 +83,8 @@
'tabula-java.und',
# 'JHotDraw-7.0.6.udb', # 12
'JHotDraw-7.0.6.und', # 12
# 'jhotdraw-6.0b1.udb', # 13
'jhotdraw-6.0b1.und', # 13
],

# CSV files path containing code smells identified by JDeodorant
Expand All @@ -99,6 +102,7 @@
'jVLT-1.3.2/Long-Method2_jvlt-1.3.2.csv',
'tabula-java/fake.csv',
'JHotDraw-7.0.6/Long-Method2_JHotDraw-7.0.6.csv',
'jhotdraw-6.0b1/Long-Method2_jhotdraw-6.0b1.csv',
],

'FEATURE_ENVY': [
Expand All @@ -115,6 +119,7 @@
'jVLT-1.3.2/Feature-Envy_jvlt-1.3.2.csv',
'tabula-java/Feature-Envy-Tabula-v1.0.6.csv',
'JHotDraw-7.0.6/Featuer-Envy2_JHotDraw-7.0.6.csv',
'jhotdraw-6.0b1/Featuer-Envy2_jhotdraw-6.0b1.csv',
],

'GOD_CLASS': [
Expand All @@ -130,7 +135,8 @@
'JSON20201115/God-Class_JASON-20201115.csv',
'jVLT-1.3.2/God-Class_jvlt-1.3.2.csv',
'tabula-java/God-Class-Tabula-v1.0.6.csv',
'JHotDraw-7.0.6/God-Class_JHotDraw-7.0.6.csv'
'JHotDraw-7.0.6/God-Class_JHotDraw-7.0.6.csv',
'jhotdraw-6.0b1/God-Class_jhotdraw-6.0b1.csv',
],
}

Expand Down Expand Up @@ -353,6 +359,22 @@
'TEST': 1., # Obtained by testability_prediction2
'TEST3': 1. # Obtained by testability_prediction3
},
"jhotdraw-6.0b1": { # 13
'ANA': 1.,
'CAMC': 1.,
'CIS': 1.,
'DAM': 1.,
'DCC': 1.,
'DSC': 1.,
'MFA': 1.,
'MOA': 1.,
'NOH': 1.,
'NOM': 1.,
'NOP': 1.,
'MODULE': 1.,
'TEST': 1., # Obtained by testability_prediction2
'TEST3': 1. # Obtained by testability_prediction3
},
}

CURRENT_METRICS = INITIAL_METRICS.get(PROJECT_NAME)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,33 @@
To be used in CodART project
"""
import multiprocessing

__version__ = '0.4.0'
__author__ = 'Morteza'

import sys
import os
import subprocess
import threading
from collections import Counter
from functools import wraps
import warnings
from deprecated import deprecated

import re
import math

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy import stats

from sklearn import preprocessing
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2, f_classif
from sklearn.feature_selection import f_classif
from sklearn.decomposition import PCA
from sklearn.model_selection import StratifiedShuffleSplit, train_test_split
from sklearn.model_selection import train_test_split
from sklearn.neighbors import LocalOutlierFactor
from sklearn.ensemble import IsolationForest
from imblearn.combine import SMOTEENN, SMOTETomek
from imblearn.over_sampling import SMOTE, ADASYN

# https://scitools.com/support/python-api/
# Python 3.8 and newer require the user add a call to os.add_dll_directory(“SciTools/bin/“
# os.add_dll_directory('C:/Program Files/SciTools/bin/pc-win64')
sys.path.insert(0, 'D:/program files/scitools/bin/pc-win64/python')
# sys.path.insert(0, 'D:/program files/scitools/bin/pc-win64/python')
try:
import understand
except ModuleNotFoundError:
Expand All @@ -47,13 +42,7 @@

from . import metrics_names
from metrics_coverability import UnderstandUtility
from metrics.metrics_jcode_odor import JCodeOdorMetric
from metrics.source_code_metrics import *
import metrics.metrics_names


__version__ = '0.4.0'
__author__ = 'Morteza'
from codart.metrics.metrics_jcode_odor import JCodeOdorMetric


def check_compute_metrics_by_class_list(project_name: str = None, database=None, class_list=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def NMO(cls, class_name):
@classmethod
def NIM(cls, class_name):
declared_methods = 0 if class_name.metric(['CountDeclMethod'])['CountDeclMethod'] is None else \
class_name.metric(['CountDeclMethod'])['CountDeclMethod']
class_name.metric(['CountDeclMethod'])['CountDeclMethod']
all_methods = 0 if class_name.metric(['CountDeclMethodAll'])['CountDeclMethodAll'] is None else \
class_name.metric(['CountDeclMethodAll'])['CountDeclMethodAll']
class_name.metric(['CountDeclMethodAll'])['CountDeclMethodAll']
return all_methods - declared_methods

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
except ImportError as e:
print(e)

from metrics.metrics_coverability import UnderstandUtility
from codart.metrics.metrics_coverability import UnderstandUtility


class JCodeOdorMetric:
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions metrics/modularity.py → codart/metrics/modularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import os
import re
import time
from collections import defaultdict

import pandas
Expand All @@ -31,7 +30,7 @@

import understand

from sbse import config
from codart import config
from codart.utility.directory_utils import export_understand_dependencies_csv


Expand Down
2 changes: 1 addition & 1 deletion metrics/qmood.py → codart/metrics/qmood.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import understand as und

from sbse import config
from codart import config


def divide_by_initial_value(func):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
"""

__version__ = '0.1.1'
__version__ = '0.1.2'
__author__ = 'Morteza Zakeri'

import math
import os
import warnings

import joblib
from joblib import Parallel, delayed
import numpy as np
import pandas as pd
from joblib import Parallel, delayed, wrap_non_picklable_objects


try:
import understand as und
Expand All @@ -31,11 +32,9 @@
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import QuantileTransformer

import metrics
from metrics import metrics_names
from metrics.metrics_jcode_odor import JCodeOdorMetric
from metrics.metrics_coverability import UnderstandUtility

from codart.metrics.metrics_jcode_odor import JCodeOdorMetric
from codart.metrics.metrics_coverability import UnderstandUtility
from codart.metrics import metrics_names

# patch_sklearn()

Expand All @@ -52,19 +51,19 @@ class TestabilityMetrics:

@classmethod
def get_class_ordinary_metrics_names(cls) -> list:
return metrics.metrics_names.class_ordinary_metrics_names
return metrics_names.class_ordinary_metrics_names

@classmethod
def get_class_lexicon_metrics_names(cls) -> list:
return metrics.metrics_names.class_lexicon_metrics_names
return metrics_names.class_lexicon_metrics_names

@classmethod
def get_package_metrics_names(cls) -> list:
return metrics.metrics_names.package_metrics_names
return metrics_names.package_metrics_names

@classmethod
def get_project_metrics_names(cls) -> list:
return metrics.metrics_names.project_metrics_names
return metrics_names.project_metrics_names

@classmethod
def get_all_metrics_names(cls) -> list:
Expand Down Expand Up @@ -92,13 +91,13 @@ def get_all_metrics_names(cls) -> list:
@classmethod
def get_all_primary_metrics_names(cls) -> list:
primary_metrics_names = list()
for metric_name in metrics.metrics_names.project_metrics_names_primary:
for metric_name in metrics_names.project_metrics_names_primary:
primary_metrics_names.append('PJ_' + metric_name)
for metric_name in metrics.metrics_names.package_metrics_names_primary:
for metric_name in metrics_names.package_metrics_names_primary:
primary_metrics_names.append('PK_' + metric_name)
for metric_name in metrics.metrics_names.class_ordinary_metrics_names_primary:
for metric_name in metrics_names.class_ordinary_metrics_names_primary:
primary_metrics_names.append('CSORD_' + metric_name)
for metric_name in metrics.metrics_names.class_lexicon_metrics_names:
for metric_name in metrics_names.class_lexicon_metrics_names:
primary_metrics_names.append('CSLEX_' + metric_name)
return primary_metrics_names

Expand Down Expand Up @@ -497,7 +496,7 @@ def compute_java_class_metrics2(cls, db=None, entity=None):
class_metrics.update({'FANIN': j_code_odor_metric.FANIN(db=db, class_entity=entity)})
class_metrics.update({'FANOUT': j_code_odor_metric.FANOUT(db=db, class_entity=entity)})

class_metrics.update({'ATFD': UnderstandUtility.ATFD(db=db, class_entity=entity)}) ### not implement
class_metrics.update({'ATFD': UnderstandUtility.ATFD(db=db, class_entity=entity)}) # Not implemented

class_metrics.update({'CFNAMM': j_code_odor_metric.CFNAMM_Class(class_name=entity)})
class_metrics.update({'DAC': UnderstandUtility.get_data_abstraction_coupling(db=db, class_entity=entity)})
Expand Down Expand Up @@ -735,8 +734,9 @@ def compute_java_package_metrics(cls, db=None, class_name: str = None):
package_metrics.update({'SDLineCodeDecl': np.std(pk_loc_decl_list)})
package_metrics.update({'SDLineCodeExe': np.std(pk_loc_exe_list)})
except:
raise TypeError('Error happen when compute packege metric for class "{0}" and list "{1}"'.format(class_name,
pk_loc_decl_list))
raise TypeError(
f'Error happen when compute packege metric for class "{class_name}" and list "{pk_loc_decl_list}"'
)

# 2.2 PKNOS (15)
pk_stmt_list = list()
Expand Down Expand Up @@ -1161,7 +1161,7 @@ def compute_metrics_for_single_class(cls, class_name, und_path, result_csv):
all_class_metrics_value.append(one_class_metrics_value)
columns = ['Class']
columns.extend(TestabilityMetrics.get_all_metrics_names())
columns2 = [metrics.metrics_names.metric_map[c_] for c_ in columns[:-1]]
columns2 = [metrics_names.metric_map[c_] for c_ in columns[:-1]]
columns2.append('NOCLINFILE')
df = pd.DataFrame(data=all_class_metrics_value, columns=columns2)
df.drop(columns=['NOCLINFILE'], inplace=True)
Expand Down Expand Up @@ -1237,8 +1237,8 @@ def main(project_path, initial_value=1.0):
# classes_longnames_list = p.extract_project_classes(db=db)
df = p.compute_metrics_by_class_list(project_path, n_jobs=7) # n_job must be set to number of CPU cores
# db.close()
model = TestabilityModel(df_path=r'../metrics/data_model/DS07012.csv')
testability_ = model.inference(model_path='../metrics/data_model/VR1_DS1.joblib', df_predict_data=df)
model = TestabilityModel(df_path=r'data_model/DS07012.csv')
testability_ = model.inference(model_path='/data_model/VR1_DS1.joblib', df_predict_data=df)
# print('testability=', testability_)
return testability_ / initial_value

Expand Down
Loading

0 comments on commit 3d5c51a

Please sign in to comment.