Added graphs
This commit is contained in:
parent
ae8c7b7024
commit
e239eb7159
20
main.py
20
main.py
@ -43,8 +43,23 @@ def startpage():
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("select * from comics LIMIT " + str(config.DEFAULT_SEARCH_NUMBER) + ";")
|
||||
result = cursor.fetchall()
|
||||
|
||||
pub_list = ["Marvel", "DC Comics","Dark Horse Comics","Oni Press"]
|
||||
count = []
|
||||
for i in pub_list:
|
||||
cursor.execute("select count(*) from comics where Publisher = '" + i + "';")
|
||||
count.append(cursor.fetchone()[0])
|
||||
|
||||
cursor.execute("SELECT volume, COUNT(volume) FROM comics GROUP BY volume ORDER BY volume;")
|
||||
volume = cursor.fetchall()
|
||||
|
||||
x = []
|
||||
y = []
|
||||
for i in volume:
|
||||
x.append(i[0])
|
||||
y.append(i[1])
|
||||
conn.close()
|
||||
return render_template("start.html", result=result)
|
||||
return render_template("start.html", result=result,pub_list=pub_list,count=count,x=x,y=y)
|
||||
|
||||
@app.route("/healthz")
|
||||
def healthz():
|
||||
@ -194,7 +209,8 @@ def catalog(path=""):
|
||||
print("c: ")
|
||||
pprint(vars(c))
|
||||
for x in c.entries:
|
||||
pprint(vars(x))
|
||||
for y in x.links:
|
||||
pprint(y.href)
|
||||
print("------")
|
||||
elapsed = timeit.default_timer() - start_time
|
||||
print("-----------------------------------------------------------------------------------------------------------------------")
|
||||
|
@ -1,3 +1,61 @@
|
||||
<html>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
|
||||
<body>
|
||||
|
||||
<canvas id="myChart" style="width:100%;max-width:600px"></canvas>
|
||||
|
||||
<script>
|
||||
var xValues = {{ pub_list | safe }};
|
||||
var yValues = {{ count }};
|
||||
var barColors = ["red", "green","blue","orange"];
|
||||
|
||||
new Chart("myChart", {
|
||||
type: "bar",
|
||||
data: {
|
||||
labels: xValues,
|
||||
datasets: [{
|
||||
backgroundColor: barColors,
|
||||
data: yValues
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
legend: {display: false},
|
||||
title: {
|
||||
display: true,
|
||||
text: "Publishers"
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<canvas id="myChart3" style="width:100%;max-width:600px"></canvas>
|
||||
|
||||
|
||||
<script>
|
||||
var xValues = {{ x | safe }};
|
||||
var yValues = {{ y | safe }};
|
||||
|
||||
new Chart("myChart3", {
|
||||
type: "line",
|
||||
data: {
|
||||
labels: xValues,
|
||||
datasets: [{
|
||||
fill: false,
|
||||
backgroundColor: "rgba(0,0,255,1.0)",
|
||||
borderColor: "rgba(0,0,255,0.1)",
|
||||
data: yValues
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
legend: {display: false},
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<table id="comics">
|
||||
{% for i in result %}
|
||||
<tr>
|
||||
@ -7,3 +65,7 @@
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user