Skip to content

Commit caa4fe3

Browse files
web-app: convert .svg figures to javascript plots (#966)
* web-app: convert .svg figures to javascript plots Signed-off-by: David Korczynski <[email protected]> * make modelling right Signed-off-by: David Korczynski <[email protected]> --------- Signed-off-by: David Korczynski <[email protected]>
1 parent 230e5ae commit caa4fe3

File tree

3 files changed

+137
-9
lines changed

3 files changed

+137
-9
lines changed

tools/web-fuzzing-introspection/app/site/models.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import datetime
16+
17+
def get_date_at_offset_as_str(day_offset=-1):
18+
datestr = (datetime.date.today() +
19+
datetime.timedelta(day_offset)).strftime("%Y-%m-%d")
20+
return datestr
21+
1522
class DBSummary:
1623
def __init__(self, all_projects, total_number_of_projects, total_fuzzers, total_functions, language_count):
1724
self.all_projects = all_projects
@@ -28,6 +35,26 @@ def __init__(self, name, language, fuzz_count, reach, runtime_cov):
2835
self.reach = reach
2936
self.runtime_cov = runtime_cov
3037

38+
# Line coverage history
39+
self.code_coverage_line_history = []
40+
for i in range(100):
41+
self.code_coverage_line_history.append((get_date_at_offset_as_str(i-100), i))
42+
43+
# Function coverage history
44+
self.code_coverage_functions_history = []
45+
for i in range(100):
46+
self.code_coverage_functions_history.append((get_date_at_offset_as_str(i-100), i*2))
47+
48+
# Static reachability history
49+
self.code_reachability_history = []
50+
for i in range(100):
51+
self.code_reachability_history.append((get_date_at_offset_as_str(i-100), i*1.5))
52+
53+
# Fuzzer count history
54+
self.fuzzer_count_history = []
55+
for i in range(100):
56+
self.fuzzer_count_history.append((get_date_at_offset_as_str(i-100), 3))
57+
3158
class Function:
3259
def __init__(self, name, project, is_reached=False, runtime_code_coverage = 32.4):
3360
self.name = name

tools/web-fuzzing-introspection/app/site/routes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def get_frontpage_summary_stats():
3535
db_summary = models.DBSummary(all_projects, total_number_of_projects, total_fuzzers, total_functions, language_count)
3636
return db_summary
3737

38-
3938
@site.route('/')
4039
def index():
4140
db_summary = get_frontpage_summary_stats()

tools/web-fuzzing-introspection/app/site/templates/project-profile.html

Lines changed: 110 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,35 @@ <h2>Project: <a href="#"> {{ project.name }}</a></h2>
4242
</div>
4343
</div>
4444
<!-- project profile table -->
45+
46+
4547
<div class="project__progress">
4648
<h2>Historical progression</h2>
4749
<div class="progress__graph">
4850
<!-- single graph -->
4951
<div class="single__graph">
52+
5053
<div class="graph__chart">
51-
<img src="{{url_for('static', filename='assets/img/progress-chart-1.svg')}}" alt="chart" />
54+
<div id="codeCoverageLinesOverTimePlot" style="width:100%;max-width:500px"></div>
5255
</div>
53-
<p>Code coverage (lines)</p>
5456
</div>
5557
<!-- single graph -->
5658
<div class="single__graph">
5759
<div class="graph__chart">
58-
<img src="{{url_for('static', filename='assets/img/progress-chart-2.svg')}}" alt="chart" />
60+
<div id="codeCoverageFunctionsOverTimePlot" style="width:100%;max-width:500px"></div>
5961
</div>
60-
<p>Code coverage (functions)</p>
6162
</div>
6263
<!-- single graph -->
6364
<div class="single__graph">
6465
<div class="graph__chart">
65-
<img src="{{url_for('static', filename='assets/img/progress-chart-3.svg')}}" alt="chart" />
66+
<div id="staticReachabilityOverTimePlot" style="width:100%;max-width:500px"></div>
6667
</div>
67-
<p>Static reachability</p>
6868
</div>
6969
<!-- single graph -->
7070
<div class="single__graph">
7171
<div class="graph__chart">
72-
<img src="{{url_for('static', filename='assets/img/progress-chart-4.svg')}}" alt="chart" />
72+
<div id="fuzzerCountOverTimePlot" style="width:100%;max-width:500px"></div>
7373
</div>
74-
<p>Fuzzer count</p>
7574
</div>
7675
</div>
7776
</div>
@@ -80,5 +79,108 @@ <h2>Historical progression</h2>
8079
</main>
8180
<!-- end main content -->
8281
<!-- footer -->
82+
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
83+
<script>
84+
85+
// Plot for code coverage in terms of lines over time
86+
const code_coverage_lines_x = [
87+
{% for x_cord, y_cord in project.code_coverage_line_history %}
88+
"{{ x_cord }}",
89+
{% endfor %}
90+
];
91+
const code_coverage_lines_y = [
92+
{% for x_cord, y_cord in project.code_coverage_line_history %}
93+
{{ y_cord }},
94+
{% endfor %}
95+
];
96+
const code_coverage_lines_data = [{
97+
x: code_coverage_lines_x,
98+
y: code_coverage_lines_y,
99+
mode:"lines"
100+
}];
101+
const code_coverage_lines_layout = {
102+
xaxis: {title: "Date"},
103+
yaxis: {title: "Coverage"},
104+
title: "Code Coverage (lines)",
105+
type: "scatter"
106+
};
107+
Plotly.newPlot("codeCoverageLinesOverTimePlot", code_coverage_lines_data, code_coverage_lines_layout);
108+
109+
110+
// Plot for code coverage in terms of functions over time
111+
const code_coverage_functions_x = [
112+
{% for x_cord, y_cord in project.code_coverage_functions_history %}
113+
"{{ x_cord }}",
114+
{% endfor %}
115+
];
116+
const code_coverage_functions_y = [
117+
{% for x_cord, y_cord in project.code_coverage_functions_history %}
118+
{{ y_cord }},
119+
{% endfor %}
120+
];
121+
const code_coverage_functions_data = [{
122+
x: code_coverage_functions_x,
123+
y: code_coverage_functions_y,
124+
mode:"lines"
125+
}];
126+
const code_coverage_functions_layout = {
127+
xaxis: {title: "Date"},
128+
yaxis: {title: "Coverage"},
129+
title: "Code Coverage (lines)",
130+
type: "scatter"
131+
};
132+
Plotly.newPlot("codeCoverageFunctionsOverTimePlot", code_coverage_functions_data, code_coverage_functions_layout);
133+
134+
135+
// Plot for static rachability over time
136+
const code_reachability_x = [
137+
{% for x_cord, y_cord in project.code_reachability_history %}
138+
"{{ x_cord }}",
139+
{% endfor %}
140+
];
141+
const code_reachability_y = [
142+
{% for x_cord, y_cord in project.code_reachability_history %}
143+
{{ y_cord }},
144+
{% endfor %}
145+
];
146+
const code_reachability_data = [{
147+
x: code_reachability_x,
148+
y: code_reachability_y,
149+
mode:"lines"
150+
}];
151+
const code_reachability_layout = {
152+
xaxis: {title: "Date"},
153+
yaxis: {title: "Coverage"},
154+
title: "Code Coverage (lines)",
155+
type: "scatter"
156+
};
157+
Plotly.newPlot("staticReachabilityOverTimePlot", code_reachability_data, code_reachability_layout);
158+
159+
160+
// Plot for fuzzer counter over time
161+
const fuzzer_count_x = [
162+
{% for x_cord, y_cord in project.fuzzer_count_history %}
163+
"{{ x_cord }}",
164+
{% endfor %}
165+
];
166+
const fuzzer_count_y = [
167+
{% for x_cord, y_cord in project.fuzzer_count_history %}
168+
{{ y_cord }},
169+
{% endfor %}
170+
];
171+
const fuzzer_count_data = [{
172+
x: fuzzer_count_x,
173+
y: fuzzer_count_y,
174+
mode:"lines"
175+
}];
176+
const fuzzer_count_layout = {
177+
xaxis: {title: "Date"},
178+
yaxis: {title: "Coverage"},
179+
title: "Code Coverage (lines)",
180+
type: "scatter"
181+
};
182+
Plotly.newPlot("fuzzerCountOverTimePlot", fuzzer_count_data, fuzzer_count_layout);
183+
184+
</script>
83185

84186
{% endblock %}

0 commit comments

Comments
 (0)