1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-22 16:56:16 +00:00

HTMLExporter: Moved from Google charts to Highcharts; implemented the heatmap.

This commit is contained in:
Fabian Schlenz 2016-07-26 06:42:48 +02:00
parent 24f8320a42
commit 68f8841d12
3 changed files with 118 additions and 89 deletions

View File

@ -430,25 +430,31 @@ public class Database {
public HashMap<String, Integer> getMessageMediaTypesWithCount() { public HashMap<String, Integer> getMessageMediaTypesWithCount() {
HashMap<String, Integer> map = new HashMap<String, Integer>(); HashMap<String, Integer> map = new HashMap<String, Integer>();
try { try {
int count = 0;
ResultSet rs = stmt.executeQuery("SELECT media_type, COUNT(id) FROM messages GROUP BY media_type"); ResultSet rs = stmt.executeQuery("SELECT media_type, COUNT(id) FROM messages GROUP BY media_type");
while (rs.next()) { while (rs.next()) {
String s = rs.getString(1); String s = rs.getString(1);
if (s==null) s="null"; if (s==null) {
s="null";
} else {
count += rs.getInt(2);
}
map.put(s, rs.getInt(2)); map.put(s, rs.getInt(2));
} }
map.put("any", count);
return map; return map;
} catch (Exception e) { throw new RuntimeException(e); } } catch (Exception e) { throw new RuntimeException(e); }
} }
public int[][] getMessageTimesMatrix(Integer dialog_id, Integer chat_id) { public int[][] getMessageTimesMatrix(Integer dialog_id, Integer chat_id) {
int result[][] = new int[24][7]; int result[][] = new int[7][24];
try { try {
ResultSet rs = stmt.executeQuery("SELECT STRFTIME('%H', time, 'unixepoch') AS hour, " + ResultSet rs = stmt.executeQuery("SELECT STRFTIME('%w', time, 'unixepoch') as DAY, " +
"STRFTIME('%w', time, 'unixepoch') as DAY, " + "STRFTIME('%H', time, 'unixepoch') AS hour, " +
"COUNT(id) FROM messages GROUP BY hour, day " + "COUNT(id) FROM messages GROUP BY hour, day " +
"ORDER BY hour, day"); "ORDER BY hour, day");
while (rs.next()) { while (rs.next()) {
result[rs.getInt(1)][rs.getInt(2) == 0 ? 6 : rs.getInt(2)-1] = rs.getInt(3); result[rs.getInt(1) == 0 ? 6 : rs.getInt(1)-1][rs.getInt(2)] = rs.getInt(3);
} }
return result; return result;
} catch (Exception e) { throw new RuntimeException(e); } } catch (Exception e) { throw new RuntimeException(e); }

View File

@ -118,13 +118,10 @@ public class HTMLExporter {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("["); sb.append("[");
for (int x=0; x<data.length; x++) { for (int x=0; x<data.length; x++) {
if (x>0) sb.append(", ");
sb.append("[");
for (int y=0; y<data[x].length; y++) { for (int y=0; y<data[x].length; y++) {
if (y>0) sb.append(", "); if (x>0 || y>0) sb.append(",");
sb.append(data[x][y]); sb.append("[" + x + "," + y + "," + data[x][y] + "]");
} }
sb.append("]");
} }
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();

View File

@ -3,59 +3,109 @@
<head> <head>
<title>Telegram Backup for {{user.getUserString}}</title> <title>Telegram Backup for {{user.getUserString}}</title>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <meta charset="UTF-8">
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
drawChartChatTypes();
drawChartMessageTypes();
drawChartMediaTypes();
}
function drawChartChatTypes() { <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
var data = google.visualization.arrayToDataTable([ <script src="https://code.highcharts.com/highcharts.js"></script>
['Type', 'Count'], <script src="https://code.highcharts.com/modules/heatmap.js"></script>
['Dialog', {{count.dialogs}}], <script src="https://code.highcharts.com/modules/drilldown.js"></script>
['Chat', {{count.chats}}]
]); <script type="text/javascript">
var options = { $(function() {
title: 'Chat types', $('#heatmap').highcharts({
legend: 'none', chart: {
pieSliceText: 'label', type: 'heatmap',
}; },
colorAxis: {
var chart = new google.visualization.PieChart(document.getElementById('chart_chat_types')); stops: [
chart.draw(data, options); [0, '#000000'],
} [1, '#FF0000'],
],
function drawChartMediaTypes() { },
var data = google.visualization.arrayToDataTable([ xAxis: {
['Type', 'Count'], categories: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
['No media', {{count.messages.media_type.null}}+0], ['Photo', {{count.messages.media_type.photo}}+0], },
['Audio', {{count.messages.media_type.audio}}+0], ['Video', {{count.messages.media_type.video}}+0], yAxis: {
['Geolocation', {{count.messages.media_type.geo}}+0], ['Document', {{count.messages.media_type.document}}+0], reversed: true,
['Sticker', {{count.messages.media_type.sticker}}+0], ['Venue', {{count.messages.media_type.venue}}+0], title: { text: "Hour", },
['Contact', {{count.messages.media_type.contact}}+0] },
]); series: [{
var options = { title: 'Media types', legend: 'none', pieSliceText: 'label' }; name: 'Messages per hour',
var chart = new google.visualization.PieChart(document.getElementById('chart_media_types')); data: {{heatmap_data}},
chart.draw(data, options); }],
} });
function drawChartMessageTypes() {
var data = google.visualization.arrayToDataTable([
['Type', 'Count'],
['Normal messages', {{count.messages.type.message}}],
['Empty messages', {{count.messages.type.empty_message}}],
['Service messages', {{count.messages.type.service_message}}]
]);
var options = { title: 'Message types', legend: 'none', pieSliceText: 'label' };
var chart = new google.visualization.PieChart(document.getElementById('chart_message_types')); $('#chart_chat_types').highcharts({
chart.draw(data, options); chart: {
} type: 'pie',
},
title: {
text: 'Chat types',
},
series: [{
name: 'Types',
data: [{
name: 'Dialogs',
y: {{count.dialogs}},
}, {
name: 'Group chats',
y: {{count.chats}},
}],
}],
});
$('#chart_media_types').highcharts({
chart: {
type: 'pie',
},
title: {
text: 'Media types',
},
subtitle: {
text: 'Click on media slice to expand',
},
series: [{
name: 'Has media',
data: [
{name: 'No media', y: {{count.messages.media_type.null}}+0, drilldown: null},
{name: 'With media', y: {{count.messages.media_type.any}}+0, drilldown: 'With media'},
],
}],
drilldown: {
series: [{
name: 'Media types',
id: 'With media',
data: [
{name: 'Photo', y: {{count.messages.media_type.photo}}+0},
{name: 'Audio', y: {{count.messages.media_type.audio}}+0},
{name: 'Video', y: {{count.messages.media_type.video}}+0},
{name: 'Geolocation', y: {{count.messages.media_type.geo}}+0},
{name: 'Document', y: {{count.messages.media_type.document}}+0},
{name: 'Sticker', y: {{count.messages.media_type.sticker}}+0},
{name: 'Venue', y: {{count.messages.media_type.venue}}+0},
{name: 'Contact', y: {{count.messages.media_type.contact}}+0},
],
}],
},
});
$('#chart_message_types').highcharts({
chart: {
type: 'pie',
},
title: {
text: 'Message types',
},
series: [{
name: 'Message types',
data: [
{name: 'Normal messages', y: {{count.messages.type.message}}+0},
{name: 'Empty messages', y: {{count.messages.type.empty_message}}+0},
{name: 'Service messages', y: {{count.messages.type.service_message}}+0},
],
}],
});
});
</script> </script>
</head> </head>
@ -88,35 +138,11 @@
{{/chats}} {{/chats}}
</ul> </ul>
<!--
count.chats: {{count.chats}}
count.dialogs: {{count.dialogs}}
count.messages: {{count.messages}}
count.messages.chats: {{count.messages.chats}}
count.messages.dialogs: {{count.messages.dialogs}}
count.messages.from_me: {{count.messages.from_me}}
count.messages.type.message: {{count.messages.type.message}}
count.messages.type.empty_message: {{count.messages.type.empty_message}}
count.messages.type.service_message: {{count.messages.type.service_message}}
count.messages.media_type.null: {{count.messages.media_type.null}}
count.messages.media_type.photo:{{count.messages.media_type.photo}}
count.messages.media_type.audio:{{count.messages.media_type.audio}}
count.messages.media_type.video:{{count.messages.media_type.video}}
count.messages.media_type.geo:{{count.messages.media_type.geo}}
count.messages.media_type.document:{{count.messages.media_type.document}}
count.messages.media_type.sticker:{{count.messages.media_type.sticker}}
count.messages.media_type.venue:{{count.messages.media_type.venue}}
count.messages.media_type.contact:{{count.messages.media_type.contact}}
{{heatmap_data}}
-->
<span id="heatmap" style="width: 400px; height: 500px;"></span>
<div id="chart_chat_types" style="width: 900px; height: 500px;"></div> <span id="chart_chat_types" style="width: 400px; height: 500px;"></span>
<div id="chart_message_types" style="width: 900px; height: 500px;"></div> <span id="chart_message_types" style="width: 400px; height: 500px;"></span>
<div id="chart_media_types" style="width: 900px; height: 500px;"></div> <span id="chart_media_types" style="width: 400px; height: 500px;"></span>
</body> </body>
</html> </html>