|
1 |
| -# -*- coding:utf-8 -*- |
| 1 | +# -*- coding: utf-8 -*- |
2 | 2 |
|
3 |
| -def extract(): |
4 |
| - with open('a.csv', 'r') as file: |
5 |
| - d = file.readlines() |
| 3 | +import sys |
6 | 4 |
|
7 |
| - text = '' |
8 |
| - flag = False |
| 5 | +import warnings |
| 6 | +import pandas as pd |
| 7 | +from pandas import DataFrame |
9 | 8 |
|
10 |
| - last_effort = 0 |
| 9 | +sys.path.append('C:/Users/gzq-712/Desktop/Git/CLDP/') |
| 10 | +from src.models.glance import * |
| 11 | +from statistics import * |
11 | 12 |
|
12 |
| - for line in d: |
13 |
| - if '=' in line: |
14 |
| - last_name = line.split(' ')[-2] |
15 |
| - text += last_name + '\n' |
16 |
| - print(last_name) |
17 |
| - else: |
18 |
| - if flag: |
19 |
| - text += line |
20 |
| - flag = False |
21 |
| - else: |
22 |
| - flag = True |
| 13 | +# Ignore warning information |
| 14 | +warnings.filterwarnings('ignore') |
23 | 15 |
|
24 |
| - with open('r.csv', 'w') as file: |
25 |
| - file.write(text) |
| 16 | +# .05, .10, .15, .20, .25, .30, .35, .40, .45, .50, .55, .60, .65, .70, .55, .80, .85, .90, .95, 1 |
| 17 | +line_level_thresholds = [.05, .10, .15, .20, .25, .30, .35, .40, .45, .50, ] |
| 18 | +indicators = ['recall', 'far', 'ce', 'd2h', 'mcc', 'ifa', 'recall_20', 'ratio'] |
26 | 19 |
|
| 20 | +output_path = '../../result/Dis1/' |
| 21 | +make_path(output_path) |
27 | 22 |
|
28 |
| -def trans(): |
29 |
| - with open('r.csv', 'r') as file: |
30 |
| - data = file.readlines() |
31 | 23 |
|
32 |
| - text = '' |
33 |
| - last_name = data[0].strip() |
34 |
| - temp = '' |
35 |
| - for line in data[1:]: |
36 |
| - if '[' not in line: |
37 |
| - text += last_name + ',' + temp + '\n' |
38 |
| - last_name = line.strip() |
39 |
| - temp = '' |
40 |
| - else: |
41 |
| - temp += line.strip().replace('[', '').replace(']', '') + ', ' |
| 24 | +def select_model(file_level_classifier, line_level_threshold, train='', test=''): |
| 25 | + if file_level_classifier == 'MD': |
| 26 | + model = Glance_MD(train, test, line_threshold=line_level_threshold, test=True) |
| 27 | + elif file_level_classifier == 'EA': |
| 28 | + model = Glance_EA(train, test, line_threshold=line_level_threshold, test=True) |
| 29 | + else: |
| 30 | + model = Glance_LR(train, test, line_threshold=line_level_threshold, test=True) |
| 31 | + return model |
42 | 32 |
|
43 |
| - text += last_name + ',' + temp + '\n' |
44 | 33 |
|
45 |
| - with open('r2.csv', 'w') as file: |
46 |
| - file.write(text) |
| 34 | +def search_parameter_Glance(clf): |
| 35 | + for threshold in line_level_thresholds: |
| 36 | + for project, releases in get_project_releases_dict().items(): |
| 37 | + for i in range(len(releases) - 1): |
| 38 | + # 1. Loading data. train data index = i, test data index = i + 1 |
| 39 | + model = select_model(clf, threshold, releases[i], releases[i + 1]) |
| 40 | + |
| 41 | + print(f'========== {model.model_name} CR PREDICTION for {releases[i + 1]} =================='[:60]) |
| 42 | + model.file_level_prediction() |
| 43 | + model.analyze_file_level_result() |
| 44 | + |
| 45 | + model.line_level_prediction() |
| 46 | + model.analyze_line_level_result() |
| 47 | + |
| 48 | + |
| 49 | +def test_parameter(clf): |
| 50 | + print(f'======================== Glance {clf} ===========================') |
| 51 | + eva_method = [mean, median] |
| 52 | + |
| 53 | + for method in eva_method: |
| 54 | + # 水平展示的变化数据, 列名为阈值 |
| 55 | + summary_data_horizontal, summary_data_vertical = list(), dict() |
| 56 | + for indicator in indicators: |
| 57 | + detail_data, column_names, mean_list = dict(), list(), list() |
| 58 | + for threshold in line_level_thresholds: |
| 59 | + model = select_model(clf, threshold) |
| 60 | + column_names.append(model.model_name) |
| 61 | + detail_data[model.model_name] = list(pd.read_csv(model.line_level_evaluation_file)[indicator]) |
| 62 | + |
| 63 | + mean_list.append(round(method(detail_data[model.model_name]), 3)) |
| 64 | + |
| 65 | + summary_data_horizontal.append(mean_list) |
| 66 | + summary_data_vertical[indicator] = mean_list |
| 67 | + |
| 68 | + detail_result = DataFrame(detail_data, index=get_test_releases_list(), columns=column_names) |
| 69 | + |
| 70 | + make_path(f'{output_path}Glance-{clf}/') |
| 71 | + detail_result.to_csv(f'{output_path}Glance-{clf}/{method.__name__}-{indicator}.csv', index=True) |
| 72 | + |
| 73 | + # '5%', '10%', '15%', '20%', '25%', '30%', '35%', '40%', '45%', '50%', |
| 74 | + # '55%', '60%', '65%', '70%', '75%', '80%', '85%', '90%', '95%', '100%', |
| 75 | + threshold_indices = ['5%', '10%', '15%', '20%', '25%', '30%', '35%', '40%', '45%', '50%', ] |
| 76 | + summary_result = DataFrame(summary_data_horizontal, index=indicators, columns=threshold_indices) |
| 77 | + summary_result.to_csv(f'{output_path}Dis1-summary-{method.__name__}-Glance-{clf}-horizontal.csv', index=True) |
| 78 | + summary_result = DataFrame(summary_data_vertical, index=threshold_indices, columns=indicators) |
| 79 | + summary_result.to_csv(f'{output_path}Dis1-summary-{method.__name__}-Glance-{clf}-vertical.csv', index=True) |
47 | 80 |
|
48 | 81 |
|
49 | 82 | if __name__ == '__main__':
|
50 |
| - trans() |
| 83 | + # |
| 84 | + file_level_classifiers = ['MD', 'EA', 'LR'] |
| 85 | + for classifier in file_level_classifiers: |
| 86 | + # search_parameter_Glance(classifier) |
| 87 | + test_parameter(classifier) |
| 88 | + pass |
| 89 | + pass |
0 commit comments