OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:math'; | 6 import 'dart:math'; |
7 import 'package:sky/framework/net/fetch.dart'; | 7 import 'package:sky/framework/net/fetch.dart'; |
8 | 8 |
9 // Snapshot from http://www.nasdaq.com/screening/company-list.aspx | 9 // Snapshot from http://www.nasdaq.com/screening/company-list.aspx |
10 // Fetched 2/23/2014. | 10 // Fetched 2/23/2014. |
11 // "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary
Quote", | 11 // "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary
Quote", |
12 // final List<List<String>> _kCompanyList = [ | 12 // final List<List<String>> _kCompanyList = [ |
13 // ["TFSC","1347 Capital Corp.","9.43","\$56.09M","2014","Finance","Business S
ervices","http://www.nasdaq.com/symbol/tfsc"], | 13 // ["TFSC","1347 Capital Corp.","9.43","\$56.09M","2014","Finance","Business S
ervices","http://www.nasdaq.com/symbol/tfsc"], |
14 // ["TFSCR","1347 Capital Corp.","0.37","n/a","2014","Finance","Business Servi
ces","http://www.nasdaq.com/symbol/tfscr"], | 14 // ["TFSCR","1347 Capital Corp.","0.37","n/a","2014","Finance","Business Servi
ces","http://www.nasdaq.com/symbol/tfscr"], |
15 // ["TFSCU","1347 Capital Corp.","9.97","\$41.67M","2014","n/a","n/a","http://
www.nasdaq.com/symbol/tfscu"], | 15 // ["TFSCU","1347 Capital Corp.","9.97","\$41.67M","2014","n/a","n/a","http://
www.nasdaq.com/symbol/tfscu"], |
16 // ["TFSCW","1347 Capital Corp.","0.2","n/a","2014","Finance","Business Servic
es","http://www.nasdaq.com/symbol/tfscw"], | 16 // ["TFSCW","1347 Capital Corp.","0.2","n/a","2014","Finance","Business Servic
es","http://www.nasdaq.com/symbol/tfscw"], |
17 // ]; | 17 // ]; |
18 | 18 |
19 class Stock { | 19 class Stock { |
20 String symbol; | 20 String symbol; |
21 String name; | 21 String name; |
22 double lastSale; | 22 double lastSale; |
23 String marketCap; | 23 String marketCap; |
24 double percentChange; | 24 double percentChange; |
25 | 25 |
26 Stock(this.symbol, this.name, this.lastSale, this.marketCap); | 26 Stock(this.symbol, this.name, this.lastSale, this.marketCap, this.percentChang
e); |
27 | 27 |
28 Stock.fromFields(List<String> fields) { | 28 Stock.fromFields(List<String> fields) { |
29 // FIXME: This class should only have static data, not lastSale, etc. | 29 // FIXME: This class should only have static data, not lastSale, etc. |
30 // "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Sum
mary Quote", | 30 // "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Sum
mary Quote", |
31 lastSale = 0.0; | 31 lastSale = 0.0; |
32 try{ | 32 try{ |
33 lastSale = double.parse(fields[2]); | 33 lastSale = double.parse(fields[2]); |
34 } catch(_) {} | 34 } catch(_) {} |
35 symbol = fields[0]; | 35 symbol = fields[0]; |
36 name = fields[1]; | 36 name = fields[1]; |
(...skipping 21 matching lines...) Expand all Loading... |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 Future<StockOracle> fetchStockOracle() async { | 61 Future<StockOracle> fetchStockOracle() async { |
62 Response response = await fetch('lib/stock_data.json'); | 62 Response response = await fetch('lib/stock_data.json'); |
63 String json = response.bodyAsString(); | 63 String json = response.bodyAsString(); |
64 JsonDecoder decoder = new JsonDecoder(); | 64 JsonDecoder decoder = new JsonDecoder(); |
65 var companyList = decoder.convert(json); | 65 var companyList = decoder.convert(json); |
66 return new StockOracle.fromCompanyList(companyList); | 66 return new StockOracle.fromCompanyList(companyList); |
67 } | 67 } |
OLD | NEW |