server.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // BlockPy Loading
  2. Blockly = {};
  3. Blockly.WorkspaceSvg = new function() {};
  4. Blockly.WorkspaceSvg.prototype = {};
  5. skulpt = require('./skulpt/dist/skulpt.min.js')
  6. skulpt_libs = require('./skulpt/dist/skulpt-stdlib.js')
  7. d3 = require('d3-3');
  8. blockpy = require('./dist/blockpy_node.js')
  9. var trace = function() {
  10. };
  11. trace.removeAll = x => x;
  12. mockFeedback = {
  13. 'isFeedbackVisible': x => true,
  14. 'clear': x => x,
  15. //'presentFeedback': x => blockpy.BlockPyFeedback.prototype.presentFeedback.bind(mockFeedback)(x),
  16. 'presentFeedback': x => x, //console.log(Sk.executionReports.instructor.complaint),
  17. 'presentAnalyzerFeedback': x => blockpy.BlockPyFeedback.prototype.presentAnalyzerFeedback.bind(mockFeedback)(x),
  18. 'instructorFeedback': (name, message, line) => name, //console.log(name, message, line),
  19. }
  20. var printHtml = ((e,v) => this.printed.push(v));
  21. main = {
  22. 'components': {
  23. 'printer': {
  24. 'print': e => this.printed.push(e.slice(0, -1)), //console.log("PRINTED", e),
  25. 'printHtml': printHtml,
  26. 'resetPrinter': e => this.printed = [], //console.log("PRINTER RESET"),
  27. 'getConfiguration': function() {
  28. var printerSettings = {}
  29. printerSettings['printHtml']= printHtml;
  30. printerSettings['width']= 500;
  31. printerSettings['pngMode']= false;
  32. printerSettings['skipDrawing']= true;
  33. printerSettings['height']= 500;
  34. printerSettings['container']= null;
  35. return printerSettings;
  36. }
  37. },
  38. 'editor': {
  39. 'triggerOnChange': 0
  40. },
  41. 'server': {
  42. 'logEvent': x => x,
  43. 'markSuccess': x => x,
  44. },
  45. 'feedback': mockFeedback,
  46. 'toolbar': {
  47. }
  48. },
  49. 'model': {
  50. 'execution': {
  51. 'reports': {},
  52. 'suppressions': {},
  53. 'status': v => this['status'] = v,
  54. 'trace': trace,
  55. 'step': x => x,
  56. 'last_step': x => x,
  57. 'line_number': x => x,
  58. 'show_trace': x => x,
  59. 'output': v => this.printed
  60. },
  61. 'programs': {
  62. '__main__': v => 'a = "Words"\nprint(a)',
  63. 'give_feedback': v => 'from instructor import *\ngently("You have failed.")\ngently("Not bad!")',
  64. },
  65. 'settings': {
  66. 'disable_timeout': x => false,
  67. 'mute_printer': x => this['mute_printer'] = x,
  68. 'preventD3': false,
  69. }
  70. }
  71. };
  72. main.components.feedback.main = main;
  73. engine = new blockpy.BlockPyEngine(main);
  74. Sk.afterSingleExecution = engine.step.bind(engine);
  75. // Progress Bar stuff
  76. var ProgressBar = require('progress');
  77. // JSON File loading
  78. const loadJsonFile = require('load-json-file');
  79. // Read as string
  80. var fs = require('fs');
  81. function readModuleFile(path, callback) {
  82. try {
  83. var filename = require.resolve(path);
  84. fs.readFile(filename, 'utf8', callback);
  85. } catch (e) {
  86. callback(e);
  87. }
  88. }
  89. StretchyTreeMatcher = blockpy.StretchyTreeMatcher;
  90. isSkBuiltin = blockpy.isSkBuiltin;
  91. mixedRemapToPy = blockpy.mixedRemapToPy;
  92. isAstNode = blockpy.isAstNode;
  93. // Hardcoded datasets
  94. _IMPORTED_DATASETS = {};
  95. AbstractInterpreter = blockpy.AbstractInterpreter;
  96. NodeVisitor = blockpy.NodeVisitor;
  97. datasets = ['publishers', 'state_demographics', 'school_scores'];
  98. datasets.forEach(slug => {
  99. readModuleFile('./data_analysis/corgis/'+slug+'_skulpt.js', function (err, words) {
  100. Sk.builtinFiles['files']['src/lib/'+slug+'/__init__.js'] = words;
  101. });
  102. require('./data_analysis/corgis/'+slug+'_abstract.js')
  103. require('./data_analysis/corgis/'+slug+'_dataset.js')
  104. });
  105. console.log(AbstractInterpreter.MODULES)
  106. // Actual work
  107. final_result = []
  108. loadJsonFile('data_analysis/f17_ct_solutions.json').then(assignment_solutions => {
  109. // f17_ct_8-5_change_steps
  110. // s17_post_run_submissions
  111. // quick_test.json
  112. // ct_f17_post_run_submissions.json
  113. loadJsonFile('data_analysis/s17_post_run_submissions.json').then(data => {
  114. subs = data.submissions;
  115. var next = function(subi, stui) {
  116. processSub(subs[subi][stui], function() {
  117. stui += 1;
  118. if (stui >= subs[subi].length) {
  119. stui = 0;
  120. subi += 1;
  121. }
  122. if (subi < subs.length) {
  123. next(subi, stui);
  124. } else {
  125. //f17_ct_stepped_new_8-5
  126. //f17_post_checked
  127. fs.writeFile('./data_analysis/s17_post_checked.json',
  128. JSON.stringify(final_result),
  129. {'spaces':2},
  130. function (err) {
  131. if (err) {
  132. console.error("ERROR", err);
  133. }
  134. });
  135. }
  136. });
  137. };
  138. function processSub(sub, callback) {
  139. var instructor_code = assignment_solutions[""+sub.aid];
  140. var student_code = sub.code;
  141. if (student_code == "") {
  142. final_result.push({
  143. 'aid': sub.aid,
  144. 'assignment': sub.assignment,
  145. 'user': sub.user,
  146. 'uid': sub.uid,
  147. 'timestamp': sub.timestamp,
  148. 'code': sub.code,
  149. 'messages': ['nocode'],
  150. 'complete': false
  151. })
  152. callback();
  153. } else {
  154. main.model.programs.__main__ = v => student_code;
  155. main.model.programs.give_feedback = v => instructor_code;
  156. Sk.console= {skipDrawing: false};
  157. result = engine.on_run(v => {
  158. var ms = Sk.executionReports.instructor.complaint ?
  159. Sk.executionReports.instructor.complaint.map(x => x.message.match(/.*\((.*)\).*/).pop())
  160. : [];
  161. console.log(sub.user, sub.assignment, ms.length);
  162. //console.log(Sk.executionReports['student']);
  163. final_result.push({
  164. 'aid': sub.aid,
  165. 'assignment': sub.assignment,
  166. 'user': sub.user,
  167. 'uid': sub.uid,
  168. 'timestamp': sub.timestamp,
  169. 'code': sub.code,
  170. 'messages': ms,
  171. 'complete': !!(Sk.executionReports.instructor.complete)
  172. })
  173. callback();
  174. });
  175. }
  176. }
  177. next(0, 0);
  178. });
  179. });