Robot-assisted programming method and system

By calculating the nesting complexity, repetition and error coefficient of the code, the programming quality index is generated, and only warning is made when the index is below the threshold, solving the problem of R&D cycle extension caused by unnecessary optimization in the existing technology, and improving the code quality and efficiency.

CN119025094APending Publication Date: 2024-11-26SHANGHAI WHALESBOT TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411045848.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

Existing robot-assisted programming methods will also issue early warnings and optimize codes when detecting problems that do not affect operation, resulting in an extended project development cycle.

Method used

By calculating the nested complexity, repetition and error coefficient of the code, a programming quality index is generated, and only warning prompts are made when the index is below the preset threshold, avoiding unnecessary code optimization.

Benefits of technology

It effectively reduces the project R&D cycle, improves the readability and maintainability of the code, and reduces unnecessary optimization steps.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025094A_ABST
    Figure CN119025094A_ABST
Patent Text Reader

Abstract

The invention relates to the field of programming, and discloses a robot-assisted programming method and system which are used for solving the problem that when codes are detected, early warning is carried out once unreasonableness is found, and consequently the project research and development period is prolonged. The method comprises the steps that the maximum nesting layer number in all nodes is found, nesting complexity is calculated, and the maximum nesting layer number is obtained by calculating a hash value; the method comprises the steps of finding out repeated segments, calculating the repetition degree of codes, calculating a code non-conciseness coefficient according to nesting complexity and the repetition degree of the codes, detecting a comprehensive efficiency coefficient of an algorithm in the codes, obtaining errors in the codes detected by a unit test, and calculating the importance of the errors in the positions according to information of the positions. A code error coefficient is obtained through calculation, the code non-conciseness coefficient, the comprehensive efficiency coefficient and the code error coefficient are subjected to weighted summation calculation to obtain a programming quality index, early warning prompt is carried out according to the programming quality index, and the research and development period of a project is effectively shortened.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of programming, and more specifically to a robot-assisted programming method and system. Background Art

[0002] Robot-assisted programming refers to the use of artificial intelligence and machine learning technologies to support developers in writing, optimizing and maintaining code through intelligent tools and platforms to improve development efficiency and code quality. These tools can provide functions such as intelligent code completion, error detection, automatic code generation, unit test generation, document generation, code refactoring and optimization, reduce developers' repetitive work, quickly locate and fix problems, improve code readability and maintainability, and promote team collaboration. This approach enables developers to focus on more creative programming tasks, improving overall development efficiency and software quality.

[0003] The existing robot-assisted programming method is to detect the robot code, and immediately issue a warning when the code is found to be unreasonable, prompting the programmer to make modifications. However, this auxiliary method will cause warnings to be issued and code to be re-optimized even when problems that do not affect operation occur, thereby extending the project development cycle.

[0004] In view of the above problems, the present invention proposes a solution. Summary of the invention

[0005] In order to overcome the above-mentioned defects of the prior art, the present invention provides a robot-assisted programming method and system to solve the problems existing in the above-mentioned background technology.

[0006] To achieve the above object, the present invention provides the following technical solutions:

[0007] The robot-assisted programming method comprises the following steps:

[0008] Use the parser to convert the code into an abstract syntax tree, traverse the AST nodes, record the number of nesting levels of each node, find the maximum number of nesting levels among all nodes as the number of nesting levels of the code, and calculate the nesting complexity. The calculation formula is: Among them C nest Expressed as nested complexity, L max is the maximum nesting level of the hypothesis, L is the nesting level of the code;

[0009] Divide the code into segments with a fixed number of lines, calculate hash values ​​for these segments, find repeated segments, and calculate the code repetition based on the repeated segments. The calculation formula is: Among them C dup It is expressed as the code repetition, R is the number of lines of repeated code, R 总 is the total number of lines of code;

[0010] The code unsophistication coefficient is obtained by taking the geometric mean of the nesting complexity and the code duplication. The calculation formula is: Where NC is the code unsophisticated coefficient, C nest Expressed as nested complexity, C dup It is expressed as the duplication of the code;

[0011] Traverse the AST nodes, identify the algorithms where the algorithms are located, detect the efficiency of each algorithm, and calculate the comprehensive efficiency coefficient;

