Skip to content

Commit

Permalink
chg: [chat viewer] add languages stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Feb 28, 2025
1 parent ff6a42f commit 02d022f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
10 changes: 10 additions & 0 deletions bin/lib/chats_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,16 @@ def api_get_nb_year_messages(chat_type, chat_instance_uuid, chat_id, year):
nb = [[date, value] for date, value in nb.items()]
return {'max': nb_max, 'nb': nb, 'year': year}, 200

def api_get_languages_stats(chat_type, chat_instance_uuid, chat_id):
chat = get_obj_chat(chat_type, chat_instance_uuid, chat_id)
if not chat.exists():
return {"status": "error", "reason": "Unknown chat"}, 404
stats = chat.get_obj_language_stats()
langs = []
for stat in stats:
langs.append({'name': Language.get_language_from_iso(stat[0]), 'value': int(stat[1])})
return langs


def api_get_chat_participants(chat_type, chat_subtype, chat_id):
if chat_type not in ['chat', 'chat-subchannel', 'chat-thread']:
Expand Down
6 changes: 4 additions & 2 deletions var/www/blueprints/chats_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ def chats_explorer_chat():
else:
chat = chat[0]
languages = Language.get_translation_languages()
languages_stats = chats_viewer.api_get_languages_stats('chat', instance_uuid, chat_id)
return render_template('chat_viewer.html', chat=chat, bootstrap_label=bootstrap_label,
ail_tags=Tag.get_modal_add_tags(chat['id'], chat['type'], chat['subtype']),
message_id=message_id,
message_id=message_id, languages_stats=languages_stats,
translation_languages=languages, translation_target=target)

@chats_explorer.route("chats/explorer/messages/stats/week", methods=['GET'])
Expand Down Expand Up @@ -179,9 +180,10 @@ def objects_subchannel_messages():
else:
subchannel = subchannel[0]
languages = Language.get_translation_languages()
languages_stats = chats_viewer.api_get_languages_stats('chat-subchannel', instance_uuid, subchannel_id)
return render_template('SubChannelMessages.html', subchannel=subchannel,
ail_tags=Tag.get_modal_add_tags(subchannel['id'], subchannel['type'], subchannel['subtype']),
message_id=message_id,
message_id=message_id, languages_stats=languages_stats,
bootstrap_label=bootstrap_label, translation_languages=languages, translation_target=target)

@chats_explorer.route("/chats/explorer/thread", methods=['GET'])
Expand Down
5 changes: 5 additions & 0 deletions var/www/templates/chats_explorer/SubChannelMessages.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<script src="{{ url_for('static', filename='js/d3.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/d3/sparklines.js')}}"></script>
<script src="{{ url_for('static', filename='js/d3/heatmap_week_hour.js')}}"></script>
<script src="{{ url_for('static', filename='js/echarts.min.js')}}"></script>

<style>
.chat-message-left,
Expand Down Expand Up @@ -111,6 +112,10 @@ <h5 class="mx-5 text-secondary">This week:</h5>
</div>
</div>

<h5>Languages:</h5>
<div id="langpie" style="width: 100%;height: 300px;"></div>
{% include 'chats_explorer/block_language_stats.html' %}

<span class="mt-3">
{% include 'objects/image/block_blur_img_slider.html' %}
</span>
Expand Down
46 changes: 46 additions & 0 deletions var/www/templates/chats_explorer/block_language_stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script>
var langPieChart = echarts.init(document.getElementById('langpie'));
window.addEventListener('resize', function() {
langPieChart.resize();
});
var optionlangpie;
optionlangpie = {
tooltip: {
trigger: 'item'
},
legend: {
top: '5%',
left: 'center'
},
series: [
{
name: 'Languages',
type: 'pie',
radius: ['40%', '70%'],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: false,
position: 'center'
},
emphasis: {
label: {
show: true,
fontSize: 40,
fontWeight: 'bold'
}
},
labelLine: {
show: false
},
data: {{ languages_stats|tojson }}
}
]
};
langPieChart.setOption(optionlangpie);

</script>
7 changes: 5 additions & 2 deletions var/www/templates/chats_explorer/chat_viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ <h5>Messages by year:</h5>
<div>
<div class="row">
<div class="col-12 col-lg-11">
<div id="heatmapyear" style="width: 100%;height: 300px;"></div>
<div id="heatmapyear" style="width: 100%;height: 250px;"></div>
</div>
<div class="col-12 col-lg-1">
{% for year in chat['years'] %}
Expand All @@ -127,6 +127,10 @@ <h5>Messages by year:</h5>
</div>
</div>

<h5>Languages:</h5>
<div id="langpie" style="width: 100%;height: 300px;"></div>
{% include 'chats_explorer/block_language_stats.html' %}

{% with translate_url=url_for('chats_explorer.chats_explorer_chat', subtype=chat['subtype']), obj_id=chat['id'], pagination=chat['pagination'] %}
{% include 'chats_explorer/block_translation.html' %}
{% endwith %}
Expand Down Expand Up @@ -287,7 +291,6 @@ <h5>Messages by year:</h5>
}
);
}

</script>


Expand Down

0 comments on commit 02d022f

Please sign in to comment.