     nopunct = (s) -> s.replace(/[\s'\.,-:;]/g, "")
     unique = {}
     for r in purposes
+      if not r.code? then r.code = "00000"
+      if not r.name? then r.name = "Unknown"
+
       r.name = r.name.trim()
       uname = r.name.toUpperCase()
       

    _.values(unique)


  @get '/aiddata-purposes.csv': ->
    pg.sql "select distinct(purpose_code) as code,purpose_name as name
              from donor_recipient_year_purpose_ma 

              SUM(num_commitments) as total_num,
              SUM(to_number(sum_amount_usd_constant, 'FM99999999999999999999')) as total_amount
            from donor_recipient_year_purpose_ma 
            
            group by purpose_code, purpose_name
            order by purpose_name
          ",
