Check-in [3c78bbb082]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:/stats_report now uses relative bar lengths, based on (rather arbitrarily) a 500-pixel 100% value.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3c78bbb0829e58df87604fecf5a8cf70f1d3e4bb
User & Date: stephan 2013-07-20 16:27:44
Context
2013-07-20
16:43
Removed the 500px baseline for /stats_report calculations, refactored the bars to now use percentage widths. check-in: 674a24a360 user: stephan tags: trunk
16:27
/stats_report now uses relative bar lengths, based on (rather arbitrarily) a 500-pixel 100% value. check-in: 3c78bbb082 user: stephan tags: trunk
15:59
Added a width to table.sbsdiffcols so that skins with a flexible body width can expand it as necessary. Seems to have no visible effect on fixed-width layouts. check-in: 47ee082a75 user: stephan tags: trunk
Changes

Changes to src/timeline.c.

1862
1863
1864
1865
1866
1867
1868









1869
1870
1871
1872
1873
1874
1875
....
1888
1889
1890
1891
1892
1893
1894

1895
1896
1897
1898
1899
1900
1901
....
1915
1916
1917
1918
1919
1920
1921












1922
1923
1924
1925
1926

1927
1928
1929
1930
1931
1932
1933
....
2019
2020
2021
2022
2023
2024
2025


2026
2027
2028
2029
2030
2031
2032
....
2035
2036
2037
2038
2039
2040
2041







2042
2043
2044
2045


2046
2047
2048
2049
2050
2051
2052
2053
....
2074
2075
2076
2077
2078
2079
2080
2081

2082

2083
2084
2085
2086
2087
2088
2089
....
2136
2137
2138
2139
2140
2141
2142







2143
2144
2145
2146


2147
2148
2149
2150
2151
2152
2153
....
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
    cgi_printf("<a href='%s/timeline?"
               "yw=%t-%t&n=%d'>%s</a>",
               g.zTop, yearPart, zWeek,
               nCount, zWeek);
  }
  db_finalize(&stWeek);
}










