decc_2050_model 3.5.0 → 3.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b26eec4356370d26fbb5ff2136b28a226d0b85f
4
- data.tar.gz: 4a63fa30a1af05d173ffddb9678824b698fb273e
3
+ metadata.gz: a61c1668f61f916a1a6f625d1222af61b07f9681
4
+ data.tar.gz: 232abaecae5eae78d80c8a4c2d99f6e16eefd2a8
5
5
  SHA512:
6
- metadata.gz: d2133d957825d1f5212b95a6eef40841ce127ea1edca9d13483312c9add3b31cec7fd36612b1e386e23469099d9ce99c3f593de742ac6a23d9a5b8cfbd05f66b
7
- data.tar.gz: 7a54468cdb811056f686a810d0f3127c9ff77f2348222c77dedb81c127f2916ad207989bf5ee2b006c4226ff4198ca0b16116f7fe04b526fd78b93e36c0e6ce0
6
+ metadata.gz: b1c32da0e29f3994976ae1fba5fb6768ad87e5d07e52c16ec75f9f92096a907183954a26400ee46e4785d53b4ba5963b41c864a1a187cc2999c4e230ad3d85aa
7
+ data.tar.gz: e42a747d886b7f24435d48cff62cc3803d85245daea2beb12edd43c7391db7e96c6b7cb66602114a58b5546187fc967d37fbf087cb27ee6ddc22341da93d7fd8
@@ -30,19 +30,19 @@ First of all, you need to be working on the github version of the code, not the
30
30
 
31
31
  git clone http://github.com/decc/decc_2050_model
32
32
 
33
- Then put the new spreadsheet in spreadsheet/2050Model.xlsx
33
+ Then put the new spreadsheet in spreadsheet/model.xlsx
34
34
 
35
35
  Then, from the top directory of the gem:
36
36
 
37
37
  bundle
38
38
  bundle exec rake
39
39
 
40
- The next step is to check whether Rakefile, lib/decc_2050_model/decc_2050_model_result.rb and lib/decc_2050_model/model_structure.rb need to be altered so that they
40
+ The next step is to check whether Rakefile, lib/model/_model_result.rb and lib/model/model_structure.rb need to be altered so that they
41
41
  pick up the correct places in the underlying excel.
42
42
 
43
43
  The final stage is to build and install the new gem:
44
44
 
45
- gem build decc_2050_model.gemspec
45
+ gem build model.gemspec
46
46
  gem install decc_2050_model-<version>.gem
47
47
 
48
48
  ... where <version> is the version number of the gem file that was created in the folder.
@@ -6,10 +6,10 @@ COMPILER = "gcc"
6
6
  COMPILE_FLAGS = "-fPIC"
7
7
  SHARED_LIBRARY_FLAGS = "-shared -fPIC"
8
8
 
9
- OUTPUT = FFI.map_library_name "decc_2050_model"
10
- OUTPUT_DIR = "../lib/decc_2050_model/"
11
- SOURCE = "decc_2050_model.c"
12
- OBJECT = "decc_2050_model.o"
9
+ OUTPUT = FFI.map_library_name "model"
10
+ OUTPUT_DIR = "../lib/model/"
11
+ SOURCE = "model.c"
12
+ OBJECT = "model.o"
13
13
 
14
14
  task :default => [:build]
15
15
 
@@ -26,4 +26,4 @@ file OBJECT => SOURCE do
26
26
  puts "Building #{SOURCE}"
27
27
  puts "Note that this is a really large c file, it may take tens of minutes to compile."
28
28
  sh "#{COMPILER} #{COMPILE_FLAGS} -o #{OBJECT} -c #{SOURCE}"
29
- end
29
+ end
@@ -1,4 +1,4 @@
1
- // /Users/tamc/Documents/2050/decc_2050_model/spreadsheet/2050Model.xlsx approximately translated into C
1
+ // /Users/tamc/Documents/2050/decc_2050_model/spreadsheet/model.xlsx approximately translated into C
2
2
  // First we have c versions of all the excel functions that we know
3
3
  #include <stdio.h>
4
4
  #include <assert.h>
