Wednesday, September 11, 2013

Timezone and Confusion in Django

https://docs.djangoproject.com/en/dev/topics/i18n/timezones/

1) We use USE_TZ = True in our settings. It means, that Django will use Time zone aware datetime objects.
so, instead of doing this,


import datetimecur = datetime.datetime.now() # which doesnt give us tzinfo

we should use this -

import datetimefrom django.utils.timezone import utc
cur = datetime.datetime.now().replace(tzinfo=utc) # Note: This is for timezone aware not for local time

This will remove the warnings we usually see, "Datetimefield received a naive datetime."

2) For converting local time into current time zone,  according to one specified in settings file. We should use this

from django.utils import timezonetimezone.localtime(timezone.now())


Wednesday, September 4, 2013

Using Google Charts to show Data Point Values

Like most of us, in order to quickly use Google Charts Library, I copy pasted a simple code from https://code.google.com/apis/ajax/playground/?type=visualization#line_chart, adjusted to my use.

I wanted a Line Graph, with two data lines,  hours(1-24) on x axis and a number on y axis. This example was easy to customize , and most of my work was done(Please note- Most of it)

Now, I only wanted to show data values in the graph. As you can see, a tooltip pops up, when we hover on data points, I wanted tooltips or data values to show without the hover action.

The only way I could find was here - http://stackoverflow.com/questions/13449467/google-charts-api-always-show-the-data-point-values-in-graph

It says - data.addColumn({type: 'string', role: 'annotation'});


Now this is new, whats data? On going through the docs, I found that I have been using a method arraytoDataTable() [here] .This is a shortcut method to add data to graph. There is a DataTable class which has methods

  • addColumn
  • addRow
  • addRows
See here  

this data in the above code, is the instance of the DataTable class. Now coming back to the same problem, in order to add annotation, we added the columns with role: annotation. Roles can be read here.

So now, I am able to see , the not so beautiful , annotations. 

What could be made better - Examples should be added for showing annotations. Currently there are none.

Tuesday, September 3, 2013

Compiling Ejabbered Module

While working on ejabbered, I came across a case where I had to compile a new module.

On googling and reading around stuff, I went through different posts -



All of these posts were indeed very helpful to start but I faced some errors to compile , even after following the given steps.

My basic mod_hello.erl module,  had 

-module(mod_hello).
-behavior(gen_mod).

-export([
    start/2,
    stop/1
    ]).
start(_Host, _Opt) ->
        ?INFO_MSG("Loading module 'mod_hello' ", []).
stop(_Host) ->
        ok.

Using commands to compile this , 
erlc mod_hello.erl
erlc  -I {erlang_src_dir}/src -pa {erlang_src_dir}/src mod_hello.erl
 But nothing worked. I looked at the compiling commands that Ejabbered src used on compiling its erl modules. It was similiar to mine. Atlast on looking through the code, I found out the missing code..
the include commands.

So now, after addiing
-include("ejabberd.hrl").
-include("jlib.hrl").
Everything worked. Hooray..