mirror of
https://github.com/ail-project/ail-framework.git
synced 2025-01-30 22:16:16 +00:00
chg: [chat viewer] heatmap messages, add year selector
This commit is contained in:
parent
9a388dc9cb
commit
d21ace8f66
3 changed files with 29 additions and 13 deletions
|
@ -762,7 +762,7 @@ def api_get_chats_selector():
|
||||||
selector.append({'id': chat.get_global_id(), 'name': f'{chat.get_chat_instance()}: {chat.get_label()}'})
|
selector.append({'id': chat.get_global_id(), 'name': f'{chat.get_chat_instance()}: {chat.get_label()}'})
|
||||||
return selector
|
return selector
|
||||||
|
|
||||||
def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, page=-1, messages=True):
|
def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, page=-1, messages=True, heatmap=False):
|
||||||
chat = Chats.Chat(chat_id, chat_instance_uuid)
|
chat = Chats.Chat(chat_id, chat_instance_uuid)
|
||||||
if not chat.exists():
|
if not chat.exists():
|
||||||
return {"status": "error", "reason": "Unknown chat"}, 404
|
return {"status": "error", "reason": "Unknown chat"}, 404
|
||||||
|
@ -778,6 +778,8 @@ def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, pa
|
||||||
if messages:
|
if messages:
|
||||||
meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page)
|
meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page)
|
||||||
meta['messages'] = get_chat_object_messages_meta(meta['messages'])
|
meta['messages'] = get_chat_object_messages_meta(meta['messages'])
|
||||||
|
if heatmap:
|
||||||
|
meta['years'] = chat.get_message_years()
|
||||||
return meta, 200
|
return meta, 200
|
||||||
|
|
||||||
def api_get_nb_message_by_week(chat_type, chat_instance_uuid, chat_id):
|
def api_get_nb_message_by_week(chat_type, chat_instance_uuid, chat_id):
|
||||||
|
@ -805,7 +807,7 @@ def api_get_nb_year_messages(chat_type, chat_instance_uuid, chat_id, year):
|
||||||
year = datetime.now().year
|
year = datetime.now().year
|
||||||
nb_max, nb = chat.get_nb_year_messages(year)
|
nb_max, nb = chat.get_nb_year_messages(year)
|
||||||
nb = [[date, value] for date, value in nb.items()]
|
nb = [[date, value] for date, value in nb.items()]
|
||||||
return {'max': nb_max, 'nb': nb}, 200
|
return {'max': nb_max, 'nb': nb, 'year': year}, 200
|
||||||
|
|
||||||
|
|
||||||
def api_get_chat_participants(chat_type, chat_subtype, chat_id):
|
def api_get_chat_participants(chat_type, chat_subtype, chat_id):
|
||||||
|
|
|
@ -93,7 +93,7 @@ def chats_explorer_chat():
|
||||||
target = None
|
target = None
|
||||||
nb_messages = request.args.get('nb')
|
nb_messages = request.args.get('nb')
|
||||||
page = request.args.get('page')
|
page = request.args.get('page')
|
||||||
chat = chats_viewer.api_get_chat(chat_id, instance_uuid, translation_target=target, nb=nb_messages, page=page)
|
chat = chats_viewer.api_get_chat(chat_id, instance_uuid, translation_target=target, nb=nb_messages, page=page, heatmap=True)
|
||||||
if chat[1] != 200:
|
if chat[1] != 200:
|
||||||
return create_json_response(chat[0], chat[1])
|
return create_json_response(chat[0], chat[1])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -114,7 +114,18 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<h5>Messages by year:</h5>
|
<h5>Messages by year:</h5>
|
||||||
<div id="heatmapyear" style="width: 100%;height: 300px;"></div>
|
<div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 col-lg-11">
|
||||||
|
<div id="heatmapyear" style="width: 100%;height: 300px;"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-lg-1">
|
||||||
|
{% for year in chat['years'] %}
|
||||||
|
<div><button class="btn btn-info mt-1" onclick="update_heatmap_year({{ year }})">{{ year }}</button></div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% with translate_url=url_for('chats_explorer.chats_explorer_chat', subtype=chat['subtype']), obj_id=chat['id'], pagination=chat['pagination'] %}
|
{% 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' %}
|
{% include 'chats_explorer/block_translation.html' %}
|
||||||
|
@ -248,8 +259,7 @@ optionheatmap = {
|
||||||
calendar: [
|
calendar: [
|
||||||
{
|
{
|
||||||
orient: 'horizontal',
|
orient: 'horizontal',
|
||||||
//range: new Date().getFullYear(),
|
range: new Date().getFullYear(),
|
||||||
range: '2024',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
series: [
|
series: [
|
||||||
|
@ -263,14 +273,18 @@ optionheatmap = {
|
||||||
};
|
};
|
||||||
heatyearChart.setOption(optionheatmap);
|
heatyearChart.setOption(optionheatmap);
|
||||||
|
|
||||||
$.getJSON("{{ url_for('chats_explorer.chats_explorer_messages_stats_year') }}?type=chat&subtype={{ chat['subtype'] }}&id={{ chat['id'] }}")
|
update_heatmap_year(null);
|
||||||
.done(function(data) {
|
function update_heatmap_year(year) {
|
||||||
optionheatmap['visualMap']['max'] = data['max']
|
$.getJSON("{{ url_for('chats_explorer.chats_explorer_messages_stats_year') }}?type=chat&subtype={{ chat['subtype'] }}&id={{ chat['id'] }}&year=" + year)
|
||||||
optionheatmap['series'][0]['data'] = data['nb']
|
.done(function(data) {
|
||||||
heatyearChart.setOption(optionheatmap)
|
optionheatmap['visualMap']['max'] = data['max']
|
||||||
|
optionheatmap['calendar'][0]['range'] = data['year']
|
||||||
|
optionheatmap['series'][0]['data'] = data['nb']
|
||||||
|
heatyearChart.setOption(optionheatmap)
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue