forked from NRCan-IETS-CE-O-HBC/HTAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateCostDataFile.rb
29 lines (22 loc) · 1 KB
/
CreateCostDataFile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env ruby
# ******************************************************************************
# CreateCostDataFile.rb
# Developed by Jeff Blake, CanmetENERGY-Ottawa, Natural Resources Canada
# Created September 2018
# Master maintained in GitHub
#
# This script creates a JSON cost data file by converting a costing spreadsheet
# that has been cleaned up from the original LEEP costing spreadsheet.
#
# This script could be modified to read directly from the large, multi-sheet
# LEEP Excel files and extract/reformat to suit with a little more effort.
# ******************************************************************************
require 'csv'
require 'json'
require 'fileutils'
extracted_data = CSV.table('./UnitCosts_Edited.csv', header_converters: nil )
transformed_data = extracted_data.map { |row| row.to_hash }
File.open('./HTAPUnitCosts.json', 'w') do |file|
file.puts JSON.pretty_generate(transformed_data)
end
puts("HTAPUnitCosts.json successfully created with #{transformed_data.count} entries.")