TaskJungler for maintaining todo list

TaskJungler is a gem available for Ruby. TaskJuggler is a modern and powerful project management tool. Its new approach to project planning and tracking is far superior to the commonly used Gantt chart editing tools. TaskJuggler uses one or more text files to describe a project. The main project should be placed in a file with the .tjp extension. This main project may include other files. Such included files must have file names with a .tji extension.

Steps for doing it :-

1) Install the gem

sudo gem install taskjuggler

2) Create the .tjp file, below is the example code for maintaining a todo list

/*
* This file contains a project skeletton. It is part of the
* TaskJuggler project management tool. You can use this as a basis to
* start you own project file.
*/
project your_project_id “Your Project Title” 2011-11-11-0:00–0500 +4m {
# Set the default time zone for the project. If not specified, UTC
# is used.
timezone “America/New_York”
# Hide the clock time. Only show the date.
timeformat “%Y-%m-%d”
# Use US format for numbers
numberformat “-” “” “,” “.” 1
# Use US financial format for currency values. Don’t show cents.
currencyformat “(” “)” “,” “.” 0
# Pick a day during the project that will be reported as ‘today’ in
# the project reports. If not specified, the current day will be
# used, but this will likely be outside of the project range, so it
# can’t be seen in the reports.
now 2011-12-24
# The currency for all money values is the Euro.
currency “USD”

# You can define multiple scenarios here if you need them.
#scenario plan “Plan” {
# scenario actual “Actual”
#}

# You can define your own attributes for tasks and resources. This
# is handy to capture additonal information about the project that
# is not directly impacting the project schedule but you like to
# keep in one place.
#extend task {
# reference spec “Link to Wiki page”
#}
#extend resource {
# text Phone “Phone”
#}
}

copyright “Claim your rights here”

# If you have any text block that you need multiple times to describe
# your project, you should define a macro for it. Macros can even have
# variable segments that you can set upon calling the macro.
#
# macro Task [
# task “A ${1} task” {
# }
# ]
#
# Can be called as
# ${Task “big”}
# to generate
# task “A big task” {
# }

# You can attach flags to accounts, resources and tasks. These can be
# used to filter out subsets of them during reporting.
flags important, hidden

# If you want to do budget planning for you project, you need to
# define some accounts.
account cost “Project Cost” {
account dev “Development”
account doc “Documentation”
}
account rev “Customer Payments”

# The Profit&Loss analysis should be rev – cost accounts.
balance cost rev

# Define you public holidays here.
vacation “New Year’s Day” 2012-01-02
vacation “Birthday of Martin Luther King, Jr.” 2012-01-16
vacation “Washington’s Birthday” 2012-02-20
vacation “Memorial Day” 2012-05-28
vacation “Independence Day” 2012-07-04
vacation “Labor Day” 2012-09-03
vacation “Columbus Day” 2012-10-08
vacation “Veterans Day” 2012-11-12
vacation “Thanksgiving Day” 2012-11-22
vacation “Christmas Day” 2012-12-25

# The daily default rate of all resources. This can be overridden for each
# resource. We specify this, so that we can do a good calculation of
# the costs of the project.
rate 400.0

# This is a set of example resources.
resource r1 “Resource 1”
resource t1 “Team 1” {
managers r1
resource r2 “Resource 2”
resource r3 “Resource 3”
}

# This is a resource that does not do any work.
resource s1 “System 1” {
efficiency 0.0
rate 600.0
}

task project “Project” {
task wp1 “Workpackage 1” {
task t1 “Task 1”
task t2 “Task 2”
}
task wp2 “Work package 2” {
depends !wp1
task t1 “Task 1”
task t2 “Task 2”
}
task deliveries “Deliveries” {
task “Item 1” {
depends !!wp1
}
task “Item 2” {
depends !!wp2
}
}
}

# Now the project has been specified completely. Stopping here would
# result in a valid TaskJuggler file that could be processed and
# scheduled. But no reports would be generated to visualize the
# results.

navigator navbar {
hidereport 0
}