[0012] The unit test detects errors in the code through the code analysis tool and locates its specific location. Based on the information of the location, the importance of the error in the location is calculated, and the importance of the detected errors is averaged to obtain the code error coefficient, which is calculated as follows: Where DC is the code error coefficient, IT i It is expressed as the importance of the ith error, and n is the number of errors in the code;

[0013] The programming quality index is calculated by weighted summing of the code unsophistication coefficient, comprehensive efficiency coefficient, and code error coefficient. The calculation formula is: Where PQ represents the programming quality index, NC represents the code unsophisticated coefficient, CE represents the comprehensive efficiency coefficient, DC represents the code error coefficient, a1, a2, a3 represent the weight coefficients of the code unsophisticated coefficient, the comprehensive efficiency coefficient and the code error coefficient;

[0014] Provide early warning prompts based on programming quality index.

[0015] Preferably, the steps of calculating hash values ​​for these fragments and finding repeated fragments are:

[0016] Split the code into fixed lines;

[0017] Standardize code snippets;

[0018] Calculate hash values ​​for each code snippet;

[0019] Duplicate code snippets are detected by comparing hash values, and code snippets with the same hash values ​​are selected as duplicate snippets.

[0020] Preferably, the steps of detecting the efficiency of each algorithm and calculating the comprehensive efficiency coefficient are:

[0021] Determine the time complexity and space complexity of each algorithm through theoretical analysis, actually measure the running time of each algorithm under different input scales, and measure the memory usage of each algorithm;

[0022] Calculate the time complexity of the algorithm, which is expressed as T(n) = O(f(n)), where T(n) represents the time complexity, that is, the running time of the algorithm, O(*) is the complexity algorithm, and f(n) represents the input size;

[0023] Calculate the algorithm space complexity, which is expressed as S(n) = O(g(n)), where S(n) represents the space complexity, that is, the memory usage of the algorithm, and g(n) represents the input size, that is, a function of n;

[0024] Select the time complexity of a benchmark algorithm, standardize the time complexity of each algorithm, and calculate the time complexity coefficient of the algorithm. The calculation formula is: in Expressed as the time complexity coefficient of algorithm i, T base (n) is the time complexity of the benchmark algorithm, T i (n) is the time complexity of algorithm i;

[0025] Select the space complexity of a benchmark algorithm, standardize the space complexity of each algorithm, and calculate the space complexity coefficient of the algorithm. The calculation formula is: in Expressed as the spatial complexity coefficient of algorithm i, S base (n) is the space complexity of the benchmark algorithm, S i (n) is the space complexity of algorithm i;

[0026] The comprehensive efficiency coefficient is calculated by the geometric mean, and the calculation formula is: Where CE is the comprehensive efficiency coefficient, Expressed as the time complexity coefficient of algorithm i, Expressed as the space complexity coefficient of algorithm i.

[0027] Preferably, the step of calculating the importance of the error in the position according to the information of the position is:

[0028] Define error types, error frequencies, code modules, impact scope, and modification costs;

[0029] Define a multidimensional importance vector for each code position Where E i is the error type of the ith error position, F i is the error frequency of the ith error position, M i is the importance of the code module where the i-th error location is located, I i is the influence range of the ith error position, C i is the modification cost of the i-th error position;

[0030] Use the minimum-maximum normalization method to convert each parameter value to the range of 0 to 1. The expression is: Where x' is the normalized parameter value, x is the original parameter value, and x min is the minimum value of the parameter in the data set, x max is the maximum value of the parameter in the data set;

[0031] The multidimensional vector is converted into a single scalar value, denoted as the error importance, using the Manhattan norm.

[0032] Preferably, the step of converting the multidimensional vector into a single scalar value using the Manhattan norm is:

[0033] Take the absolute value of each element in vector x and add all the absolute values ​​together to get a scalar value.

[0034] Preferably, the step of providing an early warning prompt according to the programming quality index is:

[0035] The programming quality index is compared with the preset threshold. If the programming quality index is greater than the preset threshold, the current code quality is determined to be good and no warning is issued. If the programming quality index is less than the preset threshold, the current code quality is determined to be poor and a warning is issued to remind programmers to optimize the code.

[0036] Preferably, the robot-assisted programming system comprises:

