blockpy_new.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Python Blockly</title>
  6. <link rel="stylesheet" href="libs/bootstrap.min.css">
  7. <link rel="stylesheet" href="libs/codemirror/codemirror.css">
  8. <link rel="stylesheet" href="libs/font-awesome.min.css">
  9. <link rel="stylesheet" href="libs/summernote/summernote.css">
  10. <link rel="stylesheet" href="libs/multi-select.css">
  11. <link rel="stylesheet" href="src/blockpy.css">
  12. <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">-->
  13. <!-- JQuery, D3, Math.js, Bootstrap -->
  14. <script type="text/javascript" src="libs/jquery.js"></script>
  15. <script type="text/javascript" src="libs/jquery-ui.min.js"></script>
  16. <script type="text/javascript" src="libs/jquery.hotkeys.js"></script>
  17. <script type="text/javascript" src="libs/jquery.multi-select.js"></script>
  18. <script type="text/javascript" src="libs/d3.min.js"></script>
  19. <script type="text/javascript" src="libs/math.0.19.0.min.js"></script>
  20. <script type="text/javascript" src="libs/bootstrap.min.js"></script>
  21. <script type="text/javascript" src="libs/bootstrap-wysiwyg.js"></script>
  22. <script type="text/javascript" src="libs/mindmup-editabletable.js"></script>
  23. <script type="text/javascript" src="libs/codemirror/codemirror.js"></script>
  24. <script type="text/javascript" src="libs/codemirror/python.js"></script>
  25. <script type="text/javascript" src="libs/codemirror/htmlmixed.js"></script>
  26. <script type="text/javascript" src="libs/codemirror/xml.js"></script>
  27. <script type="text/javascript" src="libs/knockout-3.4.0.js"></script>
  28. <script type="text/javascript" src="libs/stringify.js"></script>
  29. <!-- Summernote, a rich text editor -->
  30. <script type="text/javascript" src="libs/summernote/summernote.min.js"></script>
  31. <script type="text/javascript" src="libs/summernote/summernote-ext-hint.js"></script>
  32. <script type="text/javascript" src="libs/summernote/summernote-ext-video.js"></script>
  33. <!-- Blockly -->
  34. <script type="text/javascript" src="blockly/blockly_uncompressed.js"></script>
  35. <script type="text/javascript" src="blockly/blocks_compressed.js"></script>
  36. <script type="text/javascript" src="blockly/python_compressed.js"></script>
  37. <script type="text/javascript" src="blockly/pseudo_compressed.js"></script>
  38. <script type="text/javascript" src="blockly/javascript_compressed.js"></script>
  39. <script type="text/javascript" src="blockly/msg/js/en.js"></script>
  40. <!-- Skulpt -->
  41. <script type="text/javascript" src="skulpt/dist/skulpt.min.js"></script>
  42. <script type="text/javascript" src="skulpt/dist/skulpt-stdlib.js"></script>
  43. <!-- Source Code -->
  44. <script type="text/javascript" src="src/utilities.js"></script>
  45. <script type="text/javascript" src="src/python_errors.js"></script>
  46. <script type="text/javascript" src="src/ast_node_visitor.js"></script>
  47. <script type="text/javascript" src="src/abstract_interpreter.js"></script>
  48. <script type="text/javascript" src="src/pytifa.js"></script>
  49. <script type="text/javascript" src="src/abstract_interpreter_definitions.js"></script>
  50. <!-- <script type="text/javascript" src="src/abstract_interpreter_tests.js"></script> -->
  51. <script type="text/javascript" src="src/python_to_blockly.js"></script>
  52. <script type="text/javascript" src="src/imported.js"></script>
  53. <script type="text/javascript" src="src/blockly_blocks/class.js"></script>
  54. <script type="text/javascript" src="src/blockly_blocks/comment.js"></script>
  55. <script type="text/javascript" src="src/blockly_blocks/comprehensions.js"></script>
  56. <script type="text/javascript" src="src/blockly_blocks/dict.js"></script>
  57. <script type="text/javascript" src="src/blockly_blocks/if.js"></script>
  58. <script type="text/javascript" src="src/blockly_blocks/io.js"></script>
  59. <script type="text/javascript" src="src/blockly_blocks/lists.js"></script>
  60. <script type="text/javascript" src="src/blockly_blocks/sets.js"></script>
  61. <script type="text/javascript" src="src/blockly_blocks/loops.js"></script>
  62. <script type="text/javascript" src="src/blockly_blocks/parking.js"></script>
  63. <script type="text/javascript" src="src/blockly_blocks/tuple.js"></script>
  64. <script type="text/javascript" src="src/blockly_blocks/turtles.js"></script>
  65. <script type="text/javascript" src="src/blockly_blocks/text.js"></script>
  66. <script type="text/javascript" src="src/blockly_blocks/plots.js"></script>
  67. <script type="text/javascript" src="src/dialog.js"></script>
  68. <script type="text/javascript" src="src/storage.js"></script>
  69. <script type="text/javascript" src="src/printer.js"></script>
  70. <script type="text/javascript" src="src/interface.js"></script>
  71. <script type="text/javascript" src="src/server.js"></script>
  72. <script type="text/javascript" src="src/english.js"></script>
  73. <script type="text/javascript" src="src/corgis.js"></script>
  74. <script type="text/javascript" src="src/history.js"></script>
  75. <script type="text/javascript" src="src/presentation.js"></script>
  76. <script type="text/javascript" src="src/editor.js"></script>
  77. <script type="text/javascript" src="src/feedback.js"></script>
  78. <script type="text/javascript" src="src/toolbar.js"></script>
  79. <script type="text/javascript" src="src/sk_mod_instructor_extended.js"></script>
  80. <script type="text/javascript" src="src/sk_mod_instructor.js"></script>
  81. <script type="text/javascript" src="src/engine.js"></script>
  82. <script type="text/javascript" src="src/main.js"></script>
  83. <!-- CORGIS -->
  84. <!--<script type="text/javascript" src="test_corgis/blockpy/school_scores/school_scores_dataset.js"></script>
  85. <script type="text/javascript" src="test_corgis/blockpy/school_scores/school_scores_blockly.js"></script>
  86. <script type="text/javascript" src="test_corgis/blockpy/school_scores/school_scores_skulpt.js"></script>-->
  87. <!--<script type="text/javascript" src="test_corgis/blockpy/tate/tate_blockly.js"></script>
  88. <script type="text/javascript" src="test_corgis/blockpy/tate/tate_skulpt.js"></script>
  89. <script type="text/javascript" src="test_corgis/blockpy/tate/tate_dataset.js"></script>-->
  90. <!-- <script type="text/javascript" src="test_corgis/blockpy/tate/publishers_blockly.js"></script>
  91. <script type="text/javascript" src="test_corgis/blockpy/tate/publishers_skulpt.js"></script>
  92. <script type="text/javascript" src="test_corgis/blockpy/tate/publishers_dataset.js"></script>
  93. <script type="text/javascript" src="test_corgis/blockpy/weather/weather_blockly.js"></script>
  94. <script type="text/javascript" src="test_corgis/blockpy/weather/weather_skulpt.js"></script>
  95. <script type="text/javascript" src="test_corgis/blockpy/weather/weather_dataset.js"></script> -->
  96. <style>
  97. </style>
  98. <script>
  99. $(document).ready(function() {
  100. blockpy = new BlockPy({
  101. 'blocklyPath': "blockly/",
  102. 'attachmentPoint': document.getElementById('blockpy-div'),
  103. 'instructor': !getQueryParams()["instructor"] || getQueryParams()["instructor"]=="true",
  104. 'developer': true,
  105. 'editor': getQueryParams()["mode"] || 'Split',
  106. 'urls': {
  107. // 'import_datasets': 'https://think.cs.vt.edu/blockpy/load_corgis/',
  108. //'walk_old_code': 'http://localhost:8000/walk_code/',
  109. //'log_event': 'http://localhost:8000/save_events/'
  110. /*'save_code': 'http://localhost:8000/save_code/',
  111. 'save_success': 'http://localhost:8000/submit_grade/',
  112. 'log_event': 'http://localhost:8000/save_events/'*/
  113. }
  114. });
  115. blockpy.setAssignment(
  116. // settings
  117. {
  118. 'editor': getQueryParams()["mode"] || 'Split',
  119. 'read_only': getQueryParams()["upload"]=="true",
  120. 'disable_semantic_errors': false,
  121. 'disable_timeout': true,
  122. },
  123. // assignment
  124. {
  125. 'introduction': "Use the canvas below to calculate the sum of a list of 4 numbers.",
  126. 'name': "#1.3",
  127. //'give_feedback': 'from instructor_functions import *\nsuppress("analyzer", "Incompatible types")\nmatch_signature("curve_grade", 1, "old")\nunit_test("curve_grade", (64, True), (0, 0), (100, 100))',
  128. //'give_feedback': 'from instructor_functions import *\n5+""\nsuppress("analyzer", "Incompatible types")\nmatch_signature("rate_animal", 1, "old")\nunit_test("rate_animal", (64, True))',
  129. //'give_feedback': "log(parse_program().find_all('FunctionDef')[0].args.args[0].arg)",
  130. 'give_feedback': 'set_success()',
  131. //'give_feedback': 'from instructor_utility import *\nfrom instructor_printing import *\n\nsuppress("analyzer")\nsuppress("instructor")\nhide_correctness()\n\nast = parse_program()\n\nall_checked = True\nanswers = [("1*2*3", "6"), ("3*4","12"), ("0","0"), ("5*-5", "-25")]\nfor an_input, result in answers:\n reset_output()\n queue_input(an_input)\n run_student()\n if not get_output():\n all_checked = False\n elif result not in get_output():\n if str(float(result)) in get_output():\n give_partial(.1/len(answers), "Checking Float "+an_input)\n all_checked = False\n else:\n give_partial(.2/len(answers), "Checking "+an_input)',
  132. //'give_feedback': "from instructor_utility import *\nensure_operation('in')",
  133. //'give_feedback': 'for x in range(2):\n reset_output()\n queue_input("Test", "")\n e = run_student()\n if e:\n gently(str(e))\n log(get_output())\nif not e:\n set_success()',
  134. //'give_feedback': "from instructor_files import *\nfiles_not_handled_correctly('example.txt')",
  135. //'give_feedback': "from instructor_imports import *\nensure_imports('math', 'random')",
  136. //'give_feedback': "from instructor_plotting import * \nprevent_incorrect_plt() \nensure_correct_plot('plot') \nensure_show() \ncheck_for_plot('line', [[1,2,3],[4,5,6]])",
  137. //'give_feedback': 'ast = parse_program()\nassignments = ast.find_all("Assign")\nfor assignment in assignments:\n if assignment.targets.id == "parking_allowed":\n log(assignment.targets.data_type)',
  138. 'on_change': '',
  139. //'on_change': 'gently("Test")',
  140. 'parsons': false,
  141. 'starting_code': '',
  142. 'importable': true,
  143. 'initial_view': getQueryParams()["mode"] || 'Split',
  144. 'upload': getQueryParams()["upload"]=="true",
  145. 'modules': {
  146. 'added': ['Classes', 'Tuples', 'Data - Weather'],
  147. 'removed': []
  148. }
  149. },
  150. // programs
  151. {
  152. //'__main__': 'ss = ["Testing", "Here"]\nfor a in ss:\n print(a)\nfor b in a:\n print(b)',
  153. //'__main__': 'print("Hello world"[1:5])',
  154. '__main__': '',
  155. //'__main__': 'num = input("")\nnum_list = [int(n) for n in num.split("*")]\nfor n in num_list:\n n*n\n return 4\nprint(n)',
  156. //'__main__': 'def rate_animal(an_animal):\n if an_animal != "dog":\n 1 + ""\nrate_animal("dog")',
  157. //'__main__': 'round(float("9.5", ___))',
  158. //'__main__': getQueryParams()["code"] || "import matplotlib.pyplot as plt\nplt.plot([1, 2, 3],[4, 5, 6])\nplt.show()",
  159. //'__main__': 'i=0\nwhile i!="0":\n i=input("")\n print(i)',
  160. //'__main__': "import requests\nprint(requests.get('https://pastebin.com/raw/V7tWn1Rj').text)"
  161. //'__main__': "print(open('example.txt').read())"
  162. //'__main__': "import math\nmath\nfrom random import choice\nchoice"
  163. //'__main__': "from random import randint\nprint(5+randint(1,10))"
  164. //'__main__': 'print(input("Prompt:"))',
  165. //'__main__': 'import parking\nparking_allowed = parking.now()\nif parking.now() > parking.Time(8,30,"AM") and parking.now() < parking.Time(5,30,"PM"):\n parking_allowed = False\nelse:\n parking_allowed = True \nprint(parking_allowed)'
  166. //'__main__': 'print("Banana"[:int(len("Banana")/2)])',
  167. //'__main__': 'def curve_grade(old):\n return (old ** .5) * 10\n\nprint(90, "becomes", curve_grade(90))\nprint(50, "becomes", curve_grade(50))\nprint(20, "becomes", curve_grade(20))'
  168. //'__main__': 'print(1 != 2 and 2 != 1)'
  169. }
  170. )
  171. function inIframe () {
  172. try {
  173. return window.self !== window.top;
  174. } catch (e) {
  175. return true;
  176. }
  177. }
  178. if (inIframe()) {
  179. $("#blockpy-container").width("100%");
  180. $("#blockpy-div").css('padding', 0);
  181. }
  182. });
  183. </script>
  184. </head>
  185. <body>
  186. <div style="width:90%; margin:0 auto; height: 100vh;" id='blockpy-container'> <!-- 900px -->
  187. <div id="blockpy-div" style='height: 100%; padding: 5% 0;'></div>
  188. </div>
  189. <!-- <div id="blockpy-div2" style='height:100%'></div> -->
  190. <script>
  191. function getQueryParams(){
  192. try{
  193. url = window.location.href;
  194. query_str = url.substr(url.indexOf('?')+1, url.length-1);
  195. r_params = query_str.split('&');
  196. params = {}
  197. for( i in r_params){
  198. param = r_params[i].split('=');
  199. params[ param[0] ] = param[1];
  200. }
  201. return params;
  202. }
  203. catch(e){
  204. return {};
  205. }
  206. }
  207. </script>
  208. <!-- Google Analytics -->
  209. <script>
  210. switch(window.location.protocol) {
  211. case 'file:':
  212. break;
  213. default:
  214. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  215. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  216. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  217. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  218. ga('create', 'UA-38802329-2', 'auto');
  219. ga('send', 'pageview');
  220. }
  221. </script>
  222. </body>
  223. </html>