excel_to_code 0.1.18 → 0.1.20

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: 941c09c8afeaa5e544a63fb1085365f8a4f7f992
4
- data.tar.gz: d5a324022f70c5a83911b77a6ca059be3d738922
3
+ metadata.gz: dbfac77ee7c479c1e3608dac1dad7892a8156e92
4
+ data.tar.gz: f474343c232b69a7b91a05a51fad658253af9991
5
5
  SHA512:
6
- metadata.gz: a5fd21e7c3779df389c0b876b0369ffdc486118081d1dc875bac7c325f5bab95a66f25989180cdadf67c3c9c5c652f5c3f527a474b6dbfc36b31b520f8a019c0
7
- data.tar.gz: e45262481894791a2139ddb75cf9c961732401b433360d634063e6aafd87c792cb4fc18f034e8aaa12f0d19f9aae9a0e8630d1e845485fc4545302871d067323
6
+ metadata.gz: 20fe12e945146c0d0740e00b534a8474848231cf3d938f71a85fafff43ef977b233ba12cafc53d165a440ce0a3ed950d316ff70a53239af0a314ba1dace6884a
7
+ data.tar.gz: e6efe0d22d6f042633ea7885d83ba0319bcddda0ea00adb874784a8e05e7b90b115c6cd02c218b9d62960a99f3e0a9b6136054df623afddb048e123ebbb3e27d
data/TODO CHANGED
@@ -25,5 +25,5 @@ See doc/How_to_add_a_missing_function.md
25
25
  * Rewrite the excel_to_ruby command to use command line options
26
26
  * Refactor excel_to_c_runtime - split the functions? split the tests?
27
27
  * Tool for turning spreadsheets into tests
28
- * Option to reorder test output to make it easier to localise errors
29
28
  * Tool to create minimal failing example out of test run
29
+ * The whole thing is slow. Could hold the whole excel AST in memory and apply transforms?
data/src/compile/c/a.out CHANGED
Binary file
@@ -76,6 +76,8 @@ static ExcelValue pv_3(ExcelValue a_v, ExcelValue b_v, ExcelValue c_v);
76
76
  static ExcelValue pv_4(ExcelValue a_v, ExcelValue b_v, ExcelValue c_v, ExcelValue d_v);
77
77
  static ExcelValue pv_5(ExcelValue a_v, ExcelValue b_v, ExcelValue c_v, ExcelValue d_v, ExcelValue e_v);
78
78
  static ExcelValue excel_round(ExcelValue number_v, ExcelValue decimal_places_v);
79
+ static ExcelValue rank(ExcelValue number_v, ExcelValue range_v, ExcelValue order_v);
80
+ static ExcelValue rank_2(ExcelValue number_v, ExcelValue range_v);
79
81
  static ExcelValue rounddown(ExcelValue number_v, ExcelValue decimal_places_v);
80
82
  static ExcelValue roundup(ExcelValue number_v, ExcelValue decimal_places_v);
81
83
  static ExcelValue excel_int(ExcelValue number_v);
@@ -1096,7 +1098,6 @@ static ExcelValue mmult(ExcelValue a_v, ExcelValue b_v) {
1096
1098
  int n = a_v.columns;
1097
1099
  int a_rows = a_v.rows;
1098
1100
  int a_columns = a_v.columns;
1099
- int b_rows = b_v.rows;
1100
1101
  int b_columns = b_v.columns;
1101
1102
  ExcelValue *result = (ExcelValue*) new_excel_value_array(a_rows*b_columns);
1102
1103
  int i, j, k;
@@ -1220,6 +1221,50 @@ static ExcelValue power(ExcelValue a_v, ExcelValue b_v) {
1220
1221
  return new_excel_number(result);
1221
1222
  }
1222
1223
  }
1224
+ static ExcelValue rank(ExcelValue number_v, ExcelValue range_v, ExcelValue order_v) {
1225
+ CHECK_FOR_PASSED_ERROR(number_v)
1226
+ CHECK_FOR_PASSED_ERROR(range_v)
1227
+ CHECK_FOR_PASSED_ERROR(order_v)
1228
+
1229
+ NUMBER(number_v, number)
1230
+ NUMBER(order_v, order)
1231
+
1232
+ ExcelValue *array;
1233
+ int size;
1234
+
1235
+ CHECK_FOR_CONVERSION_ERROR
1236
+
1237
+ if(range_v.type != ExcelRange) {
1238
+ array = new_excel_value_array(1);
1239
+ array[0] = range_v;
1240
+ size = 1;
1241
+ } else {
1242
+ array = range_v.array;
1243
+ size = range_v.rows * range_v.columns;
1244
+ }
1245
+
1246
+ int ranked = 1;
1247
+ int found = false;
1248
+
1249
+ int i;
1250
+ ExcelValue cell;
1251
+
1252
+ for(i=0; i<size; i++) {
1253
+ cell = array[i];
1254
+ if(cell.type == ExcelError) { return cell; }
1255
+ if(cell.type == ExcelNumber) {
1256
+ if(cell.number == number) { found = true; }
1257
+ if(order == 0) { if(cell.number > number) { ranked++; } }
1258
+ if(order != 0) { if(cell.number < number) { ranked++; } }
1259
+ }
1260
+ }
1261
+ if(found == false) { return NA; }
1262
+ return new_excel_number(ranked);
1263
+ }
1264
+
1265
+ static ExcelValue rank_2(ExcelValue number_v, ExcelValue range_v) {
1266
+ return rank(number_v, range_v, ZERO);
1267
+ }
1223
1268
 