[0037] A code data acquisition module is used to collect relevant data in the robot programming code, including the number of code nesting levels, repeated codes, memory usage, and location information of error codes, and transmit the relevant data to the code data analysis module;

[0038] A code data analysis module is used to receive the relevant data transmitted by the code data acquisition module, analyze and obtain the code correlation coefficient, which includes the code unsophistication coefficient, the comprehensive efficiency coefficient and the code error coefficient, and transmit the code correlation coefficient to the code data evaluation module;

[0039] A code data evaluation module is used to receive the code correlation coefficient transmitted by the code data analysis module, and comprehensively evaluate to obtain a programming quality index, and transmit the programming quality index to the early warning module;

[0040] The early warning module is used to receive the programming quality index transmitted by the code data evaluation module and issue an early warning according to the programming quality index.

[0041] Technical effects and advantages of the present invention:

[0042] Find the maximum number of nested layers in all nodes and calculate the nesting complexity. By calculating the hash value, find the repeated fragments and calculate the code repetition. Calculate the code unsophistication coefficient based on the nesting complexity and the code repetition. Detect the comprehensive efficiency coefficient of the algorithm in the code. Get the errors in the code detected by the unit test. Calculate the importance of the error in the position based on the information of the position, and calculate the code error coefficient. Calculate the programming quality index by weighted summation of the code unsophistication coefficient, comprehensive efficiency coefficient and code error coefficient. Issue early warning prompts based on the programming quality index, effectively reducing the project's R&D cycle. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 It is the overall flow chart of the present invention. DETAILED DESCRIPTION

[0044] The technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the present invention. In addition, the forms of the various structures recorded in the following embodiments are merely illustrative, and the robot-assisted programming method and system involved in the present invention are not limited to the various structures recorded in the following embodiments. All other implementations obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0045] The present invention provides a robot-assisted programming method, comprising the following steps:

[0046] Use the parser to convert the code into an abstract syntax tree (AST), traverse the AST nodes, record the number of nesting levels of each node, find the maximum number of nesting levels among all nodes as the number of nesting levels of the code, and calculate the nesting complexity. The calculation formula is: Among them C nest Expressed as nested complexity, L max is the maximum number of nested levels assumed, L is the number of nested levels of the code, and the Abstract Syntax Tree (AST) is a tree data structure used to represent the abstract structure of source code in programming languages. It reflects the grammatical structure of the program, but does not contain specific grammatical details such as brackets or semicolons, but rather presents the structure and semantics of the code in an abstract way;

[0047] The maximum number of nesting levels can be used as one of the indicators to measure code complexity. Generally speaking, code structures with deeper nesting levels may be more difficult to understand and maintain, and may require further refactoring or optimization; deep nesting often leads to reduced readability and maintainability of the code. By analyzing the maximum number of nesting levels, the quality of the code can be evaluated, and possible problems can be identified and improved at an early stage; deep nesting may affect the execution efficiency of the code. In some cases, the performance of the code can be improved by reducing the number of nesting levels, especially for code segments that need to be executed frequently; based on the analysis results of the maximum number of nesting levels, the development team can consider code refactoring to simplify complex control flows and logical structures, thereby improving the readability and maintainability of the code.

[0048] Divide the code into segments with a fixed number of lines, calculate hash values ​​for these segments, find repeated segments, and calculate the code repetition based on the repeated segments. The calculation formula is: Among them C dup It is expressed as the code repetition, R is the number of lines of repeated code, R 总 is the total number of lines of code;

[0049] By calculating the code duplication, you can accurately identify and locate repeated fragments in the code. These repeated fragments may be caused by copying and pasting, lack of abstraction or improper design, which increases the maintenance cost and risk of the code base; repeated code fragments usually indicate design defects or implementation redundancy. High duplication may reduce the readability and maintainability of the code, and may also cause potential errors and consistency issues during updates.

[0050] In this embodiment, it should be specifically explained that the steps of calculating the hash values ​​of these fragments and finding the repeated fragments are as follows:

[0051] Split the code into fixed lines. The granularity of the split depends on the code structure and analysis requirements.

[0052] Before calculating the hash value, the code snippet is standardized, such as removing extra whitespace characters, comments, etc., to ensure that the same code in different formats is identified as duplicate code;

