corgis.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /**
  2. * @license
  3. * Visual Blocks Editor
  4. *
  5. * Copyright 2012 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview CORGIS big data blocks for Blockly.
  22. * @author acbart@vt.edu (Austin Cory Bart)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Blocks.corgis');
  26. goog.require('Blockly.Blocks');
  27. var WEATHER_HUE = 70,
  28. QUAKES_HUE = 60,
  29. STOCKS_HUE = 65,
  30. CRIME_HUE = 55,
  31. BOOKS_HUE = 50;
  32. /*
  33. * Weather Data
  34. */
  35. var CITIES = [['Blacksburg, VA', 'Blacksburg, VA'],
  36. ['Seattle, WA', 'Seattle, WA'],
  37. ['Miami, FL', 'Miami, FL'],
  38. ['San Jose, CA', 'San Jose, CA'],
  39. ['New York, NY', 'New York, NY']];
  40. Blockly.Blocks['weather_temperature_get'] = {
  41. init: function() {
  42. this.setColour(WEATHER_HUE);
  43. this.appendDummyInput()
  44. .appendField("get a set of temperatures");
  45. this.setInputsInline(false);
  46. this.setOutput(true, "Array");
  47. this.setTooltip('Returns a set of temperature (number)');
  48. }
  49. };
  50. Blockly.Blocks['weather_temperature'] = {
  51. init: function() {
  52. this.setHelpUrl('http://www.example.com/');
  53. this.setColour(WEATHER_HUE);
  54. this.appendDummyInput()
  55. .appendField("get temperature in")
  56. .appendField(new Blockly.FieldDropdown(CITIES), 'CITY');
  57. this.setInputsInline(false);
  58. this.setOutput(true, "Number");
  59. this.setTooltip('Returns a single temperature (number)');
  60. }
  61. };
  62. Blockly.Blocks['weather_forecasts'] = {
  63. init: function() {
  64. this.setHelpUrl('http://www.example.com/');
  65. this.setColour(WEATHER_HUE);
  66. this.appendDummyInput()
  67. .appendField("get forecasted temperatures in")
  68. .appendField(new Blockly.FieldDropdown(CITIES), 'CITY');
  69. this.setInputsInline(false);
  70. this.setOutput(true, "Array");
  71. this.setTooltip('Returns a list of forecasted temperatures (list of number)');
  72. }
  73. };
  74. Blockly.Blocks['weather_highs_lows'] = {
  75. init: function() {
  76. this.setHelpUrl('http://www.example.com/');
  77. this.setColour(WEATHER_HUE);
  78. this.appendDummyInput()
  79. .appendField("get highs and lows in")
  80. .appendField(new Blockly.FieldDropdown(CITIES), 'CITY');
  81. this.setInputsInline(false);
  82. this.setOutput(true, "dict");
  83. this.setTooltip('Returns a list of forecasted temperature highs and lows (dict of lists of numbers)');
  84. }
  85. };
  86. Blockly.Blocks['weather_report_forecasts'] = {
  87. init: function() {
  88. this.setHelpUrl('http://www.example.com/');
  89. this.setColour(WEATHER_HUE);
  90. this.appendDummyInput()
  91. .appendField("get forecasted weather in")
  92. .appendField(new Blockly.FieldDropdown(CITIES), 'CITY');
  93. this.setInputsInline(false);
  94. this.setOutput(true, "Array");
  95. this.setTooltip('Returns a list of forecasted weather reports (list of dicts)');
  96. }
  97. };
  98. Blockly.Blocks['weather_report'] = {
  99. init: function() {
  100. this.setHelpUrl('http://www.example.com/');
  101. this.setColour(WEATHER_HUE);
  102. this.appendDummyInput()
  103. .appendField("get weather in")
  104. .appendField(new Blockly.FieldDropdown(CITIES), 'CITY');
  105. this.setInputsInline(false);
  106. this.setOutput(true, "dict");
  107. this.setTooltip('Returns a weather report (dictionary)');
  108. }
  109. };
  110. Blockly.Blocks['weather_all_forecasts'] = {
  111. init: function() {
  112. this.setHelpUrl('http://www.example.com/');
  113. this.setColour(WEATHER_HUE);
  114. this.appendDummyInput()
  115. .appendField("get all forecasted temperatures");
  116. this.setInputsInline(false);
  117. this.setOutput(true, "dict");
  118. this.setTooltip('Returns a list of dictionaries of forecasts and cities');
  119. }
  120. };
  121. /*
  122. * Stocks Data
  123. */
  124. var COMPANIES = [['Facebook', 'FB'],
  125. ['Apple', 'AAPL'],
  126. ['Microsoft', 'MSFT'],
  127. ['Google', 'GOOG']]
  128. Blockly.Blocks['stocks_current'] = {
  129. init: function() {
  130. this.setHelpUrl('http://www.example.com/');
  131. this.setColour(STOCKS_HUE);
  132. this.appendDummyInput()
  133. .appendField("get current stock of")
  134. .appendField(new Blockly.FieldDropdown(COMPANIES), 'TICKER');
  135. this.setInputsInline(false);
  136. this.setOutput(true, "Number");
  137. this.setTooltip('Returns a single stock change value (number)');
  138. }
  139. };
  140. Blockly.Blocks['stocks_past'] = {
  141. init: function() {
  142. this.setHelpUrl('http://www.example.com/');
  143. this.setColour(STOCKS_HUE);
  144. this.appendDummyInput()
  145. .appendField("get past stock changes of")
  146. .appendField(new Blockly.FieldDropdown(COMPANIES), 'TICKER');
  147. this.setInputsInline(false);
  148. this.setOutput(true, "Array");
  149. this.setTooltip('Returns a list of the previous stock values');
  150. }
  151. };
  152. /*
  153. * Earthquake Data
  154. */
  155. var EARTHQUAKES = [['magnitude', 'magnitude'],
  156. ['depth', 'depth']]
  157. Blockly.Blocks['earthquake_get'] = {
  158. init: function() {
  159. this.setHelpUrl('http://www.example.com/');
  160. this.setColour(QUAKES_HUE);
  161. this.appendDummyInput()
  162. .appendField("get recent earthquakes'")
  163. .appendField(new Blockly.FieldDropdown(EARTHQUAKES), 'PROPERTY');
  164. this.setInputsInline(false);
  165. this.setOutput(true, "Array");
  166. this.setTooltip('Returns a property of an earthquake');
  167. }
  168. };
  169. Blockly.Blocks['earthquake_both'] = {
  170. init: function() {
  171. this.setHelpUrl('http://www.example.com/');
  172. this.setColour(QUAKES_HUE);
  173. this.appendDummyInput()
  174. .appendField("get earthquakes magnitude and depth'");
  175. this.setInputsInline(false);
  176. this.setOutput(true, "Array");
  177. this.setTooltip('Returns magnitude and depth of multiple earthquakes');
  178. }
  179. };
  180. Blockly.Blocks['earthquake_all'] = {
  181. init: function() {
  182. this.setHelpUrl('http://www.example.com/');
  183. this.setColour(QUAKES_HUE);
  184. this.appendDummyInput()
  185. .appendField("get complete earthquakes report'");
  186. this.setInputsInline(false);
  187. this.setOutput(true, "Array");
  188. this.setTooltip('Returns all properties of multiple earthquakes');
  189. }
  190. };
  191. /*
  192. * Crime Data
  193. */
  194. var YEARS = [];
  195. for (var i = 1960; i <= 2012; i+= 5) {
  196. YEARS.push([''+i, ''+i]);
  197. }
  198. var STATES = [['Alaska', 'alaska'], ['California', 'california'],
  199. ['Delaware', 'delaware'], ['Florida', 'florida'],
  200. ['Maryland', 'maryland'], ['Nevada', 'nevada'],
  201. ['New Jersey', 'new jersey'], ['New York', 'new york'],
  202. ['Pennsylvania', 'pennsylvania'], ['Texas', 'texas'],
  203. ['Virginia', 'virginia']];
  204. Blockly.Blocks['crime_state'] = {
  205. init: function() {
  206. this.setHelpUrl('http://www.example.com/');
  207. this.setColour(CRIME_HUE);
  208. this.appendDummyInput()
  209. .appendField("get")
  210. .appendField(new Blockly.FieldDropdown([['property', 'property'],
  211. ['violent', 'violent'],
  212. ['both kinds', 'both']]), 'TYPE')
  213. .appendField("crime rates in")
  214. .appendField(new Blockly.FieldDropdown(STATES), 'STATE');
  215. this.setInputsInline(false);
  216. this.setOutput(true, "Array");
  217. this.setTooltip('Returns all of the crime rates in the those states since 1960');
  218. }
  219. };
  220. Blockly.Blocks['crime_year'] = {
  221. init: function() {
  222. this.setHelpUrl('http://www.example.com/');
  223. this.setColour(CRIME_HUE);
  224. this.appendDummyInput()
  225. .appendField("get crime rates in")
  226. .appendField(new Blockly.FieldDropdown(YEARS), 'YEAR');
  227. this.setInputsInline(false);
  228. this.setOutput(true, "Array");
  229. this.setTooltip('Returns all of the crime rates reports for the given year by state');
  230. }
  231. };
  232. Blockly.Blocks['crime_all'] = {
  233. init: function() {
  234. this.setHelpUrl('http://www.example.com/');
  235. this.setColour(CRIME_HUE);
  236. this.appendDummyInput()
  237. .appendField("get all crime reports");
  238. this.setInputsInline(false);
  239. this.setOutput(true, "dict");
  240. this.setTooltip('Returns all of the crime rates reports');
  241. }
  242. };
  243. /*
  244. * Book Data
  245. */
  246. Blockly.Blocks['books_get'] = {
  247. init: function() {
  248. this.setHelpUrl('http://www.example.com/');
  249. this.setColour(BOOKS_HUE);
  250. this.appendDummyInput()
  251. .appendField("get books");
  252. this.setInputsInline(false);
  253. this.setOutput(true, "Array");
  254. this.setTooltip('Returns a list of books (list of dict)');
  255. }
  256. };