An open source, stand-alone, customisable public spending data web app.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

46 wiersze
1.1 KiB

  1. require 'lib/models'
  2. require 'csv'
  3. count = 0
  4. CSV::Reader.parse(File.open('data/2009Q4.csv', 'rb')) do |row|
  5. # 2009Q4 Columns:
  6. # 0: Directorate
  7. # 1: Updated
  8. # 2: TransNo
  9. # 3: Service
  10. # 4: Cost Centre
  11. # 5: Supplier Name
  12. # 6: Amount excl vat
  13. # 7: Type
  14. count += 1
  15. if (count > 4) # skip first four lines that don't contain data
  16. p row
  17. directorate = Directorate.first_or_create(:name => row[0].strip)
  18. service = Service.first_or_create(:name => row[3].strip)
  19. supplier = Supplier.first_or_create(:name => row[5].strip)
  20. payment = Payment.first_or_create(
  21. 'trans_no' => row[2],
  22. 'directorate' => directorate,
  23. 'service' => service,
  24. 'supplier' => supplier,
  25. 'cost_centre' => row[4].strip,
  26. 'amount' => row[6].strip.gsub(/,/, ''),
  27. 'd' => row[1],
  28. 'tyype' => row[7].strip
  29. )
  30. unless payment.save
  31. puts "ERROR: Failed to save payment"
  32. payment.errors.each do |e|
  33. puts e
  34. end
  35. end
  36. end
  37. end