How to use getTableData method in wpt

Best JavaScript code snippet using wpt

block_ai_learning.js

Source:block_ai_learning.js Github

copy

Full Screen

1import _floor from 'lodash/floor';2const DropDownDynamicGenerator = {3 labels: () => {4 if (Entry?.aiLearning?.labels?.length) {5 return Entry.aiLearning.labels.map((name, index) => [name, index]);6 } else {7 return [[Lang.Blocks.no_target, 'null']];8 }9 },10 tableAttrFields: () => {11 const table = Entry.aiLearning?.getTableData?.();12 if (table) {13 const { select = [], fields } = table || {};14 const attr = select?.[0] || [];15 return attr.map((fieldIndex, idx) => [fields[fieldIndex], idx]);16 } else {17 return [[Lang.Blocks.no_target, 'null']];18 }19 },20 tablePredictDataDistinct: () => {21 if (Entry.aiLearning.labels) {22 return Entry.aiLearning.labels.map((item) => [item, item]);23 } else {24 return [[Lang.Blocks.no_target, 'null']];25 }26 }27}28module.exports = {29 getBlocks() {30 return {31 learning_title_image: {32 skeleton: 'basic_text',33 color: EntryStatic.colorSet.common.TRANSPARENT,34 params: [35 {36 type: 'Text',37 text: Lang.template.learning_title_image_str,38 color: EntryStatic.colorSet.common.TEXT,39 align: 'center',40 },41 ],42 def: {43 type: 'learning_title_image',44 },45 class: 'ai_learning',46 isNotFor: ['ai_learning_image'],47 events: {},48 },49 learning_title_speech: {50 skeleton: 'basic_text',51 color: EntryStatic.colorSet.common.TRANSPARENT,52 params: [53 {54 type: 'Text',55 text: Lang.template.learning_title_speech_str,56 color: EntryStatic.colorSet.common.TEXT,57 align: 'center',58 },59 ],60 def: {61 type: 'learning_title_speech',62 },63 class: 'ai_learning',64 isNotFor: ['ai_learning_speech'],65 events: {},66 },67 learning_title_text: {68 skeleton: 'basic_text',69 color: EntryStatic.colorSet.common.TRANSPARENT,70 params: [71 {72 type: 'Text',73 text: Lang.template.learning_title_text_str,74 color: EntryStatic.colorSet.common.TEXT,75 align: 'center',76 },77 ],78 def: {79 type: 'learning_title_text',80 },81 class: 'ai_learning',82 isNotFor: ['ai_learning_text'],83 events: {},84 },85 learning_title_number: {86 skeleton: 'basic_text',87 color: EntryStatic.colorSet.common.TRANSPARENT,88 params: [89 {90 type: 'Text',91 text: Lang.template.learning_title_number_str,92 color: EntryStatic.colorSet.common.TEXT,93 align: 'center',94 },95 ],96 def: {97 type: 'learning_title_number',98 },99 class: 'ai_learning',100 isNotFor: ['ai_learning_number'],101 events: {},102 },103 learning_title_regression: {104 skeleton: 'basic_text',105 color: EntryStatic.colorSet.common.TRANSPARENT,106 params: [107 {108 type: 'Text',109 text: Lang.template.learning_title_regression_str,110 color: EntryStatic.colorSet.common.TEXT,111 align: 'center',112 },113 ],114 def: {115 type: 'learning_title_regression',116 },117 class: 'ai_learning',118 isNotFor: ['ai_learning_regression'],119 events: {},120 },121 learning_title_cluster: {122 skeleton: 'basic_text',123 color: EntryStatic.colorSet.common.TRANSPARENT,124 params: [125 {126 type: 'Text',127 text: Lang.template.learning_title_cluster_str,128 color: EntryStatic.colorSet.common.TEXT,129 align: 'center',130 },131 ],132 def: {133 type: 'learning_title_cluster',134 },135 class: 'ai_learning',136 isNotFor: ['ai_learning_cluster'],137 events: {},138 },139 insert_data_for_test: {140 color: EntryStatic.colorSet.block.default.AI_LEARNING,141 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,142 skeleton: 'basic',143 statements: [],144 params: [145 {146 type: 'Indicator',147 img: 'block_icon/ai_utilize_icon.svg',148 size: 11,149 },150 ],151 events: {},152 def: {153 params: [null],154 type: 'insert_data_for_test',155 },156 pyHelpDef: {157 params: [],158 type: 'insert_data_for_test',159 },160 paramsKeyMap: {},161 class: 'ai_learning',162 isNotFor: ['ai_learning_classification'],163 func(sprite, script) {164 if (!script.isStart) {165 script.isStart = true;166 Entry.aiLearning.openInputPopup();167 return script;168 }169 if (!Entry.aiLearning.isLoading) {170 delete script.isStart;171 return script.callReturn();172 }173 return script;174 },175 syntax: {176 js: [],177 py: [],178 },179 },180 video_capture_for_image_test: {181 color: EntryStatic.colorSet.block.default.AI_LEARNING,182 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,183 skeleton: 'basic',184 statements: [],185 params: [186 {187 type: 'Dropdown',188 options: [189 [Lang.Blocks.video_start, 'start'],190 [Lang.Blocks.video_end, 'stop'],191 ],192 value: 'on',193 fontSize: 11,194 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,195 arrowColor: EntryStatic.colorSet.common.WHITE,196 },197 {198 type: 'Indicator',199 img: 'block_icon/ai_utilize_icon.svg',200 size: 11,201 },202 ],203 events: {},204 def: {205 params: ['start', null],206 type: 'video_capture_for_image_test',207 },208 pyHelpDef: {209 params: [],210 type: 'video_capture_for_image_test',211 },212 paramsKeyMap: {213 MODE: 0,214 },215 class: 'ai_learning',216 isNotFor: ['ai_learning_image'],217 async func(sprite, script) {218 const mode = script.getField('MODE');219 if (mode === 'start') {220 Entry.aiLearning.startPredict();221 } else {222 Entry.aiLearning.stopPredict();223 }224 return script.callReturn();225 },226 syntax: {227 js: [],228 py: [],229 },230 },231 insert_text_block_for_test: {232 color: EntryStatic.colorSet.block.default.AI_LEARNING,233 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,234 skeleton: 'basic',235 statements: [],236 params: [237 {238 type: 'Block',239 accept: 'string',240 },241 {242 type: 'Indicator',243 img: 'block_icon/ai_utilize_icon.svg',244 size: 11,245 },246 ],247 events: {},248 def: {249 params: [250 {251 type: 'text',252 params: [Lang.Blocks.entry],253 },254 null,255 ],256 type: 'insert_text_block_for_test',257 },258 pyHelpDef: {259 params: [],260 type: 'insert_text_block_for_test',261 },262 paramsKeyMap: {263 TEXT: 0,264 },265 class: 'ai_learning',266 isNotFor: ['ai_learning_text'],267 async func(sprite, script) {268 const text = script.getStringValue('TEXT', script);269 await Entry.aiLearning.predict(text);270 return script.callReturn();271 },272 syntax: {273 js: [],274 py: [],275 },276 },277 test_result: {278 color: EntryStatic.colorSet.block.default.AI_LEARNING,279 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,280 skeleton: 'basic_string_field',281 statements: [],282 params: [],283 events: {},284 def: {285 params: [null],286 type: 'test_result',287 },288 pyHelpDef: {289 params: [],290 type: 'test_result',291 },292 paramsKeyMap: {},293 class: 'ai_learning',294 isNotFor: ['ai_learning_classification'],295 func(sprite, script) {296 return Entry.aiLearning.getPredictResult().className;297 },298 syntax: {299 js: [],300 py: [],301 },302 },303 accuracy_of_result: {304 color: EntryStatic.colorSet.block.default.AI_LEARNING,305 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,306 skeleton: 'basic_string_field',307 statements: [],308 params: [309 {310 type: 'DropdownDynamic',311 value: null,312 menuName: DropDownDynamicGenerator.labels,313 needDeepCopy: true,314 fontSize: 11,315 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,316 arrowColor: EntryStatic.colorSet.common.WHITE,317 defaultValue: (value, options) => {318 if (options[0] && options[0][1]) {319 return options[0][1];320 }321 return value || 0;322 },323 },324 ],325 events: {},326 def: {327 params: [0],328 type: 'accuracy_of_result',329 },330 pyHelpDef: {331 params: [],332 type: 'accuracy_of_result',333 },334 paramsKeyMap: {335 GROUP: 0,336 },337 class: 'ai_learning',338 isNotFor: ['ai_learning_classification'],339 func(sprite, script) {340 const group = script.getNumberValue('GROUP', script);341 return Entry.aiLearning.getPredictResult(group).probability;342 },343 syntax: {344 js: [],345 py: [],346 },347 },348 is_group: {349 color: EntryStatic.colorSet.block.default.AI_LEARNING,350 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,351 skeleton: 'basic_boolean_field',352 statements: [],353 params: [354 {355 type: 'DropdownDynamic',356 value: null,357 menuName: DropDownDynamicGenerator.labels,358 needDeepCopy: true,359 fontSize: 11,360 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,361 arrowColor: EntryStatic.colorSet.common.WHITE,362 defaultValue: (value, options) => {363 if (options[0] && options[0][1]) {364 return options[0][1];365 }366 return value || 0;367 },368 },369 ],370 events: {},371 def: {372 params: [0],373 type: 'is_group',374 },375 class: 'ai_learning',376 isNotFor: ['ai_learning_classification'],377 paramsKeyMap: {378 GROUP: 0,379 },380 func(sprite, script) {381 const group = script.getNumberValue('GROUP', script);382 const { labels } = Entry.aiLearning;383 const result = Entry.aiLearning.getPredictResult().className;384 return result === labels[group];385 },386 syntax: {387 js: [],388 py: [],389 },390 },391 retrain_model: {392 color: EntryStatic.colorSet.block.default.AI_LEARNING,393 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,394 skeleton: 'basic',395 statements: [],396 params: [397 {398 type: 'Indicator',399 img: 'block_icon/ai_utilize_icon.svg',400 size: 11,401 },402 ],403 events: {},404 def: {405 params: [null],406 type: 'retrain_model',407 },408 pyHelpDef: {409 params: [],410 type: 'retrain_model',411 },412 paramsKeyMap: {413 TEXT: 0,414 },415 class: 'ai_learning',416 isNotFor: ['ai_learning_train'],417 async func(sprite, script) {418 Entry.aiLearning.train();419 return script.callReturn();420 },421 syntax: {422 js: [],423 py: [],424 },425 },426 model_is_trained: {427 color: EntryStatic.colorSet.block.default.AI_LEARNING,428 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,429 skeleton: 'basic_boolean_field',430 statements: [],431 params: [],432 events: {},433 def: {434 type: 'model_is_trained',435 },436 class: 'ai_learning',437 isNotFor: ['ai_learning_train'],438 func(sprite, script) {439 return Entry.aiLearning.isTrained();440 },441 syntax: {442 js: [],443 py: [],444 },445 },446 set_train_visible: {447 color: EntryStatic.colorSet.block.default.AI_LEARNING,448 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,449 skeleton: 'basic',450 statements: [],451 params: [452 {453 type: 'Dropdown',454 options: [455 [Lang.AiLearning.show, 'show'],456 [Lang.AiLearning.hide, 'hide'],457 ],458 value: 'show',459 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,460 arrowColor: EntryStatic.colorSet.common.WHITE,461 },462 {463 type: 'Indicator',464 img: 'block_icon/ai_utilize_icon.svg',465 size: 11,466 },467 ],468 events: {},469 def: {470 params: ['show', null],471 type: 'set_train_visible',472 },473 pyHelpDef: {474 params: [],475 type: 'set_train_visible',476 },477 paramsKeyMap: {478 VISIBLE: 0,479 },480 class: 'ai_learning',481 isNotFor: ['ai_learning_train'],482 async func(sprite, script) {483 const visible = script.getField('VISIBLE');484 Entry.aiLearning.setVisible(visible === 'show' ? true : false);485 return script.callReturn();486 },487 syntax: {488 js: [],489 py: [],490 },491 },492 set_train_chart: {493 color: EntryStatic.colorSet.block.default.AI_LEARNING,494 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,495 skeleton: 'basic',496 statements: [],497 params: [498 {499 type: 'Dropdown',500 options: [501 [Lang.AiLearning.open, 'open'],502 [Lang.AiLearning.close, 'close'],503 ],504 value: 'open',505 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,506 arrowColor: EntryStatic.colorSet.common.WHITE,507 },508 {509 type: 'Indicator',510 img: 'block_icon/ai_utilize_icon.svg',511 size: 11,512 },513 ],514 events: {},515 def: {516 params: ['open', null],517 type: 'set_train_chart',518 },519 pyHelpDef: {520 params: [],521 type: 'set_train_chart',522 },523 paramsKeyMap: {524 VISIBLE: 0,525 },526 class: 'ai_learning',527 isNotFor: ['ai_learning_train_chart'],528 async func(sprite, script) {529 const visible = script.getField('VISIBLE');530 Entry.aiLearning.setChartVisible(visible === 'open' ? true : false);531 return script.callReturn();532 },533 syntax: {534 js: [],535 py: [],536 },537 },538 set_regression_option: {539 color: EntryStatic.colorSet.block.default.AI_LEARNING,540 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,541 skeleton: 'basic',542 statements: [],543 params: [544 {545 type: 'Dropdown',546 options: [547 [Lang.AiLearning.train_param_learningRate, 'learningRate'],548 [Lang.AiLearning.train_param_epochs, 'epochs'],549 [Lang.AiLearning.train_param_validationRate, 'validationRate'],550 ],551 value: 'learningRate',552 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,553 arrowColor: EntryStatic.colorSet.common.WHITE,554 },555 {556 type: 'Block',557 accept: 'string',558 defaultType: 'number',559 },560 {561 type: 'Indicator',562 img: 'block_icon/ai_utilize_icon.svg',563 size: 11,564 },565 ],566 events: {},567 def: {568 type: 'set_regression_option',569 },570 pyHelpDef: {571 params: [],572 type: 'set_regression_option',573 },574 paramsKeyMap: {575 OPTION: 0,576 VALUE: 1,577 },578 class: 'ai_learning',579 isNotFor: ['ai_learning_regression'],580 func(sprite, script) {581 const option = script.getField('OPTION', script);582 const value = script.getNumberValue('VALUE', script);583 Entry.aiLearning.setTrainOption(option, parseFloat(value));584 return script.callReturn();585 },586 syntax: {587 js: [],588 py: [],589 },590 },591 get_regression_predict_1: {592 color: EntryStatic.colorSet.block.default.AI_LEARNING,593 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,594 skeleton: 'basic_string_field',595 statements: [],596 params: [597 {598 type: 'TextDynamic',599 setValue: () => {600 const table = Entry.aiLearning?.getTableData?.();601 if (table) {602 const {603 select = [],604 fields = [],605 } = Entry.aiLearning?.getTableData?.();606 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;607 }608 return Lang.AiLearning.model_attr_str;609 },610 },611 {612 type: 'Block',613 accept: 'string',614 defaultType: 'number',615 },616 ],617 events: {},618 def: {619 type: 'get_regression_predict_1',620 },621 pyHelpDef: {622 params: [],623 type: 'get_regression_predict_1',624 },625 paramsKeyMap: {626 ATTR1: 1,627 },628 class: 'ai_learning',629 isNotFor: ['regression_attr_1'],630 async func(sprite, script) {631 const x = script.getNumberValue('ATTR1', script);632 await Entry.aiLearning.predict(x);633 return Entry.aiLearning.getPredictResult();634 },635 syntax: {636 js: [],637 py: [],638 },639 },640 get_regression_predict_2: {641 color: EntryStatic.colorSet.block.default.AI_LEARNING,642 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,643 skeleton: 'basic_string_field',644 statements: [],645 params: [646 {647 type: 'TextDynamic',648 setValue: () => {649 const table = Entry.aiLearning?.getTableData?.();650 if (table) {651 const {652 select = [],653 fields = [],654 } = Entry.aiLearning?.getTableData?.();655 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;656 }657 return Lang.AiLearning.model_attr_str;658 },659 },660 {661 type: 'Block',662 accept: 'string',663 defaultType: 'number',664 },665 {666 type: 'TextDynamic',667 setValue: () => {668 const table = Entry.aiLearning?.getTableData?.();669 if (table) {670 const {671 select = [],672 fields = [],673 } = Entry.aiLearning?.getTableData?.();674 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;675 }676 return Lang.AiLearning.model_attr_str;677 },678 },679 {680 type: 'Block',681 accept: 'string',682 defaultType: 'number',683 },684 ],685 events: {},686 def: {687 type: 'get_regression_predict_2',688 },689 pyHelpDef: {690 params: [],691 type: 'get_regression_predict_2',692 },693 paramsKeyMap: {694 ATTR1: 1,695 ATTR2: 3,696 },697 class: 'ai_learning',698 isNotFor: ['regression_attr_2'],699 async func(sprite, script) {700 const x = script.getNumberValue('ATTR1', script);701 const y = script.getNumberValue('ATTR2', script);702 await Entry.aiLearning.predict([x, y]);703 return Entry.aiLearning.getPredictResult();704 },705 syntax: {706 js: [],707 py: [],708 },709 },710 get_regression_predict_3: {711 color: EntryStatic.colorSet.block.default.AI_LEARNING,712 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,713 skeleton: 'basic_string_field',714 statements: [],715 params: [716 {717 type: 'TextDynamic',718 setValue: () => {719 const table = Entry.aiLearning?.getTableData?.();720 if (table) {721 const {722 select = [],723 fields = [],724 } = Entry.aiLearning?.getTableData?.();725 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;726 }727 return Lang.AiLearning.model_attr_str;728 },729 },730 {731 type: 'Block',732 accept: 'string',733 defaultType: 'number',734 },735 {736 type: 'TextDynamic',737 setValue: () => {738 const table = Entry.aiLearning?.getTableData?.();739 if (table) {740 const {741 select = [],742 fields = [],743 } = Entry.aiLearning?.getTableData?.();744 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;745 }746 return Lang.AiLearning.model_attr_str;747 },748 },749 {750 type: 'Block',751 accept: 'string',752 defaultType: 'number',753 },754 {755 type: 'TextDynamic',756 setValue: () => {757 const table = Entry.aiLearning?.getTableData?.();758 if (table) {759 const {760 select = [],761 fields = [],762 } = Entry.aiLearning?.getTableData?.();763 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;764 }765 return Lang.AiLearning.model_attr_str;766 },767 },768 {769 type: 'Block',770 accept: 'string',771 defaultType: 'number',772 },773 ],774 events: {},775 def: {776 type: 'get_regression_predict_3',777 },778 pyHelpDef: {779 params: [],780 type: 'get_regression_predict_3',781 },782 paramsKeyMap: {783 ATTR1: 1,784 ATTR2: 3,785 ATTR3: 5,786 },787 class: 'ai_learning',788 isNotFor: ['regression_attr_3'],789 async func(sprite, script) {790 const x = script.getNumberValue('ATTR1', script);791 const y = script.getNumberValue('ATTR2', script);792 const z = script.getNumberValue('ATTR3', script);793 await Entry.aiLearning.predict([x, y, z]);794 return Entry.aiLearning.getPredictResult();795 },796 syntax: {797 js: [],798 py: [],799 },800 },801 get_regression_predict_4: {802 color: EntryStatic.colorSet.block.default.AI_LEARNING,803 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,804 skeleton: 'basic_string_field',805 statements: [],806 params: [807 {808 type: 'TextDynamic',809 setValue: () => {810 const table = Entry.aiLearning?.getTableData?.();811 if (table) {812 const {813 select = [],814 fields = [],815 } = Entry.aiLearning?.getTableData?.();816 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;817 }818 return Lang.AiLearning.model_attr_str;819 },820 },821 {822 type: 'Block',823 accept: 'string',824 defaultType: 'number',825 },826 {827 type: 'TextDynamic',828 setValue: () => {829 const table = Entry.aiLearning?.getTableData?.();830 if (table) {831 const {832 select = [],833 fields = [],834 } = Entry.aiLearning?.getTableData?.();835 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;836 }837 return Lang.AiLearning.model_attr_str;838 },839 },840 {841 type: 'Block',842 accept: 'string',843 defaultType: 'number',844 },845 {846 type: 'TextDynamic',847 setValue: () => {848 const table = Entry.aiLearning?.getTableData?.();849 if (table) {850 const {851 select = [],852 fields = [],853 } = Entry.aiLearning?.getTableData?.();854 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;855 }856 return Lang.AiLearning.model_attr_str;857 },858 },859 {860 type: 'Block',861 accept: 'string',862 defaultType: 'number',863 },864 {865 type: 'TextDynamic',866 setValue: () => {867 const table = Entry.aiLearning?.getTableData?.();868 if (table) {869 const {870 select = [],871 fields = [],872 } = Entry.aiLearning?.getTableData?.();873 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;874 }875 return Lang.AiLearning.model_attr_str;876 },877 },878 {879 type: 'Block',880 accept: 'string',881 defaultType: 'number',882 },883 ],884 events: {},885 def: {886 type: 'get_regression_predict_4',887 },888 pyHelpDef: {889 params: [],890 type: 'get_regression_predict_4',891 },892 paramsKeyMap: {893 ATTR1: 1,894 ATTR2: 3,895 ATTR3: 5,896 ATTR4: 7,897 },898 class: 'ai_learning',899 isNotFor: ['regression_attr_4'],900 async func(sprite, script) {901 const a = script.getNumberValue('ATTR1', script);902 const b = script.getNumberValue('ATTR2', script);903 const c = script.getNumberValue('ATTR3', script);904 const d = script.getNumberValue('ATTR4', script);905 await Entry.aiLearning.predict([a, b, c, d]);906 return Entry.aiLearning.getPredictResult();907 },908 syntax: {909 js: [],910 py: [],911 },912 },913 get_regression_predict_5: {914 color: EntryStatic.colorSet.block.default.AI_LEARNING,915 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,916 skeleton: 'basic_string_field',917 statements: [],918 params: [919 {920 type: 'TextDynamic',921 setValue: () => {922 const table = Entry.aiLearning?.getTableData?.();923 if (table) {924 const {925 select = [],926 fields = [],927 } = Entry.aiLearning?.getTableData?.();928 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;929 }930 return Lang.AiLearning.model_attr_str;931 },932 },933 {934 type: 'Block',935 accept: 'string',936 defaultType: 'number',937 },938 {939 type: 'TextDynamic',940 setValue: () => {941 const table = Entry.aiLearning?.getTableData?.();942 if (table) {943 const {944 select = [],945 fields = [],946 } = Entry.aiLearning?.getTableData?.();947 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;948 }949 return Lang.AiLearning.model_attr_str;950 },951 },952 {953 type: 'Block',954 accept: 'string',955 defaultType: 'number',956 },957 {958 type: 'TextDynamic',959 setValue: () => {960 const table = Entry.aiLearning?.getTableData?.();961 if (table) {962 const {963 select = [],964 fields = [],965 } = Entry.aiLearning?.getTableData?.();966 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;967 }968 return Lang.AiLearning.model_attr_str;969 },970 },971 {972 type: 'Block',973 accept: 'string',974 defaultType: 'number',975 },976 {977 type: 'TextDynamic',978 setValue: () => {979 const table = Entry.aiLearning?.getTableData?.();980 if (table) {981 const {982 select = [],983 fields = [],984 } = Entry.aiLearning?.getTableData?.();985 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;986 }987 return Lang.AiLearning.model_attr_str;988 },989 },990 {991 type: 'Block',992 accept: 'string',993 defaultType: 'number',994 },995 {996 type: 'TextDynamic',997 setValue: () => {998 const table = Entry.aiLearning?.getTableData?.();999 if (table) {1000 const {1001 select = [],1002 fields = [],1003 } = Entry.aiLearning?.getTableData?.();1004 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;1005 }1006 return Lang.AiLearning.model_attr_str;1007 },1008 },1009 {1010 type: 'Block',1011 accept: 'string',1012 defaultType: 'number',1013 },1014 ],1015 events: {},1016 def: {1017 type: 'get_regression_predict_5',1018 },1019 pyHelpDef: {1020 params: [],1021 type: 'get_regression_predict_5',1022 },1023 paramsKeyMap: {1024 ATTR1: 1,1025 ATTR2: 3,1026 ATTR3: 5,1027 ATTR4: 7,1028 ATTR5: 9,1029 },1030 class: 'ai_learning',1031 isNotFor: ['regression_attr_5'],1032 async func(sprite, script) {1033 const a = script.getNumberValue('ATTR1', script);1034 const b = script.getNumberValue('ATTR2', script);1035 const c = script.getNumberValue('ATTR3', script);1036 const d = script.getNumberValue('ATTR4', script);1037 const e = script.getNumberValue('ATTR5', script);1038 await Entry.aiLearning.predict([a, b, c, d, e]);1039 return Entry.aiLearning.getPredictResult();1040 },1041 syntax: {1042 js: [],1043 py: [],1044 },1045 },1046 get_regression_predict_6: {1047 color: EntryStatic.colorSet.block.default.AI_LEARNING,1048 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1049 skeleton: 'basic_string_field',1050 statements: [],1051 params: [1052 {1053 type: 'TextDynamic',1054 setValue: () => {1055 const table = Entry.aiLearning?.getTableData?.();1056 if (table) {1057 const {1058 select = [],1059 fields = [],1060 } = Entry.aiLearning?.getTableData?.();1061 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;1062 }1063 return Lang.AiLearning.model_attr_str;1064 },1065 },1066 {1067 type: 'Block',1068 accept: 'string',1069 defaultType: 'number',1070 },1071 {1072 type: 'TextDynamic',1073 setValue: () => {1074 const table = Entry.aiLearning?.getTableData?.();1075 if (table) {1076 const {1077 select = [],1078 fields = [],1079 } = Entry.aiLearning?.getTableData?.();1080 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;1081 }1082 return Lang.AiLearning.model_attr_str;1083 },1084 },1085 {1086 type: 'Block',1087 accept: 'string',1088 defaultType: 'number',1089 },1090 {1091 type: 'TextDynamic',1092 setValue: () => {1093 const table = Entry.aiLearning?.getTableData?.();1094 if (table) {1095 const {1096 select = [],1097 fields = [],1098 } = Entry.aiLearning?.getTableData?.();1099 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;1100 }1101 return Lang.AiLearning.model_attr_str;1102 },1103 },1104 {1105 type: 'Block',1106 accept: 'string',1107 defaultType: 'number',1108 },1109 {1110 type: 'TextDynamic',1111 setValue: () => {1112 const table = Entry.aiLearning?.getTableData?.();1113 if (table) {1114 const {1115 select = [],1116 fields = [],1117 } = Entry.aiLearning?.getTableData?.();1118 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;1119 }1120 return Lang.AiLearning.model_attr_str;1121 },1122 },1123 {1124 type: 'Block',1125 accept: 'string',1126 defaultType: 'number',1127 },1128 {1129 type: 'TextDynamic',1130 setValue: () => {1131 const table = Entry.aiLearning?.getTableData?.();1132 if (table) {1133 const {1134 select = [],1135 fields = [],1136 } = Entry.aiLearning?.getTableData?.();1137 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;1138 }1139 return Lang.AiLearning.model_attr_str;1140 },1141 },1142 {1143 type: 'Block',1144 accept: 'string',1145 defaultType: 'number',1146 },1147 {1148 type: 'TextDynamic',1149 setValue: () => {1150 const table = Entry.aiLearning?.getTableData?.();1151 if (table) {1152 const {1153 select = [],1154 fields = [],1155 } = Entry.aiLearning?.getTableData?.();1156 return fields[select?.[0]?.[5]] || Lang.AiLearning.model_attr_str;1157 }1158 return Lang.AiLearning.model_attr_str;1159 },1160 },1161 {1162 type: 'Block',1163 accept: 'string',1164 defaultType: 'number',1165 },1166 ],1167 events: {},1168 def: {1169 type: 'get_regression_predict_6',1170 },1171 pyHelpDef: {1172 params: [],1173 type: 'get_regression_predict_6',1174 },1175 paramsKeyMap: {1176 ATTR1: 1,1177 ATTR2: 3,1178 ATTR3: 5,1179 ATTR4: 7,1180 ATTR5: 9,1181 ATTR6: 11,1182 },1183 class: 'ai_learning',1184 isNotFor: ['regression_attr_6'],1185 async func(sprite, script) {1186 const a = script.getNumberValue('ATTR1', script);1187 const b = script.getNumberValue('ATTR2', script);1188 const c = script.getNumberValue('ATTR3', script);1189 const d = script.getNumberValue('ATTR4', script);1190 const e = script.getNumberValue('ATTR5', script);1191 const f = script.getNumberValue('ATTR6', script);1192 await Entry.aiLearning.predict([a, b, c, d, e, f]);1193 return Entry.aiLearning.getPredictResult();1194 },1195 syntax: {1196 js: [],1197 py: [],1198 },1199 },1200 get_regression_accuracy: {1201 color: EntryStatic.colorSet.block.default.AI_LEARNING,1202 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1203 skeleton: 'basic_string_field',1204 statements: [],1205 params: [],1206 events: {},1207 def: {1208 type: 'get_regression_accuracy',1209 },1210 pyHelpDef: {1211 params: [],1212 type: 'get_regression_accuracy',1213 },1214 paramsKeyMap: {},1215 class: 'ai_learning',1216 isNotFor: ['ai_learning_regression'],1217 async func(sprite, script) {1218 return Entry.aiLearning?.getTrainResult()?.rsquared;1219 },1220 syntax: {1221 js: [],1222 py: [],1223 },1224 },1225 set_cluster_option_k: {1226 color: EntryStatic.colorSet.block.default.AI_LEARNING,1227 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1228 skeleton: 'basic',1229 statements: [],1230 params: [1231 {1232 type: 'Block',1233 accept: 'string',1234 defaultType: 'number',1235 },1236 {1237 type: 'Indicator',1238 img: 'block_icon/ai_utilize_icon.svg',1239 size: 11,1240 },1241 ],1242 events: {},1243 def: {1244 params: [0, null],1245 type: 'set_cluster_option_k',1246 },1247 pyHelpDef: {1248 params: [],1249 type: 'set_cluster_option_k',1250 },1251 paramsKeyMap: {1252 VALUE: 0,1253 },1254 class: 'ai_learning',1255 isNotFor: ['ai_learning_cluster'],1256 async func(sprite, script) {1257 const value = script.getStringValue('VALUE', script);1258 Entry.aiLearning.setTrainOption('k', parseInt(value));1259 return script.callReturn();1260 },1261 syntax: {1262 js: [],1263 py: [],1264 },1265 },1266 set_cluster_option_centroids: {1267 color: EntryStatic.colorSet.block.default.AI_LEARNING,1268 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1269 skeleton: 'basic',1270 statements: [],1271 params: [1272 {1273 type: 'Dropdown',1274 options: [1275 [Lang.AiLearning.cluster_option_centroids_kmpp, 'kmpp'],1276 [Lang.AiLearning.cluster_option_centroids_random, 'random'],1277 ],1278 value: 'kmpp',1279 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,1280 arrowColor: EntryStatic.colorSet.common.WHITE,1281 },1282 {1283 type: 'Indicator',1284 img: 'block_icon/ai_utilize_icon.svg',1285 size: 11,1286 },1287 ],1288 events: {},1289 def: {1290 params: [null, null],1291 type: 'set_cluster_option_centroids',1292 },1293 pyHelpDef: {1294 params: [],1295 type: 'set_cluster_option_centroids',1296 },1297 paramsKeyMap: {1298 CENTRIOD_TYPE: 0,1299 },1300 class: 'ai_learning',1301 isNotFor: ['ai_learning_cluster'],1302 async func(sprite, script) {1303 const value = script.getField('CENTRIOD_TYPE');1304 Entry.aiLearning.setTrainOption('initialCentroids', value);1305 return script.callReturn();1306 },1307 syntax: {1308 js: [],1309 py: [],1310 },1311 },1312 get_cluster_centriod_count: {1313 color: EntryStatic.colorSet.block.default.AI_LEARNING,1314 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1315 skeleton: 'basic_string_field',1316 statements: [],1317 params: [],1318 events: {},1319 def: {1320 params: [],1321 type: 'get_cluster_centriod_count',1322 },1323 pyHelpDef: {1324 params: [],1325 type: 'get_cluster_centriod_count',1326 },1327 paramsKeyMap: {},1328 class: 'ai_learning',1329 isNotFor: ['ai_learning_cluster'],1330 func(sprite, script) {1331 const { k = 0 } = Entry.aiLearning.getTrainOption() || {};1332 return k;1333 },1334 syntax: {1335 js: [],1336 py: [],1337 },1338 },1339 get_cluster_centriod_value: {1340 color: EntryStatic.colorSet.block.default.AI_LEARNING,1341 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1342 skeleton: 'basic_string_field',1343 statements: [],1344 params: [1345 {1346 type: 'Block',1347 accept: 'string',1348 defaultType: 'number',1349 },1350 {1351 type: 'DropdownDynamic',1352 value: null,1353 menuName: DropDownDynamicGenerator.tableAttrFields,1354 needDeepCopy: true,1355 fontSize: 11,1356 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,1357 arrowColor: EntryStatic.colorSet.common.WHITE,1358 defaultValue: (value, options) => {1359 if (options[0] && options[0][1]) {1360 return options[0][1];1361 }1362 return value || 0;1363 },1364 },1365 ],1366 events: {},1367 def: {1368 params: [1, 0],1369 type: 'get_cluster_centriod_value',1370 },1371 pyHelpDef: {1372 params: [],1373 type: 'get_cluster_centriod_value',1374 },1375 paramsKeyMap: {1376 K: 0,1377 ATTR: 1,1378 },1379 class: 'ai_learning',1380 isNotFor: ['ai_learning_cluster'],1381 func(sprite, script) {1382 const k = script.getNumberValue('K');1383 const attr = script.getField('ATTR');1384 const { centroids } = Entry.aiLearning.getTrainResult();1385 return centroids?.[k - 1]?.[attr] || NaN;1386 },1387 syntax: {1388 js: [],1389 py: [],1390 },1391 },1392 get_cluster_centriod_index_1: {1393 color: EntryStatic.colorSet.block.default.AI_LEARNING,1394 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1395 skeleton: 'basic_string_field',1396 statements: [],1397 params: [1398 {1399 type: 'TextDynamic',1400 setValue: () => {1401 const table = Entry.aiLearning?.getTableData?.();1402 if (table) {1403 const {1404 select = [],1405 fields = [],1406 } = Entry.aiLearning?.getTableData?.();1407 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;1408 }1409 return Lang.AiLearning.model_attr_str;1410 },1411 },1412 {1413 type: 'Block',1414 accept: 'string',1415 defaultType: 'number',1416 },1417 ],1418 def: {1419 type: 'get_cluster_centriod_index_1',1420 },1421 events: {},1422 pyHelpDef: {1423 params: [],1424 type: 'get_cluster_centriod_index_1',1425 },1426 paramsKeyMap: {1427 ATTR1: 1,1428 },1429 class: 'ai_learning',1430 isNotFor: ['cluster_attr_1'],1431 async func(sprite, script) {1432 const x = script.getNumberValue('ATTR1', script);1433 await Entry.aiLearning.predict([x]);1434 return Entry.aiLearning.getPredictResult();1435 },1436 syntax: {1437 js: [],1438 py: [],1439 },1440 },1441 get_cluster_centriod_index_2: {1442 color: EntryStatic.colorSet.block.default.AI_LEARNING,1443 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1444 skeleton: 'basic_string_field',1445 statements: [],1446 params: [1447 {1448 type: 'TextDynamic',1449 setValue: () => {1450 const table = Entry.aiLearning?.getTableData?.();1451 if (table) {1452 const {1453 select = [],1454 fields = [],1455 } = Entry.aiLearning?.getTableData?.();1456 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;1457 }1458 return Lang.AiLearning.model_attr_str;1459 },1460 },1461 {1462 type: 'Block',1463 accept: 'string',1464 defaultType: 'number',1465 },1466 {1467 type: 'TextDynamic',1468 setValue: () => {1469 const table = Entry.aiLearning?.getTableData?.();1470 if (table) {1471 const {1472 select = [],1473 fields = [],1474 } = Entry.aiLearning?.getTableData?.();1475 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;1476 }1477 return Lang.AiLearning.model_attr_str;1478 },1479 },1480 {1481 type: 'Block',1482 accept: 'string',1483 defaultType: 'number',1484 },1485 ],1486 def: {1487 type: 'get_cluster_centriod_index_2',1488 },1489 events: {},1490 pyHelpDef: {1491 params: [],1492 type: 'get_cluster_centriod_index_2',1493 },1494 paramsKeyMap: {1495 ATTR1: 1,1496 ATTR2: 3,1497 },1498 class: 'ai_learning',1499 isNotFor: ['cluster_attr_2'],1500 async func(sprite, script) {1501 const x = script.getNumberValue('ATTR1', script);1502 const y = script.getNumberValue('ATTR2', script);1503 await Entry.aiLearning.predict([x, y]);1504 return Entry.aiLearning.getPredictResult();1505 },1506 syntax: {1507 js: [],1508 py: [],1509 },1510 },1511 get_cluster_centriod_index_3: {1512 color: EntryStatic.colorSet.block.default.AI_LEARNING,1513 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1514 skeleton: 'basic_string_field',1515 statements: [],1516 params: [1517 {1518 type: 'TextDynamic',1519 setValue: () => {1520 const table = Entry.aiLearning?.getTableData?.();1521 if (table) {1522 const {1523 select = [],1524 fields = [],1525 } = Entry.aiLearning?.getTableData?.();1526 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;1527 }1528 return Lang.AiLearning.model_attr_str;1529 },1530 },1531 {1532 type: 'Block',1533 accept: 'string',1534 defaultType: 'number',1535 },1536 {1537 type: 'TextDynamic',1538 setValue: () => {1539 const table = Entry.aiLearning?.getTableData?.();1540 if (table) {1541 const {1542 select = [],1543 fields = [],1544 } = Entry.aiLearning?.getTableData?.();1545 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;1546 }1547 return Lang.AiLearning.model_attr_str;1548 },1549 },1550 {1551 type: 'Block',1552 accept: 'string',1553 defaultType: 'number',1554 },1555 {1556 type: 'TextDynamic',1557 setValue: () => {1558 const table = Entry.aiLearning?.getTableData?.();1559 if (table) {1560 const {1561 select = [],1562 fields = [],1563 } = Entry.aiLearning?.getTableData?.();1564 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;1565 }1566 return Lang.AiLearning.model_attr_str;1567 },1568 },1569 {1570 type: 'Block',1571 accept: 'string',1572 defaultType: 'number',1573 },1574 ],1575 def: {1576 type: 'get_cluster_centriod_index_3',1577 },1578 events: {},1579 pyHelpDef: {1580 params: [],1581 type: 'get_cluster_centriod_index_3',1582 },1583 paramsKeyMap: {1584 ATTR1: 1,1585 ATTR2: 3,1586 ATTR3: 5,1587 },1588 class: 'ai_learning',1589 isNotFor: ['cluster_attr_3'],1590 async func(sprite, script) {1591 const x = script.getNumberValue('ATTR1', script);1592 const y = script.getNumberValue('ATTR2', script);1593 const z = script.getNumberValue('ATTR3', script);1594 await Entry.aiLearning.predict([x, y, z]);1595 return Entry.aiLearning.getPredictResult();1596 },1597 syntax: {1598 js: [],1599 py: [],1600 },1601 },1602 get_cluster_centriod_index_4: {1603 color: EntryStatic.colorSet.block.default.AI_LEARNING,1604 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1605 skeleton: 'basic_string_field',1606 statements: [],1607 params: [1608 {1609 type: 'TextDynamic',1610 setValue: () => {1611 const table = Entry.aiLearning?.getTableData?.();1612 if (table) {1613 const {1614 select = [],1615 fields = [],1616 } = Entry.aiLearning?.getTableData?.();1617 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;1618 }1619 return Lang.AiLearning.model_attr_str;1620 },1621 },1622 {1623 type: 'Block',1624 accept: 'string',1625 defaultType: 'number',1626 },1627 {1628 type: 'TextDynamic',1629 setValue: () => {1630 const table = Entry.aiLearning?.getTableData?.();1631 if (table) {1632 const {1633 select = [],1634 fields = [],1635 } = Entry.aiLearning?.getTableData?.();1636 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;1637 }1638 return Lang.AiLearning.model_attr_str;1639 },1640 },1641 {1642 type: 'Block',1643 accept: 'string',1644 defaultType: 'number',1645 },1646 {1647 type: 'TextDynamic',1648 setValue: () => {1649 const table = Entry.aiLearning?.getTableData?.();1650 if (table) {1651 const {1652 select = [],1653 fields = [],1654 } = Entry.aiLearning?.getTableData?.();1655 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;1656 }1657 return Lang.AiLearning.model_attr_str;1658 },1659 },1660 {1661 type: 'Block',1662 accept: 'string',1663 defaultType: 'number',1664 },1665 {1666 type: 'TextDynamic',1667 setValue: () => {1668 const table = Entry.aiLearning?.getTableData?.();1669 if (table) {1670 const {1671 select = [],1672 fields = [],1673 } = Entry.aiLearning?.getTableData?.();1674 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;1675 }1676 return Lang.AiLearning.model_attr_str;1677 },1678 },1679 {1680 type: 'Block',1681 accept: 'string',1682 defaultType: 'number',1683 },1684 ],1685 def: {1686 type: 'get_cluster_centriod_index_4',1687 },1688 events: {},1689 pyHelpDef: {1690 params: [],1691 type: 'get_cluster_centriod_index_4',1692 },1693 paramsKeyMap: {1694 ATTR1: 1,1695 ATTR2: 3,1696 ATTR3: 5,1697 ATTR4: 7,1698 },1699 class: 'ai_learning',1700 isNotFor: ['cluster_attr_4'],1701 async func(sprite, script) {1702 const a = script.getNumberValue('ATTR1', script);1703 const b = script.getNumberValue('ATTR2', script);1704 const c = script.getNumberValue('ATTR3', script);1705 const d = script.getNumberValue('ATTR4', script);1706 await Entry.aiLearning.predict([a, b, c, d]);1707 return Entry.aiLearning.getPredictResult();1708 },1709 syntax: {1710 js: [],1711 py: [],1712 },1713 },1714 get_cluster_centriod_index_5: {1715 color: EntryStatic.colorSet.block.default.AI_LEARNING,1716 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1717 skeleton: 'basic_string_field',1718 statements: [],1719 params: [1720 {1721 type: 'TextDynamic',1722 setValue: () => {1723 const table = Entry.aiLearning?.getTableData?.();1724 if (table) {1725 const {1726 select = [],1727 fields = [],1728 } = Entry.aiLearning?.getTableData?.();1729 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;1730 }1731 return Lang.AiLearning.model_attr_str;1732 },1733 },1734 {1735 type: 'Block',1736 accept: 'string',1737 defaultType: 'number',1738 },1739 {1740 type: 'TextDynamic',1741 setValue: () => {1742 const table = Entry.aiLearning?.getTableData?.();1743 if (table) {1744 const {1745 select = [],1746 fields = [],1747 } = Entry.aiLearning?.getTableData?.();1748 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;1749 }1750 return Lang.AiLearning.model_attr_str;1751 },1752 },1753 {1754 type: 'Block',1755 accept: 'string',1756 defaultType: 'number',1757 },1758 {1759 type: 'TextDynamic',1760 setValue: () => {1761 const table = Entry.aiLearning?.getTableData?.();1762 if (table) {1763 const {1764 select = [],1765 fields = [],1766 } = Entry.aiLearning?.getTableData?.();1767 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;1768 }1769 return Lang.AiLearning.model_attr_str;1770 },1771 },1772 {1773 type: 'Block',1774 accept: 'string',1775 defaultType: 'number',1776 },1777 {1778 type: 'TextDynamic',1779 setValue: () => {1780 const table = Entry.aiLearning?.getTableData?.();1781 if (table) {1782 const {1783 select = [],1784 fields = [],1785 } = Entry.aiLearning?.getTableData?.();1786 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;1787 }1788 return Lang.AiLearning.model_attr_str;1789 },1790 },1791 {1792 type: 'Block',1793 accept: 'string',1794 defaultType: 'number',1795 },1796 {1797 type: 'TextDynamic',1798 setValue: () => {1799 const table = Entry.aiLearning?.getTableData?.();1800 if (table) {1801 const {1802 select = [],1803 fields = [],1804 } = Entry.aiLearning?.getTableData?.();1805 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;1806 }1807 return Lang.AiLearning.model_attr_str;1808 },1809 },1810 {1811 type: 'Block',1812 accept: 'string',1813 defaultType: 'number',1814 },1815 ],1816 def: {1817 type: 'get_cluster_centriod_index_5',1818 },1819 events: {},1820 pyHelpDef: {1821 params: [],1822 type: 'get_cluster_centriod_index_5',1823 },1824 paramsKeyMap: {1825 ATTR1: 1,1826 ATTR2: 3,1827 ATTR3: 5,1828 ATTR4: 7,1829 ATTR5: 9,1830 },1831 class: 'ai_learning',1832 isNotFor: ['cluster_attr_5'],1833 async func(sprite, script) {1834 const a = script.getNumberValue('ATTR1', script);1835 const b = script.getNumberValue('ATTR2', script);1836 const c = script.getNumberValue('ATTR3', script);1837 const d = script.getNumberValue('ATTR4', script);1838 const e = script.getNumberValue('ATTR5', script);1839 await Entry.aiLearning.predict([a, b, c, d, e]);1840 return Entry.aiLearning.getPredictResult();1841 },1842 syntax: {1843 js: [],1844 py: [],1845 },1846 },1847 get_cluster_centriod_index_6: {1848 color: EntryStatic.colorSet.block.default.AI_LEARNING,1849 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,1850 skeleton: 'basic_string_field',1851 statements: [],1852 params: [1853 {1854 type: 'TextDynamic',1855 setValue: () => {1856 const table = Entry.aiLearning?.getTableData?.();1857 if (table) {1858 const {1859 select = [],1860 fields = [],1861 } = Entry.aiLearning?.getTableData?.();1862 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;1863 }1864 return Lang.AiLearning.model_attr_str;1865 },1866 },1867 {1868 type: 'Block',1869 accept: 'string',1870 defaultType: 'number',1871 },1872 {1873 type: 'TextDynamic',1874 setValue: () => {1875 const table = Entry.aiLearning?.getTableData?.();1876 if (table) {1877 const {1878 select = [],1879 fields = [],1880 } = Entry.aiLearning?.getTableData?.();1881 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;1882 }1883 return Lang.AiLearning.model_attr_str;1884 },1885 },1886 {1887 type: 'Block',1888 accept: 'string',1889 defaultType: 'number',1890 },1891 {1892 type: 'TextDynamic',1893 setValue: () => {1894 const table = Entry.aiLearning?.getTableData?.();1895 if (table) {1896 const {1897 select = [],1898 fields = [],1899 } = Entry.aiLearning?.getTableData?.();1900 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;1901 }1902 return Lang.AiLearning.model_attr_str;1903 },1904 },1905 {1906 type: 'Block',1907 accept: 'string',1908 defaultType: 'number',1909 },1910 {1911 type: 'TextDynamic',1912 setValue: () => {1913 const table = Entry.aiLearning?.getTableData?.();1914 if (table) {1915 const {1916 select = [],1917 fields = [],1918 } = Entry.aiLearning?.getTableData?.();1919 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;1920 }1921 return Lang.AiLearning.model_attr_str;1922 },1923 },1924 {1925 type: 'Block',1926 accept: 'string',1927 defaultType: 'number',1928 },1929 {1930 type: 'TextDynamic',1931 setValue: () => {1932 const table = Entry.aiLearning?.getTableData?.();1933 if (table) {1934 const {1935 select = [],1936 fields = [],1937 } = Entry.aiLearning?.getTableData?.();1938 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;1939 }1940 return Lang.AiLearning.model_attr_str;1941 },1942 },1943 {1944 type: 'Block',1945 accept: 'string',1946 defaultType: 'number',1947 },1948 {1949 type: 'TextDynamic',1950 setValue: () => {1951 const table = Entry.aiLearning?.getTableData?.();1952 if (table) {1953 const {1954 select = [],1955 fields = [],1956 } = Entry.aiLearning?.getTableData?.();1957 return fields[select?.[0]?.[5]] || Lang.AiLearning.model_attr_str;1958 }1959 return Lang.AiLearning.model_attr_str;1960 },1961 },1962 {1963 type: 'Block',1964 accept: 'string',1965 defaultType: 'number',1966 },1967 ],1968 def: {1969 type: 'get_cluster_centriod_index_6',1970 },1971 events: {},1972 pyHelpDef: {1973 params: [],1974 type: 'get_cluster_centriod_index_6',1975 },1976 paramsKeyMap: {1977 ATTR1: 1,1978 ATTR2: 3,1979 ATTR3: 5,1980 ATTR4: 7,1981 ATTR5: 9,1982 ATTR6: 11,1983 },1984 class: 'ai_learning',1985 isNotFor: ['cluster_attr_6'],1986 async func(sprite, script) {1987 const a = script.getNumberValue('ATTR1', script);1988 const b = script.getNumberValue('ATTR2', script);1989 const c = script.getNumberValue('ATTR3', script);1990 const d = script.getNumberValue('ATTR4', script);1991 const e = script.getNumberValue('ATTR5', script);1992 const f = script.getNumberValue('ATTR6', script);1993 await Entry.aiLearning.predict([a, b, c, d, e, f]);1994 return Entry.aiLearning.getPredictResult();1995 },1996 syntax: {1997 js: [],1998 py: [],1999 },2000 },2001 set_number_learning_option_k: {2002 color: EntryStatic.colorSet.block.default.AI_LEARNING,2003 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2004 skeleton: 'basic',2005 statements: [],2006 params: [2007 {2008 type: 'Block',2009 accept: 'string',2010 defaultType: 'number',2011 },2012 {2013 type: 'Indicator',2014 img: 'block_icon/ai_utilize_icon.svg',2015 size: 11,2016 },2017 ],2018 events: {},2019 def: {2020 params: [10, null],2021 type: 'set_number_learning_option_k',2022 },2023 pyHelpDef: {2024 params: [],2025 type: 'set_number_learning_option_k',2026 },2027 paramsKeyMap: {2028 VALUE: 0,2029 },2030 class: 'ai_learning',2031 isNotFor: ['ai_learning_number'],2032 async func(sprite, script) {2033 const value = script.getNumberValue('VALUE', script);2034 Entry.aiLearning.setTrainOption('neighbors', parseInt(value));2035 return script.callReturn();2036 },2037 syntax: {2038 js: [],2039 py: [],2040 },2041 },2042 get_number_learning_predict_1: {2043 color: EntryStatic.colorSet.block.default.AI_LEARNING,2044 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2045 skeleton: 'basic_string_field',2046 statements: [],2047 params: [2048 {2049 type: 'TextDynamic',2050 setValue: () => {2051 const table = Entry.aiLearning?.getTableData?.();2052 if (table) {2053 const {2054 select = [],2055 fields = [],2056 } = Entry.aiLearning?.getTableData?.();2057 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2058 }2059 return Lang.AiLearning.model_attr_str;2060 },2061 },2062 {2063 type: 'Block',2064 accept: 'string',2065 defaultType: 'number',2066 },2067 ],2068 events: {},2069 def: {2070 type: 'get_number_learning_predict_1',2071 },2072 pyHelpDef: {2073 params: [],2074 type: 'get_number_learning_predict_1',2075 },2076 paramsKeyMap: {2077 ATTR1: 1,2078 },2079 class: 'ai_learning',2080 isNotFor: ['number_learning_attr_1'],2081 async func(sprite, script) {2082 const x = script.getNumberValue('ATTR1', script);2083 await Entry.aiLearning.predict([x]);2084 const [{ className }] = Entry.aiLearning.getPredictResult();2085 return className;2086 },2087 syntax: {2088 js: [],2089 py: [],2090 },2091 },2092 get_number_learning_predict_2: {2093 color: EntryStatic.colorSet.block.default.AI_LEARNING,2094 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2095 skeleton: 'basic_string_field',2096 statements: [],2097 params: [2098 {2099 type: 'TextDynamic',2100 setValue: () => {2101 const table = Entry.aiLearning?.getTableData?.();2102 if (table) {2103 const {2104 select = [],2105 fields = [],2106 } = Entry.aiLearning?.getTableData?.();2107 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2108 }2109 return Lang.AiLearning.model_attr_str;2110 },2111 },2112 {2113 type: 'Block',2114 accept: 'string',2115 defaultType: 'number',2116 },2117 {2118 type: 'TextDynamic',2119 setValue: () => {2120 const table = Entry.aiLearning?.getTableData?.();2121 if (table) {2122 const {2123 select = [],2124 fields = [],2125 } = Entry.aiLearning?.getTableData?.();2126 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;2127 }2128 return Lang.AiLearning.model_attr_str;2129 },2130 },2131 {2132 type: 'Block',2133 accept: 'string',2134 defaultType: 'number',2135 },2136 ],2137 events: {},2138 def: {2139 type: 'get_number_learning_predict_2',2140 },2141 pyHelpDef: {2142 params: [],2143 type: 'get_number_learning_predict_2',2144 },2145 paramsKeyMap: {2146 ATTR1: 1,2147 ATTR2: 3,2148 },2149 class: 'ai_learning',2150 isNotFor: ['number_learning_attr_2'],2151 async func(sprite, script) {2152 const x = script.getNumberValue('ATTR1', script);2153 const y = script.getNumberValue('ATTR2', script);2154 await Entry.aiLearning.predict([x, y]);2155 const [{ className }] = Entry.aiLearning.getPredictResult();2156 return className;2157 },2158 syntax: {2159 js: [],2160 py: [],2161 },2162 },2163 get_number_learning_predict_3: {2164 color: EntryStatic.colorSet.block.default.AI_LEARNING,2165 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2166 skeleton: 'basic_string_field',2167 statements: [],2168 params: [2169 {2170 type: 'TextDynamic',2171 setValue: () => {2172 const table = Entry.aiLearning?.getTableData?.();2173 if (table) {2174 const {2175 select = [],2176 fields = [],2177 } = Entry.aiLearning?.getTableData?.();2178 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2179 }2180 return Lang.AiLearning.model_attr_str;2181 },2182 },2183 {2184 type: 'Block',2185 accept: 'string',2186 defaultType: 'number',2187 },2188 {2189 type: 'TextDynamic',2190 setValue: () => {2191 const table = Entry.aiLearning?.getTableData?.();2192 if (table) {2193 const {2194 select = [],2195 fields = [],2196 } = Entry.aiLearning?.getTableData?.();2197 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;2198 }2199 return Lang.AiLearning.model_attr_str;2200 },2201 },2202 {2203 type: 'Block',2204 accept: 'string',2205 defaultType: 'number',2206 },2207 {2208 type: 'TextDynamic',2209 setValue: () => {2210 const table = Entry.aiLearning?.getTableData?.();2211 if (table) {2212 const {2213 select = [],2214 fields = [],2215 } = Entry.aiLearning?.getTableData?.();2216 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;2217 }2218 return Lang.AiLearning.model_attr_str;2219 },2220 },2221 {2222 type: 'Block',2223 accept: 'string',2224 defaultType: 'number',2225 },2226 ],2227 events: {},2228 def: {2229 type: 'get_number_learning_predict_3',2230 },2231 pyHelpDef: {2232 params: [],2233 type: 'get_number_learning_predict_3',2234 },2235 paramsKeyMap: {2236 ATTR1: 1,2237 ATTR2: 3,2238 ATTR3: 5,2239 },2240 class: 'ai_learning',2241 isNotFor: ['number_learning_attr_3'],2242 async func(sprite, script) {2243 const x = script.getNumberValue('ATTR1', script);2244 const y = script.getNumberValue('ATTR2', script);2245 const z = script.getNumberValue('ATTR3', script);2246 await Entry.aiLearning.predict([x, y, z]);2247 const [{ className }] = Entry.aiLearning.getPredictResult();2248 return className;2249 },2250 syntax: {2251 js: [],2252 py: [],2253 },2254 },2255 get_number_learning_predict_4: {2256 color: EntryStatic.colorSet.block.default.AI_LEARNING,2257 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2258 skeleton: 'basic_string_field',2259 statements: [],2260 params: [2261 {2262 type: 'TextDynamic',2263 setValue: () => {2264 const table = Entry.aiLearning?.getTableData?.();2265 if (table) {2266 const {2267 select = [],2268 fields = [],2269 } = Entry.aiLearning?.getTableData?.();2270 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2271 }2272 return Lang.AiLearning.model_attr_str;2273 },2274 },2275 {2276 type: 'Block',2277 accept: 'string',2278 defaultType: 'number',2279 },2280 {2281 type: 'TextDynamic',2282 setValue: () => {2283 const table = Entry.aiLearning?.getTableData?.();2284 if (table) {2285 const {2286 select = [],2287 fields = [],2288 } = Entry.aiLearning?.getTableData?.();2289 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;2290 }2291 return Lang.AiLearning.model_attr_str;2292 },2293 },2294 {2295 type: 'Block',2296 accept: 'string',2297 defaultType: 'number',2298 },2299 {2300 type: 'TextDynamic',2301 setValue: () => {2302 const table = Entry.aiLearning?.getTableData?.();2303 if (table) {2304 const {2305 select = [],2306 fields = [],2307 } = Entry.aiLearning?.getTableData?.();2308 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;2309 }2310 return Lang.AiLearning.model_attr_str;2311 },2312 },2313 {2314 type: 'Block',2315 accept: 'string',2316 defaultType: 'number',2317 },2318 {2319 type: 'TextDynamic',2320 setValue: () => {2321 const table = Entry.aiLearning?.getTableData?.();2322 if (table) {2323 const {2324 select = [],2325 fields = [],2326 } = Entry.aiLearning?.getTableData?.();2327 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;2328 }2329 return Lang.AiLearning.model_attr_str;2330 },2331 },2332 {2333 type: 'Block',2334 accept: 'string',2335 defaultType: 'number',2336 },2337 ],2338 events: {},2339 def: {2340 type: 'get_number_learning_predict_4',2341 },2342 pyHelpDef: {2343 params: [],2344 type: 'get_number_learning_predict_4',2345 },2346 paramsKeyMap: {2347 ATTR1: 1,2348 ATTR2: 3,2349 ATTR3: 5,2350 ATTR4: 7,2351 },2352 class: 'ai_learning',2353 isNotFor: ['number_learning_attr_4'],2354 async func(sprite, script) {2355 const a = script.getNumberValue('ATTR1', script);2356 const b = script.getNumberValue('ATTR2', script);2357 const c = script.getNumberValue('ATTR3', script);2358 const d = script.getNumberValue('ATTR4', script);2359 await Entry.aiLearning.predict([a, b, c, d]);2360 const [{ className }] = Entry.aiLearning.getPredictResult();2361 return className;2362 },2363 syntax: {2364 js: [],2365 py: [],2366 },2367 },2368 get_number_learning_predict_5: {2369 color: EntryStatic.colorSet.block.default.AI_LEARNING,2370 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2371 skeleton: 'basic_string_field',2372 statements: [],2373 params: [2374 {2375 type: 'TextDynamic',2376 setValue: () => {2377 const table = Entry.aiLearning?.getTableData?.();2378 if (table) {2379 const {2380 select = [],2381 fields = [],2382 } = Entry.aiLearning?.getTableData?.();2383 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2384 }2385 return Lang.AiLearning.model_attr_str;2386 },2387 },2388 {2389 type: 'Block',2390 accept: 'string',2391 defaultType: 'number',2392 },2393 {2394 type: 'TextDynamic',2395 setValue: () => {2396 const table = Entry.aiLearning?.getTableData?.();2397 if (table) {2398 const {2399 select = [],2400 fields = [],2401 } = Entry.aiLearning?.getTableData?.();2402 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;2403 }2404 return Lang.AiLearning.model_attr_str;2405 },2406 },2407 {2408 type: 'Block',2409 accept: 'string',2410 defaultType: 'number',2411 },2412 {2413 type: 'TextDynamic',2414 setValue: () => {2415 const table = Entry.aiLearning?.getTableData?.();2416 if (table) {2417 const {2418 select = [],2419 fields = [],2420 } = Entry.aiLearning?.getTableData?.();2421 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;2422 }2423 return Lang.AiLearning.model_attr_str;2424 },2425 },2426 {2427 type: 'Block',2428 accept: 'string',2429 defaultType: 'number',2430 },2431 {2432 type: 'TextDynamic',2433 setValue: () => {2434 const table = Entry.aiLearning?.getTableData?.();2435 if (table) {2436 const {2437 select = [],2438 fields = [],2439 } = Entry.aiLearning?.getTableData?.();2440 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;2441 }2442 return Lang.AiLearning.model_attr_str;2443 },2444 },2445 {2446 type: 'Block',2447 accept: 'string',2448 defaultType: 'number',2449 },2450 {2451 type: 'TextDynamic',2452 setValue: () => {2453 const table = Entry.aiLearning?.getTableData?.();2454 if (table) {2455 const {2456 select = [],2457 fields = [],2458 } = Entry.aiLearning?.getTableData?.();2459 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;2460 }2461 return Lang.AiLearning.model_attr_str;2462 },2463 },2464 {2465 type: 'Block',2466 accept: 'string',2467 defaultType: 'number',2468 },2469 ],2470 events: {},2471 def: {2472 type: 'get_number_learning_predict_5',2473 },2474 pyHelpDef: {2475 params: [],2476 type: 'get_number_learning_predict_5',2477 },2478 paramsKeyMap: {2479 ATTR1: 1,2480 ATTR2: 3,2481 ATTR3: 5,2482 ATTR4: 7,2483 ATTR5: 9,2484 },2485 class: 'ai_learning',2486 isNotFor: ['number_learning_attr_5'],2487 async func(sprite, script) {2488 const a = script.getNumberValue('ATTR1', script);2489 const b = script.getNumberValue('ATTR2', script);2490 const c = script.getNumberValue('ATTR3', script);2491 const d = script.getNumberValue('ATTR4', script);2492 const e = script.getNumberValue('ATTR5', script);2493 await Entry.aiLearning.predict([a, b, c, d, e]);2494 const [{ className }] = Entry.aiLearning.getPredictResult();2495 return className;2496 },2497 syntax: {2498 js: [],2499 py: [],2500 },2501 },2502 get_number_learning_predict_6: {2503 color: EntryStatic.colorSet.block.default.AI_LEARNING,2504 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2505 skeleton: 'basic_string_field',2506 statements: [],2507 params: [2508 {2509 type: 'TextDynamic',2510 setValue: () => {2511 const table = Entry.aiLearning?.getTableData?.();2512 if (table) {2513 const {2514 select = [],2515 fields = [],2516 } = Entry.aiLearning?.getTableData?.();2517 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2518 }2519 return Lang.AiLearning.model_attr_str;2520 },2521 },2522 {2523 type: 'Block',2524 accept: 'string',2525 defaultType: 'number',2526 },2527 {2528 type: 'TextDynamic',2529 setValue: () => {2530 const table = Entry.aiLearning?.getTableData?.();2531 if (table) {2532 const {2533 select = [],2534 fields = [],2535 } = Entry.aiLearning?.getTableData?.();2536 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;2537 }2538 return Lang.AiLearning.model_attr_str;2539 },2540 },2541 {2542 type: 'Block',2543 accept: 'string',2544 defaultType: 'number',2545 },2546 {2547 type: 'TextDynamic',2548 setValue: () => {2549 const table = Entry.aiLearning?.getTableData?.();2550 if (table) {2551 const {2552 select = [],2553 fields = [],2554 } = Entry.aiLearning?.getTableData?.();2555 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;2556 }2557 return Lang.AiLearning.model_attr_str;2558 },2559 },2560 {2561 type: 'Block',2562 accept: 'string',2563 defaultType: 'number',2564 },2565 {2566 type: 'TextDynamic',2567 setValue: () => {2568 const table = Entry.aiLearning?.getTableData?.();2569 if (table) {2570 const {2571 select = [],2572 fields = [],2573 } = Entry.aiLearning?.getTableData?.();2574 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;2575 }2576 return Lang.AiLearning.model_attr_str;2577 },2578 },2579 {2580 type: 'Block',2581 accept: 'string',2582 defaultType: 'number',2583 },2584 {2585 type: 'TextDynamic',2586 setValue: () => {2587 const table = Entry.aiLearning?.getTableData?.();2588 if (table) {2589 const {2590 select = [],2591 fields = [],2592 } = Entry.aiLearning?.getTableData?.();2593 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;2594 }2595 return Lang.AiLearning.model_attr_str;2596 },2597 },2598 {2599 type: 'Block',2600 accept: 'string',2601 defaultType: 'number',2602 },2603 {2604 type: 'TextDynamic',2605 setValue: () => {2606 const table = Entry.aiLearning?.getTableData?.();2607 if (table) {2608 const {2609 select = [],2610 fields = [],2611 } = Entry.aiLearning?.getTableData?.();2612 return fields[select?.[0]?.[5]] || Lang.AiLearning.model_attr_str;2613 }2614 return Lang.AiLearning.model_attr_str;2615 },2616 },2617 {2618 type: 'Block',2619 accept: 'string',2620 defaultType: 'number',2621 },2622 ],2623 events: {},2624 def: {2625 type: 'get_number_learning_predict_6',2626 },2627 pyHelpDef: {2628 params: [],2629 type: 'get_number_learning_predict_6',2630 },2631 paramsKeyMap: {2632 ATTR1: 1,2633 ATTR2: 3,2634 ATTR3: 5,2635 ATTR4: 7,2636 ATTR5: 9,2637 ATTR6: 11,2638 },2639 class: 'ai_learning',2640 isNotFor: ['number_learning_attr_6'],2641 async func(sprite, script) {2642 const a = script.getNumberValue('ATTR1', script);2643 const b = script.getNumberValue('ATTR2', script);2644 const c = script.getNumberValue('ATTR3', script);2645 const d = script.getNumberValue('ATTR4', script);2646 const e = script.getNumberValue('ATTR5', script);2647 const f = script.getNumberValue('ATTR6', script);2648 await Entry.aiLearning.predict([a, b, c, d, e, f]);2649 const [{ className }] = Entry.aiLearning.getPredictResult();2650 return className;2651 },2652 syntax: {2653 js: [],2654 py: [],2655 },2656 },2657 get_number_learning_predict_param_1: {2658 color: EntryStatic.colorSet.block.default.AI_LEARNING,2659 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2660 skeleton: 'basic_string_field',2661 statements: [],2662 params: [2663 {2664 type: 'TextDynamic',2665 setValue: () => {2666 const table = Entry.aiLearning?.getTableData?.();2667 if (table) {2668 const {2669 select = [],2670 fields = [],2671 } = Entry.aiLearning?.getTableData?.();2672 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2673 }2674 return Lang.AiLearning.model_attr_str;2675 },2676 },2677 {2678 type: 'Block',2679 accept: 'string',2680 defaultType: 'number',2681 },2682 {2683 type: 'DropdownDynamic',2684 value: null,2685 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,2686 needDeepCopy: true,2687 fontSize: 11,2688 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,2689 arrowColor: EntryStatic.colorSet.common.WHITE,2690 defaultValue: (value, options) => {2691 if (options[0] && options[0][1]) {2692 return options[0][1];2693 }2694 return value || 0;2695 },2696 },2697 {2698 type: 'Dropdown',2699 options: [2700 [Lang.AiLearning.probability, 'probability'],2701 [Lang.AiLearning.neighbor_count, 'count'],2702 ],2703 value: 'probability',2704 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,2705 arrowColor: EntryStatic.colorSet.common.WHITE,2706 },2707 ],2708 events: {},2709 def: {2710 type: 'get_number_learning_predict_param_1',2711 },2712 pyHelpDef: {2713 params: [],2714 type: 'get_number_learning_predict_param_1',2715 },2716 paramsKeyMap: {2717 ATTR1: 1,2718 CLASS: 2,2719 OPTION: 3,2720 },2721 class: 'ai_learning',2722 isNotFor: ['number_learning_attr_1'],2723 async func(sprite, script) {2724 const x = script.getNumberValue('ATTR1', script);2725 const clazz = script.getField('CLASS', script);2726 const option = script.getField('OPTION', script);2727 await Entry.aiLearning.predict([x]);2728 const result = Entry.aiLearning.getPredictResult();2729 const classData = result.find(({ className }) => className === clazz) || {};2730 return classData[option] || 0;2731 },2732 syntax: {2733 js: [],2734 py: [],2735 },2736 },2737 get_number_learning_predict_param_2: {2738 color: EntryStatic.colorSet.block.default.AI_LEARNING,2739 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2740 skeleton: 'basic_string_field',2741 statements: [],2742 params: [2743 {2744 type: 'TextDynamic',2745 setValue: () => {2746 const table = Entry.aiLearning?.getTableData?.();2747 if (table) {2748 const {2749 select = [],2750 fields = [],2751 } = Entry.aiLearning?.getTableData?.();2752 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2753 }2754 return Lang.AiLearning.model_attr_str;2755 },2756 },2757 {2758 type: 'Block',2759 accept: 'string',2760 defaultType: 'number',2761 },2762 {2763 type: 'TextDynamic',2764 setValue: () => {2765 const table = Entry.aiLearning?.getTableData?.();2766 if (table) {2767 const {2768 select = [],2769 fields = [],2770 } = Entry.aiLearning?.getTableData?.();2771 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;2772 }2773 return Lang.AiLearning.model_attr_str;2774 },2775 },2776 {2777 type: 'Block',2778 accept: 'string',2779 defaultType: 'number',2780 },2781 {2782 type: 'DropdownDynamic',2783 value: null,2784 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,2785 needDeepCopy: true,2786 fontSize: 11,2787 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,2788 arrowColor: EntryStatic.colorSet.common.WHITE,2789 defaultValue: (value, options) => {2790 if (options[0] && options[0][1]) {2791 return options[0][1];2792 }2793 return value || 0;2794 },2795 },2796 {2797 type: 'Dropdown',2798 options: [2799 [Lang.AiLearning.probability, 'probability'],2800 [Lang.AiLearning.neighbor_count, 'count'],2801 ],2802 value: 'probability',2803 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,2804 arrowColor: EntryStatic.colorSet.common.WHITE,2805 },2806 ],2807 events: {},2808 def: {2809 type: 'get_number_learning_predict_param_2',2810 },2811 pyHelpDef: {2812 params: [],2813 type: 'get_number_learning_predict_param_2',2814 },2815 paramsKeyMap: {2816 ATTR1: 1,2817 ATTR2: 3,2818 CLASS: 4,2819 OPTION: 5,2820 },2821 class: 'ai_learning',2822 isNotFor: ['number_learning_attr_2'],2823 async func(sprite, script) {2824 const x = script.getNumberValue('ATTR1', script);2825 const y = script.getNumberValue('ATTR2', script);2826 const clazz = script.getField('CLASS', script);2827 const option = script.getField('OPTION', script);2828 await Entry.aiLearning.predict([x, y]);2829 const result = Entry.aiLearning.getPredictResult();2830 const classData = result.find(({ className }) => className === clazz) || {};2831 return classData[option] || 0;2832 },2833 syntax: {2834 js: [],2835 py: [],2836 },2837 },2838 get_number_learning_predict_param_3: {2839 color: EntryStatic.colorSet.block.default.AI_LEARNING,2840 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2841 skeleton: 'basic_string_field',2842 statements: [],2843 params: [2844 {2845 type: 'TextDynamic',2846 setValue: () => {2847 const table = Entry.aiLearning?.getTableData?.();2848 if (table) {2849 const {2850 select = [],2851 fields = [],2852 } = Entry.aiLearning?.getTableData?.();2853 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2854 }2855 return Lang.AiLearning.model_attr_str;2856 },2857 },2858 {2859 type: 'Block',2860 accept: 'string',2861 defaultType: 'number',2862 },2863 {2864 type: 'TextDynamic',2865 setValue: () => {2866 const table = Entry.aiLearning?.getTableData?.();2867 if (table) {2868 const {2869 select = [],2870 fields = [],2871 } = Entry.aiLearning?.getTableData?.();2872 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;2873 }2874 return Lang.AiLearning.model_attr_str;2875 },2876 },2877 {2878 type: 'Block',2879 accept: 'string',2880 defaultType: 'number',2881 },2882 {2883 type: 'TextDynamic',2884 setValue: () => {2885 const table = Entry.aiLearning?.getTableData?.();2886 if (table) {2887 const {2888 select = [],2889 fields = [],2890 } = Entry.aiLearning?.getTableData?.();2891 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;2892 }2893 return Lang.AiLearning.model_attr_str;2894 },2895 },2896 {2897 type: 'Block',2898 accept: 'string',2899 defaultType: 'number',2900 },2901 {2902 type: 'DropdownDynamic',2903 value: null,2904 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,2905 needDeepCopy: true,2906 fontSize: 11,2907 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,2908 arrowColor: EntryStatic.colorSet.common.WHITE,2909 defaultValue: (value, options) => {2910 if (options[0] && options[0][1]) {2911 return options[0][1];2912 }2913 return value || 0;2914 },2915 },2916 {2917 type: 'Dropdown',2918 options: [2919 [Lang.AiLearning.probability, 'probability'],2920 [Lang.AiLearning.neighbor_count, 'count'],2921 ],2922 value: 'probability',2923 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,2924 arrowColor: EntryStatic.colorSet.common.WHITE,2925 },2926 ],2927 events: {},2928 def: {2929 type: 'get_number_learning_predict_param_3',2930 },2931 pyHelpDef: {2932 params: [],2933 type: 'get_number_learning_predict_param_3',2934 },2935 paramsKeyMap: {2936 ATTR1: 1,2937 ATTR2: 3,2938 ATTR3: 5,2939 CLASS: 6,2940 OPTION: 7,2941 },2942 class: 'ai_learning',2943 isNotFor: ['number_learning_attr_3'],2944 async func(sprite, script) {2945 const x = script.getNumberValue('ATTR1', script);2946 const y = script.getNumberValue('ATTR2', script);2947 const z = script.getNumberValue('ATTR3', script);2948 const clazz = script.getField('CLASS', script);2949 const option = script.getField('OPTION', script);2950 await Entry.aiLearning.predict([x, y, z]);2951 const result = Entry.aiLearning.getPredictResult();2952 const classData = result.find(({ className }) => className === clazz) || {};2953 return classData[option] || 0;2954 },2955 syntax: {2956 js: [],2957 py: [],2958 },2959 },2960 get_number_learning_predict_param_4: {2961 color: EntryStatic.colorSet.block.default.AI_LEARNING,2962 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,2963 skeleton: 'basic_string_field',2964 statements: [],2965 params: [2966 {2967 type: 'TextDynamic',2968 setValue: () => {2969 const table = Entry.aiLearning?.getTableData?.();2970 if (table) {2971 const {2972 select = [],2973 fields = [],2974 } = Entry.aiLearning?.getTableData?.();2975 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;2976 }2977 return Lang.AiLearning.model_attr_str;2978 },2979 },2980 {2981 type: 'Block',2982 accept: 'string',2983 defaultType: 'number',2984 },2985 {2986 type: 'TextDynamic',2987 setValue: () => {2988 const table = Entry.aiLearning?.getTableData?.();2989 if (table) {2990 const {2991 select = [],2992 fields = [],2993 } = Entry.aiLearning?.getTableData?.();2994 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;2995 }2996 return Lang.AiLearning.model_attr_str;2997 },2998 },2999 {3000 type: 'Block',3001 accept: 'string',3002 defaultType: 'number',3003 },3004 {3005 type: 'TextDynamic',3006 setValue: () => {3007 const table = Entry.aiLearning?.getTableData?.();3008 if (table) {3009 const {3010 select = [],3011 fields = [],3012 } = Entry.aiLearning?.getTableData?.();3013 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;3014 }3015 return Lang.AiLearning.model_attr_str;3016 },3017 },3018 {3019 type: 'Block',3020 accept: 'string',3021 defaultType: 'number',3022 },3023 {3024 type: 'TextDynamic',3025 setValue: () => {3026 const table = Entry.aiLearning?.getTableData?.();3027 if (table) {3028 const {3029 select = [],3030 fields = [],3031 } = Entry.aiLearning?.getTableData?.();3032 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;3033 }3034 return Lang.AiLearning.model_attr_str;3035 },3036 },3037 {3038 type: 'Block',3039 accept: 'string',3040 defaultType: 'number',3041 },3042 {3043 type: 'DropdownDynamic',3044 value: null,3045 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,3046 needDeepCopy: true,3047 fontSize: 11,3048 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3049 arrowColor: EntryStatic.colorSet.common.WHITE,3050 defaultValue: (value, options) => {3051 if (options[0] && options[0][1]) {3052 return options[0][1];3053 }3054 return value || 0;3055 },3056 },3057 {3058 type: 'Dropdown',3059 options: [3060 [Lang.AiLearning.probability, 'probability'],3061 [Lang.AiLearning.neighbor_count, 'count'],3062 ],3063 value: 'probability',3064 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3065 arrowColor: EntryStatic.colorSet.common.WHITE,3066 },3067 ],3068 events: {},3069 def: {3070 type: 'get_number_learning_predict_param_4',3071 },3072 pyHelpDef: {3073 params: [],3074 type: 'get_number_learning_predict_param_4',3075 },3076 paramsKeyMap: {3077 ATTR1: 1,3078 ATTR2: 3,3079 ATTR3: 5,3080 ATTR4: 7,3081 CLASS: 8,3082 OPTION: 9,3083 },3084 class: 'ai_learning',3085 isNotFor: ['number_learning_attr_4'],3086 async func(sprite, script) {3087 const a = script.getNumberValue('ATTR1', script);3088 const b = script.getNumberValue('ATTR2', script);3089 const c = script.getNumberValue('ATTR3', script);3090 const d = script.getNumberValue('ATTR4', script);3091 const clazz = script.getField('CLASS', script);3092 const option = script.getField('OPTION', script);3093 await Entry.aiLearning.predict([a, b, c, d]);3094 const result = Entry.aiLearning.getPredictResult();3095 const classData = result.find(({ className }) => className === clazz) || {};3096 return classData[option] || 0;3097 },3098 syntax: {3099 js: [],3100 py: [],3101 },3102 },3103 get_number_learning_predict_param_5: {3104 color: EntryStatic.colorSet.block.default.AI_LEARNING,3105 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,3106 skeleton: 'basic_string_field',3107 statements: [],3108 params: [3109 {3110 type: 'TextDynamic',3111 setValue: () => {3112 const table = Entry.aiLearning?.getTableData?.();3113 if (table) {3114 const {3115 select = [],3116 fields = [],3117 } = Entry.aiLearning?.getTableData?.();3118 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;3119 }3120 return Lang.AiLearning.model_attr_str;3121 },3122 },3123 {3124 type: 'Block',3125 accept: 'string',3126 defaultType: 'number',3127 },3128 {3129 type: 'TextDynamic',3130 setValue: () => {3131 const table = Entry.aiLearning?.getTableData?.();3132 if (table) {3133 const {3134 select = [],3135 fields = [],3136 } = Entry.aiLearning?.getTableData?.();3137 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;3138 }3139 return Lang.AiLearning.model_attr_str;3140 },3141 },3142 {3143 type: 'Block',3144 accept: 'string',3145 defaultType: 'number',3146 },3147 {3148 type: 'TextDynamic',3149 setValue: () => {3150 const table = Entry.aiLearning?.getTableData?.();3151 if (table) {3152 const {3153 select = [],3154 fields = [],3155 } = Entry.aiLearning?.getTableData?.();3156 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;3157 }3158 return Lang.AiLearning.model_attr_str;3159 },3160 },3161 {3162 type: 'Block',3163 accept: 'string',3164 defaultType: 'number',3165 },3166 {3167 type: 'TextDynamic',3168 setValue: () => {3169 const table = Entry.aiLearning?.getTableData?.();3170 if (table) {3171 const {3172 select = [],3173 fields = [],3174 } = Entry.aiLearning?.getTableData?.();3175 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;3176 }3177 return Lang.AiLearning.model_attr_str;3178 },3179 },3180 {3181 type: 'Block',3182 accept: 'string',3183 defaultType: 'number',3184 },3185 {3186 type: 'TextDynamic',3187 setValue: () => {3188 const table = Entry.aiLearning?.getTableData?.();3189 if (table) {3190 const {3191 select = [],3192 fields = [],3193 } = Entry.aiLearning?.getTableData?.();3194 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;3195 }3196 return Lang.AiLearning.model_attr_str;3197 },3198 },3199 {3200 type: 'Block',3201 accept: 'string',3202 defaultType: 'number',3203 },3204 {3205 type: 'DropdownDynamic',3206 value: null,3207 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,3208 needDeepCopy: true,3209 fontSize: 11,3210 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3211 arrowColor: EntryStatic.colorSet.common.WHITE,3212 defaultValue: (value, options) => {3213 if (options[0] && options[0][1]) {3214 return options[0][1];3215 }3216 return value || 0;3217 },3218 },3219 {3220 type: 'Dropdown',3221 options: [3222 [Lang.AiLearning.probability, 'probability'],3223 [Lang.AiLearning.neighbor_count, 'count'],3224 ],3225 value: 'probability',3226 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3227 arrowColor: EntryStatic.colorSet.common.WHITE,3228 },3229 ],3230 events: {},3231 def: {3232 type: 'get_number_learning_predict_param_5',3233 },3234 pyHelpDef: {3235 params: [],3236 type: 'get_number_learning_predict_param_5',3237 },3238 paramsKeyMap: {3239 ATTR1: 1,3240 ATTR2: 3,3241 ATTR3: 5,3242 ATTR4: 7,3243 ATTR5: 9,3244 CLASS: 10,3245 OPTION: 11,3246 },3247 class: 'ai_learning',3248 isNotFor: ['number_learning_attr_5'],3249 async func(sprite, script) {3250 const a = script.getNumberValue('ATTR1', script);3251 const b = script.getNumberValue('ATTR2', script);3252 const c = script.getNumberValue('ATTR3', script);3253 const d = script.getNumberValue('ATTR4', script);3254 const e = script.getNumberValue('ATTR5', script);3255 const clazz = script.getField('CLASS', script);3256 const option = script.getField('OPTION', script);3257 await Entry.aiLearning.predict([a, b, c, d, e]);3258 const result = Entry.aiLearning.getPredictResult();3259 const classData = result.find(({ className }) => className === clazz) || {};3260 return classData[option] || 0;3261 },3262 syntax: {3263 js: [],3264 py: [],3265 },3266 },3267 get_number_learning_predict_param_6: {3268 color: EntryStatic.colorSet.block.default.AI_LEARNING,3269 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,3270 skeleton: 'basic_string_field',3271 statements: [],3272 params: [3273 {3274 type: 'TextDynamic',3275 setValue: () => {3276 const table = Entry.aiLearning?.getTableData?.();3277 if (table) {3278 const {3279 select = [],3280 fields = [],3281 } = Entry.aiLearning?.getTableData?.();3282 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;3283 }3284 return Lang.AiLearning.model_attr_str;3285 },3286 },3287 {3288 type: 'Block',3289 accept: 'string',3290 defaultType: 'number',3291 },3292 {3293 type: 'TextDynamic',3294 setValue: () => {3295 const table = Entry.aiLearning?.getTableData?.();3296 if (table) {3297 const {3298 select = [],3299 fields = [],3300 } = Entry.aiLearning?.getTableData?.();3301 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;3302 }3303 return Lang.AiLearning.model_attr_str;3304 },3305 },3306 {3307 type: 'Block',3308 accept: 'string',3309 defaultType: 'number',3310 },3311 {3312 type: 'TextDynamic',3313 setValue: () => {3314 const table = Entry.aiLearning?.getTableData?.();3315 if (table) {3316 const {3317 select = [],3318 fields = [],3319 } = Entry.aiLearning?.getTableData?.();3320 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;3321 }3322 return Lang.AiLearning.model_attr_str;3323 },3324 },3325 {3326 type: 'Block',3327 accept: 'string',3328 defaultType: 'number',3329 },3330 {3331 type: 'TextDynamic',3332 setValue: () => {3333 const table = Entry.aiLearning?.getTableData?.();3334 if (table) {3335 const {3336 select = [],3337 fields = [],3338 } = Entry.aiLearning?.getTableData?.();3339 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;3340 }3341 return Lang.AiLearning.model_attr_str;3342 },3343 },3344 {3345 type: 'Block',3346 accept: 'string',3347 defaultType: 'number',3348 },3349 {3350 type: 'TextDynamic',3351 setValue: () => {3352 const table = Entry.aiLearning?.getTableData?.();3353 if (table) {3354 const {3355 select = [],3356 fields = [],3357 } = Entry.aiLearning?.getTableData?.();3358 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;3359 }3360 return Lang.AiLearning.model_attr_str;3361 },3362 },3363 {3364 type: 'Block',3365 accept: 'string',3366 defaultType: 'number',3367 },3368 {3369 type: 'TextDynamic',3370 setValue: () => {3371 const table = Entry.aiLearning?.getTableData?.();3372 if (table) {3373 const {3374 select = [],3375 fields = [],3376 } = Entry.aiLearning?.getTableData?.();3377 return fields[select?.[0]?.[5]] || Lang.AiLearning.model_attr_str;3378 }3379 return Lang.AiLearning.model_attr_str;3380 },3381 },3382 {3383 type: 'Block',3384 accept: 'string',3385 defaultType: 'number',3386 },3387 {3388 type: 'DropdownDynamic',3389 value: null,3390 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,3391 needDeepCopy: true,3392 fontSize: 11,3393 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3394 arrowColor: EntryStatic.colorSet.common.WHITE,3395 defaultValue: (value, options) => {3396 if (options[0] && options[0][1]) {3397 return options[0][1];3398 }3399 return value || 0;3400 },3401 },3402 {3403 type: 'Dropdown',3404 options: [3405 [Lang.AiLearning.probability, 'probability'],3406 [Lang.AiLearning.neighbor_count, 'count'],3407 ],3408 value: 'probability',3409 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3410 arrowColor: EntryStatic.colorSet.common.WHITE,3411 },3412 ],3413 events: {},3414 def: {3415 type: 'get_number_learning_predict_param_6',3416 },3417 pyHelpDef: {3418 params: [],3419 type: 'get_number_learning_predict_param_6',3420 },3421 paramsKeyMap: {3422 ATTR1: 1,3423 ATTR2: 3,3424 ATTR3: 5,3425 ATTR4: 7,3426 ATTR5: 9,3427 ATTR6: 11,3428 CLASS: 12,3429 OPTION: 13,3430 },3431 class: 'ai_learning',3432 isNotFor: ['number_learning_attr_6'],3433 async func(sprite, script) {3434 const a = script.getNumberValue('ATTR1', script);3435 const b = script.getNumberValue('ATTR2', script);3436 const c = script.getNumberValue('ATTR3', script);3437 const d = script.getNumberValue('ATTR4', script);3438 const e = script.getNumberValue('ATTR5', script);3439 const f = script.getNumberValue('ATTR6', script);3440 const clazz = script.getField('CLASS', script);3441 const option = script.getField('OPTION', script);3442 await Entry.aiLearning.predict([a, b, c, d, e, f]);3443 const result = Entry.aiLearning.getPredictResult();3444 const classData = result.find(({ className }) => className === clazz) || {};3445 return classData[option] || 0;3446 },3447 syntax: {3448 js: [],3449 py: [],3450 },3451 },3452 is_number_learning_group_1: {3453 color: EntryStatic.colorSet.block.default.AI_LEARNING,3454 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,3455 skeleton: 'basic_boolean_field',3456 statements: [],3457 params: [3458 {3459 type: 'TextDynamic',3460 setValue: () => {3461 const table = Entry.aiLearning?.getTableData?.();3462 if (table) {3463 const {3464 select = [],3465 fields = [],3466 } = Entry.aiLearning?.getTableData?.();3467 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;3468 }3469 return Lang.AiLearning.model_attr_str;3470 },3471 },3472 {3473 type: 'Block',3474 accept: 'string',3475 defaultType: 'number',3476 },3477 {3478 type: 'DropdownDynamic',3479 value: null,3480 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,3481 needDeepCopy: true,3482 fontSize: 11,3483 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3484 arrowColor: EntryStatic.colorSet.common.WHITE,3485 defaultValue: (value, options) => {3486 if (options[0] && options[0][1]) {3487 return options[0][1];3488 }3489 return value || 0;3490 },3491 },3492 ],3493 events: {},3494 def: {3495 params: [0],3496 type: 'is_number_learning_group_1',3497 },3498 pyHelpDef: {3499 params: [],3500 type: 'is_number_learning_group_1',3501 },3502 class: 'ai_learning',3503 isNotFor: ['number_learning_attr_1'],3504 paramsKeyMap: {3505 ATTR1: 1,3506 CLASS: 2,3507 },3508 async func(sprite, script) {3509 const x = script.getNumberValue('ATTR1', script);3510 const clazz = script.getField('CLASS', script);3511 await Entry.aiLearning.predict([x]);3512 const [{ className }] = Entry.aiLearning.getPredictResult();3513 return className === clazz;3514 },3515 syntax: {3516 js: [],3517 py: [],3518 },3519 },3520 is_number_learning_group_2: {3521 color: EntryStatic.colorSet.block.default.AI_LEARNING,3522 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,3523 skeleton: 'basic_boolean_field',3524 statements: [],3525 params: [3526 {3527 type: 'TextDynamic',3528 setValue: () => {3529 const table = Entry.aiLearning?.getTableData?.();3530 if (table) {3531 const {3532 select = [],3533 fields = [],3534 } = Entry.aiLearning?.getTableData?.();3535 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;3536 }3537 return Lang.AiLearning.model_attr_str;3538 },3539 },3540 {3541 type: 'Block',3542 accept: 'string',3543 defaultType: 'number',3544 },3545 {3546 type: 'TextDynamic',3547 setValue: () => {3548 const table = Entry.aiLearning?.getTableData?.();3549 if (table) {3550 const {3551 select = [],3552 fields = [],3553 } = Entry.aiLearning?.getTableData?.();3554 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;3555 }3556 return Lang.AiLearning.model_attr_str;3557 },3558 },3559 {3560 type: 'Block',3561 accept: 'string',3562 defaultType: 'number',3563 },3564 {3565 type: 'DropdownDynamic',3566 value: null,3567 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,3568 needDeepCopy: true,3569 fontSize: 11,3570 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3571 arrowColor: EntryStatic.colorSet.common.WHITE,3572 defaultValue: (value, options) => {3573 if (options[0] && options[0][1]) {3574 return options[0][1];3575 }3576 return value || 0;3577 },3578 },3579 ],3580 events: {},3581 def: {3582 params: [0],3583 type: 'is_number_learning_group_2',3584 },3585 pyHelpDef: {3586 params: [],3587 type: 'is_number_learning_group_2',3588 },3589 class: 'ai_learning',3590 isNotFor: ['number_learning_attr_2'],3591 paramsKeyMap: {3592 ATTR1: 1,3593 ATTR2: 3,3594 CLASS: 4,3595 },3596 async func(sprite, script) {3597 const x = script.getNumberValue('ATTR1', script);3598 const y = script.getNumberValue('ATTR2', script);3599 const clazz = script.getField('CLASS', script);3600 await Entry.aiLearning.predict([x, y]);3601 const [{ className }] = Entry.aiLearning.getPredictResult();3602 return className === clazz;3603 },3604 syntax: {3605 js: [],3606 py: [],3607 },3608 },3609 is_number_learning_group_3: {3610 color: EntryStatic.colorSet.block.default.AI_LEARNING,3611 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,3612 skeleton: 'basic_boolean_field',3613 statements: [],3614 params: [3615 {3616 type: 'TextDynamic',3617 setValue: () => {3618 const table = Entry.aiLearning?.getTableData?.();3619 if (table) {3620 const {3621 select = [],3622 fields = [],3623 } = Entry.aiLearning?.getTableData?.();3624 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;3625 }3626 return Lang.AiLearning.model_attr_str;3627 },3628 },3629 {3630 type: 'Block',3631 accept: 'string',3632 defaultType: 'number',3633 },3634 {3635 type: 'TextDynamic',3636 setValue: () => {3637 const table = Entry.aiLearning?.getTableData?.();3638 if (table) {3639 const {3640 select = [],3641 fields = [],3642 } = Entry.aiLearning?.getTableData?.();3643 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;3644 }3645 return Lang.AiLearning.model_attr_str;3646 },3647 },3648 {3649 type: 'Block',3650 accept: 'string',3651 defaultType: 'number',3652 },3653 {3654 type: 'TextDynamic',3655 setValue: () => {3656 const table = Entry.aiLearning?.getTableData?.();3657 if (table) {3658 const {3659 select = [],3660 fields = [],3661 } = Entry.aiLearning?.getTableData?.();3662 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;3663 }3664 return Lang.AiLearning.model_attr_str;3665 },3666 },3667 {3668 type: 'Block',3669 accept: 'string',3670 defaultType: 'number',3671 },3672 {3673 type: 'DropdownDynamic',3674 value: null,3675 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,3676 needDeepCopy: true,3677 fontSize: 11,3678 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3679 arrowColor: EntryStatic.colorSet.common.WHITE,3680 defaultValue: (value, options) => {3681 if (options[0] && options[0][1]) {3682 return options[0][1];3683 }3684 return value || 0;3685 },3686 },3687 ],3688 events: {},3689 def: {3690 params: [0],3691 type: 'is_number_learning_group_3',3692 },3693 pyHelpDef: {3694 params: [],3695 type: 'is_number_learning_group_3',3696 },3697 class: 'ai_learning',3698 isNotFor: ['number_learning_attr_3'],3699 paramsKeyMap: {3700 ATTR1: 1,3701 ATTR2: 3,3702 ATTR3: 5,3703 CLASS: 6,3704 },3705 async func(sprite, script) {3706 const x = script.getNumberValue('ATTR1', script);3707 const y = script.getNumberValue('ATTR2', script);3708 const z = script.getNumberValue('ATTR3', script);3709 const clazz = script.getField('CLASS', script);3710 await Entry.aiLearning.predict([x, y, z]);3711 const [{ className }] = Entry.aiLearning.getPredictResult();3712 return className === clazz;3713 },3714 syntax: {3715 js: [],3716 py: [],3717 },3718 },3719 is_number_learning_group_4: {3720 color: EntryStatic.colorSet.block.default.AI_LEARNING,3721 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,3722 skeleton: 'basic_boolean_field',3723 statements: [],3724 params: [3725 {3726 type: 'TextDynamic',3727 setValue: () => {3728 const table = Entry.aiLearning?.getTableData?.();3729 if (table) {3730 const {3731 select = [],3732 fields = [],3733 } = Entry.aiLearning?.getTableData?.();3734 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;3735 }3736 return Lang.AiLearning.model_attr_str;3737 },3738 },3739 {3740 type: 'Block',3741 accept: 'string',3742 defaultType: 'number',3743 },3744 {3745 type: 'TextDynamic',3746 setValue: () => {3747 const table = Entry.aiLearning?.getTableData?.();3748 if (table) {3749 const {3750 select = [],3751 fields = [],3752 } = Entry.aiLearning?.getTableData?.();3753 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;3754 }3755 return Lang.AiLearning.model_attr_str;3756 },3757 },3758 {3759 type: 'Block',3760 accept: 'string',3761 defaultType: 'number',3762 },3763 {3764 type: 'TextDynamic',3765 setValue: () => {3766 const table = Entry.aiLearning?.getTableData?.();3767 if (table) {3768 const {3769 select = [],3770 fields = [],3771 } = Entry.aiLearning?.getTableData?.();3772 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;3773 }3774 return Lang.AiLearning.model_attr_str;3775 },3776 },3777 {3778 type: 'Block',3779 accept: 'string',3780 defaultType: 'number',3781 },3782 {3783 type: 'TextDynamic',3784 setValue: () => {3785 const table = Entry.aiLearning?.getTableData?.();3786 if (table) {3787 const {3788 select = [],3789 fields = [],3790 } = Entry.aiLearning?.getTableData?.();3791 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;3792 }3793 return Lang.AiLearning.model_attr_str;3794 },3795 },3796 {3797 type: 'Block',3798 accept: 'string',3799 defaultType: 'number',3800 },3801 {3802 type: 'DropdownDynamic',3803 value: null,3804 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,3805 needDeepCopy: true,3806 fontSize: 11,3807 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3808 arrowColor: EntryStatic.colorSet.common.WHITE,3809 defaultValue: (value, options) => {3810 if (options[0] && options[0][1]) {3811 return options[0][1];3812 }3813 return value || 0;3814 },3815 },3816 ],3817 events: {},3818 def: {3819 params: [0],3820 type: 'is_number_learning_group_4',3821 },3822 pyHelpDef: {3823 params: [],3824 type: 'is_number_learning_group_4',3825 },3826 class: 'ai_learning',3827 isNotFor: ['number_learning_attr_4'],3828 paramsKeyMap: {3829 ATTR1: 1,3830 ATTR2: 3,3831 ATTR3: 5,3832 ATTR4: 7,3833 CLASS: 8,3834 },3835 async func(sprite, script) {3836 const a = script.getNumberValue('ATTR1', script);3837 const b = script.getNumberValue('ATTR2', script);3838 const c = script.getNumberValue('ATTR3', script);3839 const d = script.getNumberValue('ATTR4', script);3840 const clazz = script.getField('CLASS', script);3841 await Entry.aiLearning.predict([a, b, c, d]);3842 const [{ className }] = Entry.aiLearning.getPredictResult();3843 return className === clazz;3844 },3845 syntax: {3846 js: [],3847 py: [],3848 },3849 },3850 is_number_learning_group_5: {3851 color: EntryStatic.colorSet.block.default.AI_LEARNING,3852 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,3853 skeleton: 'basic_boolean_field',3854 statements: [],3855 params: [3856 {3857 type: 'TextDynamic',3858 setValue: () => {3859 const table = Entry.aiLearning?.getTableData?.();3860 if (table) {3861 const {3862 select = [],3863 fields = [],3864 } = Entry.aiLearning?.getTableData?.();3865 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;3866 }3867 return Lang.AiLearning.model_attr_str;3868 },3869 },3870 {3871 type: 'Block',3872 accept: 'string',3873 defaultType: 'number',3874 },3875 {3876 type: 'TextDynamic',3877 setValue: () => {3878 const table = Entry.aiLearning?.getTableData?.();3879 if (table) {3880 const {3881 select = [],3882 fields = [],3883 } = Entry.aiLearning?.getTableData?.();3884 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;3885 }3886 return Lang.AiLearning.model_attr_str;3887 },3888 },3889 {3890 type: 'Block',3891 accept: 'string',3892 defaultType: 'number',3893 },3894 {3895 type: 'TextDynamic',3896 setValue: () => {3897 const table = Entry.aiLearning?.getTableData?.();3898 if (table) {3899 const {3900 select = [],3901 fields = [],3902 } = Entry.aiLearning?.getTableData?.();3903 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;3904 }3905 return Lang.AiLearning.model_attr_str;3906 },3907 },3908 {3909 type: 'Block',3910 accept: 'string',3911 defaultType: 'number',3912 },3913 {3914 type: 'TextDynamic',3915 setValue: () => {3916 const table = Entry.aiLearning?.getTableData?.();3917 if (table) {3918 const {3919 select = [],3920 fields = [],3921 } = Entry.aiLearning?.getTableData?.();3922 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;3923 }3924 return Lang.AiLearning.model_attr_str;3925 },3926 },3927 {3928 type: 'Block',3929 accept: 'string',3930 defaultType: 'number',3931 },3932 {3933 type: 'TextDynamic',3934 setValue: () => {3935 const table = Entry.aiLearning?.getTableData?.();3936 if (table) {3937 const {3938 select = [],3939 fields = [],3940 } = Entry.aiLearning?.getTableData?.();3941 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;3942 }3943 return Lang.AiLearning.model_attr_str;3944 },3945 },3946 {3947 type: 'Block',3948 accept: 'string',3949 defaultType: 'number',3950 },3951 {3952 type: 'DropdownDynamic',3953 value: null,3954 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,3955 needDeepCopy: true,3956 fontSize: 11,3957 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,3958 arrowColor: EntryStatic.colorSet.common.WHITE,3959 defaultValue: (value, options) => {3960 if (options[0] && options[0][1]) {3961 return options[0][1];3962 }3963 return value || 0;3964 },3965 },3966 ],3967 events: {},3968 def: {3969 params: [0],3970 type: 'is_number_learning_group_5',3971 },3972 pyHelpDef: {3973 params: [],3974 type: 'is_number_learning_group_5',3975 },3976 class: 'ai_learning',3977 isNotFor: ['number_learning_attr_5'],3978 paramsKeyMap: {3979 ATTR1: 1,3980 ATTR2: 3,3981 ATTR3: 5,3982 ATTR4: 7,3983 ATTR5: 9,3984 CLASS: 10,3985 },3986 async func(sprite, script) {3987 const a = script.getNumberValue('ATTR1', script);3988 const b = script.getNumberValue('ATTR2', script);3989 const c = script.getNumberValue('ATTR3', script);3990 const d = script.getNumberValue('ATTR4', script);3991 const e = script.getNumberValue('ATTR5', script);3992 const clazz = script.getField('CLASS', script);3993 await Entry.aiLearning.predict([a, b, c, d, e]);3994 const [{ className }] = Entry.aiLearning.getPredictResult();3995 return className === clazz;3996 },3997 syntax: {3998 js: [],3999 py: [],4000 },4001 },4002 is_number_learning_group_6: {4003 color: EntryStatic.colorSet.block.default.AI_LEARNING,4004 outerLine: EntryStatic.colorSet.block.darken.AI_LEARNING,4005 skeleton: 'basic_boolean_field',4006 statements: [],4007 params: [4008 {4009 type: 'TextDynamic',4010 setValue: () => {4011 const table = Entry.aiLearning?.getTableData?.();4012 if (table) {4013 const {4014 select = [],4015 fields = [],4016 } = Entry.aiLearning?.getTableData?.();4017 return fields[select?.[0]?.[0]] || Lang.AiLearning.model_attr_str;4018 }4019 return Lang.AiLearning.model_attr_str;4020 },4021 },4022 {4023 type: 'Block',4024 accept: 'string',4025 defaultType: 'number',4026 },4027 {4028 type: 'TextDynamic',4029 setValue: () => {4030 const table = Entry.aiLearning?.getTableData?.();4031 if (table) {4032 const {4033 select = [],4034 fields = [],4035 } = Entry.aiLearning?.getTableData?.();4036 return fields[select?.[0]?.[1]] || Lang.AiLearning.model_attr_str;4037 }4038 return Lang.AiLearning.model_attr_str;4039 },4040 },4041 {4042 type: 'Block',4043 accept: 'string',4044 defaultType: 'number',4045 },4046 {4047 type: 'TextDynamic',4048 setValue: () => {4049 const table = Entry.aiLearning?.getTableData?.();4050 if (table) {4051 const {4052 select = [],4053 fields = [],4054 } = Entry.aiLearning?.getTableData?.();4055 return fields[select?.[0]?.[2]] || Lang.AiLearning.model_attr_str;4056 }4057 return Lang.AiLearning.model_attr_str;4058 },4059 },4060 {4061 type: 'Block',4062 accept: 'string',4063 defaultType: 'number',4064 },4065 {4066 type: 'TextDynamic',4067 setValue: () => {4068 const table = Entry.aiLearning?.getTableData?.();4069 if (table) {4070 const {4071 select = [],4072 fields = [],4073 } = Entry.aiLearning?.getTableData?.();4074 return fields[select?.[0]?.[3]] || Lang.AiLearning.model_attr_str;4075 }4076 return Lang.AiLearning.model_attr_str;4077 },4078 },4079 {4080 type: 'Block',4081 accept: 'string',4082 defaultType: 'number',4083 },4084 {4085 type: 'TextDynamic',4086 setValue: () => {4087 const table = Entry.aiLearning?.getTableData?.();4088 if (table) {4089 const {4090 select = [],4091 fields = [],4092 } = Entry.aiLearning?.getTableData?.();4093 return fields[select?.[0]?.[4]] || Lang.AiLearning.model_attr_str;4094 }4095 return Lang.AiLearning.model_attr_str;4096 },4097 },4098 {4099 type: 'Block',4100 accept: 'string',4101 defaultType: 'number',4102 },4103 {4104 type: 'TextDynamic',4105 setValue: () => {4106 const table = Entry.aiLearning?.getTableData?.();4107 if (table) {4108 const {4109 select = [],4110 fields = [],4111 } = Entry.aiLearning?.getTableData?.();4112 return fields[select?.[0]?.[5]] || Lang.AiLearning.model_attr_str;4113 }4114 return Lang.AiLearning.model_attr_str;4115 },4116 },4117 {4118 type: 'Block',4119 accept: 'string',4120 defaultType: 'number',4121 },4122 {4123 type: 'DropdownDynamic',4124 value: null,4125 menuName: DropDownDynamicGenerator.tablePredictDataDistinct,4126 needDeepCopy: true,4127 fontSize: 11,4128 bgColor: EntryStatic.colorSet.block.darken.AI_LEARNING,4129 arrowColor: EntryStatic.colorSet.common.WHITE,4130 defaultValue: (value, options) => {4131 if (options[0] && options[0][1]) {4132 return options[0][1];4133 }4134 return value || 0;4135 },4136 },4137 ],4138 events: {},4139 def: {4140 params: [0],4141 type: 'is_number_learning_group_6',4142 },4143 pyHelpDef: {4144 params: [],4145 type: 'is_number_learning_group_6',4146 },4147 class: 'ai_learning',4148 isNotFor: ['number_learning_attr_6'],4149 paramsKeyMap: {4150 ATTR1: 1,4151 ATTR2: 3,4152 ATTR3: 5,4153 ATTR4: 7,4154 ATTR5: 9,4155 ATTR6: 11,4156 CLASS: 12,4157 },4158 async func(sprite, script) {4159 const a = script.getNumberValue('ATTR1', script);4160 const b = script.getNumberValue('ATTR2', script);4161 const c = script.getNumberValue('ATTR3', script);4162 const d = script.getNumberValue('ATTR4', script);4163 const e = script.getNumberValue('ATTR5', script);4164 const f = script.getNumberValue('ATTR6', script);4165 const clazz = script.getField('CLASS', script);4166 await Entry.aiLearning.predict([a, b, c, d, e, f]);4167 const [{ className }] = Entry.aiLearning.getPredictResult();4168 return className === clazz;4169 },4170 syntax: {4171 js: [],4172 py: [],4173 },4174 },4175 };4176 },...

Full Screen

Full Screen

db-editor-service.spec.js

Source:db-editor-service.spec.js Github

copy

Full Screen

...84 it('function exists', () => {85 expect(dbEditorService.getTableData).to.exist;86 });87 it('can retrieve all records', async () => {88 const records = (await dbEditorService.getTableData('TEAM')).filteredRecords;89 expect(records.length).to.equal(36);90 expect(records[0].SID1).to.eql(127);91 expect(records[0].TRV1).to.eql(20);92 expect(records[0].TEZ1).to.eql(0);93 expect(records[0].TRV2).to.eql(31);94 expect(records[0].TEZ2).to.eql(1);95 expect(records[0].TRV3).to.eql(19);96 expect(records[0].TDNA).to.eql('Bears');97 expect(records[0].TLNA).to.eql('Chicago');98 expect(records[0].TSNA).to.eql('CHI');99 expect(records[27].SID1).to.eql(127);100 expect(records[27].TRV1).to.eql(24);101 expect(records[27].TEZ1).to.eql(27);102 expect(records[27].TRV2).to.eql(9);103 expect(records[27].TEZ2).to.eql(0);104 expect(records[27].TRV3).to.eql(4);105 expect(records[27].TDNA).to.eql('Seahawks');106 expect(records[27].TLNA).to.eql('Seattle');107 expect(records[27].TSNA).to.eql('SEA');108 });109 it('returns records if table has already been loaded', async () => {110 const records = (await dbEditorService.getTableData('TEAM')).filteredRecords;111 expect(records.length).to.equal(36);112 });113 it('can restrict the number of records to return', async () => {114 const originalRecords = (await dbEditorService.getTableData('TEAM')).filteredRecords;115 const records = (await dbEditorService.getTableData('TEAM', {116 'recordCount': 5117 })).filteredRecords;118 expect(records.length).to.equal(5);119 expect(records[0]).to.eql(originalRecords[0]);120 });121 it('can specify a starting index for the results for pagination', async () => {122 const originalRecords = (await dbEditorService.getTableData('TEAM')).filteredRecords;123 const records = (await dbEditorService.getTableData('TEAM', {124 'startIndex': 5125 })).filteredRecords;126 expect(records.length).to.equal(31);127 expect(records[0]).to.eql(originalRecords[5]);128 });129 it('if record count is larger than results, it will return the number of results', async () => {130 const records = (await dbEditorService.getTableData('TEAM', {131 'recordCount': 100132 })).filteredRecords;133 expect(records.length).to.equal(36);134 });135 it('can specify a recordCount and startIndex together', async () => {136 const originalRecords = (await dbEditorService.getTableData('TEAM')).filteredRecords;137 const records = (await dbEditorService.getTableData('TEAM', {138 'recordCount': 5,139 'startIndex': 5140 })).filteredRecords;141 expect(records.length).to.equal(5);142 expect(records[0]).to.eql(originalRecords[5]);143 expect(records[4]).to.eql(originalRecords[9]);144 });145 it('returns the total number of records', async () => {146 const totalRecords = (await dbEditorService.getTableData('TEAM')).totalRecords;147 expect(totalRecords).to.equal(36);148 });149 it('returns expected total number of records with a recordCount', async () => {150 const totalRecords = (await dbEditorService.getTableData('TEAM', {151 'recordCount': 5,152 'startIndex': 5153 })).totalRecords;154 expect(totalRecords).to.equal(36);155 });156 it('returns a mapping that defines filtered record index to actual record index', async () => {157 const indexMapping = (await dbEditorService.getTableData('TEAM', {158 'recordCount': 5,159 'startIndex': 5160 })).indexMapping;161 expect(indexMapping.length).to.equal(5);162 expect(indexMapping[0]).to.equal(5);163 expect(indexMapping[1]).to.equal(6);164 expect(indexMapping[2]).to.equal(7);165 expect(indexMapping[3]).to.equal(8);166 expect(indexMapping[4]).to.equal(9);167 });168 169 describe('sort', () => {170 it('will read the entire table even if a record count is supplied (needed for sorting/filtering)', async () => {171 await dbEditorService.getTableData('TEAM', {172 'recordCount': 5,173 'startIndex': 5174 });175 176 expect(dbEditorService.activeDbHelper.file['TEAM'].records.length).to.equal(36);177 });178 179 it('returns expected amount of records with sort parameters passed in', async () => {180 const sortedData = await dbEditorService.getTableData('TEAM', {181 'sort': {182 'field': 'SID1',183 'order': 'asc'184 }185 });186 expect(sortedData.totalRecords).to.equal(36);187 expect(sortedData.filteredRecords.length).to.equal(36);188 });189 it('returns expected index mapping', async () => {190 const sortedData = await dbEditorService.getTableData('TEAM', {191 'sort': {192 'field': 'SID1',193 'order': 'asc'194 }195 });196 expect(sortedData.indexMapping[0]).to.equal(31);197 expect(sortedData.indexMapping[1]).to.equal(6);198 expect(sortedData.indexMapping[2]).to.equal(0);199 expect(sortedData.indexMapping[3]).to.equal(1);200 expect(sortedData.indexMapping[4]).to.equal(2);201 });202 it('can sort by a field ascending', async () => {203 const sortedData = await dbEditorService.getTableData('TEAM', {204 'sort': {205 'field': 'SID1',206 'order': 'asc'207 }208 });209 expect(sortedData.filteredRecords[0].SID1).to.equal(35);210 expect(sortedData.filteredRecords[1].SID1).to.equal(46);211 expect(sortedData.filteredRecords[2].SID1).to.equal(127);212 });213 it('can sort by a field descending', async () => {214 const sortedData = await dbEditorService.getTableData('TEAM', {215 'sort': {216 'field': 'SID1',217 'order': 'desc'218 }219 });220 expect(sortedData.filteredRecords[0].SID1).to.equal(127);221 expect(sortedData.filteredRecords[34].SID1).to.equal(46);222 expect(sortedData.filteredRecords[35].SID1).to.equal(35);223 });224 it('can return unsorted results after sorting', async () => {225 await dbEditorService.getTableData('TEAM', {226 'sort': {227 'field': 'SID1',228 'order': 'asc'229 }230 });231 const unsortedResults = await dbEditorService.getTableData('TEAM');232 expect(unsortedResults.filteredRecords[0].SID1).to.equal(127);233 expect(unsortedResults.filteredRecords[1].SID1).to.equal(127);234 expect(unsortedResults.filteredRecords[2].SID1).to.equal(127);235 expect(unsortedResults.filteredRecords[6].SID1).to.equal(46);236 });237 it('can return partial results with sorting', async () => {238 const sortedData = await dbEditorService.getTableData('TEAM', {239 'recordCount': 5,240 'sort': {241 'field': 'SID1',242 'order': 'asc'243 }244 });245 expect(sortedData.filteredRecords.length).to.equal(5);246 expect(sortedData.filteredRecords[0].SID1).to.equal(35);247 expect(sortedData.filteredRecords[1].SID1).to.equal(46);248 expect(sortedData.filteredRecords[2].SID1).to.equal(127);249 });250 it('can specify a start index with sorting', async () => {251 const sortedData = await dbEditorService.getTableData('TEAM', {252 'startIndex': 10,253 'sort': {254 'field': 'SID1',255 'order': 'asc'256 }257 });258 expect(sortedData.filteredRecords.length).to.equal(26);259 expect(sortedData.filteredRecords[0].SID1).to.equal(127);260 expect(sortedData.filteredRecords[1].SID1).to.equal(127);261 });262 it('can specify a start index and record count with sorting', async () => {263 const sortedData = await dbEditorService.getTableData('TEAM', {264 'startIndex': 10,265 'recordCount': 5,266 'sort': {267 'field': 'SID1',268 'order': 'asc'269 }270 });271 expect(sortedData.filteredRecords.length).to.equal(5);272 expect(sortedData.filteredRecords[0].SID1).to.equal(127);273 expect(sortedData.filteredRecords[1].SID1).to.equal(127);274 });275 it('can sort text fields desc', async () => {276 const sortedData = await dbEditorService.getTableData('TEAM', {277 'sort': {278 'field': 'TDNA',279 'order': 'desc'280 }281 });282 expect(sortedData.filteredRecords[0].TDNA).to.equal('Vikings');283 expect(sortedData.filteredRecords[1].TDNA).to.equal('Titans');284 expect(sortedData.filteredRecords[2].TDNA).to.equal('Texans');285 });286 it('can sort text fields asc', async () => {287 const sortedData = await dbEditorService.getTableData('TEAM', {288 'sort': {289 'field': 'TLNA',290 'order': 'asc'291 }292 });293 expect(sortedData.filteredRecords[0].TLNA).to.equal('Arizona');294 expect(sortedData.filteredRecords[1].TLNA).to.equal('Atlanta');295 expect(sortedData.filteredRecords[2].TLNA).to.equal('Baltimore');296 });297 });298 describe('filtering', () => {299 describe('text filters', () => {300 it('equals', async () => {301 const data = await dbEditorService.getTableData('TEAM', {302 'filter': {303 'TDNA': { operator: 'and', constraints: [{value: 'Bears', matchMode: 'equals'}] }304 }305 });306 307 expect(data.filteredRecords.length).to.equal(1);308 expect(data.filteredRecords[0].TDNA).to.equal('Bears');309 });310 311 it('contains', async () => {312 const data = await dbEditorService.getTableData('TEAM', {313 'filter': {314 'TDNA': { operator: 'and', constraints: [{value: 'Bear', matchMode: 'contains'}] }315 }316 });317 318 expect(data.filteredRecords.length).to.equal(1);319 expect(data.filteredRecords[0].TDNA).to.equal('Bears');320 });321 322 it('starts with', async () => {323 const data = await dbEditorService.getTableData('TEAM', {324 'filter': {325 'TDNA': { operator: 'and', constraints: [{value: 'Bea', matchMode: 'startsWith'}] }326 }327 });328 329 expect(data.filteredRecords.length).to.equal(1);330 expect(data.filteredRecords[0].TDNA).to.equal('Bears');331 });332 333 it('ends with', async () => {334 const data = await dbEditorService.getTableData('TEAM', {335 'filter': {336 'TDNA': { operator: 'and', constraints: [{value: 'ars', matchMode: 'endsWith'}] }337 }338 });339 340 expect(data.filteredRecords.length).to.equal(2);341 expect(data.filteredRecords[0].TDNA).to.equal('Bears');342 expect(data.filteredRecords[1].TDNA).to.equal('Jaguars');343 });344 345 it('not equals', async () => {346 const data = await dbEditorService.getTableData('TEAM', {347 'filter': {348 'TDNA': { operator: 'and', constraints: [{value: 'Bears', matchMode: 'notEquals'}] }349 }350 });351 352 expect(data.filteredRecords.length).to.equal(35);353 });354 355 it('not contains', async () => {356 const data = await dbEditorService.getTableData('TEAM', {357 'filter': {358 'TDNA': { operator: 'and', constraints: [{value: 'Bea', matchMode: 'notContains'}] }359 }360 });361 362 expect(data.filteredRecords.length).to.equal(35);363 });364 });365 describe('number filters', () => {366 it('equals', async () => {367 const data = await dbEditorService.getTableData('TEAM', {368 'filter': {369 'TEZ2': { operator: 'and', constraints: [{value: '1', matchMode: 'equals'}] }370 }371 });372 373 expect(data.filteredRecords.length).to.equal(1);374 expect(data.filteredRecords[0].TDNA).to.equal('Bears');375 });376 it('not equals', async () => {377 const data = await dbEditorService.getTableData('TEAM', {378 'filter': {379 'TEZ2': { operator: 'and', constraints: [{value: '1', matchMode: 'notEquals'}] }380 }381 });382 383 expect(data.filteredRecords.length).to.equal(35);384 });385 it('less than', async () => {386 const data = await dbEditorService.getTableData('TEAM', {387 'filter': {388 'TEZ1': { operator: 'and', constraints: [{value: '1', matchMode: 'lt'}] }389 }390 });391 392 expect(data.filteredRecords.length).to.equal(1);393 expect(data.filteredRecords[0].TDNA).to.equal('Bears');394 });395 it('less than or equal to', async () => {396 const data = await dbEditorService.getTableData('TEAM', {397 'filter': {398 'TEZ1': { operator: 'and', constraints: [{value: '1', matchMode: 'lte'}] }399 }400 });401 402 expect(data.filteredRecords.length).to.equal(2);403 expect(data.filteredRecords[0].TDNA).to.equal('Bears');404 expect(data.filteredRecords[1].TDNA).to.equal('Bengals');405 });406 it('greater than', async () => {407 const data = await dbEditorService.getTableData('TEAM', {408 'filter': {409 'TEZ1': { operator: 'and', constraints: [{value: '31', matchMode: 'gt'}] }410 }411 });412 413 expect(data.filteredRecords.length).to.equal(4);414 expect(data.filteredRecords[0].TDNA).to.equal('HOF Unlocked');415 expect(data.filteredRecords[1].TDNA).to.equal('Free Agents');416 expect(data.filteredRecords[2].TDNA).to.equal('Draft');417 expect(data.filteredRecords[3].TDNA).to.equal('Hall Of Fame');418 });419 it('greater than or equal to', async () => {420 const data = await dbEditorService.getTableData('TEAM', {421 'filter': {422 'TEZ1': { operator: 'and', constraints: [{value: '31', matchMode: 'gte'}] }423 }424 });425 426 expect(data.filteredRecords.length).to.equal(5);427 expect(data.filteredRecords[0].TDNA).to.equal('Texans');428 expect(data.filteredRecords[1].TDNA).to.equal('HOF Unlocked');429 expect(data.filteredRecords[2].TDNA).to.equal('Free Agents');430 expect(data.filteredRecords[3].TDNA).to.equal('Draft');431 expect(data.filteredRecords[4].TDNA).to.equal('Hall Of Fame');432 });433 });434 it('filters are not case sensitive', async () => {435 const data = await dbEditorService.getTableData('TEAM', {436 'filter': {437 'TDNA': { operator: 'and', constraints: [{value: 'bears', matchMode: 'equals'}] }438 }439 });440 expect(data.filteredRecords.length).to.equal(1);441 expect(data.filteredRecords[0].TDNA).to.equal('Bears');442 });443 it('total record count is the same as filtered record count', async () => {444 const data = await dbEditorService.getTableData('TEAM', {445 'filter': {446 'TDNA': { operator: 'and', constraints: [{value: 'bears', matchMode: 'equals'}] }447 }448 });449 expect(data.totalRecords).to.equal(1);450 expect(data.filteredRecords[0].TDNA).to.equal('Bears');451 });452 it('returns expected index mapping', async () => {453 const data = await dbEditorService.getTableData('TEAM', {454 'filter': {455 'TDNA': { operator: 'and', constraints: [{value: 'bears', matchMode: 'equals'}] }456 }457 });458 expect(data.indexMapping[0]).to.equal(0);459 });460 it('supports multiple filters on a single field (and)', async () => {461 const data = await dbEditorService.getTableData('TEAM', {462 'filter': {463 'TDNA': { operator: 'and', constraints: [{value: 'Jag', matchMode: 'startsWith'}, {value: 'ars', matchMode: 'endsWith'}] }464 }465 });466 expect(data.filteredRecords.length).to.equal(1);467 expect(data.filteredRecords[0].TDNA).to.equal('Jaguars');468 });469 it('supports multiple filters on a single field (or)', async () => {470 const data = await dbEditorService.getTableData('TEAM', {471 'filter': {472 'TDNA': { operator: 'or', constraints: [{value: 'ars', matchMode: 'endsWith'}, {value: 'Browns', matchMode: 'equals'}] }473 }474 });475 expect(data.filteredRecords.length).to.equal(3);476 expect(data.filteredRecords[0].TDNA).to.equal('Bears');477 expect(data.filteredRecords[1].TDNA).to.equal('Jaguars');478 expect(data.filteredRecords[2].TDNA).to.equal('Browns');479 });480 it('returns expected index mapping with multiple filters', async () => {481 const data = await dbEditorService.getTableData('TEAM', {482 'filter': {483 'TDNA': { operator: 'or', constraints: [{value: 'ars', matchMode: 'endsWith'}, {value: 'Browns', matchMode: 'equals'}] }484 }485 });486 expect(data.indexMapping[0]).to.equal(0);487 expect(data.indexMapping[1]).to.equal(16);488 expect(data.indexMapping[2]).to.equal(4);489 });490 it('supports multiple column filters', async () => {491 const data = await dbEditorService.getTableData('TEAM', {492 'filter': {493 'TDNA': { operator: 'or', constraints: [{value: 'ars', matchMode: 'endsWith'}, {value: 'Browns', matchMode: 'equals'}] },494 'TLNA': { operator: 'or', constraints: [{value: 'Cleveland', matchMode: 'equals'}] }495 }496 });497 expect(data.filteredRecords.length).to.equal(1);498 expect(data.filteredRecords[0].TDNA).to.equal('Browns');499 });500 it('supports multiple column filters - empty case 1', async () => {501 const data = await dbEditorService.getTableData('TEAM', {502 'filter': {503 'TDNA': { operator: 'or', constraints: [{value: 'ars', matchMode: 'endsWith'}, {value: 'Browns', matchMode: 'equals'}] },504 'TLNA': { operator: 'or', constraints: [{value: 'Atlanta', matchMode: 'equals'}] }505 }506 });507 expect(data.filteredRecords.length).to.equal(0);508 });509 it('supports multiple column filters - empty case 2', async () => {510 const data = await dbEditorService.getTableData('TEAM', {511 'filter': {512 'TDNA': { operator: 'or', constraints: [{value: 'ars', matchMode: 'endsWith'}, {value: 'FakeTeam', matchMode: 'equals'}] },513 'TLNA': { operator: 'or', constraints: [{value: 'Cleveland', matchMode: 'equals'}] }514 }515 });516 expect(data.filteredRecords.length).to.equal(0);517 });518 it('ignores column names that do not exist', async () => {519 const data = await dbEditorService.getTableData('TEAM', {520 'filter': {521 'FAKE': { operator: 'or', constraints: [{value: 'ars', matchMode: 'endsWith'}, {value: 'FakeTeam', matchMode: 'equals'}] },522 }523 });524 expect(data.filteredRecords.length).to.equal(0);525 });526 });527 it('returns expected schema', async () => {528 const data = await dbEditorService.getTableData('TEAM');529 expect(data.schema.SID1).to.equal(127);530 expect(data.schema.TLNA).to.equal(15);531 });532 });533 describe('can export table data', () => {534 it('function exists', () => {535 expect(dbEditorService.exportTable).to.exist;536 });537 it('attempts to write a file to the expected path', () => {538 dbEditorService.exportTable('TEAM', {539 'exportLocation': 'C:/fakepath'540 });541 expect(xlsxMock.writeFile.callCount).to.equal(1);542 expect(xlsxMock.writeFile.firstCall.args[1]).to.equal('C:/fakepath');543 });544 it('transforms data to expected result', async () => {545 await dbEditorService.getTableData('RDBS');546 dbEditorService.exportTable('RDBS', {547 'exportLocation': 'C:/fakepath'548 });549 expect(xlsxMock.utils.json_to_sheet.callCount).to.equal(1);550 expect(xlsxMock.utils.json_to_sheet.firstCall.args[0].length).to.equal(2);551 expect(xlsxMock.utils.json_to_sheet.firstCall.args[0][0]).to.eql(['RLSP']);552 expect(xlsxMock.utils.json_to_sheet.firstCall.args[0][1]).to.eql([0]);553 });554 });555 describe('can import data', () => {556 it('function exists', () => {557 expect(dbEditorService.importTable).to.exist;558 });559 it('reads the file at the expected file path', async () => {560 await dbEditorService.importTable('RDBS', {561 'importLocation': 'C:/fakepath'562 });563 expect(xlsxMock.readFile.callCount).to.equal(1);564 expect(xlsxMock.readFile.firstCall.args[0]).to.equal('C:/fakepath');565 });566 it('overwrites the table data as expected', async () => {567 await dbEditorService.getTableData('RDBS');568 await dbEditorService.importTable('RDBS', {569 'importLocation': 'C:/fakepath'570 });571 const newData = await dbEditorService.getTableData('RDBS');572 expect(newData.filteredRecords[0].RLSP).to.equal(1);573 });574 // commented out for speed - it will take about 2s575 // it('overwrites table data - performance test', async function() {576 // this.timeout(60000);577 // await dbEditorService.getTableData('CSKL');578 // await dbEditorService.importTable('CSKL', {579 // 'importLocation': 'C:/fakepath/import-test'580 // });581 // const newData = await dbEditorService.getTableData('CSKL');582 583 // expect(newData.filteredRecords[1].SKID).to.equal(5);584 // });585 });586 describe('can update the data', () => {587 it('function exists', () => {588 expect(dbEditorService.updateTableData).to.exist;589 });590 it('updates the data as expected', async () => {591 await dbEditorService.getTableData('TEAM');592 await dbEditorService.updateTableData({593 tableName: 'TEAM',594 row: 0,595 field: 'TDNA',596 value: 'Scares'597 });598 const newData = await dbEditorService.getTableData('TEAM');599 expect(newData.filteredRecords[0].TDNA).to.eql('Scares');600 });601 });602 describe('can save the data', () => {603 it('function exists', () => {604 expect(dbEditorService.saveActiveFile).to.exist;605 });606 it('updates the data as expected', async () => {607 await dbEditorService.getTableData('TEAM');608 await dbEditorService.updateTableData({609 tableName: 'TEAM',610 row: 0,611 field: 'TDNA',612 value: 'ScareWolves'613 });614 await dbEditorService.saveActiveFile({615 'path': path.join(__dirname, '../data/db/dbSaveTest.db')616 });617 await dbEditorService.openFile(path.join(__dirname, '../data/db/dbSaveTest.db'));618 const newData = await dbEditorService.getTableData('TEAM');619 expect(newData.filteredRecords[0].TDNA).to.eql('ScareWolves');620 });621 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...18app.set('views', path.join(__dirname, 'views'))19app.set('view engine', 'ejs')20app.use(express.json())21app.use(express.urlencoded({extended:false}))22async function getTableData(tableName) {23 try {24 const result = await pool.query(`SELECT * FROM ${tableName}`);25 return result.rows26 } catch (error) {27 res.send(error)28 }29}30//NESTED AGGREGATION WITH GROUP-BY31async function getNestedData(tableName, bloodstatus) {32 try {33 var nestedQuery = `select bloodtype, sum(quantity) from blood_bag where 34 bloodstatus='${bloodstatus}' group by bloodtype;`35 const result = await pool.query(nestedQuery);36 return result.rows37 } catch (error) {38 res.send(error)39 }40}41//JOIN QUERY42async function getJoinData() {43 try {44 var joinQuery = `Select transporttobloodbank.bloodid, driveid, instno, transporttobloodbank.time as "Blood Bank Delivery Time", bankinstno, 45 hospitalinstno, transporttohospital.time as "Hospital Delivery Time" from transporttobloodbank inner join transporttohospital on 46 transporttobloodbank.bloodid = transporttohospital.bloodid;`47 const result = await pool.query(joinQuery);48 return result.rows49 } catch (error) {50 res.send(error)51 }52}53async function getDivisionData(cols) {54 55 try {56 var divisionQuery = `SELECT * FROM (SELECT * FROM donate_donor WHERE instno IN (${cols})) as sx 57 WHERE NOT EXISTS (58 (SELECT p.instno FROM blood_drive as p)59 EXCEPT60 (SELECT sp.instno FROM donate_donor as sp WHERE sp.donorid = sx.donorid));`61 if(cols.length === 1){62 divisionQuery = `SELECT * FROM donate_donor WHERE instno IN (${cols})`;63 }64 const result = await pool.query(divisionQuery);65 return result.rows66 } catch (error) {67 res.send(error)68 }69}70// SELECT QUERY71async function getSelectData(field, value) {72 try {73 const result = await pool.query(`SELECT * FROM donor_contact WHERE ${field}='${value}'`);74 return result.rows75 } catch (error) {76 res.send(error)77 }78}79// PROJECT QUERY80async function getProjectData(cols) {81 try {82 const result = await pool.query(`SELECT ${cols} FROM donor_contact`);83 return result.rows84 } catch (error) {85 res.send(error)86 }87}88// AGGREGATION QUERY89async function getAggData(agg) {90 try {91 const result = await pool.query(`SELECT * FROM donate_blood WHERE time=(SELECT ${agg}(time) FROM donate_blood)`);92 return result.rows93 } catch (error) {94 res.send(error)95 }96}97async function getInstNos() {98 try {99 var instNosQuery = `select distinct instno from donate_donor;`100 const result = await pool.query(instNosQuery);101 return result.rows102 } catch (error) {103 res.send(error)104 }105}106// GET107// main page108app.get('/', async (req, res) => {109 var relations = [];110 111 try {112 relations.push({ name: "Blood Banks", data: await getTableData("blood_bank") });113 114 relations.push({ name: "Blood Drives", data: await getTableData("blood_drive") });115 116 relations.push({ name: "Hospitals", data: await getTableData("hospital") });117 relations.push({ name: "Phlebotomists", data: await getTableData("phlebotomist") });118 relations.push({ name: "Blood Bags", data: await getTableData("blood_bag") });119 relations.push({ name: "Red Blood Cells", data: await getTableData("red_blood_cells") });120 relations.push({ name: "Plasma", data: await getTableData("plasma") });121 relations.push({ name: "Platelets", data: await getTableData("platelets") });122 relations.push({ name: "Blood Tested", data: await getTableData("testblood") }); //123 relations.push({ name: "Donations-Donors", data: await getTableData("donate_donor") });124 relations.push({ name: "Donations-Blood", data: await getTableData("donate_blood") });125 relations.push({ name: "Blood Transported From Blood Drive to Blood Bank", data: await getTableData("transporttobloodbank") });126 relations.push({ name: "Blood Transported From Blood Bank to Hospital", data: await getTableData("transporttohospital") });127 relations.push({ name: "Blood Disposed", data: await getTableData("disposeblood") }); //128 relations.push({ name: "Transfusions", data: await getTableData("transfusion") }); //129 relations.push({ name: "Volunteers", data: await getTableData("volunteer") });130 relations.push({ name: "Donors", data: await getTableData("donor") });131 relations.push({ name: "Donor Contact", data: await getTableData("donor_contact") });132 relations.push({ name: "Recipients", data: await getTableData("recipient") });133 relations.push({ name: "Conducted Questionnaires", data: await getTableData("conduct_questionnaire") });134 const data = {relations: relations}135 res.render('pages/index', data)136 } catch (error) {137 res.send(error)138 }139 140})141// individual table pages142app.get('/Blood-Banks', async (req, res) => {143 try {144 const data = { name: "Blood Banks", data: await getTableData("blood_bank") }145 res.render('pages/table', data)146 } catch (error) {147 res.send(error)148 }149})150app.get('/Blood-Drives', async (req, res) => {151 try {152 const data = { name: "Blood Drives", data: await getTableData("blood_drive") }153 res.render('pages/table', data)154 } catch (error) {155 res.send(error)156 }157})158app.get('/Hospitals', async (req, res) => {159 try {160 const data ={ name: "Hospitals", data: await getTableData("hospital") }161 res.render('pages/table', data)162 } catch (error) {163 res.send(error)164 }165})166app.get('/Phlebotomists', async (req, res) => {167 try {168 const data = { name: "Phlebotomists", data: await getTableData("phlebotomist") }169 res.render('pages/phlebotomists', data)170 } catch (error) {171 res.send(error)172 }173})174app.get('/Blood-Bags', async (req, res) => {175 try {176 const data = { name: "Blood Bags", data: await getTableData("blood_bag") }177 res.render('pages/bloodbags', data)178 } catch (error) {179 res.send(error)180 }181})182app.get('/Red-Blood-Cells', async (req, res) => {183 try {184 const data = { name: "Red Blood Cells", data: await getTableData("red_blood_cells") }185 res.render('pages/table', data)186 } catch (error) {187 res.send(error)188 }189})190app.get('/Plasma', async (req, res) => {191 try {192 const data = { name: "Plasma", data: await getTableData("plasma") }193 res.render('pages/table', data)194 } catch (error) {195 res.send(error)196 }197})198app.get('/Platelets', async (req, res) => {199 try {200 const data = { name: "Platelets", data: await getTableData("platelets") }201 res.render('pages/table', data)202 } catch (error) {203 res.send(error)204 }205})206 app.get('/Blood-Tested', async (req, res) => {207 try {208 const data = { name: "Blood Tested", data: await getTableData("testblood") }209 res.render('pages/table', data)210 } catch (error) {211 res.send(error)212 }213 })214app.get('/Donations-Donors', async (req, res) => {215 try {216 const data = { name: "Donations-Donors", data: await getTableData("donate_donor"), instnos: await getInstNos() }217 res.render('pages/donate_donor', data)218 } catch (error) {219 res.send(error)220 }221})222app.get('/Donations-Blood', async (req, res) => {223 try {224 const data = { name: "Donations-Blood", data: await getTableData("donate_blood") }225 res.render('pages/donate_blood', data)226 } catch (error) {227 res.send(error)228 }229})230app.get('/Blood-Transported-From-Blood-Drive-to-Blood-Bank', async (req, res) => {231 try {232 const data = { name: "Blood Transported From Blood Drive to Blood Bank", data: await getTableData("transporttobloodbank") }233 res.render('pages/table', data)234 } catch (error) {235 res.send(error)236 }237})238app.get('/Blood-Transported-From-Blood-Bank-to-Hospital', async (req, res) => {239 try {240 const data = { name: "Blood Transported From Blood Bank to Hospital", data: await getTableData("transporttohospital") }241 res.render('pages/table', data)242 } catch (error) {243 res.send(error)244 }245})246 app.get('/Blood-Disposed', async (req, res) => {247 try {248 const data = { name: "Blood Disposed", data: await getTableData("disposeblood") }249 res.render('pages/table', data)250 } catch (error) {251 res.send(error)252 }253 })254 app.get('/Transfusions', async (req, res) => {255 try {256 const data = { name: "Transfusions", data: await getTableData("transfusion") }257 res.render('pages/table', data)258 } catch (error) {259 res.send(error)260 }261 })262app.get('/Volunteers', async (req, res) => {263 try {264 const data = { name: "Volunteers", data: await getTableData("volunteer") }265 res.render('pages/table', data)266 } catch (error) {267 res.send(error)268 }269})270app.get('/Donors', async (req, res) => {271 try {272 const data = { name: "Donors", data: await getTableData("donor") }273 res.render('pages/table', data)274 } catch (error) {275 res.send(error)276 }277})278app.get('/Donor-Contact', async (req, res) => {279 try {280 const data = { name: "Donor Contact", data: await getTableData("donor_contact") }281 res.render('pages/donor_contact', data)282 } catch (error) {283 res.send(error)284 }285})286app.get('/Recipients', async (req, res) => {287 try {288 const data = { name: "Recipients", data: await getTableData("recipient") }289 res.render('pages/table', data)290 } catch (error) {291 res.send(error)292 }293})294app.get('/Conducted-Questionnaires', async (req, res) => {295 try {296 const data = { name: "Conducted Questionnaires", data: await getTableData("conduct_questionnaire") }297 res.render('pages/table', data)298 } catch (error) {299 res.send(error)300 }301})302//NESTED "GROUP BY" QUERY - MISHA 303//Query: Display quantitiy of blood by bloodtype304app.get('/Nested:BloodStatus', async (req, res) => {305 try {306 const data = { name: `Blood Bags: ${req.params.BloodStatus}`, data: await getNestedData("conduct_questionnaire", req.params.BloodStatus) }307 res.render('pages/bloodbags', data)308 } catch (error) {309 res.send(error)310 }311})312//JOIN QUERY - MISHA313app.get('/Join', async (req, res) => {314 try {315 const data = { name: `Blood Bags Transported History`, data: await getJoinData()}316 res.render('pages/table', data)317 } catch (error) {318 res.send(error)319 }320})321app.post('/Divide', async (req, res) => {322 // grab selected fields323 let body = JSON.parse(JSON.stringify(req.body)) // format: {'selection1': on, 'selection2': on}324 let cols = Object.keys(body).toString() // format: selection1, selection2325 326 try {327 const data = { name: `Divide Operator: Donations Donors / Blood Drives`, data: await getDivisionData(cols)}328 res.render('pages/table', data)329 } catch (error) {330 res.send(error)331 }332})333// DELETE QUERY334app.post('/deletePhleb/:phlebid', async (req,res) => {335 // console.log(req.params.phlebid.substring(1))336 try {337 var getPhleb = `DELETE FROM phlebotomist WHERE phlebid=${req.params.phlebid.substring(1)};`338 let result = await pool.query(getPhleb)339 const data = { name: `Phlebotomists`, data: await getTableData("phlebotomist") }340 // res.redirect(req.protocol+ 'pages/table', data)341 res.redirect(req.protocol + '://' + req.get('host') + '/phlebotomists' );342 } catch(error) {343 res.send(error)344}})345// INSERT QUERY346app.post('/InsertPhleb', async (req,res)=>{347 let name = req.body.phlebName348 let instNo = req.body.instNo349 // console.log(name);350 // console.log(instNo);351 try{352 var getPhleb = `INSERT INTO phlebotomist (name, instno) VALUES ('${name}', ${instNo});`353 let result = await pool.query(getPhleb)354 const data = { name: "Phlebotomists", data: await getTableData("phlebotomist") }355 res.redirect(req.protocol + '://' + req.get('host') + '/phlebotomists' )356 } catch(error){357 res.send(error)358 }359})360// Update361app.get('/updatePhleb/:phlebid', async (req,res)=> {362 let selectPhleb = req.params.phlebid.substring(1)363 let result = await pool.query(`SELECT * FROM phlebotomist WHERE phlebid='${selectPhleb}'`)364 // console.log(result.rows)365 // console.log(selectPhleb)366 try {367 var getPhleb = `SELECT * from phlebotomist where phlebid='${selectPhleb}'`368 const data = { name: `${result.rows[0].name}`, data: await result.rows }369 res.render('pages/phlebUpdate', data)370 } catch (error) {371 res.send(error)372 }373})374app.post('/updatePhleb/:phlebid', async (req,res) =>{375 let name = req.body.name376 let instNo= req.body.instNo377 let selectPhleb = req.params.phlebid.substring(1)378 // console.log(name)379 // console.log(instNo)380 // console.log(selectPhleb)381 try{382 var getPhleb = `UPDATE phlebotomist SET name = '${name}', instno=${instNo} WHERE phlebid='${selectPhleb}'`383 let result = await pool.query(getPhleb)384 const data = { name: "Phlebotomists", data: await getTableData("phlebotomist") }385 // console.log(('try'))386 res.redirect(req.protocol + '://' + req.get('host') + '/phlebotomists' )387 } catch (error) {388 res.send(error)389 }390})391// SELECT QUERY392// Query: Search for rows by a field value393// e.g. Search for rows where name="samantha"394app.post('/Select', async (req, res) => {395 let field = req.body.field;396 let value = req.body.value;397 try {398 const data = { name: `Search results for ${field} = ${value}`, data: await getSelectData(field, value)}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.getTableData(function (err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var request = require('request');10var getTableData = function (callback) {11 request(url, function (error, response, html) {12 if (!error) {13 callback(null, html);14 } else {15 callback(error, null);16 }17 });18}19module.exports = {20};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2 console.log(data);3});4var request = require('request');5var cheerio = require('cheerio');6module.exports.getTableData = function(url, callback) {7 request(url, function(error, response, body) {8 if (!error && response.statusCode == 200) {9 var $ = cheerio.load(body);10 var tableData = [];11 $('table tr').each(function(i, row) {12 var rowData = [];13 $(this).children('td').each(function(j, column) {14 rowData.push($(this).text());15 });16 tableData.push(rowData);17 });18 callback(tableData);19 }20 });21};22Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wptClient = new wpt('API_KEY');3wptClient.getTableData('TEST_ID', function(err, data) {4 console.log(data);5});6var wpt = require('wpt');7var wptClient = new wpt('API_KEY');8wptClient.getTestResults('TEST_ID', function(err, data) {9 console.log(data);10});11var wpt = require('wpt');12var wptClient = new wpt('API_KEY');13wptClient.getTestResults('TEST_ID', function(err, data) {14 console.log(data);15});16var wpt = require('wpt');17var wptClient = new wpt('API_KEY');18wptClient.getTestResults('TEST_ID', function(err, data) {19 console.log(data);20});21var wpt = require('wpt');22var wptClient = new wpt('API_KEY');23wptClient.getTestResults('TEST_ID', function(err, data) {24 console.log(data);25});26var wpt = require('wpt');27var wptClient = new wpt('API_KEY');28wptClient.getTestResults('TEST_ID', function(err, data) {29 console.log(data);30});31var wpt = require('wpt');32var wptClient = new wpt('API_KEY');33wptClient.getTestResults('TEST_ID', function(err, data) {34 console.log(data);35});36var wpt = require('wpt');37var wptClient = new wpt('API_KEY');38wptClient.getTestResults('TEST_ID', function(err, data) {39 console.log(data);40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wptObj = new wpt('your api key');3wptObj.getTableData('test id', function(err, data){4 if (err) {5 console.log(err);6 }7 else {8 console.log(data);9 }10});11var wpt = require('wpt');12var wptObj = new wpt('your api key');13wptObj.getBreakdown('test id', function(err, data){14 if (err) {15 console.log(err);16 }17 else {18 console.log(data);19 }20});21var wpt = require('wpt');22var wptObj = new wpt('your api key');23wptObj.getMedianRun('test id', function(err, data){24 if (err) {25 console.log(err);26 }27 else {28 console.log(data);29 }30});31var wpt = require('wpt');32var wptObj = new wpt('your api key');33wptObj.getLocations(function(err, data){34 if (err) {35 console.log(err);36 }37 else {38 console.log(data);39 }40});41var wpt = require('wpt');42var wptObj = new wpt('your api key');43wptObj.getTesters(function(err, data){44 if (err) {45 console.log(err);46 }47 else {48 console.log(data);49 }50});51var wpt = require('wpt');52var wptObj = new wpt('your api key');53wptObj.getTesters(function(err, data){54 if (err) {55 console.log(err);56 }57 else {58 console.log(data);59 }60});61var wpt = require('wpt');62var wptObj = new wpt('your api key');63wptObj.getTesters(function(err, data

Full Screen

Using AI Code Generation

copy

Full Screen

1var tableData = wptables.getTableData('table1');2var tableData = wptables.getTableData('table1');3var tableData = wptables.getTableData('table1');4var tableData = wptables.getTableData('table1');5var tableData = wptables.getTableData('table1');6var tableData = wptables.getTableData('table1');7var tableData = wptables.getTableData('table1');8var tableData = wptables.getTableData('table1');9var tableData = wptables.getTableData('table1');10var tableData = wptables.getTableData('table1');11var tableData = wptables.getTableData('table1');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptable = require('wptable');2var table = wptable.getTableData({3});4console.log(table);5var wptable = require('wptable');6var table = wptable.getTableData({7});8console.log(table);9var wptable = require('wptable');10var table = wptable.getTableData({11});12console.log(table);13var wptable = require('wptable');14var table = wptable.getTableData({15});16console.log(table);17var wptable = require('wptable');18var table = wptable.getTableData({19});20console.log(table);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpTable = require('./wptable');2var data = wpTable.getTableData('./sample.html');3var wpTable = require('./wptable');4var data = wpTable.getTableData('./sample.html');5var wpTable = require('./wptable');6var data = wpTable.getTableData('./sample.html');7var wpTable = require('./wptable');8var data = wpTable.getTableData('./sample.html');9var wpTable = require('./wptable');10var data = wpTable.getTableData('./sample.html');11var wpTable = require('./wptable');12var data = wpTable.getTableData('./sample.html');13var wpTable = require('./wptable');14var data = wpTable.getTableData('./sample.html');15var wpTable = require('./wptable');16var data = wpTable.getTableData('./sample.html');17var wpTable = require('./wptable');18var data = wpTable.getTableData('./sample.html');19var wpTable = require('./wptable');20var data = wpTable.getTableData('./sample.html');21var wpTable = require('./wptable');22var data = wpTable.getTableData('./sample.html');23var wpTable = require('./wptable');24var data = wpTable.getTableData('./sample.html');25var wpTable = require('./wptable');26var data = wpTable.getTableData('./sample.html');27var wpTable = require('./wptable');28var data = wpTable.getTableData('./sample.html');29var wpTable = require('./

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2 console.log(data);3});4{5 "data":{6 "data":{7 "runs":{8 "1":{9 "firstView":{

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options.key);5wpt.getLocations(function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});9 if (err) return console.error(err);10 console.log(data);11});12wpt.getTestResults('150813_9X_1e2f3c3c3b3c3d3d3e3f3f3f3f3f3f3f', function(err, data) {13 if (err) return console.error(err);14 console.log(data);15});16 var options = this.options;17 at WebPageTest.getTestResults (C:\Users\Nagaraj\Desktop\wpt\node_modules\webpagetest\lib\webpagetest.js:69:25)18 at Object.<anonymous> (C:\Users\Nagaraj\Desktop\wpt\test.js:15:9)19 at Module._compile (module.js:571:32)20 at Object.Module._extensions..js (module.js:580:10)21 at Module.load (module.js:488:32)22 at tryModuleLoad (module.js:447:12)23 at Function.Module._load (module.js:439:3)24 at Function.Module.runMain (module.js:605:10)25 at startup (bootstrap_node.js:158:16)

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful