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>
28 #define HTML_TEMPLATE \
31 <script type='text/javascript'\
32 src='https://www.google.com/jsapi'></script>\n\
33 <script type='text/javascript'>\n\
34 google.load('visualization', '1', {packages:['corechart']});\
35 google.setOnLoadCallback(drawChart);\n\
36 function drawChart() {\n\
37 var data = new google.visualization.DataTable();\n\
38 data.addColumn('string', 'Date');\n\
39 data.addColumn('number', 'Daily Download');\n\
42 var chart = new google.visualization.LineChart\
43 (document.getElementById('chart_div'));\n\
44 chart.draw(data, {width: 1024, height: 768,\
45 title: 'PPA Statistics'});\n\
51 <div id='chart_div'></div>\n\
55 char *tm_to_str(struct tm *date)
57 char *str = malloc(10+1);
59 sprintf(str, "%d-%02d-%02d",
68 generate_chart(const char *path,
71 struct daily_download_total **totals)
74 struct daily_download_total **cur;
75 struct daily_download_total *total;
77 json_object *arr, *item;
80 fprintf(stderr, "Generates %s\n", path);
83 fprintf(stderr, "ERROR: no totals\n");
90 fprintf(stderr, "ERROR: failed to open: %s\n", path);
94 arr = json_object_new_array();
99 str_date = tm_to_str(&(total->date));
101 item = json_object_new_array();
103 json_object_array_add(item, json_object_new_string(str_date));
104 json_object_array_add(item,
105 json_object_new_int(total->count));
107 json_object_array_add(arr, item);
116 json_object_to_json_string(arr));
118 json_object_put(arr);