corgis.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * @license
  3. * Visual Blocks Language
  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 Generating Python for CORGIS big data blocks.
  22. * @author acbart@vt.edu (Austin Cory Bart)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Python.corgis');
  26. goog.require('Blockly.Python');
  27. /*
  28. * Weather Data
  29. */
  30. Blockly.Python['weather_temperature_get'] = function(block) {
  31. Blockly.Python.definitions_['get_temperatures'] = "__temperatures = [{'Min Temp': 32, 'Max Temp': 46, 'Avg Temp': 39}, {'Min Temp': 31, 'Max Temp': 47, 'Avg Temp': 39}, {'Min Temp': 41, 'Max Temp': 51, 'Avg Temp': 46}, {'Min Temp': 38, 'Max Temp': 52, 'Avg Temp': 45}, {'Min Temp': 29, 'Max Temp': 38, 'Avg Temp': 34}, {'Min Temp': 31, 'Max Temp': 44, 'Avg Temp': 38}, {'Min Temp': 24, 'Max Temp': 36, 'Avg Temp': 30}, {'Min Temp': 9, 'Max Temp': 32, 'Avg Temp': 22}, {'Min Temp': 31, 'Max Temp': 36, 'Avg Temp': 34}, {'Min Temp': 33, 'Max Temp': 43, 'Avg Temp': 38}, {'Min Temp': 23, 'Max Temp': 39, 'Avg Temp': 31}, {'Min Temp': 4, 'Max Temp': 30, 'Avg Temp': 14}, {'Min Temp': 19, 'Max Temp': 34, 'Avg Temp': 27}, {'Min Temp': 35, 'Max Temp': 42, 'Avg Temp': 39}, {'Min Temp': 37, 'Max Temp': 42, 'Avg Temp': 40}, {'Min Temp': 31, 'Max Temp': 40, 'Avg Temp': 36}, {'Min Temp': 30, 'Max Temp': 37, 'Avg Temp': 34}, {'Min Temp': 33, 'Max Temp': 41, 'Avg Temp': 37}, {'Min Temp': 35, 'Max Temp': 42, 'Avg Temp': 39}, {'Min Temp': 36, 'Max Temp': 42, 'Avg Temp': 40}, {'Min Temp': 20, 'Max Temp': 33, 'Avg Temp': 27}, {'Min Temp': 20, 'Max Temp': 39, 'Avg Temp': 30}, {'Min Temp': 25, 'Max Temp': 32, 'Avg Temp': 29}, {'Min Temp': -9, 'Max Temp': 8, 'Avg Temp': 0}, {'Min Temp': 32, 'Max Temp': 42, 'Avg Temp': 37}, {'Min Temp': 60, 'Max Temp': 60, 'Avg Temp': 60}, {'Min Temp': 60, 'Max Temp': 60, 'Avg Temp': 60}, {'Min Temp': 60, 'Max Temp': 60, 'Avg Temp': 60}, {'Min Temp': 39, 'Max Temp': 46, 'Avg Temp': 43}, {'Min Temp': 33, 'Max Temp': 42, 'Avg Temp': 38}, {'Min Temp': 29, 'Max Temp': 35, 'Avg Temp': 32}, {'Min Temp': 23, 'Max Temp': 39, 'Avg Temp': 32}, {'Min Temp': 13, 'Max Temp': 29, 'Avg Temp': 21}, {'Min Temp': 2, 'Max Temp': 9, 'Avg Temp': 6}, {'Min Temp': 32, 'Max Temp': 40, 'Avg Temp': 36}, {'Min Temp': 24, 'Max Temp': 57, 'Avg Temp': 41}, {'Min Temp': 25, 'Max Temp': 54, 'Avg Temp': 40}, {'Min Temp': 45, 'Max Temp': 69, 'Avg Temp': 58}, {'Min Temp': 43, 'Max Temp': 69, 'Avg Temp': 56}, {'Min Temp': 15, 'Max Temp': 42, 'Avg Temp': 29}, {'Min Temp': 27, 'Max Temp': 51, 'Avg Temp': 39}, {'Min Temp': 27, 'Max Temp': 48, 'Avg Temp': 38}, {'Min Temp': 34, 'Max Temp': 49, 'Avg Temp': 42}, {'Min Temp': 33, 'Max Temp': 60, 'Avg Temp': 47}, {'Min Temp': 12, 'Max Temp': 42, 'Avg Temp': 27}, {'Min Temp': 21, 'Max Temp': 49, 'Avg Temp': 35}, {'Min Temp': 37, 'Max Temp': 51, 'Avg Temp': 44}, {'Min Temp': 33, 'Max Temp': 53, 'Avg Temp': 44}, {'Min Temp': 36, 'Max Temp': 55, 'Avg Temp': 46}, {'Min Temp': 41, 'Max Temp': 53, 'Avg Temp': 47}, {'Min Temp': 43, 'Max Temp': 65, 'Avg Temp': 54}, {'Min Temp': 45, 'Max Temp': 63, 'Avg Temp': 55}, {'Min Temp': 36, 'Max Temp': 50, 'Avg Temp': 44}, {'Min Temp': 38, 'Max Temp': 51, 'Avg Temp': 45}, {'Min Temp': 34, 'Max Temp': 52, 'Avg Temp': 44}, {'Min Temp': 41, 'Max Temp': 57, 'Avg Temp': 49}, {'Min Temp': 45, 'Max Temp': 64, 'Avg Temp': 55}, {'Min Temp': 41, 'Max Temp': 51, 'Avg Temp': 46}, {'Min Temp': 33, 'Max Temp': 44, 'Avg Temp': 39}, {'Min Temp': 39, 'Max Temp': 62, 'Avg Temp': 51}, {'Min Temp': 37, 'Max Temp': 63, 'Avg Temp': 51}, {'Min Temp': 33, 'Max Temp': 51, 'Avg Temp': 42}, {'Min Temp': -5, 'Max Temp': 33, 'Avg Temp': 14}, {'Min Temp': 9, 'Max Temp': 45, 'Avg Temp': 28}, {'Min Temp': -23, 'Max Temp': 3, 'Avg Temp': -10}, {'Min Temp': 12, 'Max Temp': 40, 'Avg Temp': 27}, {'Min Temp': 4, 'Max Temp': 24, 'Avg Temp': 14}, {'Min Temp': 4, 'Max Temp': 47, 'Avg Temp': 26}, {'Min Temp': 32, 'Max Temp': 43, 'Avg Temp': 38}, {'Min Temp': 27, 'Max Temp': 40, 'Avg Temp': 34}, {'Min Temp': 27, 'Max Temp': 46, 'Avg Temp': 37}, {'Min Temp': 27, 'Max Temp': 46, 'Avg Temp': 37}, {'Min Temp': 58, 'Max Temp': 68, 'Avg Temp': 63}, {'Min Temp': 70, 'Max Temp': 82, 'Avg Temp': 76}, {'Min Temp': 51, 'Max Temp': 62, 'Avg Temp': 56}, {'Min Temp': 50, 'Max Temp': 61, 'Avg Temp': 56}, {'Min Temp': 74, 'Max Temp': 82, 'Avg Temp': 79}, {'Min Temp': 70, 'Max Temp': 82, 'Avg Temp': 76}, {'Min Temp': 57, 'Max Temp': 72, 'Avg Temp': 65}, {'Min Temp': 44, 'Max Temp': 52, 'Avg Temp': 48}, {'Min Temp': 48, 'Max Temp': 57, 'Avg Temp': 53}, {'Min Temp': 59, 'Max Temp': 71, 'Avg Temp': 66}, {'Min Temp': 62, 'Max Temp': 74, 'Avg Temp': 69}, {'Min Temp': 67, 'Max Temp': 80, 'Avg Temp': 74}, {'Min Temp': 47, 'Max Temp': 58, 'Avg Temp': 51}, {'Min Temp': 36, 'Max Temp': 54, 'Avg Temp': 45}, {'Min Temp': 36, 'Max Temp': 48, 'Avg Temp': 42}, {'Min Temp': 41, 'Max Temp': 56, 'Avg Temp': 48}, {'Min Temp': 40, 'Max Temp': 53, 'Avg Temp': 47}, {'Min Temp': 49, 'Max Temp': 62, 'Avg Temp': 56}, {'Min Temp': 65, 'Max Temp': 81, 'Avg Temp': 73}, {'Min Temp': 64, 'Max Temp': 81, 'Avg Temp': 73}, {'Min Temp': 60, 'Max Temp': 80, 'Avg Temp': 71}, {'Min Temp': 64, 'Max Temp': 79, 'Avg Temp': 72}, {'Min Temp': 60, 'Max Temp': 79, 'Avg Temp': 70}, {'Min Temp': 7, 'Max Temp': 23, 'Avg Temp': 15}, {'Min Temp': 12, 'Max Temp': 29, 'Avg Temp': 21}, {'Min Temp': -4, 'Max Temp': 21, 'Avg Temp': 8}, {'Min Temp': 20, 'Max Temp': 30, 'Avg Temp': 25}, {'Min Temp': 19, 'Max Temp': 31, 'Avg Temp': 25}]";
  32. let code = "__temperatures";
  33. return [code, Blockly.Python.ORDER_ATOMIC];
  34. };
  35. Blockly.Python['weather_temperature'] = function(block) {
  36. Blockly.Python.definitions_['import_weather'] = 'import weather';
  37. var code = 'weather.get_temperature(';
  38. var argument0 = Blockly.Python.quote_(block.getFieldValue('CITY'));
  39. code += argument0 + ')';
  40. return [code, Blockly.Python.ORDER_ATOMIC];
  41. };
  42. Blockly.Python['weather_forecasts'] = function(block) {
  43. Blockly.Python.definitions_['import_weather'] = 'import weather';
  44. var code = 'weather.get_forecasts(';
  45. var argument0 = Blockly.Python.quote_(block.getFieldValue('CITY'));
  46. code += argument0 + ')';
  47. return [code, Blockly.Python.ORDER_ATOMIC];
  48. };
  49. Blockly.Python['weather_highs_lows'] = function(block) {
  50. Blockly.Python.definitions_['import_weather'] = 'import weather';
  51. var code = 'weather.get_highs_lows(';
  52. var argument0 = Blockly.Python.quote_(block.getFieldValue('CITY'));
  53. code += argument0 + ')';
  54. return [code, Blockly.Python.ORDER_ATOMIC];
  55. };
  56. Blockly.Python['weather_report'] = function(block) {
  57. Blockly.Python.definitions_['import_weather'] = 'import weather';
  58. var code = 'weather.get_report(';
  59. var argument0 = Blockly.Python.quote_(block.getFieldValue('CITY'));
  60. code += argument0 + ')';
  61. return [code, Blockly.Python.ORDER_ATOMIC];
  62. };
  63. Blockly.Python['weather_report_forecasts'] = function(block) {
  64. Blockly.Python.definitions_['import_weather'] = 'import weather';
  65. var code = 'weather.get_forecasted_reports(';
  66. var argument0 = Blockly.Python.quote_(block.getFieldValue('CITY'));
  67. code += argument0 + ')';
  68. return [code, Blockly.Python.ORDER_ATOMIC];
  69. };
  70. Blockly.Python['weather_all_forecasts'] = function(block) {
  71. Blockly.Python.definitions_['import_weather'] = 'import weather';
  72. var code = 'weather.get_all_forecasted_temperatures()'
  73. return [code, Blockly.Python.ORDER_ATOMIC];
  74. };
  75. /*
  76. * Stocks Data
  77. */
  78. Blockly.Python['stocks_current'] = function(block) {
  79. Blockly.Python.definitions_['import_stocks'] = 'import stocks';
  80. var code = 'stocks.get_current(';
  81. var argument0 = Blockly.Python.quote_(block.getFieldValue('TICKER'));
  82. code += argument0 + ')';
  83. return [code, Blockly.Python.ORDER_ATOMIC];
  84. };
  85. Blockly.Python['stocks_past'] = function(block) {
  86. Blockly.Python.definitions_['import_stocks'] = 'import stocks';
  87. var code = 'stocks.get_past(';
  88. var argument0 = Blockly.Python.quote_(block.getFieldValue('TICKER'));
  89. code += argument0 + ')';
  90. return [code, Blockly.Python.ORDER_ATOMIC];
  91. };
  92. /*
  93. * Earthquake Data
  94. */
  95. Blockly.Python['earthquake_get'] = function(block) {
  96. Blockly.Python.definitions_['import_earthquakes'] = 'import earthquakes';
  97. var code = 'earthquakes.get(';
  98. var argument0 = Blockly.Python.quote_(block.getFieldValue('PROPERTY'));
  99. code += argument0 + ')';
  100. return [code, Blockly.Python.ORDER_ATOMIC];
  101. };
  102. Blockly.Python['earthquake_both'] = function(block) {
  103. Blockly.Python.definitions_['import_earthquakes'] = 'import earthquakes';
  104. var code = 'earthquakes.get_both()';
  105. return [code, Blockly.Python.ORDER_ATOMIC];
  106. };
  107. Blockly.Python['earthquake_all'] = function(block) {
  108. Blockly.Python.definitions_['import_earthquakes'] = 'import earthquakes';
  109. var code = 'earthquakes.get_all()';
  110. return [code, Blockly.Python.ORDER_ATOMIC];
  111. };
  112. /*
  113. * Crime Data
  114. */
  115. Blockly.Python['crime_state'] = function(block) {
  116. Blockly.Python.definitions_['import_crime'] = 'import crime';
  117. var code = 'crime.get_' + block.getFieldValue('TYPE') + '_crimes(';
  118. var argument0 = Blockly.Python.quote_(block.getFieldValue('STATE'));
  119. code += argument0 + ')';
  120. return [code, Blockly.Python.ORDER_ATOMIC];
  121. };
  122. Blockly.Python['crime_year'] = function(block) {
  123. Blockly.Python.definitions_['import_crime'] = 'import crime';
  124. var code = 'crime.get_by_year(';
  125. var argument0 = Blockly.Python.quote_(block.getFieldValue('YEAR'));
  126. code += argument0 + ')';
  127. return [code, Blockly.Python.ORDER_ATOMIC];
  128. };
  129. Blockly.Python['crime_all'] = function(block) {
  130. Blockly.Python.definitions_['import_crime'] = 'import crime';
  131. var code = 'crime.get_all()';
  132. return [code, Blockly.Python.ORDER_ATOMIC];
  133. };
  134. /*
  135. * Book Data
  136. */
  137. Blockly.Python['books_get'] = function(block) {
  138. Blockly.Python.definitions_['import_books'] = 'import books';
  139. var code = 'books.get_all()';
  140. return [code, Blockly.Python.ORDER_ATOMIC];
  141. };