Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
limbra
limbra
Commits
cfc3102f
Commit
cfc3102f
authored
Feb 21, 2020
by
LE GAC Renaud
Browse files
Polish controller graphs and its views.
parent
b32b1d76
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
52 deletions
+54
-52
controllers/graphs.py
controllers/graphs.py
+16
-38
views/graphs/citations.html
views/graphs/citations.html
+26
-11
views/graphs/index.html
views/graphs/index.html
+6
-3
views/graphs/index.pdf
views/graphs/index.pdf
+6
-0
No files found.
controllers/graphs.py
View file @
cfc3102f
""" Controllers for building graphs using pandas library
"""
import
base64
import
io
from
citations_tools
import
(
PLOT_ALL
,
PLOT_PER_DOMAIN
,
PLOT_PER_PROJECT
,
...
...
@@ -21,7 +17,14 @@ from models.selector import YEAR_SUBMIT
def
citations
():
"""Return graphs showing citations
"""Generate figures with citations plots.
Returns:
dict:
* fig1 (matplotlib.Figure)
* fig2 (matplotlib.Figure)
* fig3 (matplotlib.Figure)
* fig4 (matplotlib.Figure)
"""
import
pandas
as
pd
...
...
@@ -142,25 +145,7 @@ def citations():
#
# rendering
#
dct
=
{}
buf1
=
io
.
BytesIO
()
fig1
.
savefig
(
buf1
,
format
=
"svg"
)
dct
[
"fig1"
]
=
base64
.
b64encode
(
buf1
.
getbuffer
()).
decode
(
"ascii"
)
buf2
=
io
.
BytesIO
()
fig2
.
savefig
(
buf2
,
format
=
"svg"
)
dct
[
"fig2"
]
=
base64
.
b64encode
(
buf2
.
getbuffer
()).
decode
(
"ascii"
)
buf3
=
io
.
BytesIO
()
fig3
.
savefig
(
buf3
,
format
=
"svg"
)
dct
[
"fig3"
]
=
base64
.
b64encode
(
buf3
.
getbuffer
()).
decode
(
"ascii"
)
buf4
=
io
.
BytesIO
()
fig4
.
savefig
(
buf4
,
format
=
"svg"
)
dct
[
"fig4"
]
=
base64
.
b64encode
(
buf4
.
getbuffer
()).
decode
(
"ascii"
)
return
dict
(
**
dct
)
return
dict
(
fig1
=
fig1
,
fig2
=
fig2
,
fig3
=
fig3
,
fig4
=
fig4
)
def
dashboard
():
...
...
@@ -168,6 +153,10 @@ def dashboard():
Cumulative distribution for the publications are shown for
the current year.
Returns:
dict:
* fig (matplotlib.Figure)
"""
current_year
=
request
.
now
.
year
dashboard_start
=
current
.
app
.
dashboard_start_year
...
...
@@ -219,12 +208,8 @@ def dashboard():
linechart
(
db
,
selector
,
target
=
ax2
,
title
=
title
)
# delegate the rendering to the view
buf
=
io
.
BytesIO
()
fig
.
savefig
(
buf
,
format
=
"svg"
)
data
=
base64
.
b64encode
(
buf
.
getbuffer
()).
decode
(
"ascii"
)
response
.
view
=
"graphs/index.html"
return
dict
(
data
=
data
)
return
dict
(
fig
=
fig
)
def
publications_versus_time
():
...
...
@@ -249,12 +234,5 @@ def publications_versus_time():
linechart
(
db
,
selector
,
target
=
ax
)
# delegate the rendering to the view
extension
=
request
.
extension
fmt
=
(
"svg"
if
extension
==
"html"
else
extension
)
buf
=
io
.
BytesIO
()
fig
.
savefig
(
buf
,
format
=
fmt
)
data
=
base64
.
b64encode
(
buf
.
getbuffer
()).
decode
(
"ascii"
)
response
.
view
=
"graphs/index.%s"
%
extension
return
dict
(
data
=
data
)
response
.
view
=
f
"graphs/index.
{
request
.
extension
}
"
return
dict
(
fig
=
fig
)
views/graphs/citations.html
View file @
cfc3102f
{{
#--------------------------------------------------------------------------
#
# The python controller return image as a string:
# - data (string)
# The python controller return matplotlib image(s)
#
#--------------------------------------------------------------------------
import base64
import io
import urllib.parse
# encode special character bo be used in the image URI
fig1 = urllib.parse.quote(fig1)
fig2 = urllib.parse.quote(fig2)
fig3 = urllib.parse.quote(fig3)
fig4 = urllib.parse.quote(fig4)
buf1 = io.BytesIO()
fig1.savefig(buf1, format="svg")
data1 = base64.b64encode(buf1.getbuffer()).decode("ascii")
data1 = urllib.parse.quote(data1)
buf2 = io.BytesIO()
fig2.savefig(buf2, format="svg")
data2 = base64.b64encode(buf2.getbuffer()).decode("ascii")
data2 = urllib.parse.quote(data2)
buf3 = io.BytesIO()
fig3.savefig(buf3, format="svg")
data3 = base64.b64encode(buf3.getbuffer()).decode("ascii")
data3 = urllib.parse.quote(data3)
buf4 = io.BytesIO()
fig4.savefig(buf4, format="svg")
data4 = base64.b64encode(buf4.getbuffer()).decode("ascii")
data4 = urllib.parse.quote(data4)
}}
...
...
@@ -19,7 +34,7 @@
1 General
</h2>
<img
src=
"data:image/svg+xml;base64,{{=
fig
1}}"
height=
400
>
<img
src=
"data:image/svg+xml;base64,{{=
data
1}}"
height=
400
>
<h2
class=
"dbui-h2"
style=
"margin-bottom: 0ex; font-variant: small-caps;"
>
2 Evolution of estimators as function of time
...
...
@@ -28,19 +43,19 @@
2.1 Total number of citations
</h2>
<img
src=
"data:image/svg+xml;base64,{{=
fig
2}}"
height=
400
>
<img
src=
"data:image/svg+xml;base64,{{=
data
2}}"
height=
400
>
<h2
class=
"dbui-h2"
style=
"margin-bottom: 0ex;margin-top: 0ex;"
>
2.2 Average number of citations per article
</h2>
<img
src=
"data:image/svg+xml;base64,{{=
fig
3}}"
height=
400
>
<img
src=
"data:image/svg+xml;base64,{{=
data
3}}"
height=
400
>
<h2
class=
"dbui-h2"
style=
"margin-bottom: 0ex;margin-top: 0ex;"
>
2.3 h-index
</h2>
<img
src=
"data:image/svg+xml;base64,{{=
fig
4}}"
height=
400
>
<img
src=
"data:image/svg+xml;base64,{{=
data
4}}"
height=
400
>
{{
from datetime import datetime
...
...
views/graphs/index.html
View file @
cfc3102f
{{
#--------------------------------------------------------------------------
#
# The python controller return image as a string:
# - data (string)
# The python controller return matplotlib.Image
#
#--------------------------------------------------------------------------
import base64
import io
import urllib.parse
# encode special charactier bo be used in the image URI
buf = io.BytesIO()
fig.savefig(buf, format="svg")
data = base64.b64encode(buf.getbuffer()).decode("ascii")
data = urllib.parse.quote(data)
}}
...
...
views/graphs/index.pdf
View file @
cfc3102f
{{
import base64
import io
buf = io.BytesIO()
fig.savefig(buf, format="pdf)
data = base64.b64encode(buf.getbuffer()).decode("ascii")
response.body = io.StringIO()
response.headers['Content-Type']='application/pdf'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment