Programming block detection method, device, equipment, computer readable storage medium and computer program product
By constructing hierarchical detection paths and using hash tables and stack management to detect states, the problem of difficult block anomaly detection in existing programming tools is solved, achieving efficient and accurate programming block detection, and improving user experience and programming efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2025-01-21
- Publication Date
- 2026-07-21
Smart Images

Figure CN122432017A_ABST
Abstract
Description
Technical Field
[0001] This application relates to computer technology, and more particularly to a method, apparatus, device, computer-readable storage medium, and computer program product for detecting programming blocks. Background Technology
[0002] Visual programming tools are widely used in education and development, offering rich functionality and flexibility. However, due to the high flexibility of combining and configuring blocks, users may encounter logical errors or misconfigurations during the assembly process. Current visual programming tools do not provide built-in block anomaly detection mechanisms, and there are still some limitations in block anomaly detection. Users find it difficult to quickly locate the specific block that is malfunctioning and need to spend more time and effort to check them one by one, resulting in low debugging efficiency. Summary of the Invention
[0003] This application provides a method, apparatus, device, computer-readable storage medium, and computer program product for detecting programming blocks, which can improve the efficiency and accuracy of programming block detection.
[0004] The technical solution of this application embodiment is implemented as follows:
[0005] This application provides a method for detecting programming blocks, the method comprising:
[0006] In response to a block detection request, a block combination to be detected is determined, the block combination including a first block as the starting point of programming and a plurality of second blocks associated with the first block for implementing programming logic;
[0007] Based on the connection relationship between the multiple second building blocks and the first building block, a hierarchical detection path for the building block combination is constructed. The hierarchical detection path includes multiple levels, with one level corresponding to one second building block.
[0008] Starting from the bottom block in the hierarchical detection path, anomaly detection is performed on each of the second blocks, and a first detection result is obtained.
[0009] Based on the first detection result, a second detection result for the block assembly is determined.
[0010] This application provides a detection device for programming blocks, the device comprising:
[0011] A response module is used to respond to a block detection request and determine a block combination to be detected, the block combination including a first block as the starting point of programming and multiple second blocks associated with the first block for implementing programming logic;
[0012] A construction module is used to construct a hierarchical detection path for the block combination based on the connection relationship between the plurality of second blocks and the first block. The hierarchical detection path includes multiple levels, with one level corresponding to one second block.
[0013] The first detection module is used to perform anomaly detection on each of the second blocks from the bottom block in the hierarchical detection path upwards, and obtain a first detection result;
[0014] The determining module is used to determine a second detection result of the block assembly based on the first detection result.
[0015] In the above scheme, the construction module is further used to initialize a hash table and a stack, wherein the hash table is used to store the detection status of the first building block, and the detection status is used to indicate at least one of the first detection result of each second building block and the second detection result of the building block combination; the stack is used to store each second building block to be detected; based on the connection relationship between the plurality of second building blocks, for any two connected second building blocks, the second building block connected above is the parent building block and the second building block connected below is the child building block, and each second building block is pushed into the stack in the order of the parent building block first and the child building block last; the pop-out order of the stack for each pushed second building block is determined, and a hierarchical detection path of the building block combination is constructed based on the pop-out order of each second building block; wherein, in the hierarchical detection path, for two second building blocks with adjacent pop-out orders, the second building block with the later pop-out order is the parent building block of the second building block with the earlier pop-out order; the bottom building block in the hierarchical detection path is the second building block with the earliest pop-out order.
[0016] In the above scheme, the first detection module is further configured to perform anomaly detection on the bottom-level block in the hierarchical detection path to obtain a first detection result for the bottom-level block; if the first detection result of the bottom-level block indicates that the bottom-level block does not have an anomaly, perform anomaly detection on the third block in the second block that is the upper-level block of the bottom-level block to obtain a first detection result for the third block; if the first detection result of the third block indicates that the third block does not have an anomaly and the third block is associated with multiple other child blocks, perform anomaly detection on the other child blocks associated with the third block according to the push order of the other child blocks associated with the third block in the stack to obtain a first detection result for the other child blocks associated with the third block; if the first detection result of the third block indicates that the third block has an anomaly, or if the first detection result of the other child blocks associated with the third block indicates that the other child blocks associated with the third block do not have an anomaly, backtrack to the parent block of the third block to perform anomaly detection on the other child blocks associated with the parent block of the third block.
[0017] In the above scheme, the construction module is further configured to, when the first detection result indicates that the corresponding second building block is abnormal, set the detection status of the first building block in the hash table to indicate the detection status of the first detection result; or, determine the abnormality type of the abnormal second building block and store the building block identifier of the abnormal second building block and the abnormality type in the hash table.
[0018] In the above scheme, the second building block includes a first input field. The first detection module is further configured to perform input anomaly detection on the first input field of each second building block; and to obtain a first detection result indicating that there is an input anomaly in the second building block when the first input field is empty.
[0019] In the above scheme, the first input field is used to input the first parameter. The first detection module is also used to detect whether the first parameter is input through the value input or the variable selector when the input type of the first input field is value input or variable selector input, and to determine that the first input field is empty when the first parameter is not input; and to detect whether the first input field is connected to the parameter block associated with the first parameter when the input type of the first input field is connection type input, and to determine that the first input field is empty when the first input field is not connected to the parameter block.
[0020] In the above scheme, the second building block includes a second input field for inputting a second parameter. The first detection module is further configured to, for each second building block, determine the preset type and the actual type of the second parameter when the second parameter has been input to the second input field; perform type anomaly detection on the second parameter based on the preset type and the actual type; and obtain a first detection result indicating that the second building block has a type anomaly when the actual type is inconsistent with the preset type.
[0021] In the above scheme, the first detection module is further configured to perform a legality check on each of the second building blocks; if the second building block is invalid, a first detection result indicating that the second building block is invalid is obtained.
[0022] In the above scheme, the first detection module is further configured to perform at least one of the following validity checks on the second building block: perform a usability check on the second building block to determine that the second building block is invalid if the second building block is disabled; perform a connection validity check on the second building block to determine that the second building block is invalid if the connection method of the second building block is incorrect, or if the second building block and the building block connected to the second building block are incompatible; perform a value validity check on the third input field in the second building block to determine that the second building block is invalid if the third parameter input in the third input field is invalid; perform a structure validity check on the second building block to determine that the second building block is invalid if the loop structure associated with the second building block is incorrect or the branch structure associated with the second building block is incomplete; and perform a syntax validity check on the second building block to determine that the second building block is invalid if the programming code corresponding to the second building block does not conform to the preset syntax rules.
[0023] In the above scheme, the determining module is further configured to obtain a second detection result indicating that the block combination is abnormal when the first detection result indicates that there is an abnormal second block among the plurality of second blocks.
[0024] In the above scheme, the detection device for the programming blocks further includes: a second detection module, used to determine the second detection result of the block combination, and then, in the event of a change in the block combination, perform anomaly detection on the second block in the block combination that has changed; wherein, the type of change includes at least one of the following: a change in the number of the second blocks, a change in the type of the second blocks, or a change in the connection relationship between the plurality of second blocks.
[0025] This application provides an electronic device, including:
[0026] Memory is used to store executable instructions or computer programs.
[0027] The processor, when executing computer-executable instructions or computer programs stored in the memory, implements the method for detecting programming blocks provided in the embodiments of this application.
[0028] This application provides a computer-readable storage medium storing computer-executable instructions or computer programs, which, when executed by a processor, implement the method for detecting programming blocks provided in this application.
[0029] This application provides a computer program product, including computer-executable instructions or a computer program. When the computer-executable instructions or the computer program are executed by a processor, they implement the programming block detection method provided in this application.
[0030] The embodiments of this application have the following beneficial effects:
[0031] In this application, a block combination is defined, including a first block and multiple second blocks associated with it. Based on the connection relationship between the second blocks and the first block, a hierarchical detection path is constructed. Starting from the bottom block of the path, anomalies in each second block are detected level by level upwards to obtain preliminary detection results. Based on the preliminary detection results, the final detection result of the entire block combination is determined. In this way, anomalies in the block combination can be detected and located in real time, effectively improving programming efficiency and accuracy, reducing debugging time and costs, and helping users better understand and master the relationships and functions between blocks, thereby improving programming efficiency and quality and enhancing user experience. Attached Figure Description
[0032] Figure 1 This is a schematic diagram of the architecture of the programming block detection system provided in the embodiments of this application;
[0033] Figure 2 This is a schematic diagram of the structure of an electronic device for implementing a detection method for programming blocks, as provided in an embodiment of this application.
[0034] Figure 3A This is a first flowchart illustrating the method for detecting programming blocks provided in this application embodiment;
[0035] Figure 3B This is a schematic diagram of the second process of the method for detecting programming blocks provided in the embodiments of this application;
[0036] Figure 4 This is a schematic diagram of anomaly detection provided in an embodiment of this application;
[0037] Figure 5This is a schematic diagram of the third process of the method for detecting programming blocks provided in the embodiments of this application;
[0038] Figure 6 This is a schematic diagram of the first anomaly provided in the embodiments of this application;
[0039] Figure 7 This is a schematic diagram illustrating input errors provided in an embodiment of this application;
[0040] Figure 8 This is a schematic diagram of the fourth process of the method for detecting programming blocks provided in the embodiments of this application;
[0041] Figure 9 This is a schematic diagram of the second anomaly provided in the embodiments of this application;
[0042] Figure 10 This is a schematic diagram of the algorithm triggering provided in the embodiments of this application;
[0043] Figure 11 This is a schematic diagram of the cache update process provided in the embodiments of this application. Detailed Implementation
[0044] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0045] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0046] In the following description, the terms "first, second, third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0047] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0048] Unless otherwise defined, all technical and scientific terms used in the embodiments of this application have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in the embodiments of this application is for the purpose of describing the embodiments of this application only and is not intended to limit this application.
[0049] In the implementation of this application, the collection and processing of relevant data should strictly comply with the requirements of relevant laws and regulations, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of laws and regulations and the authorization of the personal information subject.
[0050] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.
[0051] 1) In response to, used to indicate the conditions or states on which the operation performed depends. When the conditions or states on which it depends are met, one or more operations performed may be performed in real time or with a set delay. Unless otherwise specified, there is no restriction on the order in which the multiple operations are performed.
[0052] 2) Client, also known as user terminal, refers to the program that provides local services to users in contrast to the server. Except for some applications that can only run locally, it is generally installed on the terminal and needs to work in conjunction with the server. That is, there needs to be a corresponding server and service program on the network to provide the corresponding services. Thus, a specific communication connection needs to be established between the client and the server to ensure the normal operation of the application, such as virtual scene clients (such as game clients) and video clients.
[0053] This application provides a method, apparatus, device, computer-readable storage medium, and computer program product for detecting programming blocks, improving the efficiency and accuracy of programming block detection. The following describes exemplary applications of electronic devices provided in this application for implementing the programming block detection method. The devices provided in this application can be implemented as various types of terminals such as laptops, tablets, desktop computers, set-top boxes, smartphones, smart speakers, smartwatches, smart TVs, and in-vehicle terminals, or as servers.
[0054] The following describes an exemplary application system architecture, using an electronic device as a server, in which the server and terminal collaboratively implement the programming block detection method provided in this embodiment of the invention. (See also...) Figure 1 , Figure 1This is a schematic diagram of the architecture of the programming block detection system provided in this application embodiment. To support the detection application of a programming block, in Figure 1 In the programming block detection system 100, the terminal 400 is connected to the server 200 through the network 300, which can be a wide area network or a local area network, or a combination of both.
[0055] In some embodiments, in response to a user's operation on the client, the terminal 400 sends a block detection request to the server 200 via the network 300. In response to the block detection request, the server 200 determines the block combination to be detected. The block combination includes a first block as the starting point for programming and multiple second blocks associated with the first block for implementing programming logic. Based on the connection relationships between the multiple second blocks and the first block, a hierarchical detection path for the block combination is constructed. The hierarchical detection path includes multiple levels, with each level corresponding to one second block. Starting from the bottom block in the hierarchical detection path, anomaly detection is performed on each second block level by level, obtaining a first detection result. Based on the first detection result, a second detection result for the block combination is determined and sent to the terminal 400.
[0056] In other embodiments, the programming block detection method provided in this invention can also be implemented independently by a terminal. The terminal is equipped with a client that can implement the programming block detection method. When a user inputs a string in the client and requests the detection of programming blocks, the client responds to the block detection request and determines the block combination to be detected. The block combination includes a first block as the starting point of programming and multiple second blocks associated with the first block for implementing programming logic. Based on the connection relationship between the multiple second blocks and the first block, a hierarchical detection path for the block combination is constructed. The hierarchical detection path includes multiple levels, with one level corresponding to one second block. Starting from the bottom block in the hierarchical detection path, anomaly detection is performed on each second block level by level to obtain a first detection result. Based on the first detection result, a second detection result for the block combination is determined.
[0057] In other embodiments, a programming block detection plugin can be embedded in the client running on the terminal to implement the programming block detection method locally on the client. For example, after receiving a detection request for programming blocks, the terminal calls the programming block detection plugin to implement the programming block detection method. In response to the block detection request, it determines the block combination to be detected. The block combination includes a first block as the starting point of programming and multiple second blocks associated with the first block for implementing programming logic. Based on the connection relationship between the multiple second blocks and the first block, a hierarchical detection path for the block combination is constructed. The hierarchical detection path includes multiple levels, with one level corresponding to one second block. Starting from the bottom block in the hierarchical detection path, anomaly detection is performed on each second block level by level to obtain a first detection result. Based on the first detection result, a second detection result for the block combination is determined.
[0058] In some embodiments, server 200 may be a standalone physical server, a server cluster consisting of multiple physical servers, or a distributed system. Terminals and servers can be connected directly or indirectly via wired or wireless communication, and this embodiment does not impose any limitations.
[0059] In this way, anomalies in block combinations can be detected and located in real time, effectively improving programming efficiency and accuracy, reducing debugging time and costs, and helping users better understand and master the relationships and functions between blocks, thereby improving programming efficiency and quality and enhancing user experience.
[0060] See Figure 2 , Figure 2 This is a schematic diagram of the structure of an electronic device for implementing a detection method for programming blocks, provided in an embodiment of this application. In practical applications, the electronic device can be implemented as various types of terminals such as laptops, tablets, desktop computers, smartphones, smart speakers, smartwatches, smart TVs, and vehicle terminals. It can also be implemented as a server or as a device cluster composed of servers and terminals. Figure 2 The illustrated electronic device 500 includes at least one processor 510, a memory 550, at least one network interface 520, and a user interface 530. The various components in the electronic device 500 are coupled together via a bus system 540. It is understood that the bus system 540 is used to implement communication between these components. In addition to a data bus, the bus system 540 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 2 The general labeled all buses as Bus System 540.
[0061] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0062] User interface 530 includes one or more output devices 531 that enable the presentation of media content, including one or more speakers and / or one or more visual displays. User interface 530 also includes one or more input devices 532, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0063] The memory 550 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 550 may optionally include one or more storage devices physically located away from the processor 510.
[0064] The memory 550 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 550 described in this application embodiment is intended to include any suitable type of memory.
[0065] In some embodiments, memory 550 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.
[0066] Operating system 551 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, and driver layer, for implementing various basic business functions and handling hardware-based tasks.
[0067] The network communication module 552 is used to reach other electronic devices via one or more (wired or wireless) network interfaces 520, exemplary network interfaces 520 including Bluetooth, WiFi, and Universal Serial Bus (USB), etc.
[0068] Presentation module 553 enables the presentation of information (e.g., a user interface for operating peripheral devices and displaying content and information) via one or more output devices 531 (e.g., a display screen, a speaker, etc.) associated with user interface 530.
[0069] The input processing module 554 is used to detect one or more user inputs or interactions from one or more input devices 532, and to translate the detected inputs or interactions.
[0070] In some embodiments, the detection device for programming blocks provided in this application can be implemented in software. Figure 2 A detection device 555 for programming blocks stored in memory 550 is shown. This device can be software in the form of programs and plug-ins, and includes the following software modules: a response module 5551, a construction module 5552, a first detection module 5553, and a determination module 5554. These modules are logically connected and can therefore be arbitrarily combined or further separated according to the functions implemented. The functions of each module will be described below.
[0071] In other embodiments, the apparatus provided in this application can be implemented in hardware. As an example, the programmable block detection apparatus provided in this application can be a processor in the form of a hardware decoding processor, which is programmed to execute the programmable block detection method provided in this application. For example, the processor in the form of a hardware decoding processor can be one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.
[0072] Below, based on the electronic device and system provided in the embodiments of this application, the method for detecting programming blocks provided in the embodiments of this application will be described.
[0073] See Figure 3A , Figure 3A This is a schematic diagram of the first process of the programming block detection method provided in this application embodiment. In practical applications, this method can be implemented by the terminal or the server alone, or by the terminal and the server working together. The following example uses a server implementation and will be combined with... Figure 3A The steps shown illustrate the method for detecting programming blocks provided in the embodiments of this application.
[0074] In step 101, in response to the block detection request, the block combination to be detected is determined.
[0075] Here, "blocks" refer to drag-and-drop graphical code blocks. Each block represents a specific programming command or function, such as loops, conditional statements, and variable operations. Users can build program logic by dragging and assembling these blocks, eliminating the need to write traditional text code. This makes the programming process more intuitive and easier to understand, lowering the barrier to entry for programming. The block detection request contains specific information about the block combination to be detected, such as the types of blocks included in the combination, their expected functions, identifiers, and connection relationships. Based on the received detection request, the block programming environment can identify block combinations that meet the detection requirements.
[0076] The block combination includes a first block that serves as the starting point for programming and multiple second blocks associated with the first block that are used to implement programming logic. The first block is used to define when the program starts to execute. The first block can respond to various events, such as pressing a button, receiving a specific signal, or meeting certain conditions. When the first block detects the corresponding event, it will activate the blocks connected to it, that is, the multiple second blocks associated with the first block that are used to implement programming logic, thereby executing a series of predefined operations or tasks.
[0077] It should be noted that when the first block detects the corresponding event, multiple second blocks will be executed in the order they are connected. Each second block can include operations such as variable assignment, looping, conditional judgment, and function call. Multiple second blocks together define the behavior and logic of the program when a specific event occurs.
[0078] As an example, the block combination includes block A, block B, block C, block D, and block E. Block A is the first block, and blocks B, C, D, and E are multiple second blocks associated with the first block, used to implement programming logic. Block A defines the program's start condition, such as "when the button is pressed." When the user presses the button, this block triggers the execution of subsequent blocks. Block B is used to initialize a variable, such as "set the value of variable count to 0," which is executed when the user presses the button, ensuring the counter starts from 0. Block C contains a loop structure, such as "repeat the following operation 10 times." In this loop, other blocks are included to implement the specific counting logic. Block D is located inside the loop block and is used to increment the value of variable count, such as "increment the value of variable count by 1." This block is executed each time the loop occurs, causing the value of count to gradually increase. Block E is used to display the final count value after the loop ends, such as "display the value of variable count." When the user presses the button, block A detects the button press event, triggers block B to assign a value to the variable, and then enters the loop block, repeatedly executing block D to increment the count value. After the loop ends, the count value is 10, and block E is executed to display the result. In this way, this block combination realizes the function of counting and displaying the result when the button is pressed by connecting these blocks and the execution order.
[0079] In this way, by organizing multiple second blocks below the first block, users can create program modules with specific functions and responsiveness, making the entire program more modular and easier to manage. This not only improves code readability and reusability but also simplifies program debugging and expansion, making program development and maintenance more efficient and organized.
[0080] In step 102, a hierarchical detection path for the block combination is constructed based on the connection relationship between multiple second blocks and the first block.
[0081] Here, the hierarchical detection path includes multiple levels, with each level corresponding to a second block. The hierarchical detection path takes the first block as the top-level block, the second block among the multiple second blocks that does not have any subsequent connecting blocks as the bottom-level block, and the second block that is connected first among any two connected second blocks as the upper-level block of the second block that is connected later.
[0082] In some embodiments, based on the connection relationships between multiple second blocks and the first block, a hierarchical detection path for the block combination can be constructed in the following way: initializing a hash table and a stack; based on the connection relationships between multiple second blocks, for any two connected second blocks, taking the second block connected above as the parent block and the second block connected below as the child block, and pushing each second block into the stack in the order of parent block first and child block last; determining the pop-out order of each pushed second block in the stack, and constructing a hierarchical detection path for the block combination based on the pop-out order of each second block, wherein the pop-out order of the second blocks is the detection order of each second block in the hierarchical detection path.
[0083] Here, a hash table is used to store the detection status of the first block. The detection status indicates at least one of the first detection result of each second block and the second detection result of the block combination. A stack is used to store each second block to be detected. The stack is a data structure that follows the Last In First Out (LIFO) principle. It only allows data to be added and removed at one end (called the top of the stack). That is, it only allows the addition and removal of second blocks at the top of the stack. In the hierarchical detection path, the second block that is popped later is the parent block of the second block that is popped earlier. The bottom block in the hierarchical detection path is the second block that is popped first.
[0084] It should be noted that a hash table is an efficient data structure that uses a hash function to map keys to a fixed-size array. Each array element is called a bucket. The hash function converts the key into an index value, which corresponds to a position in the array and is used to store the value associated with the key. For example, the key in the hash table used to store the detection status of the first building block can be the identifier of the first building block, used to mark the uniqueness of each first building block. The identifier of the first building block is associated with the identifiers of each second building block used to implement the programming logic. Thus, based on the mapping relationship between the identifiers of the first and second building blocks, the detection status of the first building block in the hash table can be updated based on at least one of the first detection results of each second building block and the second detection results of the building block combination. The value in the hash table can be a boolean value, True or False, used to indicate whether the detection status of the first building block is that an anomaly exists. For example, True indicates that the detection status of the first building block is that an anomaly exists, and False indicates that the detection status of the first building block is that no anomaly exists. The value in the hash table can also be a more complex data structure, such as an object or array, used to store more detailed information about the detection status of the first building block, such as the anomaly type, anomaly location, anomaly description, etc.
[0085] As an example, let's take the hash table where the key is the identifier of the first block and the value is a boolean value. For the first blocks A, B, and C in the program, an empty hash table is initialized to store their detection states, initially set to False, indicating that the detection state is no anomaly. The resulting hash table is: First Block State = {"First Block A": False, "First Block B": False, "First Block C": False}. During program execution, if the first detection result of the second block B corresponding to the first block B is found to be an anomaly, the hash table is updated according to the mapping relationship between the identifiers of the first and second blocks B. The value of the first block B is set to True, indicating that the detection state is an anomaly. The updated hash table is then obtained: First Block State = {"First Block A": False, "First Block B": True, "First Block C": False}.
[0086] It is understandable that for two connected second blocks, the second block connected above is the parent block of the second block connected below, and the second block connected below is the child block of the second block connected above.
[0087] For example, if block A and block B are connected, and block B is located below block A, then block A is the parent block of block B, and block B is the child block of block A. Accordingly, when pushing blocks onto the stack, block A should be pushed onto the stack before block B. According to the principle of last-in, first-out (LIFO) of the stack, the last block pushed onto the stack will be popped off first. Therefore, when blocks are popped off the stack, their popping order will be the reverse of their pushing order, that is, block B will be popped off first, and then block A will be popped off.
[0088] In this way, by using hash tables and stacks to manage the detection status and construction hierarchy detection path of the blocks, it is ensured that each block can be processed in the correct hierarchical order during the detection process, which improves the accuracy and efficiency of detection, while also simplifying anomaly location and complexity management.
[0089] In step 103, starting from the bottom block in the hierarchical detection path, anomaly detection is performed on each second block, and the first detection result is obtained.
[0090] It should be noted that during the popping process, each popped block will determine its position in the hierarchical detection path according to its popping order. In this way, a hierarchical detection path can be constructed by the popping order of the stack, where the bottom block is the first block to be popped, that is, the block that is initially pushed into the stack.
[0091] In some embodiments, see Figure 3B , Figure 3B This is a schematic diagram of the second process of the method for detecting programming blocks provided in the embodiments of this application. Figure 3A Step 103 shown can be implemented through steps 1031A to 1034A, which are explained in detail below.
[0092] In step 1031A, for the bottom-level blocks in the hierarchical detection path, anomaly detection is performed on the bottom-level blocks to obtain the first detection result of the bottom-level blocks.
[0093] In step 1032A, if the first detection result of the bottom-level block indicates that there is no abnormality in the bottom-level block, an abnormality detection is performed on the third block, which is the upper-level block of the bottom-level block in the second block, and the first detection result of the third block is obtained.
[0094] In step 1033A, if the first detection result of the third block indicates that the third block is not abnormal and the third block is associated with multiple other sub-blocks, the other sub-blocks associated with the third block are detected for abnormality according to the pushing order of the other sub-blocks associated with the third block in the stack, and the first detection result of the other sub-blocks associated with the third block is obtained.
[0095] In step 1034A, if the first detection result of the third block indicates that the third block is abnormal, or if the first detection result of other child blocks associated with the third block indicates that the other child blocks associated with the third block are not abnormal, the process backtracks to the parent block of the third block to perform anomaly detection on the other child blocks associated with the parent block of the third block.
[0096] In this system, the bottom-level block is the last level block, i.e., the second block popped from the stack first. The first detection result includes whether an anomaly exists or not. Understandably, if the first detection result for the bottom-level block indicates that there is no anomaly, anomaly detection is performed on the third block (the parent block of the bottom-level block). That is, anomaly detection is performed on the parent block of the bottom-level block. If the first detection result indicates that there is an anomaly in the third block, the detection status of the first block corresponding to the third block in the hash table is updated to indicate that there is an anomaly, and the detection of the third block is stopped. If a third block has a parent block, the process backtracks to the parent block and continues to check the child blocks of that parent block. If the first check indicates that the third block is not abnormal and the third block is associated with multiple other child blocks, the abnormality check is performed according to the order in which the other child blocks are pushed into the stack. After the check of the third block and its child blocks is completed, if no abnormality is found, the process backtracks to the parent block and continues to check the next child block of the parent block. Conversely, if an abnormality is found during the check, the check of the current path is stopped and the process backtracks directly to the parent block.
[0097] As an example, see Figure 4 , Figure 4 This is a schematic diagram of anomaly detection provided in an embodiment of this application, for the purpose of... Figure 4 Taking the block combination 401 shown as an example, and using the base block 402 as an example, anomaly detection is performed on the base block 402. If the first detection result of the base block 402 indicates that there is no anomaly, anomaly detection is performed on the third block 404, which is the upper-level block of the second block. If the first detection result of the third block 404 indicates that there is an anomaly, the detection of the child block 403 of the third block 404 is stopped. If the third block 404 has a parent block 405, the detection is backtracked to the parent block 405 of the third block 404, and the detection of the child block 406 of the parent block 405 of the third block 404 is continued. If the first detection result of the third block 404 indicates that the third block 404 is not abnormal and the third block 404 is associated with multiple other child blocks, then the abnormality detection is performed according to the order in which the other child blocks are pushed into the stack. After the detection of the third block 404 and its child block 403 is completed, if no abnormality is found, then backtrack to the parent block 405 of the third block 404, and then continue to detect the next child block 406 of the parent block 405. Correspondingly, if an abnormality is found during the detection process, then the inspection of the current path is stopped, that is, the block associated with block 406 is no longer detected, and backtracking is directly performed to the parent block 405 of the third block.
[0098] Thus, by using the methods in steps 1031A to 1034A, it is ensured that every part of the program can be systematically checked, thereby improving the reliability and stability of the code. It can detect and resolve anomalies before they affect a wider system, reducing the potential propagation of anomalies. In addition, this method helps to quickly locate the source of the problem, facilitates backtracking and repair, reduces repetitive work, improves detection efficiency, and ultimately enhances the overall robustness of the program.
[0099] In some embodiments, if the first detection result indicates that the corresponding second block is abnormal, the detection status of the first block in the hash table is set to the detection status indicating the first detection result; or, the abnormality type of the abnormal second block is determined, and the block identifier and abnormality type of the abnormal second block are stored in the hash table.
[0100] It should be noted that when the first detection result indicates that the corresponding second block is abnormal, a cache in the form of a hash table can also be used to store the first detection result. The unique identifier (ID) of the second block is used as the key, and the detection status of the second block, such as whether it is abnormal or not, or the type of abnormality of the second block, such as whether the input field is empty or the input type is abnormal, is stored as the value in the hash table.
[0101] As an example, in a block-based programming environment, there are multiple second blocks: block A, block B, and block C. The record for block A in the cache is {1: "Input field empty exception"}, the record for block B in the cache is {2: "Input type exception"}, and the record for block C in the cache is {3: "No exception"}. When the user enters a value into the input field of block A, the detection status changes from "Input field empty exception" to "No exception". Based on the identifier "1" of block A, the corresponding record in the cache is updated to {1: "No exception"}. When the user edits block C, they clear the input field, resulting in an empty input field. At this time, the detection status of block C changes from "No exception" to "Input field empty exception". Based on the identifier "3" of block C, the corresponding record in the cache is updated to {3: "Input field empty exception"}.
[0102] Thus, when it is necessary to obtain the detection result of the second block or to detect the second block, we can first check whether the detection result of the block already exists in the cache; if it exists in the cache, we can directly use these results, avoiding repeated detection, thereby saving time and computing resources. This not only speeds up the anomaly detection and localization, but also optimizes resource usage and supports rapid program iteration and maintenance.
[0103] In other embodiments, the second block includes a first input field, see [link to relevant documentation]. Figure 5 , Figure 5 This is a schematic diagram of the third process of the detection method for programming blocks provided in the embodiments of this application. Anomaly detection is performed on each second block to obtain the first detection result. This can be achieved through the following steps 1031B to 1032B, which are described in detail below.
[0104] In step 1031B, for each second block, input anomaly detection is performed on the first input field of the second block.
[0105] In step 1032B, if the first input field is empty, a first detection result indicating that there is an input anomaly in the second block is obtained.
[0106] Here, the first input field is used to input the first parameter, which includes variables, values, etc. Correspondingly, input anomaly detection of the first input field in the second block can be achieved in the following way: when the input type of the first input field is value input or variable selector input, detect whether the first parameter is input through value input or variable selector, and if the first parameter is not input, determine that the first input field is empty, that is, there is an input field empty anomaly.
[0107] It should be noted that an empty input field exception means that an input field of a block, especially those designed to connect to other blocks, is not connected to any blocks or has not been assigned any valid value.
[0108] As an example, see Figure 6 , Figure 6 This is a schematic diagram of the first anomaly provided in the embodiments of this application. Figure 6 The second block 601 shown is assumed to contain a variable selector input 602 and a value input 603. Since there is no corresponding first parameter input at either variable selector input 602 or value input 603, it can be determined that there is an error in the second block 601 where the input field is empty, and an exclamation mark is displayed to prompt the user that the parameter input at this location is currently empty.
[0109] When the input type of the first input field is a concatenated input, it is checked whether the first input field is connected to a parameter block associated with the first parameter (i.e., the first parameter required for the first input field is input through the parameter block). If the first input field is not connected to a parameter block, it is determined that the first input field is empty, that is, there is an error that the input field is empty.
[0110] Here, a connection type input refers to the input used to receive output from other blocks, ensuring that data or instructions are passed from one block to another. Accordingly, when the input type of the first input field is a connection type input, it is checked whether each connection type input field has been correctly connected to the corresponding parameter block. If a connection type input field is not connected to any parameter block, it is determined that the first input field is empty, that is, there is an input field empty exception. An exception prompt can be displayed to the user, indicating that the input field is not correctly connected.
[0111] As an example, when performing input anomaly detection on the second block (i.e., detecting whether there is an anomaly in the input of the second block), all input fields of the second block can be obtained. These input fields are the interfaces used to receive external data or interact with other blocks during the block design. Then, each obtained input field is checked one by one to see if there is a block connected to the current second block, that is, to determine whether the output of other blocks is connected to the input field. If there is no block connected to the input field, it is determined that the first input field is empty, that is, there is an input field empty anomaly.
[0112] In this way, by identifying and alerting developers or users to empty input fields before program execution, the robustness of the program and the user experience are improved, ensuring the completeness and correctness of program input and avoiding program errors or abnormal behavior caused by missing necessary parameters. Furthermore, it facilitates the automation of exception detection and debugging, making the programming environment more user-friendly and efficient, ensuring correct program execution and improving development efficiency.
[0113] In some embodiments, the second building block includes a second input field for inputting a second parameter. Accordingly, anomaly detection is performed on each second building block to obtain a first detection result, which can be achieved in the following manner: for each second building block, if the second parameter has been input into the second input field, determine the preset type and the actual type of the second parameter; perform type anomaly detection on the second parameter based on the preset type and the actual type; if the actual type is inconsistent with the preset type, obtain a first detection result indicating that the second building block has a type anomaly.
[0114] It should be noted that, if the second parameter has been entered into the second input field, you can further check whether the actual type of the entered second parameter matches the preset type.
[0115] As an example, when performing type anomaly detection on the second block (i.e., detecting whether the type of the second block is abnormal), a type check function can be called for the input second parameter. Its function is to compare whether the actual type of the input parameter is consistent with the preset expected type of the block. Specifically, if the check result shows a mismatch, that is, the actual type of the input second parameter is inconsistent with the preset type, a first detection result indicating that the second block has a type anomaly is obtained.
[0116] In this way, by implementing the above-mentioned anomaly detection methods, it can be ensured that each parameter in the block programming environment conforms to its expected data type, thereby improving the reliability and stability of the program, reducing the possibility of program crashes or abnormal behavior, and thus providing a smoother and more reliable user experience.
[0117] In some embodiments, anomaly detection is performed on each second block to obtain a first detection result, which can be achieved by: performing a legality check on each second block; and obtaining a first detection result indicating that the second block is illegal if the second block is illegal.
[0118] Here, validity checking is a verification process designed to ensure that data, operations, or configurations conform to established rules, standards, or expected formats. It typically involves checking the data type of variables, the range of values, the correctness of the input format, and whether the code follows specific programming conventions.
[0119] In this embodiment, the validity check of the second building block can be implemented in the following ways: performing at least one of the following validity checks on the second building block: performing a usability check on the second building block to determine that the second building block is invalid if it is disabled; performing a connection validity check on the second building block to determine that the second building block is invalid if the connection method of the second building block is incorrect, or if the second building block and the building block connected to it are incompatible; performing a value validity check on the third input field in the second building block to determine that the second building block is invalid if the third parameter entered in the third input field is invalid; performing a structure validity check on the second building block to determine that the second building block is invalid if the loop structure associated with the second building block is incorrect or the branch structure associated with the second building block is incomplete; and performing a syntax validity check on the second building block to determine that the second building block is invalid if the programming code corresponding to the second building block does not conform to the preset syntax rules.
[0120] It should be noted that usability testing refers to detecting whether a second block is disabled. Because some second blocks are unsuitable in specific contexts or to restrict user operations, they need to be disabled. If a second block is disabled, it cannot be placed in the workspace, or its function cannot be executed within the workspace. Connection validity testing checks whether the connections between second blocks are valid, such as whether all inputs are correctly connected to outputs, and whether the connected block types are compatible. Value validity testing checks whether the third parameter entered in the third input field is valid. Detecting the validity of the third parameter includes checking whether the input value is valid and whether the variable value is valid. Input value validity checks whether the values in the input fields are valid, such as whether numeric inputs are within the expected range or whether string inputs meet the format requirements. Variable value validity checks whether the variable selector has selected a valid variable or whether a new variable has been correctly created. Structure validity checks include loop detection and branch integrity checks. Loop detection checks for circular references or incorrect loop structures in the program associated with the second block, while branch integrity checks check the completeness of conditional branches associated with the second block, such as whether each if-else structure has a corresponding branch block. Syntax validity checks check whether the generated code for the programming code corresponding to the second block conforms to the syntax rules of the preset language.
[0121] As an example, let's consider a second block that calculates the sum of two numbers, containing two input fields and one output field. In usability detection, if a user attempts to use a disabled block—for example, due to a software update or configuration issue—it will be deemed invalid and grayed out in the user interface, making it unusable. In connection validity detection, if a user connects a block with a string output to an input field of the second block, but that input field expects a number, an incompatible block type will be detected, the second block will be deemed invalid, a "type mismatch" message will be displayed, and the connection will be blocked. The detection algorithm will mark the block as invalid. In value validity detection, if a user enters an invalid value in the third input field of the second block... For example, if a negative number is entered, but the field expects a non-negative number, the input value will be detected as invalid, the second block will be determined to be invalid, and the error message "Input value must be non-negative" will be displayed, marking the block as invalid. In the structure validity check, if the user creates a loop structure in the second block, but the loop condition is always true, resulting in an infinite loop, the loop structure will be detected as incorrect, the second block will be determined to be invalid, and the error message "Infinite loop risk" will be displayed, marking the block as invalid. In the syntax validity check, if there is a syntax error in the programming code corresponding to the second block, such as missing necessary parentheses or keywords, the code will be detected as not conforming to the preset syntax rules, the second block will be determined to be invalid, and the error message "Syntax error: missing parentheses" will be displayed, marking the block as invalid.
[0122] In this way, by comprehensively implementing usability, connectivity, value, structure, and syntax validity checks, a comprehensive verification is provided for the building blocks in the programming environment, ensuring the correct use of the building blocks and the integrity of the program structure. This allows for the identification and correction of potential exceptions in the early stages, enhancing the stability and reliability of the program, improving development efficiency, and ensuring the high quality of the final software product.
[0123] As another example, the programming block detection method provided in this application embodiment can also be applied to game editors, such as game map editors, where users can design the interaction logic of game maps using visual programming blocks. For example, a user might want to design a level where a timed task is triggered when a player enters a specific area, an animation plays upon completion of the task, and a failure event is triggered when time runs out. During this process, the legality of the blocks placed by the user is checked. The user places a "trigger area" block in the editor to detect whether the player has entered a certain area. Next, the user connects the "trigger area" block to a "timed task" block to start a countdown. The "timed task" block is the second block, and at this point, the legality of the "timed task" block is checked.
[0124] When performing availability checks on the "Timed Task" block, it checks whether the block is disabled. For example, if the block's functionality is not yet unlocked or is not supported in the current version, the user will be prompted that the block is unavailable. When performing connection validity checks on the "Timed Task" block, it verifies whether the connection between the "Trigger Area" block and the "Timed Task" block is correct. If the output type of the "Trigger Area" block does not match the input type of the "Timed Task" block (e.g., the output is a boolean value, but the input requires an integer), a connection error will be indicated. When performing value validity checks on the "Timed Task" block, it checks whether the value of the "Timed Task" block is valid. Input parameters, such as whether the countdown time is positive, will prompt an invalid input value if the user enters a negative number or an illegal character. When performing structural validity checks on the "Timed Task" block, the logical structure of the "Timed Task" block will be checked for completeness. For example, if the user has not correctly set the branch logic for task completion or failure (such as missing the "Task Completed" or "Time Expired" branch), an incomplete structure will be prompted. When performing syntax validity checks on the "Timed Task" block, the logic of the "Timed Task" block will be converted into code and checked for compliance with preset syntax rules. If there are syntax errors in the code, the user will be prompted to correct them.
[0125] In this way, through the above legality checks, potential errors can be detected and alerted to users in real time, helping them to quickly correct them and ensuring the correctness of the map logic and the smoothness of the game.
[0126] In step 104, based on the first detection result, the second detection result of the block assembly is determined.
[0127] Here, after performing anomaly detection on multiple second blocks, the first detection result corresponding to each second block can be used. Since the block combination includes the first block as the starting point of programming and multiple second blocks, the first detection result corresponds to the second detection result. Based on the first detection result, the second detection result of the block combination can be determined.
[0128] In some embodiments, if the first detection result indicates that there is an abnormal second block among the plurality of second blocks, a second detection result indicating that there is an abnormality in the block combination is obtained.
[0129] It is understandable that each second block has a unique identifier, and each block combination has a unique identifier. Therefore, when the first detection result indicates that there is an abnormal second block among multiple second blocks, the second detection result of the block combination can be determined to be abnormal based on the mapping relationship between the unique identifier of the abnormal second block and the unique identifier of the block combination it belongs to.
[0130] As an example, for a block combination A, its unique identifier is A123, which contains two second blocks with unique identifiers B456 and B789 respectively. After performing anomaly detection on these second blocks, the first detection result shows that the second block B789 is abnormal. For example, the loop condition is set incorrectly, resulting in an infinite loop. Since the second block B789 is part of the block combination A, based on the mapping relationship between its unique identifier and the combination identifier, it can be determined that the second detection result of the block combination A is abnormal.
[0131] In this way, the above methods can quickly identify and focus on the abnormal block combination areas in the program, thereby improving the efficiency of problem diagnosis and repair, ensuring the overall stability and reliability of the program, reducing debugging time, and improving the efficiency of software development and maintenance.
[0132] In some embodiments, after determining the second detection result of the block combination, if the block combination changes, anomaly detection is performed on the second block in the block combination that has changed. The type of change includes at least one of the following: a change in the number of second blocks, a change in the type of second blocks, or a change in the connection relationship between multiple second blocks.
[0133] Here, changes in the number of second blocks can include adding new blocks to connect to, which increases the number of second blocks, or deleting blocks to connect to, which decreases the number of second blocks. For changes in the number of second blocks, i.e., when there are new or deleted blocks to connect to, it is necessary to re-perform anomaly detection for the block combination containing the new or deleted blocks to connect to, and update the hash table storing the detection status of the first blocks according to the detection results. Similarly, for changes in the type of second blocks or changes in the connection relationships between multiple second blocks, it is also necessary to re-perform anomaly detection for the block combination containing the changed blocks.
[0134] It should be noted that when a user performs a corresponding operation on a block, a corresponding event is generated. The event contains a snapshot before the change and a snapshot after the change. The snapshot before the change records the state of the work area before the change occurs, including the position and connection relationship of all blocks. The snapshot after the change records the state of the work area after the change occurs, also including the position and connection relationship of blocks. Therefore, based on the snapshots before and after the change, the second block that has changed can be identified. Based on the identifier of the second block that has changed, the block combination to which it belongs can be determined, and the block combination can be re-detected for anomalies.
[0135] The workspace refers to the virtual space where users build and program using blocks. It allows users to construct program logic by dragging, dropping, connecting, and configuring various blocks. The workspace changes dynamically as blocks are added, deleted, moved, or reconnected, and can contain multiple top-level blocks and nested blocks to form complex program structures. The state of the workspace reflects the complete blueprint of the current program, including the configuration of all blocks and the connection relationships between them.
[0136] As an example, consider two block combinations: Block Combination A and Block Combination B, which are used to perform different functions. Block Combination A has a unique identifier of A123, and Block Combination B has a unique identifier of B456. Initially, Block Combination A contains second blocks B1 and B2, and Block Combination B contains second blocks B3 and B4. During editing, the user performs the following operation: the user deletes second block B2 from Block Combination A and connects it to second block B3 in Block Combination B. This operation reduces the number of second blocks in Block Combination A and increases the number of second blocks in Block Combination B. These operations trigger events containing snapshots before and after the change. The snapshots before the change recorded the positions and connections of all blocks in block combination A and block combination B. The snapshots after the change recorded the state of block combination A after deleting B2 and the state of block combination B after adding the connection. Based on these snapshots, it was identified that block B2 was deleted from block combination A and that a connection between blocks B2 and B3 was added to block combination B. Then, anomaly detection was performed again on block combination A and block combination B. The detection results showed that block combination A functioned normally after deleting block B2, and block combination B did not show any anomalies after adding the connection. Finally, based on the identifiers of the first and second blocks, these detection results were updated in the hash table storing the detection state of the first block.
[0137] In this way, when the workspace changes, it is not necessary to re-detect the anomaly across the entire workspace. Only the block combination containing the changed second block needs to be detected. Using this localized anomaly detection strategy saves time and computing resources, improves the efficiency and response speed of anomaly detection, and allows users to get feedback faster and continue their programming work. It also reduces the system load and optimizes performance.
[0138] It should be noted that a work area can contain multiple block combinations. For all block combinations in the work area, the methods described in steps 101 to 104 above can be performed to perform anomaly detection.
[0139] As an example, when performing anomaly detection on all blocks in the workspace, an array of all top-level blocks in the workspace can be obtained. Top-level blocks refer to blocks that are not connected to other blocks, i.e., they have no parent blocks and are located directly at the top of the workspace. They are usually used as the starting point of the program or independently executed operations. They can trigger events, execute commands, or initialize variables and are the foundation for building the program structure. Then, based on the order in which the top-level blocks appear in the obtained array, anomaly detection is performed on the block combinations to which they belong.
[0140] Thus, by applying the above embodiments of this application, the program logic built by the user can be strictly verified before execution in the programming environment, which can prevent the program from encountering exceptions during runtime, improve the stability and reliability of program execution, minimize interference with the user's programming process, and ensure the comprehensiveness of detection. In addition, the introduced caching technology can store detection results, reduce duplicate detection, and thus improve detection efficiency.
[0141] The following will describe an exemplary application of the embodiments of this application in a real-world application scenario.
[0142] Visual programming tools are widely used in education and development, offering rich functionality and flexibility. However, due to the high flexibility in combining and configuring blocks, users may encounter logical errors or misconfigurations during the assembly process.
[0143] During implementation, the applicant discovered the following problems with the relevant technology for detecting programming blocks:
[0144] The block programming environment does not provide a built-in block anomaly detection mechanism, and there are still some limitations in block anomaly detection. Users find it difficult to quickly locate the specific block that is malfunctioning and need to spend more time and effort to check them one by one, resulting in low debugging efficiency.
[0145] Based on this, this application provides a depth-first search algorithm for error input checking. This algorithm uses a shared stack to store the blocks to be checked, including the current block and its child blocks. This ensures that anomalies in the current workspace are detected in a depth-first order and then categorized and summarized. See [link to relevant documentation]. Figure 7 , Figure 7 This is a schematic diagram illustrating an input error provided in an embodiment of this application. Figure 7The system includes three types of exceptions, which are categorized and summarized according to different trigger groups. Here, the trigger group corresponds to the workspace mentioned above. A workspace is defined as a trigger group, and users can switch between different trigger groups. During the switching process, the system will delete the blocks in the old workspace and load the blocks in the new workspace. In trigger group 701, there are exceptions corresponding to the trigger "When the game starts" and the trigger "When the sky environment changes". Here, the trigger is the specific function of the trigger block, which is the first block mentioned above. In trigger group 702, there is an exception corresponding to the trigger "When a signal is received". In this way, input errors can be detected in real time in the block programming environment, that is, exception detection can be performed in real time, thereby effectively improving programming efficiency and accuracy and providing a better user experience.
[0146] The following section will continue to describe the detection method for programming blocks provided in the embodiments of this application from a technical perspective.
[0147] See Figure 8 , Figure 8 This is a schematic diagram of the fourth process of the programming block detection method provided in the embodiments of this application, which will be combined with Figure 8 The steps shown illustrate the top-level block anomaly detection method provided in the embodiments of this application.
[0148] In step 801, anomaly detection begins.
[0149] It should be noted that in the block programming environment, a workspace is defined as a trigger group. A trigger group contains multiple triggers, which are the first blocks mentioned above. The trigger is the function of the trigger block and is the starting point for code execution. Multiple trigger blocks can exist simultaneously within the same trigger group. A trigger block can connect to multiple blocks used to implement other logic in the program, which are the multiple second blocks mentioned above.
[0150] Here, an empty hash table needs to be initialized to store the error state of each trigger, i.e., the detection state mentioned above. Error states include empty input error, value type error, and disabled error, etc. An empty stack is also initialized to store the blocks to be detected. The key in the hash table can be the identifier of the trigger to mark the uniqueness of each trigger. The value in the hash table can be a boolean value, True or False, to indicate whether the trigger has an exception. For example, True indicates that the trigger has an exception, and False indicates that the trigger does not have an exception. The value in the hash table can also be a more complex data structure, such as an object or array, to store more detailed information about the exception, such as exception type, exception location, exception description, etc.
[0151] Each trigger group has a unique identifier, each trigger has a unique identifier, and each block has a unique identifier. The identifier of a trigger is associated with the identifier of the trigger group to which it belongs, and the identifier of a block is associated with the identifier of the trigger to which the block corresponds.
[0152] Thus, initializing an empty hash table to store the error state of each trigger allows for quick access and updating of the current error information for each trigger block, facilitating real-time detection and response to errors in the programming environment. Simultaneously, initializing an empty stack to store the blocks to be detected ensures the algorithm can detect and traverse all blocks in the correct order. This combination of data structures not only improves the efficiency of error detection but also optimizes the program's execution flow, making the error detection process more systematic and automated.
[0153] In step 802, the top-level block array is obtained.
[0154] In the block programming environment, obtaining the top-level block array typically involves using an Application Programming Interface (API) to access all top-level blocks in the workspace. Top-level blocks refer to those blocks that are not contained or nested by other blocks, i.e., the trigger blocks or first blocks mentioned above. They are the starting point or independently executed modules in the program structure. They are located directly at the top level of the workspace and can access the workspace object in the block programming environment to obtain the array of top-level blocks, returning all top-level blocks in the current workspace.
[0155] In step 803, the top-level block array is traversed.
[0156] Here, after obtaining the top-level block array, the obtained top-level block array is pushed onto the stack in the order in which the top-level blocks appear in the array, and a block is popped to execute the exception detection method in steps 804 to 809.
[0157] In step 804, check if there are any connected blocks.
[0158] Here, you can get all the inputs to the blocks and then check if there are any connected blocks for each input.
[0159] In step 805, for connected blocks, check if the value input type matches.
[0160] If the input has connected blocks, for connected blocks, check if the type of the input value matches the expected value type.
[0161] In step 806, a type mismatch occurs, indicating an input type error.
[0162] Here, it is possible to detect whether the input value type matches. If the type of the input value does not match the expected value type, it is determined that the block has an input type error. Based on the block's identifier, the associated trigger can be found and the error status of the trigger in the trigger group can be updated.
[0163] In step 807, there is no connected block, indicating a blank input error.
[0164] If the input has no connected blocks, the algorithm will determine that there is an empty input error. Based on the block's identifier, it can find the associated trigger and update the trigger's error status in the trigger group.
[0165] In step 808, it is checked whether it is disabled.
[0166] In step 809, it was disabled, and a disable error occurred.
[0167] It should be noted that the execution order of steps 804 and 808 is not important. Checking whether it is disabled can detect whether an input block of the block is connected to a disabled block. If the block is disabled, there is a disable error. Based on the block's identifier, the associated trigger can be found and the error status of the trigger in the trigger group can be updated.
[0168] As an example, see Figure 9 , Figure 9 This is a second abnormality diagram provided in the embodiment of this application. When the input block in block 901 is connected to a disabled block, the color of block 901 can be changed to prompt the user that there is a disabled error in the block.
[0169] It should be noted that when an anomaly is detected in the top-level block, the anomaly detection for the current path is immediately stopped, and the process backtracks to the previous node. That is, further anomaly detection for the current top-level block is stopped, and blocks are popped from the stack until the next top-level block is popped, and anomaly detection continues. When no anomaly is detected in the top-level block, all child blocks of that top-level block are pushed onto the stack in the order of their connections, and then popped off one by one using the methods in steps 804 to 809 for anomaly detection. When an anomaly is detected in a child block, the detection for the current path is immediately stopped, and the process backtracks to the previous node. That is, further anomaly detection for the current block is stopped, and blocks are popped from the stack until the next top-level block is popped, and anomaly detection continues. When no anomaly is detected in a child block, the process backtracks to its parent block, that is, blocks are popped from the stack until the next top-level block is popped, and anomaly detection continues. This process is repeated until the stack is empty, ensuring that all triggers have been detected.
[0170] In this way, the ability to identify and prompt empty input errors, input type errors, and disabled errors in real time greatly improves the efficiency and accuracy of programming through this automated error detection mechanism. It not only reduces the time users spend debugging, but also helps users quickly understand and correct errors through instant feedback, thereby lowering the barrier to entry for programming.
[0171] In some embodiments, within a block-based programming environment, see Figure 10 , Figure 10 This is a schematic diagram of the algorithm triggering provided in the embodiment of this application. When the user performs block operations such as connecting, disconnecting or deleting, an efficient localized anomaly detection strategy is adopted to detect only the blocks that have changed and their associated blocks, thereby avoiding a comprehensive inspection of the entire work area. Specifically, the state of the work area can be captured before and after the user's operation to form two snapshots before and after the change. By comparing these two snapshots, the blocks that have changed are determined, and anomaly detection is performed on the blocks that have changed and their associated blocks.
[0172] Thus, by adopting a localized anomaly detection strategy, input error detection is performed only on the changed blocks and their related blocks. By eliminating the unnecessary step of performing a full inspection of the entire workspace, and focusing on the parts most likely to cause errors, the efficiency of input error detection is significantly improved, the consumption of computing resources is reduced, and the speed of error detection is accelerated, allowing users to receive feedback and make corresponding adjustments more quickly.
[0173] In some embodiments, a hash table can be introduced as a cache to store and manage the error states of detected blocks, thereby optimizing performance. See [link to relevant documentation]. Figure 11 , Figure 11 This is a schematic diagram of the cache update process provided in the embodiments of this application, which will be combined with Figure 11 The steps shown illustrate how to update the cache.
[0174] In step 1101, a new error message is generated.
[0175] In step 1102, the cache is queried to determine whether the block identifier exists in the cache.
[0176] Here, during the input error detection, i.e. anomaly detection, error messages may be generated. Error messages can be generated by the top-level block or by the child blocks of the top-level block. When an error message exists in a block, the unique identifier of the block, such as the block's ID, is used as the key to query the cache in the form of a hash table to determine whether the error message of that block already exists.
[0177] In step 1103, if any, update the error information.
[0178] If the identifier for the block already exists in the cache, the error information associated with that key is updated, such as by modifying the error type, adding error details, or changing the error status. In this way, updating the error information ensures that the error information stored in the cache is up-to-date, thus reflecting the current error information status of the block.
[0179] In step 1104, if none exists, insert a new error.
[0180] If the identifier for the block does not exist in the cache, a new entry for the block is created in the cache, including using the block's identifier as the key and inserting the newly generated error information as the value into the hash table, thus ensuring that the error status of all blocks is recorded.
[0181] In step 1105, the process ends.
[0182] Thus, by employing the above caching strategies, redundant calculations can be significantly reduced, improving the efficiency of anomaly checking. When the state of a block changes, only the corresponding anomaly information in the cache needs to be updated, without needing to re-examine the entire workspace. This not only speeds up anomaly detection but also optimizes resource utilization, enabling smoother and more responsive operation in the block programming environment.
[0183] The following description continues to illustrate the exemplary structure of the programming block detection device 555 provided in the embodiments of the present invention as a software module. In some embodiments, such as... Figure 2 As shown, the software modules of the detection device 555 for programming blocks may include: a response module 5551, a construction module 5552, a first detection module 5553, and a determination module 5554.
[0184] The response module 5551 is used to respond to a block detection request and determine a block combination to be detected, the block combination including a first block as the starting point of programming and a plurality of second blocks associated with the first block for implementing programming logic.
[0185] The construction module 5552 is used to construct a hierarchical detection path for the block combination based on the connection relationship between the plurality of second blocks and the first block. The hierarchical detection path includes multiple levels, and each level corresponds to one second block.
[0186] The first detection module 5553 is used to perform anomaly detection on each of the second blocks, starting from the bottom block in the hierarchical detection path and working upwards, to obtain a first detection result.
[0187] The determination module 5554 is used to determine a second detection result of the block assembly based on the first detection result.
[0188] In some embodiments, the construction module 5552 is further configured to initialize a hash table and a stack, wherein the hash table is used to store the detection status of the first building block, the detection status is used to indicate at least one of the first detection result of each second building block and the second detection result of the building block combination, and the stack is used to store each second building block to be detected; based on the connection relationship between the plurality of second building blocks, for any two connected second building blocks, the second building block connected above is the parent building block and the second building block connected below is the child building block, and each second building block is pushed into the stack in the order of the parent building block first and the child building block last; the pop-out order of the stack for each pushed second building block is determined, and a hierarchical detection path of the building block combination is constructed based on the pop-out order of each second building block; wherein, in the hierarchical detection path, for two second building blocks with adjacent pop-out orders, the second building block with the later pop-out order is the parent building block of the second building block with the earlier pop-out order; the bottom building block in the hierarchical detection path is the second building block with the earliest pop-out order.
[0189] In some embodiments, the first detection module 5553 is further configured to perform anomaly detection on the bottom-level block in the hierarchical detection path to obtain a first detection result for the bottom-level block; if the first detection result of the bottom-level block indicates that the bottom-level block does not have an anomaly, perform anomaly detection on the third block in the second block that is the upper-level block of the bottom-level block to obtain a first detection result for the third block; if the first detection result of the third block indicates that the third block does not have an anomaly and the third block is associated with multiple other child blocks, perform anomaly detection on the other child blocks associated with the third block according to the push order of the other child blocks associated with the third block in the stack to obtain a first detection result for the other child blocks associated with the third block; if the first detection result of the third block indicates that the third block has an anomaly, or if the first detection result of the other child blocks associated with the third block indicates that the other child blocks associated with the third block do not have an anomaly, backtrack to the parent block of the third block to perform anomaly detection on the other child blocks associated with the parent block of the third block.
[0190] In some embodiments, the construction module 5552 is further configured to, when the first detection result indicates that the corresponding second block is abnormal, set the detection status of the first block in the hash table to indicate the detection status of the first detection result; or, determine the abnormality type of the abnormal second block and store the block identifier of the abnormal second block and the abnormality type in the hash table.
[0191] In some embodiments, the second building block includes a first input field, and the first detection module 5553 is further configured to perform input anomaly detection on the first input field in each of the second building blocks; and to obtain a first detection result indicating that there is an input anomaly in the second building block when the first input field is empty.
[0192] In some embodiments, the first input field is used to input a first parameter. The first detection module 5553 is further used to detect whether the first parameter is input through the value input or the variable selector when the input type of the first input field is value input or variable selector input, and to determine that the first input field is empty when the first parameter is not input; and to detect whether the first input field is connected to a parameter block associated with the first parameter when the input type of the first input field is connection type input, and to determine that the first input field is empty when the first input field is not connected to the parameter block.
[0193] In some embodiments, the second building block includes a second input field for inputting a second parameter. The first detection module 5553 is further configured to, for each of the second building blocks, determine a preset type and an actual type of the second parameter when the second parameter has been input to the second input field; perform type anomaly detection on the second parameter based on the preset type and the actual type; and obtain a first detection result indicating that the second building block has a type anomaly when the actual type is inconsistent with the preset type.
[0194] In some embodiments, the first detection module 5553 is further configured to perform a legality detection on each of the second building blocks; and if the second building block is invalid, obtain a first detection result indicating that the second building block is invalid.
[0195] In some embodiments, the first detection module 5553 is further configured to perform at least one of the following validity checks on the second building block: perform an availability check on the second building block to determine that the second building block is invalid if the second building block is disabled; perform a connection validity check on the second building block to determine that the second building block is invalid if the connection method of the second building block is incorrect, or if the second building block and the building block connected to the second building block are incompatible; perform a value validity check on the third input field in the second building block to determine that the second building block is invalid if the third parameter input in the third input field is invalid; perform a structure validity check on the second building block to determine that the second building block is invalid if the loop structure associated with the second building block is incorrect or the branch structure associated with the second building block is incomplete; and perform a syntax validity check on the second building block to determine that the second building block is invalid if the programming code corresponding to the second building block does not conform to a preset syntax rule.
[0196] In some embodiments, the determining module 5554 is further configured to obtain a second detection result indicating that the block combination is abnormal when the first detection result indicates that there is an abnormal second block among the plurality of second blocks.
[0197] In some embodiments, the detection device for the programming blocks further includes: a second detection module, configured to, after determining a second detection result of the block combination, perform anomaly detection on the second block in the block combination that has changed when the block combination changes; wherein the type of change includes at least one of the following: a change in the number of the second blocks, a change in the type of the second blocks, or a change in the connection relationship between the plurality of second blocks.
[0198] This application provides a computer program product, which includes a computer program or computer-executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the electronic device to perform the programming block detection method described above in this application.
[0199] This application provides a computer-readable storage medium storing computer-executable instructions or a computer program. When the computer-executable instructions or the computer program are executed by a processor, the processor will execute the detection method for programming blocks provided in this application. For example, ... Figure 3A , Figure 3B The methods shown are as follows.
[0200] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.
[0201] In some embodiments, computer-executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.
[0202] As an example, computer-executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files that store one or more modules, subroutines, or code sections).
[0203] As an example, computer-executable instructions can be deployed to execute on a single electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.
[0204] In summary, the embodiments of this application define a block combination including a first block and multiple associated second blocks. Based on the connection relationships between the second blocks and the first block, a hierarchical detection path is constructed. Starting from the bottom block of the path, anomalies in each second block are detected level by level upwards to obtain preliminary detection results. Based on the preliminary detection results, the final detection result of the entire block combination is determined. In this way, anomalies in the block combination can be detected and located in real time, effectively improving programming efficiency and accuracy, reducing debugging time and costs, and helping users better understand and master the relationships and functions between blocks, thereby improving programming efficiency and quality and enhancing user experience.
[0205] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A method for detecting programming blocks, characterized in that, The method includes: In response to a block detection request, a block combination to be detected is determined, the block combination including a first block as the starting point of programming and a plurality of second blocks associated with the first block for implementing programming logic; Based on the connection relationship between the multiple second building blocks and the first building block, a hierarchical detection path for the building block combination is constructed. The hierarchical detection path includes multiple levels, with one level corresponding to one second building block. Starting from the bottom block in the hierarchical detection path, anomaly detection is performed on each of the second blocks, and a first detection result is obtained. Based on the first detection result, a second detection result for the block assembly is determined.
2. The method according to claim 1, characterized in that, The construction of the hierarchical detection path for the block combination based on the connection relationships between the plurality of second blocks and the first block includes: Initialize a hash table and a stack, wherein the hash table is used to store the detection status of the first building block, the detection status is used to indicate at least one of the first detection result of each second building block and the second detection result of the building block combination, and the stack is used to store each second building block to be detected; Based on the connection relationship between the multiple second blocks, for any two connected second blocks, the second block connected above is the parent block and the second block connected below is the child block, and each second block is pushed into the stack in the order of pushing the parent block first and the child block last. The pop-out order of each of the pushed second blocks in the stack is determined, and a hierarchical detection path of the block combination is constructed based on the pop-out order of each of the second blocks; wherein, in the hierarchical detection path, the second block with the later pop-out order is the parent block of the second block with the earlier pop-out order; the bottom block in the hierarchical detection path is the second block with the earliest pop-out order.
3. The method according to claim 2, characterized in that, The process of performing anomaly detection on each of the second blocks, starting from the bottom block and proceeding upwards in the hierarchical detection path, to obtain a first detection result includes: For the bottom-level block in the hierarchical detection path, anomaly detection is performed on the bottom-level block to obtain the first detection result of the bottom-level block; If the first detection result of the bottom-level building block indicates that there is no abnormality in the bottom-level building block, an abnormality detection is performed on the third building block, which is the upper-level building block of the bottom-level building block in the second building block, and the first detection result of the third building block is obtained. If the first detection result of the third building block indicates that the third building block is not abnormal and the third building block is associated with multiple other sub-building blocks, the other sub-building blocks associated with the third building block are subjected to abnormal detection according to the pushing order of the other sub-building blocks associated with the third building block in the stack, and the first detection result of the other sub-building blocks associated with the third building block is obtained. If the first detection result of the third building block indicates that the third building block is abnormal, or if the first detection result of the other child building blocks associated with the third building block indicates that the other child building blocks associated with the third building block are not abnormal, the detection process is backtracked to the parent building block of the third building block to perform anomaly detection on the other child building blocks associated with the parent building block of the third building block.
4. The method according to claim 3, characterized in that, The method further includes: If the first detection result indicates that the corresponding second block is abnormal, the detection status of the first block in the hash table is set to indicate the detection status of the first detection result; Alternatively, determine the anomaly type of the second block that is abnormal, and store the block identifier of the second block that is abnormal and the anomaly type in the hash table.
5. The method according to claim 1, characterized in that, The second building block includes a first input field, and the step of performing anomaly detection on each of the second building blocks to obtain a first detection result includes: For each of the second building blocks, input anomaly detection is performed on the first input field in the second building block; If the first input field is empty, a first detection result indicating that there is an input anomaly in the second block is obtained.
6. The method according to claim 5, characterized in that, The first input field is used to input a first parameter, and the step of performing input anomaly detection on the first input field in the second block includes: If the input type of the first input field is value input or variable selector input, it is detected whether the first parameter is input through the value input or the variable selector, and if the first parameter is not input, it is determined that the first input field is empty; If the input type of the first input field is a concatenated input, it is detected whether the first input field is connected to the parameter block associated with the first parameter, and if the first input field is not connected to the parameter block, it is determined that the first input field is empty.
7. The method according to claim 1, characterized in that, The second building block includes a second input field for inputting a second parameter, and the step of performing anomaly detection on each of the second building blocks to obtain a first detection result includes: For each of the second building blocks, if the second parameter has been input into the second input field, determine the preset type and the actual type of the input of the second parameter; Based on the preset type and the actual type, type anomaly detection is performed on the second parameter; When the actual type is inconsistent with the preset type, a first detection result indicating that the second building block has a type anomaly is obtained.
8. The method according to claim 1, characterized in that, The step of performing anomaly detection on each of the second building blocks to obtain a first detection result includes: For each of the second building blocks, a legality check is performed on the second building block; If the second block is invalid, a first detection result indicating that the second block is invalid is obtained.
9. The method according to claim 8, characterized in that, The legality check of the second building block includes: Perform at least one of the following validity checks on the second building block: Availability testing is performed on the second building block to determine that the second building block is invalid if it is disabled. The connection validity of the second building block is checked to determine that the second building block is invalid if the connection method of the second building block is incorrect or if the second building block and the building block connected to the second building block are incompatible. The third input field in the second block is subjected to a value validity check, so that if the third parameter entered in the third input field is invalid, the second block is determined to be invalid; The second building block is subjected to a structural legality check to determine that the second building block is invalid if the loop structure associated with the second building block is incorrect or the branch structure associated with the second building block is incomplete. The second block is subjected to a syntax validity check to determine that the second block is invalid if the programming code corresponding to the second block does not conform to the preset syntax rules.
10. The method according to claim 1, characterized in that, The step of determining the second detection result of the block assembly based on the first detection result includes: If the first detection result indicates that there is an abnormal second block among the plurality of second blocks, a second detection result indicating that there is an abnormality in the block combination is obtained.
11. The method according to claim 1, characterized in that, After determining the second detection result of the block assembly, the method further includes: In the event of a change in the block combination, an anomaly detection is performed on the second block in the block combination that has changed. The types of changes include at least one of the following: changes in the number of the second building blocks, changes in the type of the second building blocks, and changes in the connection relationships between the plurality of second building blocks.
12. A detection device for programming blocks, characterized in that, The device includes: A response module is used to respond to a block detection request and determine a block combination to be detected, the block combination including a first block as the starting point of programming and multiple second blocks associated with the first block for implementing programming logic; A construction module is used to construct a hierarchical detection path for the block combination based on the connection relationship between the plurality of second blocks and the first block. The hierarchical detection path includes multiple levels, with one level corresponding to one second block. The first detection module is used to perform anomaly detection on each of the second blocks from the bottom block in the hierarchical detection path upwards, and obtain a first detection result; The determining module is used to determine a second detection result of the block assembly based on the first detection result.
13. An electronic device, characterized in that, The electronic device includes: Memory is used to store executable instructions or computer programs. A processor, when executing computer-executable instructions or computer programs stored in the memory, implements the detection method for programming blocks according to any one of claims 1 to 11.
14. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, the method for detecting programming blocks according to any one of claims 1 to 11 is implemented.
15. A computer program product comprising computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, the method for detecting programming blocks according to any one of claims 1 to 11 is implemented.