[ckan-dev] A quick dirty hack to fix wrong months on stats charts

Luca De Santis desantis at netseven.it
Wed Sep 5 10:49:43 UTC 2012


Hi all, 
as a follow up of my previous email, I came up with a very quick & dirty fix to allow stats to show Dates correctly on charts.

For the detail of the problem I copy below my original message.

In short: stats get drawn via JavaScript. Data are loaded in JavaScript arrays in form of couples (Date, number).

The issue arises since JavaScript Date objects are created through 
   new Date ( year, month, date )
where month must be within [0, 11]. See: http://www.elated.com/articles/working-with-dates/

Here is the quick - admittedly dirty - hack in stats template to fix the issue.

Just change 
   new Date(${week_date.replace('-', ',')}), ...
as
   new Date(${"%s,%02d,%s" % (week_date[0:4],int(week_date[5:7])-1, week_date[8:11])}), ...

Hope it helps...

Ciao,
Luca

Inizio messaggio inoltrato:

> Da: Luca De Santis <desantis at netseven.it>
> Data: 31 agosto 2012 16.27.36 GMT+02.00
> A: CKAN Development Discussions <ckan-dev at lists.okfn.org>
> Oggetto: Wrong months on stats charts + Recline preview misbehavior
> 
> Hi all,
> there are two issues that I've met in CKAN 1.7.1.
> 
> 1. Statistics
> As you can see here http://dati.toscana.it/stats apparently the new packages and package revisions graphs show only data for August and September.
> It should be of course July and August: see also the source data that gets loaded (you can check it doing a "view source").
> It seems that the month is interpreted in a wrong way when writing the label.
> Please note that the same results is shown if I use the original Stats template. It seems a JavaScript issue in the chart library.
> 
> 2. Sort on column in the Recline preview doesn't always work
> See for example:
> http://ckan.hyperborea.com/dataset/albums/resource/04dbbd48-b09c-42f7-b825-1198a9e24b1d
> (a silly resource on a development server).
> Select the column "band" and click on "Sort ascending" (or "descending").
> 
> After that only 3 rows, out of 7, are shown. Has the presence of white spaces some influence on that? A similar (mis)behavior happens when sorting for "album" while for all the others columns (eg. "year") it works correctly.
> 
> Any guess?
> 
> Have a nice week-end you all,
> L.

--
Luca De Santis
 Net7 Srl
 Via Marche, 10
 56123 Pisa - ITALY
 ---
 mail: desantis at netseven.it
 telephone: +39 050 552574
 mobile: +39 335 7376153
 skype: lucadex





More information about the ckan-dev mailing list