macro TaskTip [
tooltip istask() -8<-
”’Start: ”’ <-query attribute=’start’->
”’End: ”’ <-query attribute=’end’->
—-
”’Resources:”’

<-query attribute=’resources’->
—-
”’Precursors: ”’

<-query attribute=’precursors’->
—-
”’Followers: ”’

<-query attribute=’followers’->
->8-
]

textreport frame “” {
header -8<-
== TaskJuggler Project Template ==
<[navigator id=”navbar”]>
->8-
footer “—-“
textreport index “Overview” {
formats html
center ‘<[report id=”overview”]>’
}

textreport “Status” {
formats html
center -8<-
<[report id=”status.dashboard”]>
—-
<[report id=”status.completed”]>
—-
<[report id=”status.ongoing”]>
—-
<[report id=”status.future”]>
->8-
}

textreport wps “Work packages” {
textreport wp1 “Work package 1” {
formats html
center ‘<[report id=”wp1″]>’
}

textreport wp2 “Work package 2” {
formats html
center ‘<[report id=”wp2″]>’
}
}

textreport “Deliveries” {
formats html
center ‘<[report id=”deliveries”]>’
}

textreport “ContactList” {
formats html
title “Contact List”
center ‘<[report id=”contactList”]>’
}
textreport “ResourceGraph” {
formats html
title “Resource Graph”
center ‘<[report id=”resourceGraph”]>’
}
}

# A traditional Gantt chart with a project overview.
taskreport overview “” {
header -8<-
=== Project Overview ===

The project is structured into 2 work packages.

# Specification
# <-reportlink id=’frame.wps.wp1′->
# <-reportlink id=’frame.wps.wp2′->
# Testing

=== Original Project Plan ===
->8-
columns bsi { title ‘WBS’ },
name, start, end, effort, cost,
revenue, chart { ${TaskTip} }
# For this report we like to have the abbreviated weekday in front
# of the date. %a is the tag for this.
timeformat “%a %Y-%m-%d”
loadunit days
hideresource 1
balance cost rev
caption ‘All effort values are in man days.’

footer -8<-
=== Staffing ===

All project phases are properly staffed. See [[ResourceGraph]] for
detailed resource allocations.

=== Current Status ===

Some blurb about the current situation.
->8-
}

# Macro to set the background color of a cell according to the alert
# level of the task.
macro AlertColor [
cellcolor plan.alert = 0 “#00D000” # green
cellcolor plan.alert = 1 “#D0D000” # yellow
cellcolor plan.alert = 2 “#D00000” # red
]

taskreport status “” {
columns bsi { width 50 title ‘WBS’ }, name { width 150 },
start { width 100 }, end { width 100 },
effort { width 100 },
alert { tooltip plan.journal
!= ” “<-query attribute=’journal’->” width 150 },
status { width 150 }

taskreport dashboard “” {
headline “Project Dashboard (<-query attribute=’now’->)”
columns name { title “Task” ${AlertColor} width 200},
resources { width 200 ${AlertColor}
listtype bullets
listitem “<-query attribute=’name’->”
start ${projectstart} end ${projectend} },
alerttrend { title “Trend” ${AlertColor} width 50 },
journal { width 350 ${AlertColor} }
journalmode status_up
journalattributes headline, author, date, summary, details
hidetask ~hasalert(0)
sorttasks alert.down, plan.end.up
period %{${now} – 1w} +1w
}
taskreport completed “” {
headline “Already completed tasks”
hidetask ~(plan.end <= ${now})
}
taskreport ongoing “” {
headline “Ongoing tasks”
hidetask ~((plan.start <= ${now}) & (plan.end > ${now}))
}
taskreport future “” {
headline “Future tasks”
hidetask ~(plan.start > ${now})
}
}

# A list of tasks showing the resources assigned to each task.
taskreport wp1 “” {
headline “Work package 1 – Resource Allocation Report”
columns bsi { title ‘WBS’ }, name, start, end, effort { title “Work” },
duration, chart { ${TaskTip} scale day width 500 }
timeformat “%Y-%m-%d”
hideresource ~(isleaf() & isleaf_())
sortresources name.up
taskroot project.wp1
}
# A list of tasks showing the resources assigned to each task.
taskreport wp2 “” {
headline “Work package 2 – Resource Allocation Report”
columns bsi { title ‘WBS’ }, name, start, end, effort { title “Work” },
duration, chart { ${TaskTip} scale day width 500 }
timeformat “%Y-%m-%d”
hideresource ~(isleaf() & isleaf_())
sortresources name.up
taskroot project.wp2
}