[0053] Calculate a hash value for each code snippet. The hash value maps the code snippet to a string of fixed length for easy comparison. The hash value (HashValue) maps input data of any length (such as a file, string) to an output value of fixed length (usually a large integer or a string of fixed length) through a hash function (HashFunction);

[0054] Duplicate code snippets are detected by comparing hash values, and code snippets with the same hash values ​​are screened out, which are duplicate snippets.

[0055] The code unsophistication coefficient is obtained by taking the geometric mean of the nesting complexity and the code duplication. The calculation formula is: Where NC is the code unsophisticated coefficient, C nest Expressed as nested complexity, C dup It is expressed as the duplication of the code;

[0056] Traverse the AST nodes, identify the functions or methods where the algorithms are located, detect the efficiency of each algorithm, and calculate the comprehensive efficiency coefficient;

[0057] By detecting and comparing the comprehensive efficiency of different algorithms, it is possible to determine which algorithm has better execution speed and resource utilization on a given problem and data set. This helps developers choose the best algorithm to optimize the performance of the program, especially in scenarios that require processing big data or real-time computing; the comprehensive efficiency of an algorithm includes not only time complexity, but also space complexity and other resource consumption. Detecting and evaluating the comprehensive efficiency of algorithms can help developers reasonably allocate computing resources and optimize memory usage to improve the stability and reliability of the program; in the software development process, choosing the right algorithm directly affects the execution efficiency and response time of the program. By detecting the comprehensive efficiency of the algorithm, the development team can make more informed choices based on actual data and needs to ensure that the program can complete the task within the expected time.

[0058] In this embodiment, it should be specifically explained that the steps of detecting the efficiency of each algorithm and calculating the comprehensive efficiency coefficient are as follows:

[0059] Determine the time complexity and space complexity of each algorithm through theoretical analysis (such as Big O notation), actually measure the running time of each algorithm at different input sizes, and measure the memory usage of each algorithm;

[0060] Calculate the time complexity of the algorithm, which is expressed as T(n) = O(f(n)), where T(n) represents the time complexity, that is, the running time of the algorithm, O(*) is the complexity algorithm, and f(n) represents the input size;

[0061] Calculate the algorithm space complexity, which is expressed as S(n) = O(g(n)), where S(n) represents the space complexity, that is, the memory usage of the algorithm, and g(n) represents the input size, that is, a function of n;

[0062] Select the time complexity of a benchmark algorithm, standardize the time complexity of each algorithm, and calculate the time complexity coefficient of the algorithm. The calculation formula is: in Expressed as the time complexity coefficient of algorithm i, T base(n) is the time complexity of the benchmark algorithm, T i (n) is the time complexity of algorithm i;

[0063] Select the space complexity of a benchmark algorithm, standardize the space complexity of each algorithm, and calculate the space complexity coefficient of the algorithm. The calculation formula is: in Expressed as the spatial complexity coefficient of algorithm i, S base (n) is the space complexity of the benchmark algorithm, S i (n) is the space complexity of algorithm i;

[0064] The comprehensive efficiency coefficient is calculated by the geometric mean, and the calculation formula is: Where CE is the comprehensive efficiency coefficient, Expressed as the time complexity coefficient of algorithm i, Expressed as the space complexity coefficient of algorithm i, the geometric mean is a form of the average of a set of data. It differs from the arithmetic mean in that it takes the nth root of the product of the data items as its calculation method. To calculate the geometric mean of a set of data, multiply all the data together and then take the nth root of the product, where n is the size of the data set.

[0065] The unit test detects errors in the code through the code analysis tool and locates its specific location. Based on the information of the location, the importance of the error in the location is calculated, and the importance of the detected errors is averaged to obtain the code error coefficient, which is calculated as follows: Where DC is the code error coefficient, IT i It is expressed as the importance of the ith error, and n is the number of errors in the code;

[0066] By analyzing the importance of the error location, critical errors that have a greater impact on system functions or performance can be prioritized. This helps to ensure the core functions and user experience of the system and reduce the impact of system failures on the business; determining the importance of the error location can help the development team allocate resources for repair more quickly and effectively. Errors with high importance usually receive priority attention and processing, thereby shortening the time for fault repair; in the software testing phase, analyzing the importance of the error location can guide the optimization of the test strategy. By focusing on or increasing the test coverage of the code parts with high importance, the efficiency and accuracy of discovering potential problems can be improved.

