Skip to content

Commit

Permalink
Merge pull request #48 from Minjung-Baek/master
Browse files Browse the repository at this point in the history
Add feature for code Metrics
  • Loading branch information
Minjung-Baek committed Apr 2, 2016
2 parents e213a9e + 31839f5 commit a905680
Show file tree
Hide file tree
Showing 166 changed files with 40,351 additions and 585 deletions.
14 changes: 14 additions & 0 deletions project/dexter-server/codeMetric.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"codeMetricThreshold":{
"cc":{
"moderate":"25",
"caution":"50"
},
"sloc":"500",
"class":"20",
"method":"50"
},
"codeMetricQuantity":"3"
}
]
2 changes: 0 additions & 2 deletions project/dexter-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"start": "node server.js"
},
"dependencies": {
"bluebird": "^3.3.1",
"express": "3.5.1",
"json-bigint": "^0.1.4",
"line-reader": "^0.2.4",
Expand Down Expand Up @@ -34,7 +33,6 @@
"mocha": "^2.1.0",
"proxyquire": "^1.7.3",
"request": "^2.67.0",
"rewire": "^2.5.1",
"should": "^3.2.0",
"sinon": "^1.14.1"
}
Expand Down
16 changes: 16 additions & 0 deletions project/dexter-server/public/ccList/ccListApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var ccListApp = angular.module('ccListApp', ['ngRoute', 'ngGrid', 'ngAnimate', 'ui.bootstrap', 'ngSanitize']);

ccListApp.config(function($routeProvider){
$routeProvider
.when('/', {
controller: 'ccListCtrl',
templateUrl: 'ccListView.html'
})
.when("/:fileName/",{
controller: 'ccListCtrlForFile',
templateUrl: 'ccListViewForFile.html'
})
;
$routeProvider.otherwise({"redirectTo":"/"})

});
41 changes: 41 additions & 0 deletions project/dexter-server/public/ccList/ccListCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
ccListApp.controller('ccListCtrl',function($scope, $http, $location, $log){
"use strict";
var rowHeight = 28;
var headerHeight = 30;

$scope.ccListForFile = [];

$scope.isTooHigh = function(value){
return value > 20;
};

$http.get('/api/v1/codeMetrics/ccList', {
}).then(function(result){
if(result && result.data){
$scope.ccList=result.data.result;
}
}, function (results){
$log.info('Error code:' + results.status +';');
});

angular.element('#showLoading').hide();
$scope.ccListGridOptions = {
data: 'ccList',
multiSelect : false,
enablePaging: true,
showFooter: true,
enablePinning: true,
enableColumnResize: true,
enableColumnReordering: true,
enableRowSelection: true,
enableRowReordering: true,
totalServerItems: 'allCCListCount',
headerRowHeight: headerHeight,
rowHeight: rowHeight,
columnDefs:[
{field:"fileName", displayName:'File', width: 200, cellClass:'textAlignCenter'},
{field:"modulePath", displayName:'Module', cellClass:'textAlignLeft'},
{field:"metricValue", displayName:'CC', cellClass:'textAlignCenter', cellTemplate: '<div ng-class="{redBG: isTooHigh(row.getProperty(col.field))}"><div class="ngCellText">{{row.getProperty(col.field)}}</div></div>'}
]
};
})
39 changes: 39 additions & 0 deletions project/dexter-server/public/ccList/ccListCtrlForFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ccListApp.controller('ccListCtrlForFile',function($scope, $http, $location, $routeParams, $log){
"use strict";

var rowHeight = 28;
var headerHeight = 30;

$scope.ccListForFile = [];

$http.get('/api/v1/codeMetrics/ccList', {
}).then(function(result){
if(result && result.data){
$scope.ccListForFile=result.data.result;
}
}, function (results){
$log.info('Error code:' + results.status +';');
});

angular.element('#showLoading').hide();

$scope.ccListGridOptionsForFile = {
data: 'ccListForFile',
multiSelect : false,
enablePaging: true,
showFooter: true,
enablePinning: true,
enableColumnResize: true,
enableColumnReordering: true,
enableRowSelection: true,
enableRowReordering: true,
totalServerItems: 'allCCListCount',
headerRowHeight: headerHeight,
rowHeight: rowHeight,
columnDefs:[
{field:"fileName", displayName:'fileName', width: 150, cellClass:'textAlignCenter'},
{field:"modulePath", displayName:'modulePath', width: 300, cellClass:'textAlignLeft'},
{field:"metricValue", displayName:'CC Value', width: 100, cellClass:'textAlignCenter'}
]
};
})
67 changes: 67 additions & 0 deletions project/dexter-server/public/ccList/ccListView.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<font face="Tahoma, Lucida Grande, Helvetica, Arial, sans-serif">