# A list of all tasks with the percentage completed for each task
taskreport deliveries “” {
headline “Project Deliverables”
columns bsi { title ‘WBS’ }, name, start, end, note { width 150 }, complete,
chart { ${TaskTip} }
taskroot project.deliveries
hideresource 1
}
# A list of all employees with their contact details.
resourcereport contactList “” {
headline “Contact list and duty plan”
columns name,
email { celltext 1 “[mailto:<-email-> <-email->]” },
managers { title “Manager” },
chart { scale day }
hideresource ~isleaf()
sortresources name.up
hidetask 1
}

# A graph showing resource allocation. It identifies whether each
# resource is under- or over-allocated for.
resourcereport resourceGraph “” {
headline “Resource Allocation Graph”
columns no, name, effort, rate, weekly { ${TaskTip} }
loadunit shortauto
# We only like to show leaf tasks for leaf resources.
hidetask ~(isleaf() & isleaf_())
sorttasks plan.start.up
}

3) Execute the file  using the below command

tj3 filename.tjp

The HTML files will be created in the folder you execute the above command with the Todo list details. This can be carried out in any folders, it’s not necessary that this has to be done inside the rails application folder.

For more examples, https://github.com/taskjuggler/TaskJuggler

Count, Size & Length methods. Which one to use where? What’s the difference between these?

Even the experienced developers will struggle to answer this correctly. Where to use count method? Where to use size method? Where to use length method? What is the difference among these? What is the advantages/disadvantages of using this? Which one is effective in using which areas? etc…, Find the answer below for the above questions :-

Consider, you have use any of these methods in both Active record (and) as a ruby method. First let us see which one to use as a ruby method.

AS A RUBY METHOD

names=[“Sachin”, “Dravid”, “Ashwin”]

Now, if you use names.size it will return the value 3. If you use names.length again it will return the same value 3. But I would recommended to go for names.length rather than names.size. Because, see the below example :-

If you try to find the size of any numbers using size method, it will return you some value whereas length method will throw the error. So if we use size method, we will not be 100% sure whether the output returned is correct or not..

1.size => 4