[0067] In this embodiment, it should be specifically explained that the step of calculating the importance of the error in the position according to the information of the position is:

[0068] Define error types, error frequencies, code modules, impact scope, and modification costs;

[0069] The error types include syntax errors, logic errors, performance issues, and security vulnerabilities;

[0070] The error frequency refers to the frequency that occurs in different versions or in different environments;

[0071] The code module is the criticality of the module or function where the error is located. For example, the core business logic module is usually more important than the auxiliary module;

[0072] The impact scope is the impact scope of the error on the system or application, including but not limited to user impact, data corruption, system crash, etc.

[0073] The modification cost is the time and resources required to fix the error, including code complexity, dependencies, testing costs, etc.

[0074] Define a multidimensional importance vector for each code position, Where E i is the error type of the ith error position, F i is the error frequency of the ith error position, M i is the importance of the code module where the i-th error location is located, I i is the influence range of the ith error position, C i is the modification cost of the i-th error position;

[0075] Use the minimum-maximum normalization method to convert each parameter value to the range of 0 to 1. The expression is: Where x' is the normalized parameter value, x is the original parameter value, and x min is the minimum value of the parameter in the data set, x max The Min-Max Normalization is a commonly used data normalization method used to scale values ​​to a specific range, usually [0, 1] or [-1, 1]. It maps the original data to the specified range through linear transformation, so that all data falls within the same interval, avoiding deviations caused by differences in numerical values ​​between different features or data;

[0076] The multidimensional vector is converted into a single scalar value, recorded as the importance of the error, using the Manhattan norm, which is a way to measure the sum of the absolute values ​​of each element of a vector in a vector space. It adds the absolute value of each element in the vector to form a single scalar value that reflects the city block distance from the origin to the endpoint of the vector (i.e., the Manhattan distance). In machine learning and optimization problems, the Manhattan norm is often used to represent and regularize sparse vectors, and is widely used in fields such as feature selection and model training due to its intuitive measurement method and mathematical properties.

[0077] In this embodiment, it should be specifically explained that the step of converting a multidimensional vector into a single scalar value using the Manhattan norm is:

[0078] Suppose there is a d-dimensional vector x=(x1,x2,...,x d ), where x i Represents the value of the i-th dimension of a vector;

[0079] Take the absolute value of each element in vector x, add all the absolute values ​​together, and get a scalar value, which is expressed as ||x||1=|x1|+|x2|+...+|x d |, this formula represents the sum of the absolute distances from the origin to the components of vector x.

[0080] The programming quality index is calculated by weighted summing of the code unsophistication coefficient, comprehensive efficiency coefficient, and code error coefficient. The calculation formula is: Where PQ is the programming quality index, NC is the code unsophisticated coefficient, and the code unsophisticated coefficient is inversely proportional to the programming quality index, which means that as the code unsophisticated coefficient increases, the programming quality index will decrease. In other words, if the code is more complex, has a high degree of repetition, or has a deep nesting level, its unsophisticated coefficient will increase, which may lead to a decrease in code readability, maintainability, and performance, thereby affecting the overall programming quality. Therefore, by reducing the unsophisticated coefficient, the quality and efficiency of the code can be improved, making it easier to understand, debug, and maintain. CE is the comprehensive efficiency coefficient, which is proportional to the programming quality index, indicating that as the comprehensive efficiency coefficient increases, the programming quality index will also increase accordingly. This means that when the code performs well in terms of execution efficiency, memory utilization, and algorithm optimization, its programming quality index will be significantly enhanced. By optimizing algorithm design, reducing unnecessary calculations and resource consumption, and ensuring that the code logic is clear and the structure is reasonable, the maintainability, performance, and overall quality of the code can be effectively improved, thereby improving the efficiency and quality of software development. DC is the code error coefficient, which is inversely proportional to the programming quality index, meaning that as the code error coefficient increases, the programming quality index will decrease. This means that the more errors that appear in the code, whether they are syntax errors, logical errors or performance issues, the quality and reliability of the code will be significantly reduced. Therefore, by reducing the number of errors in the code and a rigorous testing process, the programming quality index can be improved to ensure that the software system is more stable, reliable and efficient. Effective error management and repair strategies can significantly improve the productivity of the development team and user satisfaction. a1, a2, and a3 are expressed as weight coefficients of the code unsophistication coefficient, the comprehensive efficiency coefficient, and the code error coefficient, and this embodiment does not perform specific calculations on the specific values ​​of a1, a2, and a3;