<head>
<link rel="stylesheet" href="../defect/asset/css/prettify.css" />
<script src="../defect/asset/js/prettify.js"></script>
<script type="text/javascript">
$(function() {

window.prettyPrint && prettyPrint();
$('#id-check-horizontal').removeAttr('checked').on('click', function(){
$('#dt-list-1').toggleClass('dl-horizontal').prev().html(this.checked ? '&lt;dl class="dl-horizontal"&gt;' : '&lt;dl&gt;');
});

})
</script>
</head>
<div class = "ccListDiv">
<div class="row">
<div class="col-xs-6">
<div class="ccList" id="ccListGrid" ng-grid="ccListGridOptions">

</div>
</div>
<div class="col-xs-6">
<br><font size="5"><span class="glyphicon glyphicon-subtitles"></span>&nbsp;&nbsp;What is the Cyclomatic Complexity(CC) ?</font>
<br>
Cyclomatic complexity is a software metric (measurement), used to indicate the complexity of a program.<br>
It is a quantitative measure of the number of linearly independent paths through a program's code.
<br><br><br><font size="5"><span class="glyphicon glyphicon-tag"></span>&nbsp;&nbsp;How to REDUCE Cyclomatic Complexity(CC) ?</font>
<br>
1. Add private methods with meaningful names to remove duplicate code<br>
2. Add private methods with meaningful names to wrap any functionalities that are not directly related to business logic such as<br>
<br><br><font size="5"><span class="glyphicon glyphicon-check"></span>&nbsp;&nbsp;SAMPLE CODE </font>
<br><br>
<pre class="prettyprint linenums warning">
@ Bad Code
public ResponseObject generateResponseObject(String route) {
ResponseObject responseObject;
if (route.equals("time")) {
responseObject = new TimeResponse();
} else if (route.equals("echo")) {
responseObject = new EchoResponse();
} else if (route.equals("redirect")) {
responseObject = new RedirectResponse();
} else if (route.equals("file")) {
responseObject = new FileResponse();
} else {
responseObject = new FormResponse();
}
return responseObject;
}
</pre>

<br><br>
<pre class="prettyprint linenums correct">
@ Good Code
public ResponseObject generateResponseObject(HashMap<String, ResponseObject> routes) {
ResponseObject responseObject;
String route = httpRequestContent.get("route");
responseObject = routes.get(route);
return responseObject;
}
</pre>
</div>
</div>
</font>
61 changes: 61 additions & 0 deletions project/dexter-server/public/ccList/ccListViewForFile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<font face="Tahoma, Lucida Grande, Helvetica, Arial, sans-serif">

<head>
<link rel="stylesheet" href="../defect/asset/css/prettify.css" />
<script src="../defect/asset/js/prettify.js"></script>
<script type="text/javascript">
$(function() {

window.prettyPrint && prettyPrint();
$('#id-check-horizontal').removeAttr('checked').on('click', function(){
$('#dt-list-1').toggleClass('dl-horizontal').prev().html(this.checked ? '&lt;dl class="dl-horizontal"&gt;' : '&lt;dl&gt;');
});

})
</script>
</head>

<div class = "ccListDiv">
<h3 id="title">For Each File / {{fileNameForCC}}</h3>
<div class="row">

<div class="col-xs-6">
<div class="ccList" id="ccListGridForFile" ng-grid="ccListGridOptionsForFile">

</div>
</div>
<div class="col-xs-6">
<br><font size="5"><span class="glyphicon glyphicon-subtitles"></span>&nbsp;&nbsp;What is the Cyclomatic Complexity(CC) ?</font>
<br>
Cyclomatic complexity is a software metric (measurement), used to indicate the complexity of a program.<br>
It is a quantitative measure of the number of linearly independent paths through a program's code.
<br><br><br><font size="5"><span class="glyphicon glyphicon-tag"></span>&nbsp;&nbsp;How to REDUCE Cyclomatic Complexity(CC) ?</font>
<br>
1. Add private methods with meaningful names to remove duplicate code<br>
2. Add private methods with meaningful names to wrap any functionalities that are not directly related to business logic such as<br>
<br><br><font size="5"><span class="glyphicon glyphicon-check"></span>&nbsp;&nbsp;SAMPLE CODE </font>
<br><br>
<pre class="prettyprint linenums warning">
@ Bad Code
Map<String, Float> multipliers = new HashMap<String, Float>();
map.put("S", 60 * 60);
map.put("ms", 60 * 60 * 1000);
map.put("m", 60);
map.put("H", 1);
map.put("d", 1.0 / 24);
map.put("w", 1.0 / (24 * 7));
</pre>

