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
25 #include <json/json.h>
30 #define HTML_TEMPLATE \
33 <script type='text/javascript' src='https://www.google.com/jsapi'></script>\n\
34 <script type='text/javascript'>\n\
35 google.load('visualization', '1', {packages:['corechart']});\
36 google.setOnLoadCallback(drawChart);\n\
37 function drawChart() {\n\
38 var data = new google.visualization.DataTable();\n\
39 data.addColumn('string', 'Date');\n\
43 var chart = new google.visualization.LineChart(document.getElementById('chart_div'));\n\
44 chart.draw(data, {width: 1024, height: 768, title: 'PPA Statistics'});\n\
50 <div id='chart_div'></div>\n\
55 get_count_array(json_object *data, const char *date)
58 json_object *o, *o_date;
61 n = json_object_array_length(data);
62 for (i = 0; i < n; i++) {
63 o = json_object_array_get_idx(data, i);
64 o_date = json_object_array_get_idx(o, 0);
65 date2 = json_object_get_string(o_date);
67 if (!strcmp(date2, date))
74 static json_object *count_array_new(json_object *data, const char *d, int n)
76 json_object *result = json_object_new_array();
79 json_object_array_add(result, json_object_new_string(d));
81 for (i = 0; i < n; i++)
82 json_object_array_add(result, json_object_new_int(0));
84 json_object_array_add(data, result);
90 build_package_display_name(struct binary_package_publishing_history *b)
92 char *str = malloc(strlen(b->binary_package_name)+
94 strlen(b->binary_package_version)+
98 b->binary_package_name, b->binary_package_version);
104 build_addcolums_str(struct binary_package_publishing_history **list)
106 struct binary_package_publishing_history **cur = list;
107 struct binary_package_publishing_history *b;
113 const char *pattern = "%s data.addColumn('number', '%s');\n";
117 dname = build_package_display_name(b);
119 tmpstr = malloc(strlen(str)+strlen(pattern)+strlen(dname)+1);
120 sprintf(tmpstr, pattern, str, dname);
134 build_data_str(struct binary_package_publishing_history **list)
140 n = list_length((void **)list);
142 data = json_object_new_array();
143 for (i = 0; i < n; i++) {
144 struct binary_package_publishing_history *binary;
145 const struct distro_arch_series *dist;
146 struct daily_download_total **totals;
147 struct daily_download_total **t_cur;
150 dist = get_distro_arch_series(binary->distro_arch_series_link);
152 totals = get_daily_download_totals(binary->self_link);
156 char *d = malloc(10+1);
159 sprintf(d, "%d-%02d-%02d",
160 (*t_cur)->date.tm_year+1900,
161 (*t_cur)->date.tm_mon+1,
162 (*t_cur)->date.tm_mday);
164 data2 = get_count_array(data, d);
167 data2 = count_array_new(data, d, n);
169 json_object_array_put_idx
171 i+1, json_object_new_int((*t_cur)->count));
177 daily_download_total_list_free(totals);
180 str = strdup(json_object_to_json_string(data));
182 json_object_put(data);
187 void ppa_to_html(const char *owner, const char *ppa)
189 struct binary_package_publishing_history **list;
190 char *archive_url = get_archive_url(owner, ppa);
191 char *addcolumns_str;
194 list = get_binary_package_publishing_history_list(archive_url);
198 fprintf(stderr, "Failed to retrieve PPA information\n");
202 addcolumns_str = build_addcolums_str(list);
203 data_str = build_data_str(list);
205 printf(HTML_TEMPLATE, addcolumns_str, data_str);
207 free(addcolumns_str);
209 binary_package_publishing_history_list_free(list);