/*
** Implements the "byyear" and "bymonth" reports for /stats_report.
** If includeMonth is true then it generates the "bymonth" report,
** else the "byyear" report. If zUserName is not NULL and not empty
** then the report is restricted to events created by the named user
** account.
................................................................................
  char zPrevYear[5] = {0};           /* For keeping track of when
                                        we change years while looping */
  int nEventsPerYear = 0;            /* Total even count for the
                                        current year */
  char showYearTotal = 0;            /* Flag telling us when to show
                                        the per-year event totals */
  Blob header = empty_blob;          /* Page header text */


  blob_appendf(&header, "Timeline Events by year%s",
               (includeMonth ? "/month" : ""));
  blob_appendf(&sql,
               "SELECT substr(date(mtime),1,%d) AS timeframe, "
               "count(*) AS eventCount "
               "FROM event ",
................................................................................
  @  cellspacing='0' id='statsTable'>
  @ <thead>
  @ <th>%s(zTimeLabel)</th>
  @ <th>Events</th>
  @ <th><!-- relative commits graph --></th>
  @ </thead><tbody>
  blob_reset(&header);












  while( SQLITE_ROW == db_step(&query) ){
    char const * zTimeframe = db_column_text(&query, 0);
    int const nCount = db_column_int(&query, 1);
    int const nSize = 1 + ((nPixelsPerEvent * nCount)
                           / (includeMonth ? 1 : 10));

    showYearTotal = 0;
    if(includeMonth){
      /* For Month/year view, add a separator for each distinct year. */
      if(!*zPrevYear ||
         (0!=fossil_strncmp(zPrevYear,zTimeframe,4))){
        showYearTotal = *zPrevYear;
        if(showYearTotal){
................................................................................
  Stmt query = empty_Stmt;
  int const nPixelsPerEvent = 1;     /* for sizing the "graph" part */
  int nRowNumber = 0;                /* current TR number */
  int nEventTotal = 0;               /* Total event count */
  int rowClass = 0;                  /* counter for alternating
                                        row colors */
  Blob sql = empty_blob;             /* SQL */


  blob_append(&sql,
               "SELECT user, "
               "COUNT(*) AS eventCount "
               "FROM event "
               "GROUP BY user ORDER BY eventCount DESC",
              -1);
  db_prepare(&query, blob_str(&sql));
................................................................................
  @ <table class='statistics-report-table-events' border='0'
  @ cellpadding='2' cellspacing='0' id='statsTable'>
  @ <thead><tr>
  @ <th>User</th>
  @ <th>Events</th>
  @ <th><!-- relative commits graph --></th>
  @ </tr></thead><tbody>







  while( SQLITE_ROW == db_step(&query) ){
    char const * zUser = db_column_text(&query, 0);
    int const nCount = db_column_int(&query, 1);
    int const nSize = 1+((nPixelsPerEvent * nCount) / 10);


    if(!nCount) continue /* arguable! */;
    rowClass = ++nRowNumber % 2;
    nEventTotal += nCount;
    @<tr class='row%d(rowClass)'>
    @ <td>
    @ <a href="?view=bymonth&user=%h(zUser)" target="_new">%h(zUser)</a>
    @ </td><td>%d(nCount)</td>
    @ <td>
................................................................................
static void stats_report_year_weeks(char const * zUserName){
  char const * zYear = P("y");
  int nYear = zYear ? strlen(zYear) : 0;
  int i = 0;
  Stmt qYears = empty_Stmt;
  char * zDefaultYear = NULL;
  Blob sql = empty_blob;
  cgi_printf("Select year: ");



  blob_append(&sql,
              "SELECT DISTINCT substr(date(mtime),1,4) AS y "
              "FROM event WHERE 1 ", -1);
  if(zUserName&&*zUserName){
    blob_appendf(&sql,"AND user=%Q ", zUserName);
  }
  blob_append(&sql,"GROUP BY y ORDER BY y", -1);
................................................................................
               "<th>Week</th>"
               "<th>Events</th>"
               "<th><!-- relative commits graph --></th>"
               "</tr></thead>"
               "<tbody>");
    db_prepare(&stWeek, blob_str(&sql));
    blob_reset(&sql);







    while( SQLITE_ROW == db_step(&stWeek) ){
      char const * zWeek = db_column_text(&stWeek,0);
      int const nCount = db_column_int(&stWeek,1);
      int const graphSize = nPixelsPerEvent * nCount;


      total += nCount;
      cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
      cgi_printf("<td><a href='%s/timeline?yw=%t-%s&n=%d",
                 g.zTop, zYear, zWeek, nCount);
      if(zUserName && *zUserName){
        cgi_printf("&u=%t",zUserName);
      }
................................................................................
      cgi_printf("'>%s</a></td>",zWeek);

      cgi_printf("<td>%d</td>",nCount);
      cgi_printf("<td>");
      if(nCount){
        cgi_printf("<div class='statistics-report-graph-line'"
                   "style='height:16px;width:%dpx;'></div>",
                   graphSize);
      }
      cgi_printf("</td></tr>");
    }
    db_finalize(&stWeek);
    free(zDefaultYear);
    if(total){
      cgi_printf("<tr class='row%d'>", ++rowCount%2);







>
>
>
>
>
>
>
>
>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>



|
|
>







 







>
>







 







>
>
>
>
>
>
>



|
>
>
|







 







|
>

>







 







>
>
>
>
>
>
>



|
>
>







 







|







1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
....
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
....
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
....
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
....
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
....
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
....
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
....
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
    cgi_printf("<a href='%s/timeline?"
               "yw=%t-%t&n=%d'>%s</a>",
               g.zTop, yearPart, zWeek,
               nCount, zWeek);
  }
  db_finalize(&stWeek);
}

/**
   Pixel width for the longest bar in
   the /stats_report graphs. This is considered
   the 100% value and all lengths are calculated
   as a percentage of this value.
 */
static int const nStatReportLineWidth = 500;


/*
** Implements the "byyear" and "bymonth" reports for /stats_report.
** If includeMonth is true then it generates the "bymonth" report,
** else the "byyear" report. If zUserName is not NULL and not empty
** then the report is restricted to events created by the named user
** account.
................................................................................
  char zPrevYear[5] = {0};           /* For keeping track of when
                                        we change years while looping */
  int nEventsPerYear = 0;            /* Total even count for the
                                        current year */
  char showYearTotal = 0;            /* Flag telling us when to show
                                        the per-year event totals */
  Blob header = empty_blob;          /* Page header text */
  int nMaxEvents  = 1;            /* for calculating length of graph bars. */

  blob_appendf(&header, "Timeline Events by year%s",
               (includeMonth ? "/month" : ""));
  blob_appendf(&sql,
               "SELECT substr(date(mtime),1,%d) AS timeframe, "
               "count(*) AS eventCount "
               "FROM event ",
................................................................................
  @  cellspacing='0' id='statsTable'>
  @ <thead>
  @ <th>%s(zTimeLabel)</th>
  @ <th>Events</th>
  @ <th><!-- relative commits graph --></th>
  @ </thead><tbody>
  blob_reset(&header);
  /*
     Run the query twice. The first time we calculate the maximum
     number of events for a given row. Maybe someone with better SQL
     Fu can re-implement this with a single query.
  */
  while( SQLITE_ROW == db_step(&query) ){
    int const nCount = db_column_int(&query, 1);
    if(nCount>nMaxEvents){
      nMaxEvents = nCount;
    }
  }
  db_reset(&query);
  while( SQLITE_ROW == db_step(&query) ){
    char const * zTimeframe = db_column_text(&query, 0);
    int const nCount = db_column_int(&query, 1);
    int const nSize = nCount
      ? (int)(1.0 * nCount / nMaxEvents * nStatReportLineWidth)
      : 1;
    showYearTotal = 0;
    if(includeMonth){
      /* For Month/year view, add a separator for each distinct year. */
      if(!*zPrevYear ||
         (0!=fossil_strncmp(zPrevYear,zTimeframe,4))){
        showYearTotal = *zPrevYear;
        if(showYearTotal){
................................................................................
  Stmt query = empty_Stmt;
  int const nPixelsPerEvent = 1;     /* for sizing the "graph" part */
  int nRowNumber = 0;                /* current TR number */
  int nEventTotal = 0;               /* Total event count */
  int rowClass = 0;                  /* counter for alternating
                                        row colors */
  Blob sql = empty_blob;             /* SQL */
  int nMaxEvents = 1;                /* max number of events for
                                        all rows. */
  blob_append(&sql,
               "SELECT user, "
               "COUNT(*) AS eventCount "
               "FROM event "
               "GROUP BY user ORDER BY eventCount DESC",
              -1);
  db_prepare(&query, blob_str(&sql));
................................................................................
  @ <table class='statistics-report-table-events' border='0'
  @ cellpadding='2' cellspacing='0' id='statsTable'>
  @ <thead><tr>
  @ <th>User</th>
  @ <th>Events</th>
  @ <th><!-- relative commits graph --></th>
  @ </tr></thead><tbody>
  while( SQLITE_ROW == db_step(&query) ){
    int const nCount = db_column_int(&query, 1);
    if(nCount>nMaxEvents){
      nMaxEvents = nCount;
    }
  }
  db_reset(&query);
  while( SQLITE_ROW == db_step(&query) ){
    char const * zUser = db_column_text(&query, 0);
    int const nCount = db_column_int(&query, 1);
    int const nSize = nCount
      ? (int)(1.0 * nCount / nMaxEvents * nStatReportLineWidth)
      : 0;
    if(!nCount) continue /* arguable! Possible? */;
    rowClass = ++nRowNumber % 2;
    nEventTotal += nCount;
    @<tr class='row%d(rowClass)'>
    @ <td>
    @ <a href="?view=bymonth&user=%h(zUser)" target="_new">%h(zUser)</a>
    @ </td><td>%d(nCount)</td>
    @ <td>
................................................................................
static void stats_report_year_weeks(char const * zUserName){
  char const * zYear = P("y");
  int nYear = zYear ? strlen(zYear) : 0;
  int i = 0;
  Stmt qYears = empty_Stmt;
  char * zDefaultYear = NULL;
  Blob sql = empty_blob;
  int nMaxEvents = 1;                /* max number of events for
                                        all rows. */

  cgi_printf("Select year: ");
  blob_append(&sql,
              "SELECT DISTINCT substr(date(mtime),1,4) AS y "
              "FROM event WHERE 1 ", -1);
  if(zUserName&&*zUserName){
    blob_appendf(&sql,"AND user=%Q ", zUserName);
  }
  blob_append(&sql,"GROUP BY y ORDER BY y", -1);
................................................................................
               "<th>Week</th>"
               "<th>Events</th>"
               "<th><!-- relative commits graph --></th>"
               "</tr></thead>"
               "<tbody>");
    db_prepare(&stWeek, blob_str(&sql));
    blob_reset(&sql);
    while( SQLITE_ROW == db_step(&stWeek) ){
      int const nCount = db_column_int(&stWeek, 1);
      if(nCount>nMaxEvents){
        nMaxEvents = nCount;
      }
    }
    db_reset(&stWeek);
    while( SQLITE_ROW == db_step(&stWeek) ){
      char const * zWeek = db_column_text(&stWeek,0);
      int const nCount = db_column_int(&stWeek,1);
      int const nSize = nCount
        ? (int)(1.0 * nCount / nMaxEvents * nStatReportLineWidth)
        : 0;
      total += nCount;
      cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
      cgi_printf("<td><a href='%s/timeline?yw=%t-%s&n=%d",
                 g.zTop, zYear, zWeek, nCount);
      if(zUserName && *zUserName){
        cgi_printf("&u=%t",zUserName);
      }
................................................................................
      cgi_printf("'>%s</a></td>",zWeek);

      cgi_printf("<td>%d</td>",nCount);
      cgi_printf("<td>");
      if(nCount){
        cgi_printf("<div class='statistics-report-graph-line'"
                   "style='height:16px;width:%dpx;'></div>",
                   nSize);
      }
      cgi_printf("</td></tr>");
    }
    db_finalize(&stWeek);
    free(zDefaultYear);
    if(total){
      cgi_printf("<tr class='row%d'>", ++rowCount%2);