<br><br>
<pre class="prettyprint linenums correct">
@ Good Code
Pattern foo = Pattern.compile(".*(\\d+)\\s*(\\w+)");
Matcher bar = foo.matcher(sValue);
if(bar.matches()) {
return (long) (Double.parseDouble(bar.group(1)) * multipliers.get(bar.group(2);
}
</pre>
</div>
</div>
</font>
58 changes: 58 additions & 0 deletions project/dexter-server/public/ccList/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html ng-app="ccListApp">
<head>
<meta charset="UTF-8">
<title id = "indexAdminTitle">ccListApp</title>
<link href="../css/jq/jquery-ui-1.9.2.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<link rel="stylesheet" type="text/css" href="../css/ng/ng-table.min.css" />
<link rel="stylesheet" type="text/css" href="../css/ng/ng-table.css" />
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css" />

<link rel="stylesheet" type="text/css" href="../css/jq/layout-default.css" />
<link rel="stylesheet" type="text/css" href="../css/ng/ng-grid.min.css" />

<script src="../js/jq/jquery-1.11.1.min.js"></script>
<script src="../js/jq/jquery-ui-1.9.2.min.js"></script>
<script src="../js/jq/jquery.layout-latest.js"></script>
<script src="../js/ng/angular.min.js"></script>
<script src="../js/ng/angular-animate.min.js"></script>
<script src="../js/ng/angular-route.min.js"></script>
<script src="../js/ng/angular-resource.min.js"></script>
<script src="../js/ng/angular-sanitize.min.js"></script>
<script src="../js/ng/ng-grid-2.0.11.min.js"></script>
<script src="../js/ng/ui-bootstrap-tpls-0.11.0.min.js"></script>
<script src="../js/common.js"></script>

<script src="../js/bootstrap-button.js"></script>
<!--script src="../util/util/dexter-util.js"></script-->

<!--
* Sets this component properties.
*
* @public
* @function : checkBrowser
* @author [email protected]
*
* @detail description
* Dexter Web is supported below browser : [opera|chrome|safari|firefox|msie]
* If the developers are use another browser, we need to show the "/error/NotSupportedBrowser.html" page.
* @since 1.11.19
-->
<script>
checkBrowser();
$(document).ready(function(){
});
</script>
</head>
<body>
<div ng-include="'../header.html'"></div>
<div ng-view=""></div>
<div ng-include="'../footer.html'"></div>

<script src="ccListApp.js"></script>
<script src="ccListCtrl.js"></script>
<script src="ccListCtrlForFile.js"></script>

</body>
</html>
8 changes: 8 additions & 0 deletions project/dexter-server/public/classInfo/classInfoApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var classInfoApp = angular.module('classInfoApp', ['ngRoute', 'ngGrid', 'ngAnimate', 'ui.bootstrap', 'ngSanitize']);

classInfoApp.config(function($routeProvider){
$routeProvider.when('/', {
controller: 'classInfoCtrl',
templateUrl: 'classInfoView.html'
});
});
32 changes: 32 additions & 0 deletions project/dexter-server/public/classInfo/classInfoCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
classInfoApp.controller('classInfoCtrl',function($scope, $http, $location){
"use strict";
var rowHeight = 28;
var headerHeight = 30;

$scope.ccList = [
{id:'1'},
{id:'2'},
{id:'3'}
];

angular.element('#showLoading').hide();

$scope.classInfoGridOptions = {
data: 'ccList',
multiSelect : false,
enablePaging: true,
showFooter: true,
enablePinning: true,
enableColumnResize: true,
enableColumnReordering: true,
enableRowSelection: true,
enableRowReordering: true,
totalServerItems: 'allCCListCount',
headerRowHeight: headerHeight,
rowHeight: rowHeight,
columnDefs:[
{field:"id", displayName:'ID', width: 350, cellClass:'textAlignCenter'},
{field:"id", displayName:'ID2', width: 350, cellClass:'textAlignCenter'}
]
};
})
Loading

0 comments on commit a905680

Please sign in to comment.