1224
1269
  static ExcelValue excel_round(ExcelValue number_v, ExcelValue decimal_places_v) {
1225
1270
  CHECK_FOR_PASSED_ERROR(number_v)
@@ -1693,7 +1738,7 @@ static ExcelValue text(ExcelValue number_v, ExcelValue format_v) {
1693
1738
  return format_v;
1694
1739
  }
1695
1740
 
1696
- if(format_v.string == "0%") {
1741
+ if(strcmp(format_v.string,"0%") == 0) {
1697
1742
  // FIXME: Too little?
1698
1743
  s = malloc(100);
1699
1744
  free_later(s);
@@ -2525,6 +2570,25 @@ int test_functions() {
2525
2570
  assert(mmult_result_5_a[2].type == ExcelError);
2526
2571
  assert(mmult_result_5_a[3].type == ExcelError);
2527
2572
 
2573
+ // Test the RANK() function
2574
+ ExcelValue rank_1_a[] = { FIVE, BLANK, THREE, ONE, ONE, FOUR, FIVE, TRUE, SIX, new_excel_string("Hi")};
2575
+ ExcelValue rank_2_a[] = { FIVE, BLANK, THREE, NA, ONE, FOUR, FIVE, TRUE, SIX, new_excel_string("Hi")};
2576
+ ExcelValue rank_1_v = new_excel_range( rank_1_a, 2, 5);
2577
+ ExcelValue rank_2_v = new_excel_range( rank_2_a, 2, 5);
2578
+
2579
+ // Basics
2580
+ assert(rank(THREE, rank_1_v, ZERO).number == 5);
2581
+ assert(rank_2(THREE, rank_1_v).number == 5);
2582
+ assert(rank(THREE, rank_1_v, ONE).number == 3);
2583
+ assert(rank(ONE, rank_1_v, ZERO).number == 6);
2584
+ assert(rank(new_excel_string("3"), rank_1_v, ONE).number == 3);
2585
+
2586
+ // Errors
2587
+ assert(rank(TEN, rank_1_v, ZERO).type == ExcelError);
2588
+ assert(rank(THREE, rank_2_v, ZERO).type == ExcelError);
2589
+
2590
+
2591
+
2528
2592
  // Release memory
2529
2593
  free_all_allocated_memory();
2530
2594
 
@@ -60,6 +60,8 @@ class MapFormulaeToC < MapValuesToC
60
60
  'PV3' => 'pv_3',
61
61
  'PV4' => 'pv_4',
62
62
  'PV5' => 'pv_5',
63
+ 'RANK2' => 'rank_2',
64
+ 'RANK3' => 'rank',
63
65
  'ROUND' => 'excel_round',
64
66
  'ROUNDDOWN' => 'rounddown',
65
67
  'ROUNDUP' => 'roundup',
@@ -44,6 +44,7 @@ class MapFormulaeToRuby < MapValuesToRuby
44
44
  'PMT' => 'pmt',
45
45
  'POWER' => 'power',
46
46
  'PV' => 'pv',
47
+ 'RANK' => 'rank',
47
48
  'ROUND' => 'round',
48
49
  'ROUNDDOWN' => 'rounddown',
49
50
  'ROUNDUP' => 'roundup',
@@ -85,3 +85,5 @@ require_relative 'excel_functions/hlookup'
85
85
  require_relative 'excel_functions/log'
86
86
 
87
87
  require_relative 'excel_functions/mmult'
88
+
89
+ require_relative 'excel_functions/rank'
@@ -0,0 +1,29 @@
1
+ module ExcelFunctions
2
+
3
+ def rank(number, list, order = 0)
4
+ number = number_argument(number)
5
+ order = number_argument(order)
6
+ list = [[list]] unless list.is_a?(Array)
7
+
8
+ return number if number.is_a?(Symbol)
9
+ return order if order.is_a?(Symbol)
10
+ return list if list.is_a?(Symbol)
11
+
12
+ ranked = 1
13
+ found = false
14
+
15
+ list.flatten.each do |cell|
16
+ return cell if cell.is_a?(Symbol)
17
+ next unless cell.is_a?(Numeric)
18
+ found = true if cell == number
19
+ if order == 0
20
+ ranked += 1 if cell > number
21
+ else
22
+ ranked +=1 if cell < number
23
+ end
24
+ end
25
+ return :na unless found
26
+ return ranked
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel_to_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Counsell, Green on Black Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-22 00:00:00.000000000 Z
11
+ date: 2013-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg
@@ -157,6 +157,7 @@ files:
157
157
  - src/excel/excel_functions/pmt.rb
158
158
  - src/excel/excel_functions/power.rb
159
159
  - src/excel/excel_functions/pv.rb
160
+ - src/excel/excel_functions/rank.rb
160
161
  - src/excel/excel_functions/round.rb
161
162
  - src/excel/excel_functions/rounddown.rb
162
163
  - src/excel/excel_functions/roundup.rb
@@ -235,7 +236,8 @@ files:
235
236
  - bin/excel_to_c
236
237
  - bin/excel_to_ruby
237
238
  homepage: http://github.com/tamc/excel_to_code
238
- licenses: []
239
+ licenses:
240
+ - MIT
239
241
  metadata: {}
240
242
  post_install_message:
241
243
  rdoc_options: []