The project uses tempate for writing report generation code. please refer the file gather_report.tpl.html
The AWK script apply_template.awk is used for generating the report.sql (or ../gather_report.sql)
cat gather_report.tpl.html | awk -f apply_template.awk > report.sql; psql -X -f report.sql > out.html
Please refer SQL documentation on SQL statement used in this project.