@@ -62,6 +62,7 @@ static ExcelValue hlookup(ExcelValue lookup_value_v,ExcelValue lookup_table_v, E
62
62
  static ExcelValue iferror(ExcelValue value, ExcelValue value_if_error);
63
63
  static ExcelValue excel_index(ExcelValue array_v, ExcelValue row_number_v, ExcelValue column_number_v);
64
64
  static ExcelValue excel_index_2(ExcelValue array_v, ExcelValue row_number_v);
65
+ static ExcelValue excel_isnumber(ExcelValue number);
65
66
  static ExcelValue large(ExcelValue array_v, ExcelValue k_v);
66
67
  static ExcelValue left(ExcelValue string_v, ExcelValue number_of_characters_v);
67
68
  static ExcelValue left_1(ExcelValue string_v);
@@ -505,6 +506,14 @@ static ExcelValue not_equal(ExcelValue a_v, ExcelValue b_v) {
505
506
  return result;
506
507
  }
507
508
 
509
+ static ExcelValue excel_isnumber(ExcelValue potential_number) {
510
+ if(potential_number.type == ExcelNumber) {
511
+ return TRUE;
512
+ } else {
513
+ return FALSE;
514
+ }
515
+ }
516
+
508
517
  static ExcelValue excel_if(ExcelValue condition, ExcelValue true_case, ExcelValue false_case ) {
509
518
  CHECK_FOR_PASSED_ERROR(condition)
510
519
 
@@ -2590,6 +2599,15 @@ int test_functions() {
2590
2599
  assert(rank(THREE, rank_2_v, ZERO).type == ExcelError);
2591
2600
 
2592
2601
 
2602
+ // Test the ISNUMBER function
2603
+ assert(excel_isnumber(ONE).type == ExcelBoolean);
2604
+ assert(excel_isnumber(ONE).number == 1);
2605
+ assert(excel_isnumber(BLANK).type == ExcelBoolean);
2606
+ assert(excel_isnumber(BLANK).number == 0);
2607
+ assert(excel_isnumber(new_excel_string("Hello")).type == ExcelBoolean);
2608
+ assert(excel_isnumber(new_excel_string("Hello")).number == 0);
2609
+ assert(excel_isnumber(TRUE).type == ExcelBoolean);
2610
+ assert(excel_isnumber(TRUE).number == 0);
2593
2611
 
2594
2612
  // Release memory
2595
2613
  free_all_allocated_memory();
@@ -2605,7 +2623,7 @@ int main() {
2605
2623
  // Start of the file specific functions
2606
2624
 
2607
2625
  // definitions
2608
- static ExcelValue ORIGINAL_EXCEL_FILENAME = {.type = ExcelString, .string = "/Users/tamc/Documents/2050/decc_2050_model/spreadsheet/2050Model.xlsx" };
2626
+ static ExcelValue ORIGINAL_EXCEL_FILENAME = {.type = ExcelString, .string = "/Users/tamc/Documents/2050/decc_2050_model/spreadsheet/model.xlsx" };
2609
2627
  static ExcelValue _common0();
2610
2628
  static ExcelValue _common1();
2611
2629
  static ExcelValue _common2();
@@ -65187,7 +65205,7 @@ void reset() {
65187
65205
  };
65188
65206
 
65189
65207
  // starting the value constants
65190
- static ExcelValue C1 = {.type = ExcelString, .string = "Version 3.5.0"};
65208
+ static ExcelValue C1 = {.type = ExcelString, .string = "Version 3.5.1"};
65191
65209
  static ExcelValue C2 = {.type = ExcelString, .string = "Doesn't tackle climate change (All at level 1)"};
65192
65210
  static ExcelValue C3 = {.type = ExcelString, .string = "Maximium demand, no supply"};
65193
65211
  static ExcelValue C4 = {.type = ExcelString, .string = "Maximum supply, no demand"};
@@ -211269,7 +211287,7 @@ void set_control_e32(ExcelValue newValue) { variable_set[6276] = 1; control_e32_
211269
211287
  ExcelValue control_f32() {
211270
211288
  static ExcelValue result;
211271
211289
  if(variable_set[6277] == 1) { return result;}
211272
- result = C16;
211290
+ result = C46;
211273
211291
  variable_set[6277] = 1;
211274
211292
  return result;
211275
211293
  }
@@ -1,7 +1,6 @@
1
- require_relative "decc_2050_model/decc_2050_model"
2
- require_relative "decc_2050_model/decc_2050_model_utilities"
3
- require_relative "decc_2050_model/decc_2050_model_result"
4
- require_relative "decc_2050_model/model_structure"
5
- require_relative "decc_2050_model/model_choice"
6
- require_relative "decc_2050_model/model_alternative"
7
- require_relative "decc_2050_model/decc_2050_model_version"
1
+ require_relative 'model'
2
+
3
+ Decc2050Model = Model
4
+ Decc2050ModelShim = ModelShim
5
+ Decc2050ModelResult = ModelResult
6
+
@@ -0,0 +1,7 @@
1
+ require_relative "model/model"
2
+ require_relative "model/model_utilities"
3
+ require_relative "model/model_result"
4
+ require_relative "model/model_structure"
5
+ require_relative "model/model_choice"
6
+ require_relative "model/model_alternative"
7
+ require_relative "model/model_version"
@@ -1,7 +1,7 @@
1
1
  require 'ffi'
2
2
  require 'singleton'
3
3
 
4
- class Decc2050ModelShim
4
+ class ModelShim
5
5
 
6
6
  # WARNING: this is not thread safe
7
7
  def initialize
@@ -9,7 +9,7 @@ class Decc2050ModelShim
9
9
  end
10
10
 
11
11
  def reset
12
- Decc2050Model.reset
12
+ Model.reset
13
13
  end
14
14
 
15
15
  def method_missing(name, *arguments)
@@ -23,8 +23,8 @@ class Decc2050ModelShim
23
23
  end
24
24
 
25
25
  def get(name)
26
- return 0 unless Decc2050Model.respond_to?(name)
27
- ruby_value_from_excel_value(Decc2050Model.send(name))
26
+ return 0 unless Model.respond_to?(name)
27
+ ruby_value_from_excel_value(Model.send(name))
28
28
  end
29
29
 
30
30
  def ruby_value_from_excel_value(excel_value)
@@ -37,11 +37,11 @@ class Decc2050ModelShim
37
37
  r = excel_value[:rows]
38
38
  c = excel_value[:columns]
39
39
  p = excel_value[:array]
40
- s = Decc2050Model::ExcelValue.size
40
+ s = Model::ExcelValue.size
41
41
  a = Array.new(r) { Array.new(c) }
42
42
  (0...r).each do |row|
43
43
  (0...c).each do |column|
44
- a[row][column] = ruby_value_from_excel_value(Decc2050Model::ExcelValue.new(p + (((row*c)+column)*s)))
44
+ a[row][column] = ruby_value_from_excel_value(Model::ExcelValue.new(p + (((row*c)+column)*s)))
45
45
  end
46
46
  end
47
47
  return a
@@ -54,11 +54,11 @@ class Decc2050ModelShim
54
54
  def set(name, ruby_value)
55
55
  name = name.to_s
56
56
  name = "set_#{name[0..-2]}" if name.end_with?('=')
57
- return false unless Decc2050Model.respond_to?(name)
58
- Decc2050Model.send(name, excel_value_from_ruby_value(ruby_value))
57
+ return false unless Model.respond_to?(name)
58
+ Model.send(name, excel_value_from_ruby_value(ruby_value))
59
59
  end
60
60
 
61
- def excel_value_from_ruby_value(ruby_value, excel_value = Decc2050Model::ExcelValue.new)
61
+ def excel_value_from_ruby_value(ruby_value, excel_value = Model::ExcelValue.new)
62
62
  case ruby_value
63
63
  when Numeric
64
64
  excel_value[:type] = :ExcelNumber
@@ -82,10 +82,10 @@ class Decc2050ModelShim
82
82
  excel_value[:columns] = ruby_value.size
83
83
  end
84
84
  ruby_values = ruby_value.flatten
85
- pointer = FFI::MemoryPointer.new(Decc2050Model::ExcelValue, ruby_values.size)
85
+ pointer = FFI::MemoryPointer.new(Model::ExcelValue, ruby_values.size)
86
86
  excel_value[:array] = pointer
87
87
  ruby_values.each.with_index do |v,i|
88
- excel_value_from_ruby_value(v, Decc2050Model::ExcelValue.new(pointer[i]))
88
+ excel_value_from_ruby_value(v, Model::ExcelValue.new(pointer[i]))
89
89
  end
90
90
  when Symbol
91
91
  excel_value[:type] = :ExcelError
@@ -99,9 +99,9 @@ class Decc2050ModelShim
99
99
  end
100
100
 
101
101
 
102
- module Decc2050Model
102
+ module Model
103
103
  extend FFI::Library
104
- ffi_lib File.join(File.dirname(__FILE__),FFI.map_library_name('decc_2050_model'))
104
+ ffi_lib File.join(File.dirname(__FILE__),FFI.map_library_name('model'))
105
105
  ExcelType = enum :ExcelEmpty, :ExcelNumber, :ExcelString, :ExcelBoolean, :ExcelError, :ExcelRange
106
106
 
107
107
  class ExcelValue < FFI::Struct
@@ -1,10 +1,10 @@
1
- require_relative '../decc_2050_model'
1
+ require_relative '../model'
2
2
 
3
- class Decc2050ModelResult < Decc2050ModelUtilities
3
+ class ModelResult < ModelUtilities
4
4
  attr_accessor :excel, :pathway
5
5
 
6
6
  def initialize
7
- @excel = Decc2050ModelShim.new
7
+ @excel = ModelShim.new
8
8
  end
9
9
 
10
10
  def self.calculate_pathway(code)
@@ -210,13 +210,13 @@ class Decc2050ModelResult < Decc2050ModelUtilities
210
210
  end
211
211
 
212
212
  if __FILE__ == $0
213
- g = Decc2050ModelResult.new
213
+ g = ModelResult.new
214
214
 
215
215
  tests = 100
216
216
  t = Time.now
217
217
  a = []
218
218
  tests.times do
219
- a << g.calculate_pathway(Decc2050ModelResult::CONTROL.map { rand(4)+1 }.join)
219
+ a << g.calculate_pathway(ModelResult::CONTROL.map { rand(4)+1 }.join)
220
220
  end
221
221
  te = Time.now - t
222
222
  puts "#{te/tests} seconds per run"
@@ -1,13 +1,13 @@
1
- require_relative 'decc_2050_model'
1
+ require_relative 'model'
2
2
  require 'singleton'
3
3
 
4
- class ModelStructure < Decc2050ModelUtilities
4
+ class ModelStructure < ModelUtilities
5
5
  include Singleton
6
6
 
7
7
  attr_accessor :excel, :choices
8
8
 
9
9
  def initialize
10
- @excel = Decc2050ModelShim.new
10
+ @excel = ModelShim.new
11
11
  @choices = []
12
12
  types.each_with_index do |choice_type,i|
13
13
  case choice_type
@@ -1,4 +1,4 @@
1
- class Decc2050ModelUtilities
1
+ class ModelUtilities
2
2
  # Set the 9 decimal points between 1.1 and 3.9
3
3
  FLOAT_TO_LETTER_MAP = Hash["abcdefghijklmnopqrstuvwxyzABCD".split('').map.with_index { |l,i| [(i/10.0)+1,l] }]
4
4
  FLOAT_TO_LETTER_MAP[0.0] = '0'
@@ -0,0 +1 @@
1
+ def Model.last_modified_date() @last_modified_date ||= Time.utc(*[55, 52, 11, 27, 11, 2013, 3, 331, false, "GMT"]); end
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
- # Create a test for decc_2050_model_result
3
- require_relative '../lib/decc_2050_model'
2
+ # Create a test for model_result
3
+ require_relative '../lib/model'
4
4
  require 'pp'
5
5
 
6
6
  pathway = ARGV[0].strip
7
7
  tests_folder = File.join(File.dirname(__FILE__),"expected_results")
8
8
 
9
9
  puts "Creating a copy of the output for pathway #{pathway} and puting it in #{tests_folder}"
10
- puts "To compare future versions of the model with this test result, run test_decc_2050_model_result.rb"
10
+ puts "To compare future versions of the model with this test result, run test_model_result.rb"
11
11
 
12
- model = Decc2050ModelResult.new
12
+ model = ModelResult.new
13
13
  File.open(File.join(tests_folder,"#{pathway}.json"),'w') do |f|
14
14
  result = model.calculate_pathway(pathway).pretty_inspect
15
15
  f.puts pathway
@@ -1,18 +1,18 @@
1
1
  # coding: utf-8
2
- # Test for decc_2050_model
2
+ # Test for model
3
3
  require 'rubygems'
4
4
  gem 'minitest'
5
5
  require 'minitest/autorun'
6
- require_relative '../lib/decc_2050_model'
6
+ require_relative '../lib/model'
7
7
 
8
- class TestDecc2050Model < Minitest::Test
8
+ class TestModel < Minitest::Test
9
9
  def self.runnable_methods
10
10
  puts 'Overriding minitest to run tests in a defined order'
11
11
  methods = methods_matching(/^test_/)
12
12
  end
13
13
  def worksheet; @worksheet ||= init_spreadsheet; end
14
- def init_spreadsheet; Decc2050ModelShim.new end
15
- def test_control_m1; assert_equal("Version 3.5.0", worksheet.control_m1); end
14
+ def init_spreadsheet; ModelShim.new end
15
+ def test_control_m1; assert_equal("Version 3.5.1", worksheet.control_m1); end
16
16
  def test_control_m4; assert_equal("Doesn't tackle climate change (All at level 1)", worksheet.control_m4); end
17
17
  def test_control_n4; assert_equal("Maximium demand, no supply", worksheet.control_n4); end
18
18
  def test_control_o4; assert_equal("Maximum supply, no demand", worksheet.control_o4); end
@@ -559,7 +559,7 @@ class TestDecc2050Model < Minitest::Test
559
559
  def test_control_bq31; assert_equal("By 2050, 20% conventional combustion engine cars, with 32% in plug-in hybrid vehicles and 48% in zero emission vehicles: 22% of bus travel fully electric or fuel cell electric ", worksheet.control_bq31); end
560
560
  def test_control_br31; assert_equal("By 2050 100% electric motor or hydrogen fuel cell; all passenger trains electrified; 50% bus electrified ", worksheet.control_br31); end
561
561
  def test_control_d32; assert_equal("Choice of fuel cells or batteries", worksheet.control_d32); end
562
- def test_control_f32; assert_in_epsilon(4, worksheet.control_f32, 0.001); end
562
+ def test_control_f32; assert_equal("D", worksheet.control_f32); end
563
563
  def test_control_h32; assert_equal("100% of zero emission cars use batteries by 2050", worksheet.control_h32); end
564
564
  def test_control_i32; assert_equal("Among zero emission cars, 80% use batteries and 20% use fuel cells by 2050", worksheet.control_i32); end
565
565
  def test_control_j32; assert_equal("Among zero emission cars, 20% use batteries and 80% use fuel cells by 2050", worksheet.control_j32); end
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
- # Test for decc_2050_model_result
2
+ # Test for model_result
3
3
  require 'rubygems'
4
4
  gem 'minitest'
5
5
  require 'test/unit'
6
- require_relative '../lib/decc_2050_model'
6
+ require_relative '../lib/model'
7
7
  require 'pp'
8
8
 
9
- class TestDecc2050ModelResult < Test::Unit::TestCase
9
+ class TestModelResult < Test::Unit::TestCase
10
10
 
11
11
  def test_results
12
- @model = Decc2050ModelResult.new
12
+ @model = ModelResult.new
13
13
  tests_folder = File.join(File.dirname(__FILE__),"expected_results")
14
14
  Dir[File.join(tests_folder, "*.json")].each do |test|
15
15
  expected = IO.readlines(test)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decc_2050_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Counsell, Department of Energy and Climate Change, Her Majesty's Government,
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-19 00:00:00.000000000 Z
12
+ date: 2013-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -51,11 +51,11 @@ description: "# DECC 2050 CALCULATOR TOOL\n\nA C version and ruby wrapper for th
51
51
  10-20 minutes or so\n\n gem install decc_2050_model\n \n## UPDATING TO NEWER
52
52
  VERSIONS OF EXCEL MODEL\n\nFirst of all, you need to be working on the github version
53
53
  of the code, not the rubygem:\n \n git clone http://github.com/decc/decc_2050_model\n\nThen
54
- put the new spreadsheet in spreadsheet/2050Model.xlsx\n\nThen, from the top directory
54
+ put the new spreadsheet in spreadsheet/model.xlsx\n\nThen, from the top directory
55
55
  of the gem:\n \n bundle\n bundle exec rake\n \nThe next step is to check
56
- whether Rakefile, lib/decc_2050_model/decc_2050_model_result.rb and lib/decc_2050_model/model_structure.rb
57
- need to be altered so that they\npick up the correct places in the underlying excel.\n
58
- \ \nThe final stage is to build and install the new gem:\n \n gem build decc_2050_model.gemspec\n
56
+ whether Rakefile, lib/model/_model_result.rb and lib/model/model_structure.rb need
57
+ to be altered so that they\npick up the correct places in the underlying excel.\n
58
+ \ \nThe final stage is to build and install the new gem:\n \n gem build model.gemspec\n
59
59
  \ gem install decc_2050_model-<version>.gem \n\n... where <version> is the version
60
60
  number of the gem file that was created in the folder.\n \nNow follow the instructions
61
61
  in the twenty-fifty server directory in order to ensure that it is using this new
@@ -67,24 +67,25 @@ extensions:
67
67
  extra_rdoc_files: []
68
68
  files:
69
69
  - README.markdown
70
- - lib/decc_2050_model/decc_2050_model.rb
71
- - lib/decc_2050_model/decc_2050_model_result.rb
72
- - lib/decc_2050_model/decc_2050_model_utilities.rb
73
- - lib/decc_2050_model/decc_2050_model_version.rb
74
- - lib/decc_2050_model/model_alternative.rb
75
- - lib/decc_2050_model/model_choice.rb
76
- - lib/decc_2050_model/model_structure.rb
77
70
  - lib/decc_2050_model.rb
78
- - ext/decc_2050_model.c
79
- - test/create_decc_2050_model_result.rb
71
+ - lib/model/model.rb
72
+ - lib/model/model_alternative.rb
73
+ - lib/model/model_choice.rb
74
+ - lib/model/model_result.rb
75
+ - lib/model/model_structure.rb
76
+ - lib/model/model_utilities.rb
77
+ - lib/model/model_version.rb
78
+ - lib/model.rb
79
+ - ext/model.c
80
+ - test/create_model_result.rb
80
81
  - test/expected_results/10111111111111110111111001111110111101101101110110111.json
81
82
  - test/expected_results/10111111111111110111111004444440444404203304440420111.json
82
83
  - test/expected_results/40444444444444440444444001111110111101101101110110441.json
83
84
  - test/expected_results/40444444444444440444444004444440444404203304440420441.json
84
85
  - test/expected_results/e0d3jrg221ci12110222112004423220444404202304440420141.json
85
86
  - test/expected_results/i0g2dd2pp1121f1i032211p004314110433304202304320420121.json
86
- - test/test_decc_2050_model.rb
87
- - test/test_decc_2050_model_result.rb
87
+ - test/test_model.rb
88
+ - test/test_model_result.rb
88
89
  - ext/Rakefile
89
90
  homepage: http://github.com/decc/decc_2050_model
90
91
  licenses:
@@ -111,3 +112,4 @@ signing_key:
111
112
  specification_version: 4
112
113
  summary: A C version of DECC's 2050 Pathway Excel Spreadsheet
113
114
  test_files: []
115
+ has_rdoc: false
@@ -1 +0,0 @@
1
- def Decc2050Model.last_modified_date() @last_modified_date ||= Time.utc(*[10, 19, 11, 19, 11, 2013, 2, 323, false, "GMT"]); end