From: Jean-Philippe Orsini Date: Sat, 3 Sep 2011 16:45:49 +0000 (+0000) Subject: generate html page for the ppa itself X-Git-Tag: v1.3.0~153 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=ppastats.git;a=commitdiff_plain;h=ec6a36243780275a8f67d3f983c338841ff20899 generate html page for the ppa itself --- diff --git a/NEWS b/NEWS index 57c85c9..91c7cf4 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ ** Fixed memory issue (patch submitted by Lekensteyn). ** Added help for -s option. ** Don't generate manpage if help2man not present. +** Generate html page for the PPA. * v0.0.3 ** Generated HTML pages for package versions. diff --git a/src/html.c b/src/html.c index 6ae462d..a903009 100644 --- a/src/html.c +++ b/src/html.c @@ -105,6 +105,37 @@ enum file_copy_error { \n\ " +#define HTML_INDEX_TEMPLATE \ +"\n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ +

N/A

\n\ +
\n\ + Packages:\n\ + \n\ +
\n\ +
\n\ + \n\ +" + + #define FCOPY_BUF_SZ 4096 static int file_copy(FILE * src, FILE * dst) { @@ -323,6 +354,47 @@ static char *version_to_json(struct ppa_stats *ppa, return ret; } +static char *ppa_to_json(struct ppa_stats *ppa) +{ + char *ret; + json_object *json, *json_pkgs, *json_pkg; + struct package_stats **pkgs; + + json = json_object_new_object(); + + json_object_object_add(json, + "ppa_name", json_object_new_string(ppa->name)); + json_object_object_add(json, + "ppa_owner", + json_object_new_string(ppa->owner)); + + json_add_ddts(json, ppa->daily_download_totals); + + pkgs = ppa->packages; + json_pkgs = json_object_new_array(); + json_object_object_add(json, "packages", json_pkgs); + while (*pkgs) { + json_pkg = json_object_new_object(); + json_object_array_add(json_pkgs, json_pkg); + + json_object_object_add(json_pkg, "name", + json_object_new_string((*pkgs)->name)); + + json_object_object_add + (json_pkg, "count", + json_object_new_int((*pkgs)->download_count)); + + pkgs++; + } + + ret = strdup(json_object_to_json_string(json)); + + json_object_put(json); + + return ret; +} + + static void pkg_to_html(struct ppa_stats *ppa, struct package_stats *pkg, const char *dir) { @@ -399,6 +471,27 @@ packages_to_html(struct ppa_stats *ppa, } } +static void +index_to_html(struct ppa_stats *ppa, const char *dir) +{ + char *path; + FILE *f; + + path = get_path(dir, "index"); + f = fopen(path, "w"); + + if (!f) { + fprintf(stderr, "ERROR: failed to open: %s\n", path); + return ; + } + + fprintf(f, HTML_INDEX_TEMPLATE, ppa_to_json(ppa)); + + fclose(f); + + free(path); +} + static char *append_path(const char *odir, const char *name) { char *dir; @@ -452,6 +545,8 @@ ppa_to_html(const char *owner, packages_to_html(ppastats, ppastats->packages, output_dir); + index_to_html(ppastats, output_dir); + ppa_stats_free(ppastats); free(path); diff --git a/src/main.c b/src/main.c index 2314f81..c9a94fd 100644 --- a/src/main.c +++ b/src/main.c @@ -126,7 +126,7 @@ static void print_help() generates HTML pages into 'PATH'."); puts("\ - -s, --status=[STATUS] retrieves only package of the given status\n\ + -s, --status=[STATUS] retrieves only package of the given status\n\ (possible values are: Pending, Published, \n\ Superseded, Deleted or Obsolete)."); diff --git a/www/js/ppastats.js b/www/js/ppastats.js index 43c75be..e0bd70e 100644 --- a/www/js/ppastats.js +++ b/www/js/ppastats.js @@ -98,4 +98,51 @@ function ppastats_ver() { }); } +function ppastats_ppa() { + $(document).ready(function() { + var data_chart = []; + var ddts = data["ddts"]; + var max_date = null; + var min_date = null; + var pkg_url = data["pkg_name"]+".html"; + + $("#ppa_name").html(data["ppa_owner"]+"/"+data["ppa_name"]); + + $.each(ddts, function(i, item) { + var tm = item["time"]; + var d = new Date(tm[0], tm[1]-1, tm[2], 0, 0, 0, 0); + var entry = [d, item["value"]]; + data_chart.push(entry); + + if (max_date == null || max_date < d) { + max_date = d; + } + + if (min_date == null || min_date > d) { + min_date = d; + } + }); + + $.each(data["packages"], function(i, item) { + var url = item["name"]+".html"; + $("#pkgs").append("
  • "+item["name"]+": "+item["count"]+"
  • "); + }); + + var plot1 = $.jqplot ('chart', [data_chart], { + axes: { + xaxis: { + renderer:$.jqplot.DateAxisRenderer, + tickOptions:{formatString:'%Y/%m/%d'}, + min: min_date, + max: max_date + }, + yaxis: { + min: 0 + } + }, + series: [{lineWidth:1,showMarker:false}] + }); + }); +} + \ No newline at end of file