chg: dev: title rank
This commit is contained in:
parent
c66b25d774
commit
d2c7ad0cc0
@ -440,16 +440,20 @@ def view_statistic():
|
|||||||
for tags in tag_set:
|
for tags in tag_set:
|
||||||
tag_items.extend([x.strip() for x in tags.split(',') if x.strip()])
|
tag_items.extend([x.strip() for x in tags.split(',') if x.strip()])
|
||||||
tag_counter = Counter(tag_items)
|
tag_counter = Counter(tag_items)
|
||||||
|
title_items = [x[2] for x in all_bookmarks]
|
||||||
|
title_counter = Counter(title_items)
|
||||||
statistic_datetime = arrow.now()
|
statistic_datetime = arrow.now()
|
||||||
STATISTIC_DATA = {
|
STATISTIC_DATA = {
|
||||||
'datetime': statistic_datetime,
|
'datetime': statistic_datetime,
|
||||||
'netloc': netloc,
|
'netloc': netloc,
|
||||||
'tag_counter': tag_counter,
|
'tag_counter': tag_counter,
|
||||||
|
'title_counter': title_counter,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
netloc = statistic_data['netloc']
|
netloc = statistic_data['netloc']
|
||||||
statistic_datetime = statistic_data['datetime']
|
statistic_datetime = statistic_data['datetime']
|
||||||
tag_counter = statistic_data['tag_counter']
|
tag_counter = statistic_data['tag_counter']
|
||||||
|
title_counter = statistic_data['title_counter']
|
||||||
|
|
||||||
netloc_counter = Counter(netloc)
|
netloc_counter = Counter(netloc)
|
||||||
unique_netloc_len = len(set(netloc))
|
unique_netloc_len = len(set(netloc))
|
||||||
@ -482,6 +486,19 @@ def view_statistic():
|
|||||||
most_common_tags = [
|
most_common_tags = [
|
||||||
[val[0], val[1], tag_colors[idx]] for idx, val in enumerate(most_common_tags)]
|
[val[0], val[1], tag_colors[idx]] for idx, val in enumerate(most_common_tags)]
|
||||||
|
|
||||||
|
unique_title_len = len(title_counter)
|
||||||
|
show_title_rank_table = False
|
||||||
|
if unique_title_len > len(colors):
|
||||||
|
max_title_item = len(colors)
|
||||||
|
title_colors = colors
|
||||||
|
show_title_rank_table = True
|
||||||
|
else:
|
||||||
|
title_colors = colors[:unique_title_len]
|
||||||
|
max_title_item = unique_title_len
|
||||||
|
most_common_titles = title_counter.most_common(max_title_item)
|
||||||
|
most_common_titles = [
|
||||||
|
[val[0], val[1], title_colors[idx]] for idx, val in enumerate(most_common_titles)]
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'bukuserver/statistic.html',
|
'bukuserver/statistic.html',
|
||||||
most_common_netlocs=most_common_netlocs,
|
most_common_netlocs=most_common_netlocs,
|
||||||
@ -490,6 +507,9 @@ def view_statistic():
|
|||||||
most_common_tags=most_common_tags,
|
most_common_tags=most_common_tags,
|
||||||
tag_counter=tag_counter,
|
tag_counter=tag_counter,
|
||||||
show_tag_rank_table=show_tag_rank_table,
|
show_tag_rank_table=show_tag_rank_table,
|
||||||
|
most_common_titles=most_common_titles,
|
||||||
|
title_counter=title_counter,
|
||||||
|
show_title_rank_table=show_title_rank_table,
|
||||||
datetime=statistic_datetime,
|
datetime=statistic_datetime,
|
||||||
datetime_text=statistic_datetime.humanize(arrow.now(), granularity='second'),
|
datetime_text=statistic_datetime.humanize(arrow.now(), granularity='second'),
|
||||||
)
|
)
|
||||||
|
@ -140,6 +140,81 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<h3>Title</h3>
|
||||||
|
|
||||||
|
{% if most_common_titles %}
|
||||||
|
<div class="col-md-6">
|
||||||
|
<canvas id="mostCommonTitleChart" width="500" height="500"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
{% if show_title_rank_table %}
|
||||||
|
<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#titleModal">
|
||||||
|
View all
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>Rank</th>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Number</th>
|
||||||
|
</tr>
|
||||||
|
{% for item, number, _ in most_common_titles %}
|
||||||
|
<tr>
|
||||||
|
<td>{{loop.index}}</td>
|
||||||
|
<td>
|
||||||
|
{% if item %}
|
||||||
|
<a href="{{url_for('search_bookmarks-html')}}?keywords-0={{item}}">{{item}}</a>
|
||||||
|
{% else %}
|
||||||
|
(No Title)
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>{{number}}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<span> No Title found.</span>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_title_rank_table %}
|
||||||
|
<div class="modal fade" id="titleModal" tabindex="-1" role="dialog">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
<h4 class="modal-title" id="myModalLabel">Title ranking</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<table class="table table-condensed">
|
||||||
|
<tr>
|
||||||
|
<th>Rank</th>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Number</th>
|
||||||
|
</tr>
|
||||||
|
{% for item, number in title_counter.most_common() %}
|
||||||
|
{% if number > 1 %}
|
||||||
|
<tr>
|
||||||
|
<td>{{loop.index}}</td>
|
||||||
|
<td style="word-break:break-all;">
|
||||||
|
{% if item %}
|
||||||
|
<a href="{{url_for('search_bookmarks-html')}}?keywords-0={{item}}">{{item}}</a>
|
||||||
|
{% else %}
|
||||||
|
<span class="btn btn-default" disabled="disabled">(No Title)</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="text-right">{{number}}</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var ctx = document.getElementById("mostCommonChart").getContext('2d');
|
var ctx = document.getElementById("mostCommonChart").getContext('2d');
|
||||||
var netlocChart = new Chart(ctx, {
|
var netlocChart = new Chart(ctx, {
|
||||||
@ -206,6 +281,47 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var ctx = document.getElementById("mostCommonTitleChart").getContext('2d');
|
||||||
|
var netlocChart = new Chart(ctx, {
|
||||||
|
type: 'pie',
|
||||||
|
data: {
|
||||||
|
datasets: [{
|
||||||
|
data: [
|
||||||
|
{% for val in most_common_titles %} {{val.1}}, {% endfor %}
|
||||||
|
],
|
||||||
|
backgroundColor: [
|
||||||
|
{% for val in most_common_titles %} "{{val.2}}", {% endfor %}
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
// These labels appear in the legend and in the tooltips when hovering different arcs
|
||||||
|
labels: [
|
||||||
|
{% for val in most_common_titles %} "{{val.0}}", {% endfor %}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
'onClick' : function (evt, item) {
|
||||||
|
var value = this.data.labels[item[0]._index];
|
||||||
|
var form = $('<form></form>');
|
||||||
|
|
||||||
|
form.attr("method", "get");
|
||||||
|
form.attr("action", "{{url_for('search_bookmarks-html')}}");
|
||||||
|
|
||||||
|
var field = $('<input></input>');
|
||||||
|
|
||||||
|
field.attr("type", "hidden");
|
||||||
|
field.attr("name", "keywords-0");
|
||||||
|
field.attr("value", value);
|
||||||
|
form.append(field);
|
||||||
|
|
||||||
|
// The form needs to be a part of the document in
|
||||||
|
// order for us to be able to submit it.
|
||||||
|
$(document.body).append(form);
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
netlocChart.canvas.parentNode.style.height = '128px';
|
netlocChart.canvas.parentNode.style.height = '128px';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user