1.length => NoMethodError: undefined method `length’ for 1:Fixnum

AS A ACTIVE RECORD METHOD

Assume that we have 2 tables, one is user  and another is chats which has the relation as below :-

User -> has many –> Chats

Chats -> belongs_to –> User

user.chats.length –> This always loads the content of the association into memory, and then returns the number of elements loaded.

Chat Load (0.1ms)   SELECT * FROM `chats` WHERE (`chats`.user_id = 1) 

user.chats.count –> Determines the number of elements with the simple SQL count query.

1st time (Before the collection was loaded)

Chat Columns (1.0ms) SHOW FIELDS FROM `chats`
SQL (0.1ms) SELECT count(*) AS count_all FROM `chats` WHERE (`chats`.user_id = 1)

2nd time (Before the collection was loaded)

SQL (0.1ms) SELECT count(*) AS count_all FROM `chats` WHERE (`chats`.user_id = 1)

After running user.chats.length (or collection was already loaded)

SQL (0.1ms) SELECT count(*) AS count_all FROM `chats` WHERE (`chats`.user_id = 1)

user.chats.size –> This method has some caching mechanism, and it is like using the ‘count’ method if the collection was not already loaded (Executes the SQL count query). But if the collection was already loaded, it just takes the caching mechanism to display the size without even firing a SQL query.

1st time (Before the collection was loaded)

Chat Columns (1.0ms) SHOW FIELDS FROM `chats`

SQL (0.1ms) SELECT count(*) AS count_all FROM `chats` WHERE (`chats`.user_id = 1)

2nd time (Before the collection was loaded)

SQL (0.1 ms) SELECT count(*) AS count_all FROM `chats` WHERE (`chats`.user_id = 1)

After running user.chats.length (or collection was already loaded)

(NO SQL QUERY WILL BE FIRED, AND IT RETURNS THE CACHE VALUE)

CONCLUSION 


If you are going to use any of these methods during ActiveRecord I would suggest you to use the SIZE method.

If you are going to use any of these methods during normal ruby process I would suggest you to use the LENGTH method. 

Extracting the URL into several parts, in RoR

  From the following example we can notice that the values of headers are coming in a HASH and from there it can be extracted easily.
Headers (request.headers) :  
{“HTTP_HOST”=>”localhost:3000”, “HTTP_ACCEPT”=>”text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”, “SERVER_NAME”=>”localhost”, “rack.session”=>{:session_id=>”7aad641cdd3c586d8112302977101ce0”}, “rack.url_scheme”=>”http”, “REQUEST_PATH”=>”/user/login”, “HTTP_USER_AGENT”=>”Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8”, “HTTP_KEEP_ALIVE”=>”115”, “rack.errors”=>#<IO:0xb76e6560>, “HTTP_ACCEPT_LANGUAGE”=>”en-us,en;q=0.5”, “SERVER_PROTOCOL”=>”HTTP/1.1”, “action_controller.request.request_parameters”=>{}, “rack.version”=>[1, 0], “rack.run_once”=>false, “SERVER_SOFTWARE”=>”Mongrel 1.1.5”, “PATH_INFO”=>”/user/login”, “REMOTE_ADDR”=>”127.0.0.1”, “SCRIPT_NAME”=>””, “rack.multithread”=>false, “HTTP_VERSION”=>”HTTP/1.1”, “rack.multiprocess”=>false, “REQUEST_URI”=>”/user/login?client_id=70104c672f9bf60561a7f16ade1216a3&scope=DC,TL&id=dd&redirect_url=http://google.com“, “action_controller.request.path_parameters”=>{“action”=>”login_manage”, “controller”=>”manage_profiles”}, “HTTP_ACCEPT_CHARSET”=>”ISO-8859-1,utf-8;q=0.7,*;q=0.7”, “SERVER_PORT”=>”3000”, “rack.request.query_hash”=>{“scope”=>”DC,TL”, “redirect_url”=>”dfdf”, “id”=>”123456”, “client_id”=>”70104c672f9bf60561a7f16ade1216a3”}…………}
From the above we can extract the values separately as below :-
Protocol (request.headers[‘rack.url_scheme’]) –> http
Host Name (request.headers[‘SERVER_NAME’]) –> localhost
Host Port (request.headers[‘SERVER_PORT’]) –> 3000
URL Path (request.headers[‘REQUEST_PATH’]) –> /user/login
Parameters :
Scope (request.headers[‘rack.request.query_hash’][‘scope’]) –> DC,TL
Redirect URL (request.headers[‘rack.request.query_hash’][‘redirect_url’]) –> http://google.com
ID (request.headers[‘rack.request.query_hash’][‘id’]) –> 123456
Client ID (request.headers[‘rack.request.query_hash’][‘client_id’]) –> 70104c672f9bf60561a7f16ade1216a3

Code Example :-

p “Protocol : #{request.headers[‘rack.url_scheme’]}”
p “Host Name: #{request.headers[‘SERVER_NAME’]}”
p “Host Port: #{request.headers[‘SERVER_PORT’]}”
p “Path : #{request.headers[‘REQUEST_PATH’]}”
p “Scope : #{request.headers[‘rack.request.query_hash’][‘scope’]}”
p “Redirect URL : #{request.headers[‘rack.request.query_hash’][‘redirect_url’]}”
p “ID : #{request.headers[‘rack.request.query_hash’][‘id’]}”
p “Client ID : #{request.headers[‘rack.request.query_hash’][‘client_id’]}”

Result :-

“Protocol : http”
“Host Name: localhost”
“Host Port: 3000”
“Path : /user/login”
“Scope : DC,TL”
“Redirect URL : http://google.com
“ID : 123456”
“Client ID : 70104c672f9bf60561a7f16ade1216a3”