Update(boards): 所有板卡执行 build:prod

This commit is contained in:
王立帮
2024-09-21 22:29:48 +08:00
parent 61ae2048fb
commit 6501c5895c
102 changed files with 1447 additions and 52068 deletions

View File

@@ -208,17 +208,17 @@ export const controls_if = {
var elseStatementConnection = null;
while (clauseBlock) {
switch (clauseBlock.type) {
case 'controls_if_elseif':
this.elseifCount_++;
valueConnections.push(clauseBlock.valueConnection_);
statementConnections.push(clauseBlock.statementConnection_);
break;
case 'controls_if_else':
this.elseCount_++;
elseStatementConnection = clauseBlock.statementConnection_;
break;
default:
throw Error('Unknown block type: ' + clauseBlock.type);
case 'controls_if_elseif':
this.elseifCount_++;
valueConnections.push(clauseBlock.valueConnection_);
statementConnections.push(clauseBlock.statementConnection_);
break;
case 'controls_if_else':
this.elseCount_++;
elseStatementConnection = clauseBlock.statementConnection_;
break;
default:
throw Error('Unknown block type: ' + clauseBlock.type);
}
clauseBlock = clauseBlock.nextConnection &&
clauseBlock.nextConnection.targetBlock();
@@ -239,22 +239,22 @@ export const controls_if = {
var i = 1;
while (clauseBlock) {
switch (clauseBlock.type) {
case 'controls_if_elseif':
var inputIf = this.getInput('IF' + i);
var inputDo = this.getInput('DO' + i);
clauseBlock.valueConnection_ =
case 'controls_if_elseif':
var inputIf = this.getInput('IF' + i);
var inputDo = this.getInput('DO' + i);
clauseBlock.valueConnection_ =
inputIf && inputIf.connection.targetConnection;
clauseBlock.statementConnection_ =
clauseBlock.statementConnection_ =
inputDo && inputDo.connection.targetConnection;
i++;
break;
case 'controls_if_else':
var inputDo = this.getInput('ELSE');
clauseBlock.statementConnection_ =
i++;
break;
case 'controls_if_else':
var inputDo = this.getInput('ELSE');
clauseBlock.statementConnection_ =
inputDo && inputDo.connection.targetConnection;
break;
default:
throw 'Unknown block type.';
break;
default:
throw 'Unknown block type.';
}
clauseBlock = clauseBlock.nextConnection &&
clauseBlock.nextConnection.targetBlock();
@@ -544,17 +544,17 @@ export const controls_try_finally = {
var elseStatementConnection = null;
while (clauseBlock) {
switch (clauseBlock.type) {
case 'controls_except':
this.elseifCount_++;
valueConnections.push(clauseBlock.valueConnection_);
statementConnections.push(clauseBlock.statementConnection_);
break;
case 'controls_finally':
this.elseCount_++;
elseStatementConnection = clauseBlock.statementConnection_;
break;
default:
throw Error('Unknown block type: ' + clauseBlock.type);
case 'controls_except':
this.elseifCount_++;
valueConnections.push(clauseBlock.valueConnection_);
statementConnections.push(clauseBlock.statementConnection_);
break;
case 'controls_finally':
this.elseCount_++;
elseStatementConnection = clauseBlock.statementConnection_;
break;
default:
throw Error('Unknown block type: ' + clauseBlock.type);
}
clauseBlock = clauseBlock.nextConnection &&
clauseBlock.nextConnection.targetBlock();
@@ -575,22 +575,22 @@ export const controls_try_finally = {
var i = 1;
while (clauseBlock) {
switch (clauseBlock.type) {
case 'controls_except':
var inputIf = this.getInput('IF' + i);
var inputDo = this.getInput('DO' + i);
clauseBlock.valueConnection_ =
case 'controls_except':
var inputIf = this.getInput('IF' + i);
var inputDo = this.getInput('DO' + i);
clauseBlock.valueConnection_ =
inputIf && inputIf.connection.targetConnection;
clauseBlock.statementConnection_ =
clauseBlock.statementConnection_ =
inputDo && inputDo.connection.targetConnection;
i++;
break;
case 'controls_finally':
var inputDo = this.getInput('ELSE');
clauseBlock.statementConnection_ =
i++;
break;
case 'controls_finally':
var inputDo = this.getInput('ELSE');
clauseBlock.statementConnection_ =
inputDo && inputDo.connection.targetConnection;
break;
default:
throw 'Unknown block type.';
break;
default:
throw 'Unknown block type.';
}
clauseBlock = clauseBlock.nextConnection &&
clauseBlock.nextConnection.targetBlock();
@@ -794,15 +794,17 @@ export const controls_for_range = {
};
controls_whileUntil.OPERATORS =
[[Blockly.Msg.LANG_CONTROLS_WHILEUNTIL_OPERATOR_WHILE, 'WHILE'],
[Blockly.Msg.LANG_CONTROLS_WHILEUNTIL_OPERATOR_UNTIL, 'UNTIL']];
controls_whileUntil.OPERATORS = [
[Blockly.Msg.LANG_CONTROLS_WHILEUNTIL_OPERATOR_WHILE, 'WHILE'],
[Blockly.Msg.LANG_CONTROLS_WHILEUNTIL_OPERATOR_UNTIL, 'UNTIL']
];
controls_flow_statements.OPERATORS =
[[Blockly.Msg.LANG_CONTROLS_FLOW_STATEMENTS_OPERATOR_BREAK, 'BREAK'],
[Blockly.Msg.LANG_CONTROLS_FLOW_STATEMENTS_OPERATOR_CONTINUE, 'CONTINUE']];
controls_flow_statements.OPERATORS = [
[Blockly.Msg.LANG_CONTROLS_FLOW_STATEMENTS_OPERATOR_BREAK, 'BREAK'],
[Blockly.Msg.LANG_CONTROLS_FLOW_STATEMENTS_OPERATOR_CONTINUE, 'CONTINUE']
];
@@ -1022,7 +1024,7 @@ export const get_unique_identifier = {
init: function () {
this.setColour(LOOPS_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_GET + Blockly.Msg.MIXLY_DEVICE +'ID');
.appendField(Blockly.Msg.MIXLY_GET + Blockly.Msg.MIXLY_DEVICE + 'ID');
this.setInputsInline(true);
this.setOutput(true);
this.setTooltip(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN + Blockly.Msg.MIXLY_GET_UNIQUE_IDEN);

View File

@@ -442,12 +442,12 @@ export const dicts_add_change_del = {
var e = b.getFieldValue("WHERE"),
d = "";
switch (e) {
case "INSERT":
d = Blockly.Msg.DICTS_ADD_TOOLTIP;
break;
case "DELETE":
d = Blockly.Msg.DICTS_DELETE_TOOLTIP;
break;
case "INSERT":
d = Blockly.Msg.DICTS_ADD_TOOLTIP;
break;
case "DELETE":
d = Blockly.Msg.DICTS_DELETE_TOOLTIP;
break;
}
//if ("FROM_START" == e || "FROM_END" == e) d += " " + Blockly.Msg.LISTS_INDEX_FROM_START_TOOLTIP.replace("%1", ONE_BASED_INDEXING ? "#1": "#0");
return d

View File

@@ -194,20 +194,20 @@ export const text_char_at2 = {
e = b.getFieldValue("WHERE"),
d = "";
switch (a + " " + e) {
case "GET FROM_START":
case "GET FROM_END":
d = Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_FROM;
break;
case "GET RANDOM":
d = Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_RANDOM;
break;
case "GET_REMOVE FROM_START":
case "GET_REMOVE FROM_END":
d = Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FROM;
break;
case "GET_REMOVE RANDOM":
d = Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_RANDOM;
break;
case "GET FROM_START":
case "GET FROM_END":
d = Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_FROM;
break;
case "GET RANDOM":
d = Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_RANDOM;
break;
case "GET_REMOVE FROM_START":
case "GET_REMOVE FROM_END":
d = Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FROM;
break;
case "GET_REMOVE RANDOM":
d = Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_RANDOM;
break;
}
if ("FROM_START" == e || "FROM_END" == e) d += " " + Blockly.Msg.LISTS_INDEX_FROM_START_TOOLTIP.replace("%1", Blockly.Msg.ONE_BASED_INDEXING ? "#1" : "#0");
return d
@@ -296,14 +296,16 @@ export const text_substring2 = {
* @this Blockly.Block
*/
init: function () {
this['WHERE_OPTIONS_1'] =
[[Blockly.Msg.LISTS_GET_INDEX_FROM_START, 'FROM_START'],
[Blockly.Msg.LISTS_GET_INDEX_FROM_END, 'FROM_END'],
[Blockly.Msg.LISTS_GET_SUBLIST_START_FIRST, 'FIRST']];
this['WHERE_OPTIONS_2'] =
[[Blockly.Msg.LISTS_GET_SUBLIST_END_FROM_START, 'FROM_START'],
[Blockly.Msg.LISTS_GET_SUBLIST_END_FROM_END, 'FROM_END'],
[Blockly.Msg.LISTS_GET_SUBLIST_END_LAST, 'LAST']];
this['WHERE_OPTIONS_1'] = [
[Blockly.Msg.LISTS_GET_INDEX_FROM_START, 'FROM_START'],
[Blockly.Msg.LISTS_GET_INDEX_FROM_END, 'FROM_END'],
[Blockly.Msg.LISTS_GET_SUBLIST_START_FIRST, 'FIRST']
];
this['WHERE_OPTIONS_2'] = [
[Blockly.Msg.LISTS_GET_SUBLIST_END_FROM_START, 'FROM_START'],
[Blockly.Msg.LISTS_GET_SUBLIST_END_FROM_END, 'FROM_END'],
[Blockly.Msg.LISTS_GET_SUBLIST_END_LAST, 'LAST']
];
this.setHelpUrl(Blockly.Msg.LISTS_GET_SUBLIST_HELPURL);
this.setColour(TEXTS_HUE);
this.appendValueInput("VAR")
@@ -423,10 +425,11 @@ export const text_substring = {
export const text_equals_starts_ends = {
init: function () {
var TEXT_DOWHAT =
[[Blockly.Msg.MIXLY_EQUALS, '==='],
[Blockly.Msg.MIXLY_STARTSWITH, 'startswith'],
[Blockly.Msg.MIXLY_ENDSWITH, 'endswith']];
var TEXT_DOWHAT = [
[Blockly.Msg.MIXLY_EQUALS, '==='],
[Blockly.Msg.MIXLY_STARTSWITH, 'startswith'],
[Blockly.Msg.MIXLY_ENDSWITH, 'endswith']
];
this.setColour(TEXTS_HUE);
this.appendValueInput("STR1")
.setCheck(String);
@@ -454,9 +457,13 @@ export const text_compare_to = {
export const text_capital = {
init: function () {
var TEXT_CAPITAL =
[[Blockly.Msg.TEXT_UPPER, 'upper'], [Blockly.Msg.TEXT_TITLE, 'title'], [Blockly.Msg.TEXT_CAPITALIZE, 'capitalize'], [Blockly.Msg.TEXT_SWAPCASE, 'swapcase'],
[Blockly.Msg.TEXT_LOWER, 'lower']];
var TEXT_CAPITAL = [
[Blockly.Msg.TEXT_UPPER, 'upper'],
[Blockly.Msg.TEXT_TITLE, 'title'],
[Blockly.Msg.TEXT_CAPITALIZE, 'capitalize'],
[Blockly.Msg.TEXT_SWAPCASE, 'swapcase'],
[Blockly.Msg.TEXT_LOWER, 'lower']
];
this.setColour(TEXTS_HUE);
this.appendValueInput("VAR")
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET)
@@ -480,10 +487,11 @@ export const text_capital = {
export const text_center = {
init: function () {
var TEXT_CENTER =
[[Blockly.Msg.TEXT_LJUST, 'ljust'],
[Blockly.Msg.TEXT_CENTER, 'center'],
[Blockly.Msg.TEXT_RJUST, 'rjust']];
var TEXT_CENTER = [
[Blockly.Msg.TEXT_LJUST, 'ljust'],
[Blockly.Msg.TEXT_CENTER, 'center'],
[Blockly.Msg.TEXT_RJUST, 'rjust']
];
this.setColour(TEXTS_HUE);
this.appendValueInput("VAR")
.appendField(new Blockly.FieldDropdown(TEXT_CENTER), 'CENTER')

View File

@@ -132,10 +132,10 @@ export const controls_whileUntil = function (a, generator) {
//ok
export const controls_flow_statements = function (a) {
switch (a.getFieldValue("FLOW")) {
case "BREAK":
return "break\n";
case "CONTINUE":
return "continue\n"
case "BREAK":
return "break\n";
case "CONTINUE":
return "continue\n"
}
throw "Unknown flow statement.";
}

View File

@@ -129,17 +129,16 @@ export const dicts_add_change_del = function (block, generator) {
// var text=this.getFieldValue('KEY');
switch (mode) {
case 'INSERT':
//var at2 = block.getFieldValue('AT2');
var at2 = generator.valueToCode(this, 'AT2', generator.ORDER_ASSIGNMENT) || '0';
var code = dict + "[" + KEY + "] = " + at2 + '\n'
break;
case 'DELETE':
var code = 'del ' + dict + "[" + KEY + "]\n"
break;
default:
throw 'Unhandled option (lists_setIndex2)';
case 'INSERT':
//var at2 = block.getFieldValue('AT2');
var at2 = generator.valueToCode(this, 'AT2', generator.ORDER_ASSIGNMENT) || '0';
var code = dict + "[" + KEY + "] = " + at2 + '\n'
break;
case 'DELETE':
var code = 'del ' + dict + "[" + KEY + "]\n"
break;
default:
throw 'Unhandled option (lists_setIndex2)';
}
return code;
}

View File

@@ -150,36 +150,36 @@ export const list_trig = function (a, generator) {
generator.definitions_['import_math'] = "import math";
a = generator.valueToCode(a, 'data', generator.ORDER_NONE)
switch (b) {
case "LEN":
c = "len(" + a + ")";
break;
case "SUM":
c = "sum(" + a + ")";
break;
case "MIN":
c = "min(" + a + ")";
break;
case "MAX":
c = "max(" + a + ")";
break;
case 'AVERAGE':
generator.definitions_['import_mixpy_math_mean'] = "from mixpy import math_mean";
c = 'math_mean(' + a + ')';
break;
case 'MEDIAN':
generator.definitions_['import_mixpy_math_median'] = "from mixpy import math_median";
c = 'math_median(' + a + ')';
break;
case 'MODE':
generator.definitions_['import_mixpy_math_modes'] = "from mixpy import math_modes";
c = 'math_modes(' + a + ')';
break;
case 'STD_DEV':
generator.definitions_['import_mixpy_math_standard_deviation'] = "from mixpy import math_standard_deviation";
c = 'math_standard_deviation(' + a + ')';
break;
default:
throw 'Unknown operator: ' + b;
case "LEN":
c = "len(" + a + ")";
break;
case "SUM":
c = "sum(" + a + ")";
break;
case "MIN":
c = "min(" + a + ")";
break;
case "MAX":
c = "max(" + a + ")";
break;
case 'AVERAGE':
generator.definitions_['import_mixpy_math_mean'] = "from mixpy import math_mean";
c = 'math_mean(' + a + ')';
break;
case 'MEDIAN':
generator.definitions_['import_mixpy_math_median'] = "from mixpy import math_median";
c = 'math_median(' + a + ')';
break;
case 'MODE':
generator.definitions_['import_mixpy_math_modes'] = "from mixpy import math_modes";
c = 'math_modes(' + a + ')';
break;
case 'STD_DEV':
generator.definitions_['import_mixpy_math_standard_deviation'] = "from mixpy import math_standard_deviation";
c = 'math_standard_deviation(' + a + ')';
break;
default:
throw 'Unknown operator: ' + b;
}
if (c)
return [c, generator.ORDER_ATOMIC];

View File

@@ -70,13 +70,13 @@ export const math_selfcalcu = function (_, generator) {
var argument1 = generator.valueToCode(this, 'B', generator.ORDER_RELATIONAL) || '0';
var operator = this.getFieldValue('OP');
switch (operator) {
case 'ADD': var op = '+='; break;
case 'MINUS': var op = '-='; break;
case 'MULTIPLY': var op = '*='; break;
case 'DIVIDE': var op = '/='; break;
case 'QUYU': var op = '%='; break;
case 'ZHENGCHU': var op = '//='; break;
case 'POWER': var op = '**='; break;
case 'ADD': var op = '+='; break;
case 'MINUS': var op = '-='; break;
case 'MULTIPLY': var op = '*='; break;
case 'DIVIDE': var op = '/='; break;
case 'QUYU': var op = '%='; break;
case 'ZHENGCHU': var op = '//='; break;
case 'POWER': var op = '**='; break;
}
var code = argument0 + ' ' + op + ' ' + argument1 + '\n';
return code;
@@ -90,66 +90,66 @@ export const math_single = function (a, generator) {
generator.definitions_['import_math'] = "import math";
a = "SIN" == b || "COS" == b || "TAN" == b ? generator.valueToCode(a, "NUM", generator.ORDER_MULTIPLICATIVE) || "0" : generator.valueToCode(a, "NUM", generator.ORDER_NONE) || "0";
switch (b) {
case "ABS":
c = "math.fabs(" + a + ")";
break;
case "ROOT":
c = "math.sqrt(" +
case "ABS":
c = "math.fabs(" + 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 = "math.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 + ")";
break;
case "COS":
c = "math.cos(" + a + ")";
break;
case "TAN":
c = "math.tan(" + a + ")";
break;
case "++":
c = "++(" + a + ")";
break;
case "--":
c = "--(" + a + ")";
break;
case "-":
c = "-(" + a + ")";
break;
default:
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 = "math.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 + ")";
break;
case "COS":
c = "math.cos(" + a + ")";
break;
case "TAN":
c = "math.tan(" + a + ")";
break;
case "++":
c = "++(" + a + ")";
break;
case "--":
c = "--(" + a + ")";
break;
case "-":
c = "-(" + a + ")";
break;
default:
}
if (c)
return [c, generator.ORDER_EXPONENTIATION];
switch (b) {
case "ASIN":
c = "math.degrees(math.asin(" + a + "))";
break;
case "ACOS":
c = "math.degrees(math.acos(" + a + "))";
break;
case "ATAN":
c = "math.degrees(math.atan(" + a + "))";
break;
case "ASIN":
c = "math.degrees(math.asin(" + a + "))";
break;
case "ACOS":
c = "math.degrees(math.acos(" + a + "))";
break;
case "ATAN":
c = "math.degrees(math.atan(" + a + "))";
break;
}
return [c, generator.ORDER_MULTIPLICATIVE]
}

View File

@@ -50,15 +50,15 @@ export const text_char_at2 = function (a, generator) {
var c = a.getFieldValue("WHERE") || "FROM_START",
str = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC) || '""';
switch (c) {
case "FROM_START":
a = generator.getAdjustedInt(a, "AT");
return [str + "[" + a + "]", generator.ORDER_ATOMIC];
case "FROM_END":
a = generator.getAdjustedInt(a, "AT", 1, !0);
return [str + "[" + a + "]", generator.ORDER_ATOMIC];
case "RANDOM":
generator.definitions_.import_random = "import random";
return ["random.choice(" + str + ")", generator.ORDER_FUNCTION_CALL];
case "FROM_START":
a = generator.getAdjustedInt(a, "AT");
return [str + "[" + a + "]", generator.ORDER_ATOMIC];
case "FROM_END":
a = generator.getAdjustedInt(a, "AT", 1, !0);
return [str + "[" + a + "]", generator.ORDER_ATOMIC];
case "RANDOM":
generator.definitions_.import_random = "import random";
return ["random.choice(" + str + ")", generator.ORDER_FUNCTION_CALL];
}
throw "Unhandled combination (lists_getIndex).";
}
@@ -96,41 +96,41 @@ export const text_substring2 = function (block, generator) {
var where1 = block.getFieldValue('WHERE1');
var where2 = block.getFieldValue('WHERE2');
switch (where1) {
case 'FROM_START':
var at1 = generator.getAdjustedInt(block, 'AT1');
if (at1 == '0') {
at1 = '';
}
break;
case 'FROM_END':
var at1 = generator.getAdjustedInt(block, 'AT1', 0, true);
break;
case 'FIRST':
var at1 = '0';
break;
default:
throw 'Unhandled option (lists_getSublist)';
case 'FROM_START':
var at1 = generator.getAdjustedInt(block, 'AT1');
if (at1 == '0') {
at1 = '';
}
break;
case 'FROM_END':
var at1 = generator.getAdjustedInt(block, 'AT1', 0, true);
break;
case 'FIRST':
var at1 = '0';
break;
default:
throw 'Unhandled option (lists_getSublist)';
}
switch (where2) {
case 'FROM_START':
var at2 = generator.getAdjustedInt(block, 'AT2');
break;
case 'FROM_END':
var at2 = generator.getAdjustedInt(block, 'AT2', 0, true);
// Ensure that if the result calculated is 0 that sub-sequence will
// include all elements as expected.
if (!Blockly.isNumber(String(at2))) {
generator.definitions_['import_sys'] = 'import sys';
at2 += ' or sys.maxsize';
} else if (at2 == '0') {
at2 = '';
}
break;
case 'LAST':
var at2 = '-1';
break;
default:
throw 'Unhandled option (lists_getSublist)';
case 'FROM_START':
var at2 = generator.getAdjustedInt(block, 'AT2');
break;
case 'FROM_END':
var at2 = generator.getAdjustedInt(block, 'AT2', 0, true);
// Ensure that if the result calculated is 0 that sub-sequence will
// include all elements as expected.
if (!Blockly.isNumber(String(at2))) {
generator.definitions_['import_sys'] = 'import sys';
at2 += ' or sys.maxsize';
} else if (at2 == '0') {
at2 = '';
}
break;
case 'LAST':
var at2 = '-1';
break;
default:
throw 'Unhandled option (lists_getSublist)';
}
var code = str + '[' + at1 + ' : ' + at2 + ']';
return [code, generator.ORDER_ATOMIC];

View File

@@ -107,90 +107,90 @@ export const tuple_trig = function (a, generator) {
generator.definitions_['import_math'] = "import math";
a = generator.valueToCode(a, 'data', generator.ORDER_NONE)
switch (b) {
case "LEN":
c = "len(" + a + ")";
break;
case "SUM":
c = "sum(" + a + ")";
break;
case "MIN":
c = "min(" + a + ")";
break;
case "MAX":
c = "max(" + a + ")";
break;
case 'AVERAGE':
// generator.definitions_['from_numbers_import_Number'] =
// 'from numbers import Number';
var functionName = generator.provideFunction_(
'math_mean',
// This operation excludes null and values that aren't int or float:',
// math_mean([null, null, "aString", 1, 9]) == 5.0.',
['def ' + generator.FUNCTION_NAME_PLACEHOLDER_ + '(myList):',
' localList = [e for e in myList if type(e) == int or type(e) == float]',
' if not localList: return',
' return float(sum(localList)) / len(localList)']);
c = functionName + '(' + a + ')';
break;
case 'MEDIAN':
// generator.definitions_['from_numbers_import_Number'] =
// 'from numbers import Numberd';
var functionName = generator.provideFunction_(
'math_median',
// This operation excludes null values:
// math_median([null, null, 1, 3]) == 2.0.
['def ' + generator.FUNCTION_NAME_PLACEHOLDER_ + '(myList):',
' localList = sorted([e for e in myList if type(e) == int or type(e) == float])',
' if not localList: return',
' if len(localList) % 2 == 0:',
' return (localList[len(localList) // 2 - 1] + ' +
case "LEN":
c = "len(" + a + ")";
break;
case "SUM":
c = "sum(" + a + ")";
break;
case "MIN":
c = "min(" + a + ")";
break;
case "MAX":
c = "max(" + a + ")";
break;
case 'AVERAGE':
// generator.definitions_['from_numbers_import_Number'] =
// 'from numbers import Number';
var functionName = generator.provideFunction_(
'math_mean',
// This operation excludes null and values that aren't int or float:',
// math_mean([null, null, "aString", 1, 9]) == 5.0.',
['def ' + generator.FUNCTION_NAME_PLACEHOLDER_ + '(myList):',
' localList = [e for e in myList if type(e) == int or type(e) == float]',
' if not localList: return',
' return float(sum(localList)) / len(localList)']);
c = functionName + '(' + a + ')';
break;
case 'MEDIAN':
// generator.definitions_['from_numbers_import_Number'] =
// 'from numbers import Numberd';
var functionName = generator.provideFunction_(
'math_median',
// This operation excludes null values:
// math_median([null, null, 1, 3]) == 2.0.
['def ' + generator.FUNCTION_NAME_PLACEHOLDER_ + '(myList):',
' localList = sorted([e for e in myList if type(e) == int or type(e) == float])',
' 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]']);
c = functionName + '(' + a + ')';
break;
case 'MODE':
var functionName = generator.provideFunction_(
'math_modes',
// As a list of numbers can contain more than one mode,
// the returned result is provided as an array.
// Mode of [3, 'x', 'x', 1, 1, 2, '3'] -> ['x', 1].
['def ' + generator.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 ' +
' else:',
' return localList[(len(localList) - 1) // 2]']);
c = functionName + '(' + a + ')';
break;
case 'MODE':
var functionName = generator.provideFunction_(
'math_modes',
// As a list of numbers can contain more than one mode,
// the returned result is provided as an array.
// Mode of [3, 'x', 'x', 1, 1, 2, '3'] -> ['x', 1].
['def ' + generator.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']);
c = functionName + '(' + a + ')';
break;
case 'STD_DEV':
generator.definitions_['import_math'] = 'import math';
var functionName = generator.provideFunction_(
'math_standard_deviation',
['def ' + generator.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)']);
c = functionName + '(' + a + ')';
break;
default:
throw 'Unknown operator: ' + b;
' 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']);
c = functionName + '(' + a + ')';
break;
case 'STD_DEV':
generator.definitions_['import_math'] = 'import math';
var functionName = generator.provideFunction_(
'math_standard_deviation',
['def ' + generator.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)']);
c = functionName + '(' + a + ')';
break;
default:
throw 'Unknown operator: ' + b;
}
if (c)
return [c, generator.ORDER_FUNCTION_CALL];
@@ -204,42 +204,42 @@ export const tuple_getSublist = function (block, generator) {
var where1 = block.getFieldValue('WHERE1');
var where2 = block.getFieldValue('WHERE2');
switch (where1) {
case 'FROM_START':
var at1 = generator.getAdjustedInt(block, 'AT1');
if (at1 == '0') {
at1 = '';
}
break;
case 'FROM_END':
var at1 = generator.getAdjustedInt(block, 'AT1', 1, true);
break;
case 'FIRST':
var at1 = '0';
break;
default:
throw 'Unhandled option (lists_getSublist)';
case 'FROM_START':
var at1 = generator.getAdjustedInt(block, 'AT1');
if (at1 == '0') {
at1 = '';
}
break;
case 'FROM_END':
var at1 = generator.getAdjustedInt(block, 'AT1', 1, true);
break;
case 'FIRST':
var at1 = '0';
break;
default:
throw 'Unhandled option (lists_getSublist)';
}
switch (where2) {
case 'FROM_START':
var at2 = generator.getAdjustedInt(block, 'AT2', 1);
at2 = at2 - 1;
break;
case 'FROM_END':
var at2 = generator.getAdjustedInt(block, 'AT2', 1, true);
// Ensure that if the result calculated is 0 that sub-sequence will
// include all elements as expected.
if (!Blockly.isNumber(String(at2))) {
generator.definitions_['import_sys'] = 'import sys';
at2 += ' or sys.maxsize';
} else if (at2 == '0') {
at2 = '';
}
break;
case 'LAST':
var at2 = '-1';
break;
default:
throw 'Unhandled option (lists_getSublist)';
case 'FROM_START':
var at2 = generator.getAdjustedInt(block, 'AT2', 1);
at2 = at2 - 1;
break;
case 'FROM_END':
var at2 = generator.getAdjustedInt(block, 'AT2', 1, true);
// Ensure that if the result calculated is 0 that sub-sequence will
// include all elements as expected.
if (!Blockly.isNumber(String(at2))) {
generator.definitions_['import_sys'] = 'import sys';
at2 += ' or sys.maxsize';
} else if (at2 == '0') {
at2 = '';
}
break;
case 'LAST':
var at2 = '-1';
break;
default:
throw 'Unhandled option (lists_getSublist)';
}
var code = list + '[' + at1 + ' : ' + at2 + ']';
return [code, generator.ORDER_MEMBER];

View File

@@ -1,6 +1,6 @@
{
"name": "@mixly/python",
"version": "1.1.0",
"version": "1.2.0",
"description": "适用于mixly的python模块",
"scripts": {
"build:dev": "webpack --config=webpack.dev.js",