Skip to content

Commit

Permalink
Add bug path length column to Bug overview
Browse files Browse the repository at this point in the history
Add bug path length column to `Bug overview` table to indicate how long the
report path is.
  • Loading branch information
csordasmarton committed Dec 11, 2017
1 parent aa2631a commit 52589bf
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 17 deletions.
6 changes: 4 additions & 2 deletions api/v6/report_server.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ enum SortType {
CHECKER_NAME,
SEVERITY,
REVIEW_STATUS,
DETECTION_STATUS
DETECTION_STATUS,
BUG_PATH_LENGTH
}


Expand Down Expand Up @@ -156,7 +157,8 @@ struct ReportData {
9: i64 column, // column number of the report main section (not part of the path).
10: Severity severity, // Checker severity.
11: ReviewData reviewData, // Bug review status information.
12: DetectionStatus detectionStatus // State of the bug (see the enum constant values).
12: DetectionStatus detectionStatus, // State of the bug (see the enum constant values).
13: i64 bugPathLength, // Length of the bug path.
}
typedef list<ReportData> ReportDataList

Expand Down
41 changes: 41 additions & 0 deletions db_migrate/versions/7f759046740b_add_bug_path_length_to_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Add bug path length to reports
Revision ID: 7f759046740b
Revises: 4b38fa14c27b
Create Date: 2017-12-11 11:24:31.363284
"""

# revision identifiers, used by Alembic.
revision = '7f759046740b'
down_revision = '4b38fa14c27b'
branch_labels = None
depends_on = None


from alembic import op
import sqlalchemy as sa
from libcodechecker.server.database.run_db_model import *


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('reports',
sa.Column('bug_path_length', sa.Integer(), nullable=True))

bind = op.get_bind()
session = Session(bind=bind)

session.query(Report.id).update({'bug_path_length': (
select([func.count(BugPathEvent.report_id)])
.where(BugPathEvent.report_id == Report.id)
.group_by(BugPathEvent.report_id)
)}, synchronize_session=False)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('reports', 'bug_path_length')
# ### end Alembic commands ###
22 changes: 13 additions & 9 deletions libcodechecker/server/api/report_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ def get_sort_map(sort_types, is_unique=False):
sort_type_map = {
SortType.FILENAME: [(File.filepath, 'filepath'),
(Report.line, 'line')],
SortType.BUG_PATH_LENGTH: [
(Report.bug_path_length, 'bug_path_length')],
SortType.CHECKER_NAME: [(Report.checker_id, 'checker_id')],
SortType.SEVERITY: [(Report.severity, 'severity')],
SortType.REVIEW_STATUS: [(ReviewStatus.status, 'rw_status')],
Expand Down Expand Up @@ -766,8 +768,8 @@ def getRunResults(self, run_ids, limit, offset, sort_types,

q = session.query(Report.id, Report.bug_id,
Report.checker_message, Report.checker_id,
Report.severity, ReviewStatus, File.filename,
File.filepath) \
Report.severity, Report.bug_path_length,
ReviewStatus, File.filename, File.filepath) \
.outerjoin(File, Report.file_id == File.id) \
.outerjoin(ReviewStatus,
ReviewStatus.bug_hash == Report.bug_id) \
Expand All @@ -783,7 +785,7 @@ def getRunResults(self, run_ids, limit, offset, sort_types,
order_type_map)

for report_id, bug_id, checker_msg, checker, severity, \
status, filename, path in \
bug_path_length, status, filename, path in \
q:
review_data = create_review_data(status)

Expand All @@ -793,14 +795,15 @@ def getRunResults(self, run_ids, limit, offset, sort_types,
checkerMsg=checker_msg,
checkerId=checker,
severity=severity,
reviewData=review_data))
reviewData=review_data,
bugPathLength=bug_path_length))
else:
q = session.query(Report.run_id, Report.id, Report.file_id,
Report.line, Report.column,
Report.detection_status, Report.bug_id,
Report.checker_message, Report.checker_id,
Report.severity, ReviewStatus,
File.filepath) \
Report.severity, Report.bug_path_length,
ReviewStatus, File.filepath) \
.outerjoin(File, Report.file_id == File.id) \
.outerjoin(ReviewStatus,
ReviewStatus.bug_hash == Report.bug_id) \
Expand All @@ -821,8 +824,8 @@ def getRunResults(self, run_ids, limit, offset, sort_types,
q = q.limit(limit).offset(offset)

for run_id, report_id, file_id, line, column, d_status, \
bug_id, checker_msg, checker, severity, r_status, path \
in q:
bug_id, checker_msg, checker, severity, bug_path_length, \
r_status, path in q:

review_data = create_review_data(r_status)
results.append(
Expand All @@ -838,7 +841,8 @@ def getRunResults(self, run_ids, limit, offset, sort_types,
severity=severity,
reviewData=review_data,
detectionStatus=detection_status_enum(
d_status)))
d_status),
bugPathLength=bug_path_length))

return results

Expand Down
3 changes: 2 additions & 1 deletion libcodechecker/server/api/store_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ def addReport(storage_session,
main_section['location']['col'],
severity,
detection_status,
detection_time)
detection_time,
len(events))

session.add(report)
session.flush()
Expand Down
5 changes: 4 additions & 1 deletion libcodechecker/server/database/run_db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class Report(Base):
detected_at = Column(DateTime, nullable=False)
fixed_at = Column(DateTime)

bug_path_length = Column(Integer)

# Cascade delete might remove rows SQLAlchemy warns about this
# to remove warnings about already deleted items set this to False.
__mapper_args__ = {
Expand All @@ -219,7 +221,7 @@ class Report(Base):
# Priority/severity etc...
def __init__(self, run_id, bug_id, file_id, checker_message, checker_id,
checker_cat, bug_type, line, column, severity,
detection_status, detection_date):
detection_status, detection_date, bug_path_length):
self.run_id = run_id
self.file_id = file_id
self.bug_id = bug_id
Expand All @@ -232,6 +234,7 @@ def __init__(self, run_id, bug_id, file_id, checker_message, checker_id,
self.line = line
self.column = column
self.detected_at = detection_date
self.bug_path_length = bug_path_length


class Comment(Base):
Expand Down
27 changes: 23 additions & 4 deletions www/scripts/codecheckerviewer/ListOfBugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
define([
'dojo/_base/declare',
'dojo/dom-construct',
'dojo/dom-style',
'dojo/Deferred',
'dojo/data/ObjectStore',
'dojo/store/api/Store',
Expand All @@ -21,9 +22,9 @@ define([
'codechecker/RunHistory',
'codechecker/hashHelper',
'codechecker/util'],
function (declare, dom, Deferred, ObjectStore, Store, QueryResults, topic,
BorderContainer, TabContainer, Tooltip, DataGrid, BugViewer, BugFilterView,
RunHistory, hashHelper, util) {
function (declare, dom, style, Deferred, ObjectStore, Store, QueryResults,
topic, BorderContainer, TabContainer, Tooltip, DataGrid, BugViewer,
BugFilterView, RunHistory, hashHelper, util) {

function getRunData(runIds, runNames) {
var runFilter = new CC_OBJECTS.RunFilter();
Expand Down Expand Up @@ -183,6 +184,8 @@ function (declare, dom, Deferred, ObjectStore, Store, QueryResults, topic,
? CC_OBJECTS.SortType.DETECTION_STATUS
: sort.attribute === 'reviewStatus'
? CC_OBJECTS.SortType.REVIEW_STATUS
: sort.attribute === 'bugPathLength'
? CC_OBJECTS.SortType.BUG_PATH_LENGTH
: CC_OBJECTS.SortType.SEVERITY;
sortMode.ord
= sort.descending
Expand Down Expand Up @@ -239,6 +242,20 @@ function (declare, dom, Deferred, ObjectStore, Store, QueryResults, topic,
return '<span class="link">' + checkerId + '</span>';
}

function bugPathLengthFormatter(length) {
var d = dom.create('span', { innerHTML : length, class : 'length' });

// This value says that bug path length with this value and above are
// difficult to understand. The background color of these bug path lengths
// will be red.
var bugPathLengthLimit = 20;
var blendColor = util.generateRedGreenGradientColor(length,
bugPathLengthLimit, 0.5);
style.set(d, 'background-color', blendColor);

return d.outerHTML;
}

var ListOfBugsGrid = declare(DataGrid, {
constructor : function () {
var width = (100 / 5).toString() + '%';
Expand All @@ -248,6 +265,7 @@ function (declare, dom, Deferred, ObjectStore, Store, QueryResults, topic,
{ name : 'Message', field : 'checkerMsg', width : '100%', formatter : checkerMessageFormatter },
{ name : 'Checker name', field : 'checkerId', width : '50%', formatter: checkerNameFormatter },
{ name : 'Severity', field : 'severity', cellClasses : 'severity', width : '15%', formatter : severityFormatter },
{ name : 'Difficulty', field : 'bugPathLength', cellClasses : 'bug-path-length', width : '15%', formatter : bugPathLengthFormatter },
{ name : 'Review status', field : 'reviewStatus', cellClasses : 'review-status', width : '15%', formatter : reviewStatusFormatter },
{ name : 'Review comment', cellClasses : 'review-comment-message compact', field : 'reviewComment', width : '50%' },
{ name : 'Detection status', field : 'detectionStatus', cellClasses : 'detection-status', width : '15%', formatter : detectionStatusFormatter }
Expand All @@ -270,8 +288,9 @@ function (declare, dom, Deferred, ObjectStore, Store, QueryResults, topic,
canSort : function (inSortInfo) {
var cell = this.getCell(Math.abs(inSortInfo) - 1);

return cell.field === 'file' ||
return cell.field === 'bugPathLength' ||
cell.field === 'checkerId' ||
cell.field === 'file' ||
cell.field === 'severity' ||
cell.field === 'reviewStatus' ||
cell.field === 'detectionStatus';
Expand Down
8 changes: 8 additions & 0 deletions www/scripts/codecheckerviewer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ function (locale, dom, style, json) {
return dojo.blendColors(baseColour, new dojo.Color(blendColour), ratio);
},

generateRedGreenGradientColor : function (value, max, opacity) {
var red = (255 * value) / max;
var green = (255 * (max - value)) / max;
var blue = 0;
return 'rgba(' + parseInt(red) + ',' + parseInt(green) + ',' + blue
+ ',' + opacity + ')';
},

/**
* Converts the given number of seconds into a more human-readable
* 'hh:mm:ss' format.
Expand Down
9 changes: 9 additions & 0 deletions www/style/codecheckerviewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -1300,3 +1300,12 @@ span[class*="severity-"] {
color: #357ea7;
border: 1px solid #cad2da;
}

.bug-path-length {
position: relative;
}

.bug-path-length .length {
display: block;
text-align: center;
}

0 comments on commit 52589bf

Please sign in to comment.