2 Copyright (C) 2011 jeanfi@gmail.com
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <json/json.h>
27 #define HTML_TEMPLATE \
30 <script type='text/javascript'\
31 src='https://www.google.com/jsapi'></script>\n\
32 <script type='text/javascript'>\n\
33 google.load('visualization', '1', {packages:['corechart']});\
34 google.setOnLoadCallback(drawChart);\n\
35 function drawChart() {\n\
36 var data = new google.visualization.DataTable();\n\
37 data.addColumn('string', 'Date');\n\
38 data.addColumn('number', 'Daily Download');\n\
41 var chart = new google.visualization.LineChart\
42 (document.getElementById('chart_div'));\n\
43 chart.draw(data, {width: 1024, height: 768,\
44 title: 'PPA Statistics'});\n\
50 <div id='chart_div'></div>\n\
54 char *tm_to_str(struct tm *date)
56 char *str = malloc(10+1);
58 sprintf(str, "%d-%02d-%02d",
67 generate_chart(const char *path,
70 struct daily_download_total **totals)
73 struct daily_download_total **cur;
74 struct daily_download_total *total;
76 json_object *arr, *item;
79 fprintf(stderr, "ERROR: no totals\n");
86 fprintf(stderr, "ERROR: failed to open: %s\n", path);
90 arr = json_object_new_array();
95 str_date = tm_to_str(&(total->date));
97 item = json_object_new_array();
99 json_object_array_add(item, json_object_new_string(str_date));
100 json_object_array_add(item,
101 json_object_new_int(total->count));
103 json_object_array_add(arr, item);
112 json_object_to_json_string(arr));
114 json_object_put(arr);