added generation of package graph
[ppastats.git] / src / html.c
1 /*
2     Copyright (C) 2011 jeanfi@gmail.com
3
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.
8
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.
13
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
17     02110-1301 USA
18 */
19
20 #include <string.h>
21
22 #include "chart.h"
23 #include "html.h"
24 #include "lp_ws.h"
25 #include "ppastats.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 static char *get_path(const char *dir, const char *file)
31 {
32         char *path = malloc(strlen(dir)+1+
33                             strlen(file)+
34                             strlen(".html")+
35                             1);
36
37         strcpy(path, dir);
38         strcat(path, "/");
39         strcat(path, file);
40         strcat(path, ".html");
41
42         return path;
43 }
44
45 static void
46 packages_to_html(struct package_stats **packages,
47                  const char *dir)
48 {
49         struct package_stats **cur;
50         struct package_stats *p;
51         char *path;
52
53         cur = packages;
54         while (*cur) {
55                 p = *cur;
56
57                 path = get_path(dir, p->name);
58                 generate_chart(path, p->name, p->name,
59                                p->daily_download_totals);
60                 free(path);
61
62                 cur++;
63         }
64 }
65
66 void
67 ppa_to_html(const char *owner,
68             const char *ppa,
69             const char *package_status,
70             const char *output_dir)
71 {
72         char *path;
73         struct ppa_stats *ppastats;
74         struct daily_download_total **totals;
75
76         ppastats = create_ppa_stats(owner, ppa, package_status);
77         totals = ppastats->daily_download_totals;
78
79         path = get_path(output_dir, "ppa");
80         generate_chart(path, "PPA Statistics", ppa, totals);
81         free(path);
82
83         packages_to_html(ppastats->packages, output_dir);
84
85         ppa_stats_free(ppastats);
86 }