[0081] Combining multiple indicators to evaluate programming quality can comprehensively analyze the pros and cons of the code from different angles. The unsophisticated coefficient reflects the structural complexity of the code, the comprehensive efficiency coefficient evaluates the execution efficiency of the code, and the code error coefficient measures the stability and robustness of the code. Taking these factors into consideration can more comprehensively evaluate the performance of the code in terms of readability, performance, and reliability; through quantitative evaluation indicators, the development team can clearly understand the problems and bottlenecks of the code. The analysis of different indicators can provide the team with specific improvement directions, such as reducing code complexity, optimizing algorithm implementation, and enhancing error handling capabilities, thereby improving the overall code quality.

[0082] In the process of software development and maintenance, resources are usually limited and need to be allocated reasonably to solve the most important problems. Comprehensive assessment can help the team determine the priority code areas or problems, such as solving the parts with high importance, low efficiency and prone to errors first, to maximize resource utilization efficiency and problem solving speed.

[0083] The programming quality index is compared with the preset threshold. If the programming quality index is greater than the preset threshold, the current code quality is determined to be good and no warning is issued. If the programming quality index is less than the preset threshold, the current code quality is determined to be poor and a warning is issued to remind programmers to optimize the code.

[0084] In this embodiment, it should be specifically explained that the robot-assisted programming system includes:

[0085] A code data acquisition module is used to collect relevant data in the robot programming code, including the number of code nesting levels, repeated codes, memory usage, and location information of error codes, and transmit the relevant data to the code data analysis module;

[0086] A code data analysis module is used to receive the relevant data transmitted by the code data acquisition module, analyze and obtain the code correlation coefficient, which includes the code unsophistication coefficient, the comprehensive efficiency coefficient and the code error coefficient, and transmit the code correlation coefficient to the code data evaluation module;

[0087] A code data evaluation module is used to receive the code correlation coefficient transmitted by the code data analysis module, and comprehensively evaluate to obtain a programming quality index, and transmit the programming quality index to the early warning module;

[0088] The early warning module is used to receive the programming quality index transmitted by the code data evaluation module and issue an early warning according to the programming quality index.

[0089] Finally: The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

[0090] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. Robot-assisted programming methods, It is characterized in that The following steps are involved: Use the parser to convert the code into an abstract syntax tree, traverse the AST nodes, record the number of nesting levels of each node, find the maximum number of nesting levels among all nodes as the number of nesting levels of the code, and calculate the nesting complexity. The calculation formula is: Among them C nest Expressed as nested complexity, L max is the maximum nesting level of the hypothesis, L is the nesting level of the code; Divide the code into segments with a fixed number of lines, calculate hash values ​​for these segments, find repeated segments, and calculate the code repetition based on the repeated segments. The calculation formula is: Among them C dup It is expressed as the code repetition, R is the number of lines of repeated code, R 总 is the total number of lines of code; The code unsophistication coefficient is obtained by taking the geometric mean of the nesting complexity and the code duplication. The calculation formula is: Where NC is the code unsophisticated coefficient, C nest Expressed as nested complexity, C dup It is expressed as the duplication of the code; Traverse the AST nodes, identify the algorithms where the algorithms are located, detect the efficiency of each algorithm, and calculate the comprehensive efficiency coefficient; The unit test detects errors in the code through the code analysis tool and locates its specific location. Based on the information of the location, the importance of the error in the location is calculated, and the importance of the detected errors is averaged to obtain the code error coefficient, which is calculated as follows: Where DC is the code error coefficient, IT i It is expressed as the importance of the ith error, and n is the number of errors in the code; The programming quality index is calculated by weighted summing of the code unsophistication coefficient, comprehensive efficiency coefficient, and code error coefficient. The calculation formula is: Where PQ represents programming quality index, NC represents code unsophistication coefficient, CE represents comprehensive efficiency coefficient, DC represents code error coefficient, a1, a2, a3 represent weight coefficients of code unsophistication coefficient, comprehensive efficiency coefficient and code error coefficient; Provide early warning prompts based on programming quality index.

