Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: client/samples/total/src/SYLKReader.dart

Issue 8292003: Total now reads mortgage sample from server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class SYLKReader extends Reader { 5 class SYLKReader extends Reader {
6 6
7 SYLKReader() : super() { } 7 SYLKReader() : super() { }
8 8
9 void loadSpreadsheet(Spreadsheet spreadsheet, List<String> sylk) { 9 void loadSpreadsheet(Spreadsheet spreadsheet, List<String> sylk) {
10 int row, col; 10 int row, col;
(...skipping 26 matching lines...) Expand all
37 String part = parts[j]; 37 String part = parts[j];
38 if (part.startsWith("Y")) { 38 if (part.startsWith("Y")) {
39 row = Math.parseInt(part.substring(1, part.length)); 39 row = Math.parseInt(part.substring(1, part.length));
40 } else if (part.startsWith("X")) { 40 } else if (part.startsWith("X")) {
41 col = Math.parseInt(part.substring(1, part.length)); 41 col = Math.parseInt(part.substring(1, part.length));
42 } if (part.startsWith("K")) { 42 } if (part.startsWith("K")) {
43 contents = StringUtils.stripQuotes(part.substring(1, part.length)); 43 contents = StringUtils.stripQuotes(part.substring(1, part.length));
44 } 44 }
45 } 45 }
46 if (row == -1) { 46 if (row == -1) {
47 throw new RuntimeException("No row (Y) specified in ${sylk[i]}"); 47 throw new RuntimeException("${i}: No row (Y) specified in ${sylk[i]}") ;
48 } 48 }
49 if (col == -1) { 49 if (col == -1) {
50 throw new RuntimeException("No col (X) specified in ${sylk[i]}"); 50 throw new RuntimeException("${i}: No col (X) specified in ${sylk[i]}") ;
51 } 51 }
52 lastLocation = new CellLocation(spreadsheet, new RowCol(row, col)); 52 lastLocation = new CellLocation(spreadsheet, new RowCol(row, col));
53 spreadsheet.execute(new SetCellContentsCommand(lastLocation, contents)); 53 spreadsheet.execute(new SetCellContentsCommand(lastLocation, contents));
54 break; 54 break;
55 case "F": 55 case "F":
56 Cell lastCell = lastLocation.getCell(); 56 Cell lastCell = lastLocation.getCell();
57 if (lastCell == null) { 57 if (lastCell == null) {
58 break; 58 break;
59 } 59 }
60 Style style = lastCell.style; 60 Style style = lastCell.style;
(...skipping 26 matching lines...) Expand all
87 break; 87 break;
88 } 88 }
89 } 89 }
90 } 90 }
91 spreadsheet.setCellStyle(lastLocation.rowCol, style); 91 spreadsheet.setCellStyle(lastLocation.rowCol, style);
92 break; 92 break;
93 } 93 }
94 } 94 }
95 } 95 }
96 96
97 List<String> makeExample(String id) { 97 void request(String name, void callback(String spreadsheet)) {
98 if (id == "mortgage") { 98 String url = '/spreadsheet/get?name=$name';
99 return _makeMortgageExample(); 99 XMLHttpRequest req = new XMLHttpRequest();
100 } else if (id == "insertTest") { 100 req.on.readyStateChange.add((Event event) {
101 return _makeInsertTest(); 101 if (req.readyState != XMLHttpRequest.DONE) {
102 } else if (id == "collatz") { 102 return;
103 return _makeCollatzTest(); 103 }
104 }
105 }
106 104
107 List<String> _makeCollatzTest() { 105 String text;
108 List<String> sylk = new List<String>(); 106 switch (true) {
109 sylk.add('ID;P'); 107 case req.status == 200 && req.responseText != null :
110 sylk.add('B;X1;Y180'); 108 text = req.responseText;
111 sylk.add("C;X1;Y1;K871"); 109 break;
112 for (int row = 2; row < 180; row++) {
113 // x even ==> x / 2
114 // x odd ==> 3 * x + 1
115 // Note that (x - 2*trunc(x/2)) is 0 when x is even and 1 when x is odd
116 sylk.add("C;X1;Y${row};K=(R[-1]C-2*TRUNC(R[-1]C/2))*(3*R[-1]C+1)+(1-(R[-1] C-2*TRUNC(R[-1]C/2)))*(R[-1]C/2)");
117 }
118 return sylk;
119 }
120 110
121 List<String> _makeInsertTest() { 111 default:
122 List<String> sylk = new List<String>(); 112 text = '''ID;P
113 B;X1;Y3
114 C;Y1;X1;K${req.status}
115 C;Y2;X1;K"spreadsheet/get"
116 C;Y3;X1;K"not found"
117 ''';
118 break;
119 }
123 120
124 sylk.add('ID;P'); 121 try {
125 sylk.add('B;X6;Y3'); 122 callback(text);
123 } catch (var e, var s) {
124 print(e);
125 }
126 });
126 127
127 sylk.add('C;Y1;X1;K"InsertTest"'); 128 req.open('GET', url, true);
128 sylk.add('F;SD;FD0C'); 129 req.send();
129 sylk.add('C;Y2;X1;K"Absolute"');
130 sylk.add('F;SD;FD0C');
131 sylk.add('C;Y3;X1;K"Relative"');
132 sylk.add('F;SD;FD0C');
133 sylk.add('C;Y1;X2;K"Fixed"');
134 sylk.add('F;SD;FD0C');
135 sylk.add('C;Y1;X3;K"NS to NS"');
136 sylk.add('F;SD;FD0C');
137 sylk.add('C;Y1;X4;K"NS to S"');
138 sylk.add('F;SD;FD0C');
139 sylk.add('C;Y1;X5;K"S to NS"');
140 sylk.add('F;SD;FD0C');
141 sylk.add('C;Y1;X6;K"S to S"');
142 sylk.add('F;SD;FD0C');
143
144 sylk.add('C;Y2;X2;K1');
145 sylk.add('F;P1;FD0C');
146 sylk.add('C;Y3;X2;K2');
147 sylk.add('F;P1;FD0C');
148
149 sylk.add('C;Y2;X3;K=(R2C2+10)');
150 sylk.add('F;P1;FD0C');
151 sylk.add('C;Y3;X3;K=(R[0]C[-1] + 10)');
152 sylk.add('F;P1;FD0C');
153
154 sylk.add('C;Y2;X4;K=(R2C5-1000)');
155 sylk.add('F;P1;FD0C');
156 sylk.add('C;Y3;X4;K=(R[0]C[1] - 1000)');
157 sylk.add('F;P1;FD0C');
158
159 sylk.add('C;Y2;X5;K=(R2C3+1100)');
160 sylk.add('F;P1;FD0C');
161 sylk.add('C;Y3;X5;K=(R[0]C[-2] + 1100)');
162 sylk.add('F;P1;FD0C');
163
164 sylk.add('C;Y2;X6;K=(R2C5+10000)');
165 sylk.add('F;P1;FD0C');
166 sylk.add('C;Y3;X6;K=(R[0]C[-1] + 10000)');
167 sylk.add('F;P1;FD0C');
168
169 sylk.add('C;Y4;X1;K"Sums Relative"');
170 sylk.add('F;SD;FD0C');
171 sylk.add('C;Y4;X2;K=SUM(R[-2]C[0]:R[-1]C[0])');
172 sylk.add('F;P1;FD0C');
173 sylk.add('C;Y4;X3;K=SUM(R[-2]C[0]:R[-1]C[0])');
174 sylk.add('F;P1;FD0C');
175 sylk.add('C;Y4;X4;K=SUM(R[-2]C[0]:R[-1]C[0])');
176 sylk.add('F;P1;FD0C');
177 sylk.add('C;Y4;X5;K=SUM(R[-2]C[0]:R[-1]C[0])');
178 sylk.add('F;P1;FD0C');
179 sylk.add('C;Y4;X6;K=SUM(R[-2]C[0]:R[-1]C[0])');
180 sylk.add('F;P1;FD0C');
181
182 sylk.add('C;Y5;X1;K"Sums Absolute"');
183 sylk.add('F;SD;FD0C');
184 sylk.add('C;Y5;X2;K=SUM(B2:B3)');
185 sylk.add('F;P1;FD0C');
186 sylk.add('C;Y5;X3;K=SUM(C2:C3)');
187 sylk.add('F;P1;FD0C');
188 sylk.add('C;Y5;X4;K=SUM(D2:D3)');
189 sylk.add('F;P1;FD0C');
190 sylk.add('C;Y5;X5;K=SUM(E2:E3)');
191 sylk.add('F;P1;FD0C');
192 sylk.add('C;Y5;X6;K=SUM(F2:F3)');
193 sylk.add('F;P1;FD0C');
194
195 return sylk;
196 }
197
198 List<String> _makeMortgageExample() {
199 int years = 8;
200 int payments = years * 12;
201 List<String> sylk = new List<String>();
202 sylk.add('ID;P');
203 sylk.add('B;X4;Y${payments + 4}');
204 sylk.add('C;Y1;X1;K"Loan Amount"');
205 sylk.add('F;SD;FD0C');
206 sylk.add('C;Y1;X2;K"Interest Rate"');
207 sylk.add('F;SD;FD0C');
208 sylk.add('C;Y1;X3;K"Years"');
209 sylk.add('F;SD;FD0C');
210 sylk.add('C;Y1;X4;K"\$/Month"');
211 sylk.add('F;SD;FD0C');
212 sylk.add('C;Y2;X1;K30000');
213 sylk.add('F;P5;F\$2R');
214 sylk.add('C;Y2;X2;K.05375');
215 sylk.add('F;P8;F%3R');
216 sylk.add('C;Y2;X3;K${years}');
217 sylk.add('F;P2;FD0R');
218 sylk.add('C;Y2;X4;K=ROUND((R2C1 * ((R2C2/12)/(1 - POWER((1 + (R2C2/12)), (-1 2 * R2C3))))), 2)');
219 sylk.add('F;P5;F\$2R');
220 sylk.add('C;Y3;X1;K"Payment #"');
221 sylk.add('F;SD;FD0C');
222 sylk.add('C;Y3;X2;K"Balance"');
223 sylk.add('F;SD;FD0C');
224 sylk.add('C;Y3;X3;K"Interest"');
225 sylk.add('F;SD;FD0C');
226 sylk.add('C;Y3;X4;K"Principal"');
227 sylk.add('F;SD;FD0C');
228 sylk.add('C;Y4;X1;K1');
229 sylk.add('F;P2;FD0C');
230 sylk.add('C;Y4;X2;K=R2C1');
231 sylk.add('F;P5;F\$2R');
232 sylk.add('C;Y4;X3;K=(RC[-1] * R2C2)/12');
233 sylk.add('F;P5;F\$2R');
234 sylk.add('C;Y4;X4;K=R2C4 - RC[-1]');
235 sylk.add('F;P5;F\$2R');
236 for (int j = 5; j < payments + 4; j++) {
237 sylk.add('C;Y${j};X1;K=R[-1]C + 1');
238 sylk.add('F;P2;FD0C');
239 sylk.add('C;Y${j};X2;K=R[-1]C - R[-1]C[2]');
240 sylk.add('F;P5;F\$2R');
241 sylk.add('C;Y${j};X3;K=(RC[-1] * R2C2)/12');
242 sylk.add('F;P5;F\$2R');
243 sylk.add('C;Y${j};X4;K=R2C4 - RC[-1]');
244 sylk.add('F;P5;F\$2R');
245 }
246
247 int p3 = payments + 3;
248 int p4 = payments + 4;
249 sylk.add('C;Y${p4};X1;K"Totals"');
250 sylk.add('F;SD;FD0C');
251 sylk.add('C;Y${p4};X2;K=C${p4} + D${p4}');
252 sylk.add('F;P5;F\$2R');
253 sylk.add('C;Y${p4};X3;K=SUM(C4:C${p3})');
254 sylk.add('F;P5;F\$2R');
255 sylk.add('C;Y${p4};X4;K=SUM(D4:D${p3})');
256 sylk.add('F;P5;F\$2R');
257 return sylk;
258 } 130 }
259 } 131 }
OLDNEW
« no previous file with comments | « no previous file | client/samples/total/src/Total.dart » ('j') | samples/total/src/GetSpreadsheet.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698