Load data for StocksApp incrementally

Previously we would spend a lot of time during startup processing all 3k stocks
in the data set. This CL breaks the data up into 100 stock chunks and loads
them incrementally off the network. A future CL will switch to loading them on
demand.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/1038533002
This commit is contained in:
Adam Barth 2015-03-24 14:58:42 -07:00
parent 19c63f4643
commit b05db52145
33 changed files with 29725 additions and 2995 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,632 @@
[
[
"WSFSL",
"WSFS Financial Corporation",
"26.3499",
"n/a",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/wsfsl"
],
[
"WSTC",
"West Corporation",
"34.78",
"$2.93B",
"2013",
"Miscellaneous",
"Business Services",
"http://www.nasdaq.com/symbol/wstc"
],
[
"WSTG",
"Wayside Technology Group, Inc.",
"17.08",
"$83.72M",
"n/a",
"Technology",
"Retail: Computer Software & Peripheral Equipment",
"http://www.nasdaq.com/symbol/wstg"
],
[
"WSTL",
"Westell Technologies, Inc.",
"1.54",
"$92.7M",
"1995",
"Public Utilities",
"Telecommunications Equipment",
"http://www.nasdaq.com/symbol/wstl"
],
[
"WTBA",
"West Bancorporation",
"17.99",
"$288.18M",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/wtba"
],
[
"WTFC",
"Wintrust Financial Corporation",
"47.69",
"$2.23B",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/wtfc"
],
[
"WTFCW",
"Wintrust Financial Corporation",
"25.25",
"n/a",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/wtfcw"
],
[
"WVFC",
"WVS Financial Corp.",
"11.5",
"$23.58M",
"n/a",
"Finance",
"Banks",
"http://www.nasdaq.com/symbol/wvfc"
],
[
"WVVI",
"Willamette Valley Vineyards, Inc.",
"5.9499",
"$28.93M",
"n/a",
"Consumer Non-Durables",
"Beverages (Production/Distribution)",
"http://www.nasdaq.com/symbol/wvvi"
],
[
"WWD",
"Woodward, Inc.",
"48.75",
"$3.17B",
"n/a",
"Energy",
"Industrial Machinery/Components",
"http://www.nasdaq.com/symbol/wwd"
],
[
"WWWW",
"Web.com Group, Inc.",
"18.01",
"$946.04M",
"n/a",
"Technology",
"Computer Software: Prepackaged Software",
"http://www.nasdaq.com/symbol/wwww"
],
[
"WYNN",
"Wynn Resorts, Limited",
"158.47",
"$16.06B",
"2002",
"Consumer Services",
"Hotels/Resorts",
"http://www.nasdaq.com/symbol/wynn"
],
[
"XBKS",
"Xenith Bankshares, Inc.",
"6.4001",
"$82.71M",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/xbks"
],
[
"XCRA",
"Xcerra Corporation",
"8.68",
"$472.42M",
"n/a",
"Capital Goods",
"Electrical Products",
"http://www.nasdaq.com/symbol/xcra"
],
[
"XENE",
"Xenon Pharmaceuticals Inc.",
"19.38",
"$274.83M",
"2014",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xene"
],
[
"XENT",
"Intersect ENT, Inc.",
"22.7",
"$530.65M",
"2014",
"Health Care",
"Medical/Dental Instruments",
"http://www.nasdaq.com/symbol/xent"
],
[
"XGTI",
"XG Technology, Inc",
"0.49",
"$12.26M",
"2013",
"Consumer Durables",
"Telecommunications Equipment",
"http://www.nasdaq.com/symbol/xgti"
],
[
"XGTIW",
"XG Technology, Inc",
"0.26",
"n/a",
"2013",
"Consumer Durables",
"Telecommunications Equipment",
"http://www.nasdaq.com/symbol/xgtiw"
],
[
"XIV",
"VelocityShares Daily Inverse VIX Short Term ETN",
"31.285",
"$485.35M",
"n/a",
"Finance",
"Investment Bankers/Brokers/Service",
"http://www.nasdaq.com/symbol/xiv"
],
[
"XLNX",
"Xilinx, Inc.",
"41.675",
"$10.9B",
"1990",
"Technology",
"Semiconductors",
"http://www.nasdaq.com/symbol/xlnx"
],
[
"XLRN",
"Acceleron Pharma Inc.",
"39.98",
"$1.29B",
"2013",
"Health Care",
"Biotechnology: Biological Products (No Diagnostic Substances)",
"http://www.nasdaq.com/symbol/xlrn"
],
[
"XNCR",
"Xencor, Inc.",
"15.06",
"$473.52M",
"2013",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xncr"
],
[
"XNET",
"Xunlei Limited",
"7.25",
"$471.36M",
"2014",
"Technology",
"Computer Software: Prepackaged Software",
"http://www.nasdaq.com/symbol/xnet"
],
[
"XNPT",
"XenoPort, Inc.",
"7.19",
"$447.49M",
"2005",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xnpt"
],
[
"XOMA",
"XOMA Corporation",
"4.05",
"$469.36M",
"1986",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xoma"
],
[
"XONE",
"The ExOne Company",
"16.32",
"$235.71M",
"2013",
"Capital Goods",
"Industrial Machinery/Components",
"http://www.nasdaq.com/symbol/xone"
],
[
"XOOM",
"Xoom Corporation",
"16.43",
"$631.69M",
"2013",
"Finance",
"Investment Bankers/Brokers/Service",
"http://www.nasdaq.com/symbol/xoom"
],
[
"XPLR",
"Xplore Technologies Corp",
"6.82",
"$57.83M",
"n/a",
"Technology",
"Computer Manufacturing",
"http://www.nasdaq.com/symbol/xplr"
],
[
"XRAY",
"DENTSPLY International Inc.",
"52.53",
"$7.43B",
"1987",
"Health Care",
"Medical/Dental Instruments",
"http://www.nasdaq.com/symbol/xray"
],
[
"XTLB",
"XTL Biopharmaceuticals Ltd.",
"2.21",
"$25.73M",
"n/a",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xtlb"
],
[
"XXIA",
"Ixia",
"10.45",
"$819.24M",
"2000",
"Capital Goods",
"Electrical Products",
"http://www.nasdaq.com/symbol/xxia"
],
[
"YDIV",
"First Trust NASDAQ Technology Dividend Index Fund",
"19.3412",
"$12.57M",
"n/a",
"n/a",
"n/a",
"http://www.nasdaq.com/symbol/ydiv"
],
[
"YDLE",
"Yodlee, Inc.",
"13.01",
"$380.3M",
"2014",
"Technology",
"Computer Software: Prepackaged Software",
"http://www.nasdaq.com/symbol/ydle"
],
[
"YHOO",
"Yahoo! Inc.",
"44.11",
"$41.79B",
"1996",
"Technology",
"EDP Services",
"http://www.nasdaq.com/symbol/yhoo"
],
[
"YNDX",
"Yandex N.V.",
"17.01",
"$5.41B",
"2011",
"Technology",
"Computer Software: Programming, Data Processing",
"http://www.nasdaq.com/symbol/yndx"
],
[
"YOD",
"You On Demand Holdings, Inc.",
"2.25",
"$53.4M",
"n/a",
"Consumer Services",
"Television Services",
"http://www.nasdaq.com/symbol/yod"
],
[
"YORW",
"The York Water Company",
"23.07",
"$295.51M",
"n/a",
"Public Utilities",
"Water Supply",
"http://www.nasdaq.com/symbol/yorw"
],
[
"YPRO",
"AdvisorShares YieldPro ETF",
"23.94",
"$68.23M",
"n/a",
"n/a",
"n/a",
"http://www.nasdaq.com/symbol/ypro"
],
[
"YRCW",
"YRC Worldwide, Inc.",
"19.96",
"$623.91M",
"n/a",
"Transportation",
"Trucking Freight/Courier Services",
"http://www.nasdaq.com/symbol/yrcw"
],
[
"YY",
"YY Inc.",
"61.82",
"$3.5B",
"2012",
"Technology",
"EDP Services",
"http://www.nasdaq.com/symbol/yy"
],
[
"Z",
"Zillow Group, Inc.",
"125.42",
"$5.12B",
"2011",
"Miscellaneous",
"Business Services",
"http://www.nasdaq.com/symbol/z"
],
[
"ZAGG",
"ZAGG Inc",
"6.51",
"$197.48M",
"n/a",
"Consumer Services",
"Other Specialty Stores",
"http://www.nasdaq.com/symbol/zagg"
],
[
"ZAZA",
"ZaZa Energy Corporation",
"2.11",
"$27.28M",
"n/a",
"Energy",
"Oil & Gas Production",
"http://www.nasdaq.com/symbol/zaza"
],
[
"ZBRA",
"Zebra Technologies Corporation",
"91",
"$4.63B",
"1991",
"Technology",
"Industrial Machinery/Components",
"http://www.nasdaq.com/symbol/zbra"
],
[
"ZEUS",
"Olympic Steel, Inc.",
"16.35",
"$179.56M",
"1994",
"Basic Industries",
"Metal Fabrications",
"http://www.nasdaq.com/symbol/zeus"
],
[
"ZFGN",
"Zafgen, Inc.",
"40.64",
"$1.08B",
"2014",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/zfgn"
],
[
"ZGNX",
"Zogenix, Inc.",
"1.55",
"$237.21M",
"2010",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/zgnx"
],
[
"ZHNE",
"Zhone Technologies, Inc.",
"1.54",
"$50.05M",
"n/a",
"Public Utilities",
"Telecommunications Equipment",
"http://www.nasdaq.com/symbol/zhne"
],
[
"ZINC",
"Horsehead Holding Corp.",
"13.49",
"$763.52M",
"2007",
"Capital Goods",
"Metal Fabrications",
"http://www.nasdaq.com/symbol/zinc"
],
[
"ZION",
"Zions Bancorporation",
"26.33",
"$5.34B",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/zion"
],
[
"ZIONW",
"Zions Bancorporation",
"3.4",
"n/a",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/zionw"
],
[
"ZIONZ",
"Zions Bancorporation",
"2.45",
"n/a",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/zionz"
],
[
"ZIOP",
"ZIOPHARM Oncology Inc",
"9.56",
"$1.11B",
"n/a",
"Health Care",
"Medical Specialities",
"http://www.nasdaq.com/symbol/ziop"
],
[
"ZIV",
"VelocityShares Daily Inverse VIX Medium Term ETN",
"41.1",
"$37.81M",
"n/a",
"Finance",
"Investment Bankers/Brokers/Service",
"http://www.nasdaq.com/symbol/ziv"
],
[
"ZIXI",
"Zix Corporation",
"3.81",
"$216.48M",
"n/a",
"Technology",
"EDP Services",
"http://www.nasdaq.com/symbol/zixi"
],
[
"ZLTQ",
"ZELTIQ Aesthetics, Inc.",
"34.23",
"$1.3B",
"2011",
"Health Care",
"Biotechnology: Electromedical & Electrotherapeutic Apparatus",
"http://www.nasdaq.com/symbol/zltq"
],
[
"ZN",
"Zion Oil & Gas Inc",
"1.85",
"$65.29M",
"n/a",
"Energy",
"Oil & Gas Production",
"http://www.nasdaq.com/symbol/zn"
],
[
"ZNGA",
"Zynga Inc.",
"2.32",
"$2.09B",
"2011",
"Technology",
"EDP Services",
"http://www.nasdaq.com/symbol/znga"
],
[
"ZNWAA",
"Zion Oil & Gas Inc",
"n/a",
"n/a",
"n/a",
"Energy",
"Oil & Gas Production",
"http://www.nasdaq.com/symbol/znwaa"
],
[
"ZSAN",
"Zosano Pharma Corporation",
"11.09",
"$131.04M",
"2015",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/zsan"
],
[
"ZSPH",
"ZS Pharma, Inc.",
"50.51",
"$1.05B",
"2014",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/zsph"
],
[
"ZU",
"zulily, inc.",
"14.4",
"$1.8B",
"2013",
"Consumer Services",
"Catalog/Specialty Distribution",
"http://www.nasdaq.com/symbol/zu"
],
[
"ZUMZ",
"Zumiez Inc.",
"38.77",
"$1.13B",
"2005",
"Consumer Services",
"Clothing/Shoe/Accessory Stores",
"http://www.nasdaq.com/symbol/zumz"
]
]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -34,18 +34,16 @@ class StocksApp extends App {
${typography.white.title};'''
);
List<Stock> _sortedStocks = [];
StockDataFetcher _stockDataFetcher;
List<Stock> _stocks = [];
bool _isSearching = false;
bool _isShowingMenu = false;
String _searchQuery;
StocksApp() : super() {
fetchStockOracle().then((oracle) {
_stockDataFetcher = new StockDataFetcher((StockData data) {
setState(() {
_sortedStocks = oracle.stocks;
trace('StocksApp::sortStocks', () {
_sortedStocks.sort((a, b) => a.symbol.compareTo(b.symbol));
});
data.appendTo(_stocks);
});
});
}
@ -155,7 +153,7 @@ class StocksApp extends App {
return new Scaffold(
actionBar: actionBar,
content: new Stocklist(stocks: _sortedStocks, query: _searchQuery),
content: new Stocklist(stocks: _stocks, query: _searchQuery),
fab: new FloatingActionButton(
content: new Icon(type: 'content/add_white', size: 24), level: 3),
drawer: drawer,

View File

@ -12,6 +12,8 @@ import 'package:sky/framework/net/fetch.dart';
// "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary Quote",
// Data in stock_data.json
final Random _rng = new Random();
class Stock {
String symbol;
String name;
@ -31,36 +33,41 @@ class Stock {
symbol = fields[0];
name = fields[1];
marketCap = fields[4];
var rng = new Random();
percentChange = (rng.nextDouble() * 20) - 10;
percentChange = (_rng.nextDouble() * 20) - 10;
}
}
class StockOracle {
List<Stock> stocks;
class StockData {
List<List<String>> _data;
StockOracle(this.stocks);
StockData(this._data);
StockOracle.fromCompanyList(List<List<String>> list) {
stocks = list.map((fields) => new Stock.fromFields(fields)).toList();
void appendTo(List<Stock> stocks) {
for (List<String> fields in _data)
stocks.add(new Stock.fromFields(fields));
}
}
typedef void StockDataCallback(StockData data);
const _kChunkCount = 30;
class StockDataFetcher {
int _currentChunk = 0;
final StockDataCallback callback;
StockDataFetcher(this.callback) {
_fetchNextChunk();
}
Stock lookupBySymbol(String symbol) {
this.stocks.forEach((stock) {
if (stock.symbol == symbol)
return stock;
void _fetchNextChunk() {
fetch('data/stock_data_${_currentChunk++}.json').then((Response response) {
String json = response.bodyAsString();
JsonDecoder decoder = new JsonDecoder();
callback(new StockData(decoder.convert(json)));
if (_currentChunk < _kChunkCount)
_fetchNextChunk();
});
return null;
}
}
Future<StockOracle> fetchStockOracle() async {
Response response = await fetch('lib/stock_data.json');
return trace('stocks::fetchStockOracle', () {
String json = response.bodyAsString();
JsonDecoder decoder = new JsonDecoder();
var companyList = decoder.convert(json);
return new StockOracle.fromCompanyList(companyList);
});
}

File diff suppressed because it is too large Load Diff