2. The robot-assisted programming method according to claim 1, Features: The steps of calculating hash values ​​for these fragments and finding duplicate fragments are as follows: Split the code into fixed lines; Standardize code snippets; Calculate hash values ​​for each code snippet; Duplicate code snippets are detected by comparing hash values, and code snippets with the same hash values ​​are selected as duplicate snippets.

3. The robot-assisted programming method according to claim 1, Features: The steps of detecting the efficiency of each algorithm and calculating the comprehensive efficiency coefficient are as follows: Determine the time complexity and space complexity of each algorithm through theoretical analysis, actually measure the running time of each algorithm under different input scales, and measure the memory usage of each algorithm; Calculate the time complexity of the algorithm, which is expressed as T(n) = O(f(n)), where T(n) represents the time complexity, that is, the running time of the algorithm, O(*) is the complexity algorithm, and f(n) represents the input size; Calculate the algorithm space complexity, which is expressed as S(n) = O(g(n)), where S(n) represents the space complexity, that is, the memory usage of the algorithm, and g(n) represents the input size, that is, a function of n; Select the time complexity of a benchmark algorithm, standardize the time complexity of each algorithm, and calculate the time complexity coefficient of the algorithm. The calculation formula is: in Expressed as the time complexity coefficient of algorithm i, T base (n) is the time complexity of the benchmark algorithm, T i (n) is the time complexity of algorithm i; Select the space complexity of a benchmark algorithm, standardize the space complexity of each algorithm, and calculate the space complexity coefficient of the algorithm. The calculation formula is: in Expressed as the spatial complexity coefficient of algorithm i, S base (n) is the space complexity of the benchmark algorithm, S i (n) is the space complexity of algorithm i; The comprehensive efficiency coefficient is calculated by the geometric mean, and the calculation formula is: Where CE is the comprehensive efficiency coefficient, Expressed as the time complexity coefficient of algorithm i, Expressed as the space complexity coefficient of algorithm i.

4. The robot-assisted programming method according to claim 1, Features: The step of calculating the importance of the error in the position according to the information of the position is: Define error types, error frequencies, code modules, impact scope, and modification costs; Define a multidimensional importance vector for each code position Where E i is the error type of the ith error position, F i is the error frequency of the ith error position, M i is the importance of the code module where the i-th error location is located, I i is the influence range of the ith error position, C i is the modification cost of the i-th error position; Use the minimum-maximum normalization method to convert each parameter value to the range of 0 to 1. The expression is: Where x' is the normalized parameter value, x is the original parameter value, and x min is the minimum value of the parameter in the data set, x max is the maximum value of the parameter in the data set; The multidimensional vector is converted into a single scalar value, denoted as the error importance, using the Manhattan norm.

5. The robot-assisted programming method according to claim 4, Features: The steps of converting a multidimensional vector into a single scalar value using the Manhattan norm are: Take the absolute value of each element in vector x and add all the absolute values ​​together to get a scalar value.

6. The robot-assisted programming method according to claim 1, Features: The steps of providing early warning prompts according to the programming quality index are as follows: The programming quality index is compared with the preset threshold. If the programming quality index is greater than the preset threshold, the current code quality is determined to be good and no warning is issued. If the programming quality index is less than the preset threshold, the current code quality is determined to be poor and a warning is issued to remind programmers to optimize the code.

7. Robot-assisted programming system, Features: The system comprises: A code data acquisition module is used to collect relevant data in the robot programming code, including the number of code nesting levels, repeated codes, memory usage, and location information of error codes, and transmit the relevant data to the code data analysis module; A code data analysis module is used to receive the relevant data transmitted by the code data acquisition module, analyze and obtain the code correlation coefficient, which includes the code unsophistication coefficient, the comprehensive efficiency coefficient and the code error coefficient, and transmit the code correlation coefficient to the code data evaluation module; A code data evaluation module is used to receive the code correlation coefficient transmitted by the code data analysis module, and comprehensively evaluate to obtain a programming quality index, and transmit the programming quality index to the early warning module; The early warning module is used to receive the programming quality index transmitted by the code data evaluation module and issue an early warning according to the programming quality index.

Citation Information

Cited By

  • Code generation model training method and electronic equipment

    CN120822039A