// Do not edit this file; automatically generated by build.py. 'use strict'; // Copyright 2012 Google Inc. Apache License 2.0 Blockly.Pseudo=new Blockly.Generator("Pseudo");Blockly.Pseudo.addReservedWords("and,as,assert,break,class,continue,def,del,elif,else,except,exec,finally,for,from,global,if,import,in,is,lambda,not,or,pass,print,raise,return,try,while,with,yield,True,False,None,NotImplemented,Ellipsis,__debug__,quit,exit,copyright,license,credits,crime,stocks,earthquakes,books,weather,plt,math,abs,divmod,input,open,staticmethod,all,enumerate,int,ord,str,any,eval,isinstance,pow,sum,basestring,execfile,issubclass,print,super,bin,file,iter,property,tuple,bool,filter,len,range,type,bytearray,float,list,raw_input,unichr,callable,format,locals,reduce,unicode,chr,frozenset,long,reload,vars,classmethod,getattr,map,repr,xrange,cmp,globals,max,reversed,zip,compile,hasattr,memoryview,round,__import__,complex,hash,min,set,apply,delattr,help,next,setattr,buffer,dict,hex,object,slice,coerce,dir,id,oct,sorted,intern"); Blockly.Pseudo.ORDER_ATOMIC=0;Blockly.Pseudo.ORDER_COLLECTION=1;Blockly.Pseudo.ORDER_STRING_CONVERSION=1;Blockly.Pseudo.ORDER_MEMBER=2;Blockly.Pseudo.ORDER_FUNCTION_CALL=2;Blockly.Pseudo.ORDER_EXPONENTIATION=3;Blockly.Pseudo.ORDER_UNARY_SIGN=4;Blockly.Pseudo.ORDER_BITWISE_NOT=4;Blockly.Pseudo.ORDER_MULTIPLICATIVE=5;Blockly.Pseudo.ORDER_ADDITIVE=6;Blockly.Pseudo.ORDER_BITWISE_SHIFT=7;Blockly.Pseudo.ORDER_BITWISE_AND=8;Blockly.Pseudo.ORDER_BITWISE_XOR=9;Blockly.Pseudo.ORDER_BITWISE_OR=10; Blockly.Pseudo.ORDER_RELATIONAL=11;Blockly.Pseudo.ORDER_LOGICAL_NOT=12;Blockly.Pseudo.ORDER_LOGICAL_AND=13;Blockly.Pseudo.ORDER_LOGICAL_OR=14;Blockly.Pseudo.ORDER_CONDITIONAL=15;Blockly.Pseudo.ORDER_LAMBDA=16;Blockly.Pseudo.ORDER_NONE=99;Blockly.Pseudo.PASS=" Do nothing.\n";Blockly.Pseudo.init=function(a){Blockly.Pseudo.definitions_=Object.create(null);Blockly.Pseudo.functionNames_=Object.create(null);Blockly.Pseudo.variableDB_?Blockly.Pseudo.variableDB_.reset():Blockly.Pseudo.variableDB_=new Blockly.Names(Blockly.Pseudo.RESERVED_WORDS_)}; Blockly.Pseudo.finish=function(a){var b=[],c=[],d;for(d in Blockly.Pseudo.definitions_){var e=Blockly.Pseudo.definitions_[d];e.match(/^(from\s+\S+\s+)?import\s+\S+/)?b.push(e):c.push(e)}delete Blockly.Pseudo.definitions_;delete Blockly.Pseudo.functionNames_;Blockly.Pseudo.variableDB_.reset();return(b.join("\n")+"\n"+c.join("\n\n")).replace(/\n\n+/g,"\n").replace(/\n*$/,"\n\n")+a};Blockly.Pseudo.scrubNakedValue=function(a){return a+"\n"}; Blockly.Pseudo.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n");if(-1= stop:"," yield start"," start -= abs(step)"])};a=function(a,b,c){return"("+a+" <= "+b+") and "+h()+"("+a+", "+b+", "+c+") or "+k()+"("+a+", "+b+", "+c+")"};if(Blockly.isNumber(c)&&Blockly.isNumber(d)&& Blockly.isNumber(e))c=parseFloat(c),d=parseFloat(d),e=Math.abs(parseFloat(e)),0===c%1&&0===d%1&&0===e%1?(c<=d?(d++,a=0==c&&1==e?d:c+", "+d,1!=e&&(a+=", "+e)):(d--,a=c+", "+d+", -"+e),a="range("+a+")"):(a=c"+b+".\nFor every element inside of the list "+c+", set "+b+" to that element's value and execute the following indented commands:\n"+d+"\n"}; Blockly.Pseudo.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"Stop this loop.\n";case "CONTINUE":return"Continue this loop, using the next value.\n"}throw"Unknown flow statement.";};Blockly.Pseudo.controls_pass=function(a){return"Do nothing.\n"};Blockly.Pseudo.math={};Blockly.Pseudo.addReservedWords("math,random");Blockly.Pseudo.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));return[a,0>a?Blockly.Pseudo.ORDER_UNARY_SIGN:Blockly.Pseudo.ORDER_ATOMIC]}; Blockly.Pseudo.math_arithmetic=function(a){var b={ADD:[" added to ",Blockly.Pseudo.ORDER_ADDITIVE],MINUS:[" minus ",Blockly.Pseudo.ORDER_ADDITIVE],MULTIPLY:[" multiplied by ",Blockly.Pseudo.ORDER_MULTIPLICATIVE],DIVIDE:[" divided by ",Blockly.Pseudo.ORDER_MULTIPLICATIVE],POWER:[" raised to the power of ",Blockly.Pseudo.ORDER_EXPONENTIATION],MODULO:[" remainder ",Blockly.Pseudo.ORDER_MULTIPLICATIVE]}[a.getFieldValue("OP")],c=b[0];b=b[1];var d=Blockly.Pseudo.valueToCode(a,"A",b)||"___";a=Blockly.Pseudo.valueToCode(a, "B",b)||"___";return[d+c+a,b]}; Blockly.Pseudo.math_single=function(a){var b=a.getFieldValue("OP");if("NEG"==b){var c=Blockly.Pseudo.valueToCode(a,"NUM",Blockly.Pseudo.ORDER_UNARY_SIGN)||"___";return["negative"+c,Blockly.Pseudo.ORDER_UNARY_SIGN]}"ABS"!=b&&"POW"!=b&&"ROUND"!=b&&(Blockly.Pseudo.definitions_.import_math="import math");a="SIN"==b||"COS"==b||"TAN"==b?Blockly.Pseudo.valueToCode(a,"NUM",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___":Blockly.Pseudo.valueToCode(a,"NUM",Blockly.Pseudo.ORDER_NONE)||"___";switch(b){case "ABS":c= "abs("+a+")";break;case "ROOT":c="math.sqrt("+a+")";break;case "LN":c="math.log("+a+")";break;case "LOG10":c="math.log10("+a+")";break;case "EXP":c="math.exp("+a+")";break;case "POW10":c="pow(10,"+a+")";break;case "ROUND":c="round("+a+")";break;case "ROUNDUP":c="math.ceil("+a+")";break;case "ROUNDDOWN":c="math.floor("+a+")";break;case "SIN":c="math.sin("+a+" / 180.0 * math.pi)";break;case "COS":c="math.cos("+a+" / 180.0 * math.pi)";break;case "TAN":c="math.tan("+a+" / 180.0 * math.pi)"}if(c)return[c, Blockly.Pseudo.ORDER_FUNCTION_CALL];switch(b){case "ASIN":c="math.asin("+a+") / math.pi * 180";break;case "ACOS":c="math.acos("+a+") / math.pi * 180";break;case "ATAN":c="math.atan("+a+") / math.pi * 180";break;default:throw"Unknown math operator: "+b;}return[c,Blockly.Pseudo.ORDER_MULTIPLICATIVE]}; Blockly.Pseudo.math_constant=function(a){var b={PI:["math.pi",Blockly.Pseudo.ORDER_MEMBER],E:["math.e",Blockly.Pseudo.ORDER_MEMBER],GOLDEN_RATIO:["(1 + math.sqrt(5)) / 2",Blockly.Pseudo.ORDER_MULTIPLICATIVE],SQRT2:["math.sqrt(2)",Blockly.Pseudo.ORDER_MEMBER],SQRT1_2:["math.sqrt(1.0 / 2)",Blockly.Pseudo.ORDER_MEMBER],INFINITY:["float('inf')",Blockly.Pseudo.ORDER_ATOMIC]};a=a.getFieldValue("CONSTANT");"INFINITY"!=a&&(Blockly.Pseudo.definitions_.import_math="import math");return b[a]}; Blockly.Pseudo.math_number_property=function(a){var b=Blockly.Pseudo.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___",c=a.getFieldValue("PROPERTY");if("PRIME"==c)return Blockly.Pseudo.definitions_.import_math="import math",[Blockly.Pseudo.provideFunction_("math_isPrime",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(n):"," # https://en.wikipedia.org/wiki/Primality_test#Naive_methods"," # If n is not a number but a string, try parsing it."," if type(n) not in (int, float, long):", " try:"," n = float(n)"," except:"," return False"," if n == 2 or n == 3:"," return True"," # False if n is negative, is 1, or not whole, or if n is divisible by 2 or 3."," if n <= 1 or n % 1 != 0 or n % 2 == 0 or n % 3 == 0:"," return False"," # Check all the numbers of form 6k +/- 1, up to sqrt(n)."," for x in range(6, int(math.sqrt(n)) + 2, 6):"," if n % (x - 1) == 0 or n % (x + 1) == 0:"," return False"," return True"])+"("+b+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]; switch(c){case "EVEN":var d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":d=b+" % 1 == 0";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.Pseudo.valueToCode(a,"DIVISOR",Blockly.Pseudo.ORDER_MULTIPLICATIVE);if(!a||"0"==a)return["False",Blockly.Pseudo.ORDER_ATOMIC];d=b+" % "+a+" == 0"}return[d,Blockly.Pseudo.ORDER_RELATIONAL]}; Blockly.Pseudo.math_change=function(a){var b=Blockly.Pseudo.valueToCode(a,"DELTA",Blockly.Pseudo.ORDER_ADDITIVE)||"___";return"Increase "+Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" by"+b+".\n"};Blockly.Pseudo.math_round=Blockly.Pseudo.math_single;Blockly.Pseudo.math_trig=Blockly.Pseudo.math_single; Blockly.Pseudo.math_on_list=function(a){var b=a.getFieldValue("OP");a=Blockly.Pseudo.valueToCode(a,"LIST",Blockly.Pseudo.ORDER_NONE)||"___";switch(b){case "SUM":b="the sum of the list "+a;break;case "MIN":b="the lowest value of the list "+a;break;case "MAX":b="the highest value of the list "+a;break;case "AVERAGE":b=Blockly.Pseudo.provideFunction_("math_mean",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(myList):"," localList = [e for e in myList if type(e) in (int, float, long)]"," if not localList: return", " return float(sum(localList)) / len(localList)"]);b=b+"("+a+")";break;case "MEDIAN":b=Blockly.Pseudo.provideFunction_("math_median",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(myList):"," localList = sorted([e for e in myList if type(e) in (int, float, long)])"," if not localList: return"," if len(localList) % 2 == 0:"," return (localList[len(localList) / 2 - 1] + localList[len(localList) / 2]) / 2.0"," else:"," return localList[(len(localList) - 1) / 2]"]);b=b+"("+a+")";break; case "MODE":b=Blockly.Pseudo.provideFunction_("math_modes",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(some_list):"," modes = []"," # Using a lists of [item, count] to keep count rather than dict",' # to avoid "unhashable" errors when the counted item is itself a list or dict.'," counts = []"," maxCount = 1"," for item in some_list:"," found = False"," for count in counts:"," if count[0] == item:"," count[1] += 1"," maxCount = max(maxCount, count[1])"," found = True", " if not found:"," counts.append([item, 1])"," for counted_item, item_count in counts:"," if item_count == maxCount:"," modes.append(counted_item)"," return modes"]);b=b+"("+a+")";break;case "STD_DEV":Blockly.Pseudo.definitions_.import_math="import math";b=Blockly.Pseudo.provideFunction_("math_standard_deviation",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(numbers):"," n = len(numbers)"," if n == 0: return"," mean = float(sum(numbers)) / n"," variance = sum((x - mean) ** 2 for x in numbers) / n", " return math.sqrt(variance)"]);b=b+"("+a+")";break;case "RANDOM":Blockly.Pseudo.definitions_.import_random="import random";b="random.choice("+a+")";break;default:throw"Unknown operator: "+b;}return[b,Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.math_modulo=function(a){var b=Blockly.Pseudo.valueToCode(a,"DIVIDEND",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___";a=Blockly.Pseudo.valueToCode(a,"DIVISOR",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___";return[b+" % "+a,Blockly.Pseudo.ORDER_MULTIPLICATIVE]}; Blockly.Pseudo.math_constrain=function(a){var b=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___",c=Blockly.Pseudo.valueToCode(a,"LOW",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"HIGH",Blockly.Pseudo.ORDER_NONE)||"___";return["min(max("+b+", "+c+"), "+a+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]}; Blockly.Pseudo.math_random_int=function(a){Blockly.Pseudo.definitions_.import_random="import random";var b=Blockly.Pseudo.valueToCode(a,"FROM",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"TO",Blockly.Pseudo.ORDER_NONE)||"___";return["random.randint("+b+", "+a+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.math_random_float=function(a){Blockly.Pseudo.definitions_.import_random="import random";return["random.random()",Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.plot={};Blockly.Pseudo.plot_title=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";return"Set the title of the current plot to "+Blockly.Pseudo.quote_(a.getFieldValue("TEXT"))+".\n"}; Blockly.Pseudo.plot_line=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";return"Plot the list "+((Blockly.Pseudo.valueToCode(a,"y_values",Blockly.Pseudo.ORDER_NONE)||"___")+" onto the current canvas as a line.\n")}; Blockly.Pseudo.plot_lineXY=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";var b=Blockly.Pseudo.valueToCode(a,"x_values",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"y_values",Blockly.Pseudo.ORDER_NONE)||"___";return"Plot the list "+(b+","+a+" onto the current canvas as an XY Plot\n")}; Blockly.Pseudo.plot_scatter=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";var b=Blockly.Pseudo.valueToCode(a,"x_values",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"y_values",Blockly.Pseudo.ORDER_NONE)||"___";return"plt.scatter("+(b+","+a+")\n")}; Blockly.Pseudo.plot_show=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";return"Make the plot appear.\n"};Blockly.Pseudo.procedures={}; Blockly.Pseudo.procedures_defreturn=function(a){for(var b=[],c=b.length-1;0<=c;c--){var d=b[c];-1==a.arguments_.indexOf(d)?b[c]=Blockly.Pseudo.variableDB_.getName(d,Blockly.Variables.NAME_TYPE):b.splice(c,1)}b=b.length?" global "+b.join(", ")+"\n":"";c=Blockly.Pseudo.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE);d=Blockly.Pseudo.statementToCode(a,"STACK");Blockly.Pseudo.STATEMENT_PREFIX&&(d=Blockly.Pseudo.prefixLines(Blockly.Pseudo.STATEMENT_PREFIX.replace(/%1/g,"'"+a.id+ "'"),Blockly.Pseudo.INDENT)+d);Blockly.Pseudo.INFINITE_LOOP_TRAP&&(d=Blockly.Pseudo.INFINITE_LOOP_TRAP.replace(/%1/g,'"'+a.id+'"')+d);var e=Blockly.Pseudo.valueToCode(a,"RETURN",Blockly.Pseudo.ORDER_NONE)||"";e?e="Now the function is done, so it returns "+e+".\n":d||(d=Blockly.Pseudo.PASS);for(var f=[],g=0;g"+Blockly.Pseudo.variableDB_.getName(a.arguments_[g],Blockly.Variables.NAME_TYPE)+"";a=0"+c+".\n"+a+".\nWhen called, it will do the following:\n"+b+d+e+"\n"};Blockly.Pseudo.procedures_defnoreturn=Blockly.Pseudo.procedures_defreturn; Blockly.Pseudo.procedures_callreturn=function(a){for(var b=Blockly.Pseudo.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d"+Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+"",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.variables_set=function(a){var b=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___";return"Set the property "+Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" to "+b+".\n"};