A method, device, storage medium and electronic device for code level evaluation
By optimizing and analyzing the original code, the problem of inaccurate and subjective impact of code quality evaluation in the existing technology is solved, and a more accurate and efficient code quality evaluation is achieved.
Patent Information
- Application Number
- CN202510147850.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-11
- Publication Date
- 2025-06-03
- Estimated Expiration
- 2045-02-11
AI Technical Summary
The code quality evaluation tools in the prior art can only conduct simple syntax and rule checks, resulting in inaccurate evaluation results, and rely on the developer's experience and preferences, and are vulnerable to subjective influence.
By optimizing the original code, the corrected code is obtained; the code difference between the original code and the corrected code is determined; based on the code difference, the corrected code level of the corrected code is determined, and the corrected code level is pushed to the object.
Code quality evaluation is carried out through code differences, reduce the influence of subjective factors, improve the accuracy and efficiency of code quality evaluation, and achieve more accurate reflection of the actual quality level of code.
Smart Images

Figure CN119621515B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technologies, and in particular, to a method, apparatus, storage medium, and electronic device for code level evaluation. Background Art
[0002] In the field of software development, the evaluation of programmers' code quality is an important link to ensure software stability and performance. However, with the continuous increase in software scale and complexity, the difficulty of accurately evaluating code quality is also increasing.
[0003] Currently, most of the code quality evaluation tools in the related technologies quantify the code quality by analyzing aspects such as the syntax, structure, and naming conventions of the code. However, the code quality evaluation tools in the related technologies can only perform simple syntax and rule checks, resulting in inaccurate evaluation results. At the same time, the code quality evaluation in the related technologies depends on developers' experience and preferences, and is easily subject to subjective influences, making the evaluation results somewhat subjective. Summary of the Invention
[0004] The present disclosure provides a method, apparatus, storage medium, and electronic device for code level evaluation.
[0005] According to a first aspect of the present disclosure, there is provided a method for code level evaluation, the method including: optimizing the original code of a first object to obtain a corrected code corresponding to the original code; determining the code difference degree between the original code and the corrected code; and based on the code difference degree, determining the corrected code level of the corrected code and pushing the corrected code level to the first object.
[0006] In some embodiments of the present disclosure, before optimizing the original code of the first object to obtain a corrected code corresponding to the original code, the method includes: obtaining the real-time input code of the first object; determining the abnormal code in the real-time input code; determining an initial correction suggestion corresponding to the abnormal code, and giving an initial correction prompt to the first object, so that the first object corrects the real-time input code based on the initial correction prompt to obtain the original code.
[0007] In some embodiments of the present disclosure, the original code of the first object is optimized to obtain a corrected code corresponding to the original code, including: determining the evaluation results of the original code under multiple evaluation metrics, where the multiple evaluation metrics include code complexity, code duplication rate, code coverage rate, code style inconsistency ratio, code review feedback score, code security rate, and code team collaboration score; determining the comprehensive evaluation result of the original code based on the evaluation results and the preset weights corresponding to each evaluation metric; comparing the comprehensive evaluation result with a preset scoring threshold, and based on the comparison result, determining the original code level of the original code, where the original code level includes an excellent level, a medium level, and a poor level; and optimizing the original code of the first object based on the original code level of the original code to obtain a corrected code.
[0008] In some embodiments of the present disclosure, based on the original code level of the original code, the original code of the first object is optimized to obtain a corrected code, including: when the original code level is a medium level or a poor level, detecting the pre-annotated weak content in the original code to determine the area to be corrected; generating a first correction suggestion based on the area to be corrected, and optimizing the original code based on the first correction suggestion to obtain a corrected code.
[0009] In some embodiments of the present disclosure, determining the code difference degree between the original code and the corrected code includes: respectively performing a decomposition operation on the original code and the corrected code to construct a first abstract syntax network corresponding to the original code and a second abstract syntax network corresponding to the corrected code, where the first abstract syntax network includes first code elements corresponding to the original code, and the second abstract syntax network includes second code elements corresponding to the corrected code; constructing a dynamic programming table based on the first code elements and the second code elements; determining the longest common subsequence based on the dynamic programming table; determining the different elements in the first code elements and the second code elements based on the longest common subsequence, and marking the different elements to obtain a difference label; determining the difference distance between the first code elements and the second code elements; and determining the code difference degree by combining the difference label and the difference distance with a preset graph convolutional neural network.
[0010] In some embodiments of the present disclosure, determining the code difference degree by combining the difference label and the difference distance with a preset graph convolutional neural network includes: using the difference label and the difference distance as the input of the preset graph convolutional neural network, and determining the code difference degree by using the first hidden layer and the second hidden layer in the preset graph convolutional neural network;
[0011] The first hidden layer is formula 1:
[0012] Formula 1
[0013] Where is the adjacency matrix of the graph data with self-connections added, and D is the degree matrix. is the normalized adjacency matrix; W(0) is the weight matrix of the first hidden layer.
[0014] The second hidden layer is given by Equation 2:
[0015] Equation 2
[0016] where is the adjacency matrix of the graph data with self-connections added, and D is the degree matrix. is the normalized adjacency matrix, and W(1) is the weight matrix of the second hidden layer.
[0017] In some embodiments of the present disclosure, based on the code difference degree, the correction code level of the corrected code is determined, including: comparing the code difference degree with a preset difference threshold, and based on the comparison result, determining the correction code level of the corrected code, where the correction code level includes an excellent level, a medium level, and a poor level.
[0018] According to a second aspect of the present disclosure, there is provided a code level evaluation device, which includes:
[0019] An optimization unit for optimizing the original code of the first object to obtain the corrected code corresponding to the original code;
[0020] A determination unit for determining the code difference degree between the original code and the corrected code;
[0021] An evaluation unit for determining the correction code level of the corrected code based on the code difference degree and pushing the correction code level to the first object.
[0022] According to a third aspect of the present disclosure, there is provided a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method of the foregoing first aspect is implemented.
[0023] According to a fourth aspect of the present disclosure, there is provided an electronic device, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, and when the processor executes the computer program, the method of the foregoing first aspect is implemented.
[0024] The code level evaluation method provided by the present disclosure optimizes the original code of the first object to obtain the corrected code corresponding to the original code; determines the code difference degree between the original code and the corrected code; determines the correction code level of the corrected code based on the code difference degree and pushes the correction code level to the first object, and performs code quality evaluation through the code difference degree to reduce the influence of subjective factors and improve the accuracy and efficiency of code quality evaluation.
[0025] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present application, nor is it used to limit the scope of the present application. Other features of the present application will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The drawings are used to better understand the solution and do not constitute a limitation to the disclosure. Among them:
[0027] Figure 1 is a schematic flowchart of a method for evaluating code levels provided by an embodiment of the present disclosure;
[0028] Figure 2 is a schematic flowchart of another method for evaluating code levels provided by an embodiment of the present disclosure;
[0029] Figure 3 is a schematic flowchart of another method for evaluating code levels provided by an embodiment of the present disclosure;
[0030] Figure 4 is a schematic flowchart of another method for evaluating code levels provided by an embodiment of the present disclosure;
[0031] Figure 5 is a schematic structural diagram of a device for evaluating code levels provided by an embodiment of the present disclosure;
[0032] Figure 6 is a schematic hardware structure diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0033] The following describes exemplary embodiments of the present disclosure with reference to the accompanying drawings. Various details of the embodiments of the present disclosure are included to assist in understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0034] In the field of software development, the evaluation of programmers' code quality is an important link to ensure software stability and performance. However, with the continuous increase in software scale and complexity, the difficulty of accurately evaluating code quality is also increasing.
[0035] Currently, most of the code quality assessment tools in the related art quantify the code quality by analyzing aspects such as the syntax, structure, and naming conventions of the code. However, the code quality assessment tools in the related art can only perform simple syntax and rule checks, resulting in inaccurate assessment results. At the same time, the code quality assessment in the related art depends on the experience and preferences of developers, is easily subject to subjective influences, and makes the assessment results somewhat subjective.
[0036] To solve the problems in the related art, the code level assessment method proposed in the present disclosure optimizes the original code of the first object to obtain the corrected code corresponding to the original code; determines the code difference degree between the original code and the corrected code; based on the code difference degree, determines the corrected code level of the corrected code, and pushes the corrected code level to the first object, improving the accuracy and efficiency of code quality assessment, reducing the influence of subjective factors through the code difference degree, realizing a more accurate reflection of the actual quality level of the code, and providing more scientific and comprehensive support for code quality management in the software development process.
[0037] The following describes the code level assessment method, device, electronic device, storage medium, and computer program product according to the embodiments of the present disclosure with reference to the accompanying drawings.
[0038] Figure 1 It is a schematic flowchart of a code level assessment method provided by an embodiment of the present disclosure. As Figure 1 shown, the method includes:
[0039] Step 101: Optimize the original code of the first object to obtain the corrected code corresponding to the original code.
[0040] In some embodiments, the original code in the present disclosure can be stored in various places, such as a version control system (such as Git), a code library, a development environment, or a file provided by the first object. The first object in the present disclosure can refer to the owner, developer, etc. of the code.
[0041] The present disclosure first needs to clarify the storage location and access method of the original code to ensure sufficient permissions to access and extract the original code.
[0042] After determining the storage location, access method of the original code, and having the access permission to the original code, the present disclosure can use appropriate tools (such as Git clone, FTP download, export from the development environment, etc.) to extract the original code.
[0043] Among them, after obtaining the original code of the first object, the present disclosure can also verify the integrity of the original code and check whether the extracted code is complete without damaged or missing files.
[0044] In some embodiments, the present disclosure may also regularly obtain the latest original code from the version control system according to a preset period.
[0045] After obtaining the original code of the first object, the present disclosure may perform a level evaluation on the original code to determine the original code level of the original code, and then optimize the original code based on the original code level to obtain a corrected code.
[0046] Specifically, the present disclosure may perform a level evaluation on the extracted original code according to a preset code evaluation criterion.
[0047] Among them, the preset code evaluation criterion may include multiple evaluation indicators. The present disclosure may evaluate the original code for multiple evaluation indicators to obtain the evaluation results of the original code under each evaluation indicator, and thus determine the original code level of the original code based on the evaluation results.
[0048] It can be understood that when the present disclosure performs a level evaluation on the original code, methods such as static code analysis tools, code reviews, or manual evaluations may be used to evaluate the code. After obtaining the original code level, the present disclosure may record the original code level and the evaluation results under each evaluation indicator in a report, generate an original code evaluation report, and send the original code evaluation report to the first object.
[0049] After obtaining the original code level of the original code, the present disclosure may perform targeted code optimization according to the original code level to improve the code quality and performance.
[0050] Specifically, when the original code level is medium or poor based on the original code level, the present disclosure may identify weak content in the original code, determine the area to be corrected in the original code, and generate a correction suggestion corresponding to the area to be corrected, so as to correct the original code according to the correction suggestion.
[0051] Among them, the weak content may include but is not limited to: redundant code, performance bottlenecks, security vulnerabilities, non-standard naming and annotations, etc.
[0052] Step 102: Determine the code difference degree between the original code and the corrected code.
[0053] In some embodiments, after obtaining the corrected code, the present disclosure may determine the difference tags and the difference distance between the original code and the corrected code; based on the difference tags and the difference distance, combined with a preset graph convolutional neural network, determine the code difference degree between the original code and the corrected code.
[0054] Among them, before the present disclosure determines the code difference degree between the original code and the corrected code, the present disclosure may determine a comparison range based on the code marked as bugfix obtained from the code repository (i.e., the corrected code of the present disclosure), and thus determine the code difference degree between the original code and the corrected code based on this comparison range.
[0055] Specifically, if the corrected code only involves a specific file or code block, the comparison range is determined to be this specific file or code block. If the corrected code involves multiple files or extensive code changes, the comparison range is the entire project or module.
[0056] Step 103: Determine the corrected code level of the corrected code based on the code difference degree, and push the corrected code level to the first object.
[0057] In some embodiments, the present disclosure may perform a re-level evaluation on the optimized corrected code based on the code difference degree, and push the evaluation result to the first object.
[0058] Specifically, the present disclosure may compare the code difference degree with a preset difference threshold, and based on the comparison result, determine the corrected code level of the corrected code. The corrected code level includes an excellent level, a medium level, and a poor level.
[0059] The present disclosure may, according to the comparison result of the code difference degree and the preset difference threshold, when the code difference degree is greater than or equal to a third preset difference threshold, determine that the code level is an excellent level; when the code difference degree is less than the third preset difference threshold and greater than or equal to a fourth preset difference threshold, determine that the code level is a medium level; when the code difference degree is less than the fourth preset difference threshold, determine that the code level is a poor level.
[0060] Among them, after the present disclosure determines the corrected code level of the corrected code, it may directly push the corrected code level to the first object, or generate a level evaluation report corresponding to the corrected code based on this corrected code level, and push this level evaluation report to the first object. This level evaluation report includes the original code level, the code difference degree, and the corrected code level.
[0061] In summary, the technical solution provided by the present disclosure optimizes the original code of the first object to obtain the corrected code corresponding to the original code; determines the code difference degree between the original code and the corrected code; determines the corrected code level of the corrected code based on the code difference degree, and pushes the corrected code level to the first object, and performs code quality evaluation through the code difference degree to reduce the influence of subjective factors and improve the accuracy and efficiency of code quality evaluation.
[0062] As a possible implementation, such as Figure 2The flowchart of another code level evaluation method shown. On the basis of the above embodiments, the original code of the first object is optimized to obtain the corrected code corresponding to the original code. The specific process before includes the following steps:
[0063] Step 201: Obtain the real-time input code of the first object.
[0064] In some embodiments, the present disclosure can capture the code input by the first object in an editor or IDE (Integrated Development Environment). That is, the present disclosure can obtain the current input code of the first object from the editor according to a preset code acquisition period.
[0065] For example, the present disclosure can use a timer (such as setInterval) to regularly obtain the value in a text box (textarea or contenteditable div), or capture the code content through an IDE plugin or extension.
[0066] Among them, for real-time feedback, the present disclosure can also use technologies such as WebSocket to send the captured code to the server for analysis.
[0067] Step 202: Determine the abnormal code in the real-time input code.
[0068] In some embodiments, the present disclosure can analyze the captured real-time input code to identify the possible abnormal codes therein. These abnormal codes include obvious code errors such as syntax errors, logical errors, and type mismatches.
[0069] Specifically, the present disclosure can use technologies such as static analysis, dynamic analysis, and pattern matching to detect abnormal codes.
[0070] After detecting the abnormal code, the present disclosure can also classify the detected errors, classifying the abnormal code into serious abnormalities and warning abnormalities. Among them, serious abnormalities refer to abnormal codes that cause the program to fail to compile or run, and warning abnormalities refer to abnormal codes that do not affect the program running but may cause performance problems or potential errors.
[0071] When detecting the abnormal code, the present disclosure can also record the abnormal code process for subsequent analysis and reporting.
[0072] For example, the present disclosure can use static code analysis tools (such as ESLint for JavaScript, Pylint for Python, etc.) combined with predefined detection rules to check the code.
[0073] Step 203: Determine the initial correction suggestions corresponding to the exception code, and give an initial correction prompt to the first object, so that the first object corrects the real-time input code based on the initial correction prompt to obtain the original code.
[0074] In some embodiments, the present disclosure can generate initial correction suggestions according to the detected exception code. The initial correction suggestions are used to quickly and accurately correct errors in the code.
[0075] Specifically, the present disclosure can use a preset rule library and a machine learning model to generate correction suggestions.
[0076] The correction suggestions can mark errors in the code editor and provide correction options, display error messages and suggestions through a pop-up window, list errors and suggestions in a log or report, etc.
[0077] The present disclosure can improve the user interface, allowing the first object to select, accept or reject the correction suggestions, and allowing the first object to further edit or customize the correction content. In addition, the present disclosure can also automatically correct the exception code based on the correction suggestions to obtain the original code.
[0078] Among them, when the first object corrects the real-time input code based on the initial correction prompt, the present disclosure can also verify whether the corrected code still contains exceptions and generate the final original code.
[0079] In summary, the present disclosure improves the code quality of the original code, reduces human errors, and improves development efficiency through an automated initial exception code detection and correction process.
[0080] As a possible implementation, as Figure 3 shown in the flowchart of another code level evaluation method, on the basis of the above embodiments, the specific process of optimizing the original code of the first object to obtain the corrected code corresponding to the original code includes the following steps:
[0081] Step 301: Determine the evaluation results of the original code under multiple evaluation metrics, where the multiple evaluation metrics include code complexity, code duplication rate, code coverage rate, code style inconsistency ratio, code review feedback score, code security rate, code team collaboration score.
[0082] In some embodiments, the present disclosure can evaluate the original code from multiple dimensions, and these dimensions include but are not limited to code complexity, code duplication rate, code coverage rate, code style inconsistency ratio, code review feedback score, code security rate, code team collaboration score.
[0083] Regarding code complexity, code complexity is used to measure the logical complexity of code. High complexity may lead to difficulty in understanding and maintenance. This disclosure can use static code analysis tools to calculate cyclomatic complexity and N-path complexity, and identify code segments with high logical complexity. This disclosure can calculate the logical complexity of the code based on the calculated cyclomatic complexity and N-path complexity, combined with preset weights. Among them, when the logical complexity is higher than the preset complexity threshold, it indicates that the code is too complex and may need to be optimized.
[0084] Specifically, the cyclomatic complexity in this disclosure is an indicator that measures the number of independent paths in the code and is usually used to evaluate the logical complexity of the code. This disclosure can be calculated by the following formula:
[0085] M = E - N + 2P
[0086] Where: M represents the cyclomatic complexity; E represents the number of edges in the program (including jump edges and sequential edges in the control flow graph); N represents the number of nodes in the program (usually statements or instructions in the code); P represents the number of connected components in the program (if the program has only one connected component, then P = 1; otherwise, P is an integer greater than 1).
[0087] This disclosure can use static code analysis tools to automatically calculate the cyclomatic complexity of the code. Through the above formula calculation, the cyclomatic complexity of the code is obtained.
[0088] N-path complexity is another indicator to measure code complexity, which considers all possible execution paths in the code. Different from cyclomatic complexity, N-path complexity not only considers the independent paths in the control flow graph, but also considers all possible execution paths generated by conditional statements (such as if-else, switch-case, etc.).
[0089] When this disclosure calculates the N-path complexity, it needs to traverse each conditional statement in the code and calculate the number of execution paths generated by each conditional statement. Then, multiply these numbers to get the N-path complexity of the entire code.
[0090] To perform code complexity analysis more effectively, this disclosure can combine the use of static code analysis tools and large language models (such as GPT series, BERT, etc.).
[0091] Static code analysis tools can automatically parse the code, construct the control flow graph, and calculate cyclomatic complexity and N-path complexity. Large language models can deeply parse the code, understand the logical structure and semantic relationships of the code, and can assist static code analysis tools in constructing a more accurate control flow graph and calculating complexity.
[0092] In addition, large language models can also provide optimization suggestions based on the results of code complexity analysis, such as refactoring the code, simplifying the logic, etc.
[0093] After obtaining the cyclomatic complexity and N - path complexity, the present disclosure can calculate the comprehensive logic complexity of the current code according to the preset weights corresponding to the cyclomatic complexity and the preset weights corresponding to the N - path complexity, so as to achieve multi - dimensional evaluation based on the comprehensive logic complexity.
[0094] For the code duplication rate, the code duplication rate is used to detect redundant parts in the code. Reducing duplicate code can improve the maintainability and reusability of the code. The present disclosure can identify duplicate segments in the code through semantic analysis technology, calculate the proportion of duplicate code in the total code, so as to obtain the code duplication rate. Among them, when the code duplication rate is higher than the preset duplication threshold, it indicates that there is a large amount of duplicate code in the code and needs to be refactored.
[0095] Specifically, the present disclosure can calculate the code duplication rate by using code clone detection technology. Code clone detection refers to identifying similar or identical code segments in a software code library through technical means. Thereby reducing redundant code, reducing the size and complexity of the code library; improving the maintainability of the code (because when an error is found or a function needs to be updated, only one piece of code needs to be modified); promoting code reuse and improving development efficiency.
[0096] The code clone detection of the present disclosure can be based on text - based clone detection (i.e., by comparing the character sequences of the code to identify similar code segments), and can also be based on semantic clone detection (i.e., by parsing the abstract syntax tree (AST) of the code or performing more complex semantic analysis to identify code segments with the same or similar functions).
[0097] The clone detection tool in the present disclosure is a large model of deep learning or natural language processing. By using the large model of deep learning or natural language processing to perform semantic analysis on the code, potential code clones can be identified. It combines the advantages of text matching and semantic understanding and can identify more complex code clones.
[0098] The present disclosure performs semantic analysis on the code through a clone detection tool (i.e., a large model of deep learning or natural language processing), identifies duplicate code segments in the code, and then counts the total number of characters or lines of the duplicate code segments.
[0099] The present disclosure also needs to count the total number of characters or lines of the entire code. By calculating the ratio of the total number of characters or lines of the duplicate code segments to the total number of characters or lines of the entire code, the duplicate code rate of the code can be obtained.
[0100] Regarding code coverage, code coverage is used to represent the degree to which the code is covered by tests, ensuring that the code is fully tested and improving the reliability and stability of the code. The present disclosure can use a test coverage tool to analyze the coverage of unit tests and integration tests, thereby obtaining the code coverage. Among them, when the code coverage is lower than a preset coverage threshold, it indicates that there are untested code paths in the code, and test cases need to be added.
[0101] Specifically, the present disclosure can first calculate the unit test coverage and the integration test coverage. Based on the unit test coverage and the integration test coverage, combined with the preset weights corresponding to the unit test coverage and the preset weights corresponding to the integration test coverage, the code coverage of the final code is obtained.
[0102] The unit test coverage aims to measure the degree of independent testing of each module or function in the code, while the integration test coverage focuses on the testing of interactions between modules. Together, they ensure that the code is comprehensively tested, thereby improving the reliability and stability of the software.
[0103] The present disclosure can use a test coverage tool in combination with a large model to automatically analyze the execution of test cases, obtaining the unit test coverage and the integration test coverage. Common test coverage tools include JaCoCo (Java), Cobertura (Java), Coverage.py (Python), etc.
[0104] In addition, the present disclosure can also perform semantic analysis on test cases and code through a large model to identify which code paths are covered by test cases and which are not, that is, obtaining the uncovered code fragments. This helps to more accurately evaluate the sufficiency of testing, providing suggestions for developers to write test cases to improve the sufficiency of testing and the quality of the code.
[0105] Regarding the code style inconsistency ratio, the code style inconsistency ratio is used to represent the degree of compliance with code specifications and styles, ensuring that the code follows a unified coding specification and style, and improving the readability and consistency of the code. The present disclosure can check naming conventions, indentation, space usage, etc. according to the coding specification, and use a large model for intelligent analysis to obtain the code style inconsistency ratio. Among them, when the code style inconsistency ratio is higher than a preset specification threshold, it indicates that the code style is inconsistent or does not conform to the specification, and adjustment is required.
[0106] Specifically, the present disclosure can first perform a style consistency check on the code to obtain the code style inconsistency ratio. The style consistency check aims to ensure that all code in the project is consistent in naming conventions, indentation, space usage, etc., thereby improving the readability of the code and the efficiency of team collaboration.
[0107] The present disclosure can perform intelligent analysis using large models, that is, by having large models learn from a large number of code samples to understand and identify different coding styles. Subsequently, the trained large model is used to compare the current code with preset coding specifications (such as file structure, comment style, code structure, etc.) or existing code styles, and intelligently analyze the code segments that do not meet the style consistency requirements, thereby calculating the ratio between the total number of characters or lines in the code segments that do not meet the style consistency requirements and the total number of characters or lines in the overall code to determine the code style inconsistency ratio of the current code.
[0108] Meanwhile, the present disclosure can also provide specific style unification suggestions for developers based on the analysis results using large models, such as modifying naming conventions, adjusting indentation levels, deleting unnecessary spaces, etc.
[0109] Regarding the code review feedback score, the code review feedback score is used to represent the overall quality of code review, evaluate code quality, discover potential problems through review, and put forward improvement suggestions. The present disclosure can obtain the code review feedback score by having team members review and score the code and provide feedback. Among them, when the code review feedback score is lower than the preset review threshold, it indicates that there are more problems in the code or major modifications are required, and attention and improvement are needed.
[0110] Specifically, the code review feedback score of the present disclosure can be calculated by combining the code review passing rate and the code review cycle with preset weights.
[0111] The main purpose of counting the code review passing rate is to measure the developers' response and improvement ability to code review feedback. By counting the proportion of modification suggestions that are adopted, it can intuitively reflect the developers' attention to feedback and their efforts in code quality improvement.
[0112] The present disclosure can record the number of modification suggestions put forward in each code review and the number of suggestions finally adopted. Subsequently, by calculating the ratio of the number of adopted suggestions to the number of modification suggestions put forward, the code review passing rate is determined.
[0113] Among them, the present disclosure can also store the code review passing rate obtained each time, and draw a trend chart of the code review passing rate based on the historical code review passing rate to observe whether the developers' response and improvement ability to feedback have been improved.
[0114] Meanwhile, the present disclosure can also perform code review cycle analysis. The main purpose of code review cycle analysis is to evaluate the efficiency of code review and the speed of code quality improvement. By analyzing the time required for the code to pass the review from submission, the bottlenecks and problems in the review process can be revealed, thereby providing optimization suggestions for the team.
[0115] That is, the present disclosure can record the time of each code submission and the time of final review passing. By calculating the difference between the time of review passing and the code submission time, the code review cycle can be obtained. When the code review cycle exceeds the preset review cycle threshold, bottlenecks and problems in the review process can be further identified, such as insufficient reviewers, unclear review criteria, etc.
[0116] After obtaining the code review passing rate and the code review cycle, the present disclosure can calculate the final code review feedback score by combining the preset weight corresponding to the code review passing rate and the preset weight corresponding to the code review cycle.
[0117] Regarding the code security rate, the code security rate is used to represent the security level of the code, ensure that the code does not contain security vulnerabilities, and improve the security of the software. The present disclosure can use a security analysis tool to check whether there are common security vulnerabilities in the code, such as SQL injection, XSS, etc., and obtain the code security rate according to the inspection results. Among them, when the code security rate is lower than the preset security threshold, it indicates that there is a security risk and immediate repair is required.
[0118] Specifically, the security analysis tool in the present disclosure can specifically be large model technology. The present disclosure can use large model technology to conduct in-depth static analysis of the code to discover potential security vulnerabilities and weaknesses. These vulnerabilities may include common security threats, such as SQL injection, cross-site scripting (XSS), cross-site request forgery (CSRF), etc.
[0119] That is, the present disclosure can use a large model to comprehensively scan the code to identify potential security problems. Then, according to the known security vulnerability patterns and attack vectors, check whether there are vulnerable code segments in the code. After obtaining the code segments, the present disclosure can calculate the ratio of the total number of characters or lines of the vulnerable code segments to the total number of characters or lines of the overall code to determine the code security rate of the current code.
[0120] At the same time, the present disclosure can also use the large model to generate detailed security coding suggestions for the detected vulnerable code segments to guide developers on how to repair and improve.
[0121] In addition, the present disclosure can conduct an evaluation of the use of security libraries, that is, evaluate whether developers use secure third-party libraries and APIs and follow the best security practices. Third-party libraries and APIs are widely used in software development, but they may also bring potential security risks.
[0122] Regarding the code team assistance score, the code team assistance score is used to represent the performance of the first object's code in team collaboration, evaluate the performance of the code in team collaboration, and promote cooperation and communication among team members. The present disclosure can evaluate based on indicators such as the code submission frequency and the efficiency of resolving merge conflicts of the first object, combined with the feedback from team members, to obtain the code team assistance score. Among them, when the code team assistance score is lower than the preset assistance threshold, it indicates that there are problems in team collaboration and the collaboration process and communication methods need to be optimized.
[0123] Specifically, the present disclosure can first calculate the code submission frequency and the code merge score, and then use the code submission frequency and the code merge score to obtain the code team assistance score.
[0124] The code submission frequency statistics of the present disclosure aims to evaluate the activity and work rhythm of developers by recording and analyzing the number of code submissions and the amount of code submitted each time within a certain period of time. This helps the team understand the work habits and efficiency of each member, so as to put forward targeted suggestions for optimizing collaboration efficiency.
[0125] That is, the present disclosure can use the data recorded by a version control system (such as Git) to collect the code submission records of the first object (i.e., the developer). Statistically analyze the collected data, calculate the number of submissions of each developer, and then calculate the ratio of the code submission times to the total submission times by using the submission times to obtain the code submission frequency.
[0126] The present disclosure can also calculate the code fragments of each submission of each developer, calculate the ratio between the total number of characters or lines of the code fragments of each code submission and the total number of characters or lines of the overall code to determine the code submission amount.
[0127] The code merge score mainly focuses on evaluating code merge conflicts, aiming to evaluate the efficiency and quality of developers in resolving conflicts during the code merge process, as well as the frequency of code merges. This helps the team identify and solve bottlenecks and problems during the merge process and optimize the merge process.
[0128] That is, the present disclosure can record the conflicts that occur during each code merge process and their resolution situations, analyze the time required for developers to resolve conflicts and the code quality after resolution, count the frequency of code merges, and thus calculate the code merge score based on the time required for resolving conflicts and the code quality after resolution, and the frequency of code merges, to understand the collaboration habits of team members and the progress speed of the project.
[0129] After obtaining the code submission frequency and the code merge score, the present disclosure can use the preset weights corresponding to the code submission frequency and the preset weights corresponding to the code merge score to calculate the code team assistance score.
[0130] Step 302: Determine the comprehensive evaluation result of the original code based on the evaluation results and the preset weights corresponding to each evaluation metric.
[0131] In some embodiments, after obtaining the evaluation results of each evaluation metric, the present disclosure multiplies the evaluation result of each evaluation metric by its corresponding preset weight, and then sums them up to obtain the comprehensive evaluation result.
[0132] Among them, the preset weights corresponding to each evaluation result are not limited in the embodiments of the present disclosure and are subject to the actual situation.
[0133] Step 303, compare the comprehensive evaluation result with the preset scoring threshold, and based on the comparison result, determine the original code level of the original code. The original code level includes excellent level, medium level, and poor level.
[0134] In some embodiments, the present disclosure can compare the comprehensive evaluation result with the preset scoring threshold to determine the level of the original code.
[0135] Specifically, the present disclosure can set clear scoring thresholds, such as excellent level (90 points and above), medium level (60 - 89 points), and poor level (59 points and below).
[0136] The present disclosure can, according to the comparison result between the comprehensive evaluation result and the preset evaluation threshold, when the comprehensive evaluation result is greater than or equal to the first preset evaluation threshold, determine that the code level is excellent level; when the comprehensive evaluation result is less than the first preset evaluation threshold and greater than or equal to the second preset evaluation threshold, determine that the code level is medium level; when the comprehensive evaluation result is less than the second preset evaluation threshold, determine that the code level is poor level.
[0137] Step 304, optimize the original code of the first object based on the original code level of the original code to obtain the corrected code.
[0138] In some embodiments, when the original code level is medium level or poor level, detect the pre - marked weak content in the original code to determine the area to be corrected; generate a first correction suggestion based on the area to be corrected, and optimize the original code based on the first correction suggestion to obtain the corrected code.
[0139] In some embodiments, the pre - marked weak content in the present disclosure is the known potential problems, performance bottlenecks, security vulnerabilities, and parts that do not conform to best practices pre - marked by the first object when inputting the code.
[0140] The present disclosure can deeply evaluate and analyze these pre-labeled weak areas through methods such as static code analysis tools, dynamic testing, and code reviews to determine which parts actually have problems or can be further optimized. Based on the detection results, it is clear which areas need to be corrected, and these areas will be used as areas to be corrected.
[0141] In some embodiments, the present disclosure can use code optimization tools or intelligent algorithms to automatically generate a series of first correction suggestions according to the specific problems in the areas to be corrected. These first correction suggestions can include aspects such as code refactoring, algorithm optimization, security enhancement, and performance improvement.
[0142] After the present disclosure determines the first correction suggestions, it makes corresponding modifications and optimizations to the original code according to the first correction suggestions, such as modifying the code structure of the original code, adjusting the algorithm logic of the original code, adding security measures to the original code, and improving the readability of the original code, so as to obtain the corrected code.
[0143] The present disclosure further improves the quality and performance of the code by targeted optimization and correction of the weak content in the original code.
[0144] In summary, the present disclosure analyzes the original code using multiple evaluation metrics, calculates the evaluation results of each evaluation metric, thereby determining the original code level of the original code, achieving a comprehensive and objective evaluation of the quality of the original code, which not only helps to improve the readability, maintainability, and security of the code, but also promotes team collaboration and continuous improvement.
[0145] As a possible implementation, as Figure 4 shown in the flowchart of another code level evaluation method, on the basis of the above embodiments, the specific process of determining the code difference degree between the original code and the corrected code includes the following steps:
[0146] Step 401, decompose the original code and the corrected code respectively, construct the first abstract syntax network corresponding to the original code and the second abstract syntax network corresponding to the corrected code. The first abstract syntax network includes the first code elements corresponding to the original code, and the second abstract syntax network includes the second code elements corresponding to the corrected code.
[0147] In some embodiments, the present disclosure can decompose the corrected code and the original code into the first code elements and the second code elements respectively. The code elements include a series of lexical units (tokens), such as keywords, identifiers, operators, delimiters, etc. According to the syntax rules of the programming language, the lexical units are organized into a syntax structure to form an abstract syntax tree (AST), that is, the first abstract syntax network corresponding to the original code and the second abstract syntax network corresponding to the corrected code.
[0148] Specifically, each node vi in the first abstract syntax network and the second abstract syntax network in the present disclosure not only represents a syntax element (the syntax element includes variables, operators, and statement blocks), but can also represent the relationships between these elements, such as parent-child relationships, sibling relationships, or other types of dependency relationships. Additionally, the present disclosure can construct the first abstract syntax network into first graph data and the second abstract syntax network into second graph data, where i = 1, 2, …… N, and N is the total number of nodes.
[0149] Step 402: Based on the first code element and the second code element, construct a dynamic programming table.
[0150] In some embodiments, after obtaining the first abstract syntax network corresponding to the original code and the second abstract syntax network corresponding to the corrected code, the present disclosure can construct a dynamic programming table.
[0151] That is, based on the first code element and the second code element, create a two-dimensional array dp, where dp[i][j] represents the length of the longest common subsequence of the first i elements of the first code element sequence X and the first j elements of the second code element sequence Y (the elements include functions, classes, and modules). The size of the array is (m + 1) x (n + 1), where m and n are the lengths of sequences X and Y respectively. Sequence X is the first code element, and sequence Y is the second code element.
[0152] Initialize the first row and the first column of the two-dimensional array dp to 0 because an empty sequence is a subsequence of any sequence and has a length of 0.
[0153] Use a double loop to traverse each element of the first code element sequence X and the second code element sequence Y to calculate and obtain the two-dimensional array, that is, obtain the dynamic programming table.
[0154] Step 403: Based on the dynamic programming table, determine the longest common subsequence.
[0155] In some embodiments, the present disclosure can compare the sizes of the two-dimensional data of the first code element and the two-dimensional data of the second code element in the dynamic programming table to determine the longest common subsequence; when the two-dimensional data of the first code element is equal to the two-dimensional data of the second code element, determine that the longest common subsequence is the two-dimensional data of the first code element and the two-dimensional data of the second code element; when the two-dimensional data of the first code element is not equal to the two-dimensional data of the second code element, determine that the two-dimensional data of the maximum value in the two-dimensional data of the first code element and the two-dimensional data of the second code element is the longest common subsequence.
[0156] Specifically, for dp[i][j], there are two cases:
[0157] If X[i - 1] is equal to Y[j - 1], then dp[i][j] = dp[i - 1][j - 1] + 1, because the longest common subsequence includes X[i - 1] and Y[j - 1].
[0158] If X[i - 1] is not equal to Y[j - 1], then dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]), because the longest common subsequence either does not include X[i - 1] or does not include Y[j - 1], and we take the larger value of the two.
[0159] After calculating the two-dimensional array, we can trace back the longest common subsequence in reverse starting from dp[m][n]. If dp[i][j] = dp[i - 1][j - 1] + 1, then X[i - 1] and Y[j - 1] are part of the longest common subsequence; otherwise, depending on the size relationship between dp[i - 1][j] and dp[i][j - 1], we decide whether to exclude X[i - 1] or Y[j - 1].
[0160] Step 404, based on the longest common subsequence, determine the different elements in the first code element and the second code element, and mark the different elements to obtain a difference label.
[0161] In some embodiments, after obtaining the longest common subsequence, we can analyze which elements are different between the two sequences by comparing the differences between the two original sequences and the longest common subsequence, so as to understand the specific changes between different versions or different parts of the code.
[0162] The present disclosure can traverse the two original sequences, and for the elements not in the longest common subsequence, mark them as different elements. In this way, we can clearly find out the elements that have changed in the two sequences (i.e., different elements), and then mark the different elements to determine the difference label. The present disclosure can comprehensively extract the difference label and extract relevant features from the difference results, such as frequently changed node types, key functions or variables involved in the changes, etc. These features can help further analyze the impact brought by code changes, such as whether it has an impact on key functions, performance, etc.
[0163] Step 405, determine the difference distance between the first code element and the second code element.
[0164] In some embodiments, after determining the different elements, the present disclosure can determine the difference distance (i.e., the edit distance) between the first code element and the second code element. The difference distance refers to the minimum number of operations required to convert one sequence into another sequence by insertion, deletion, or replacement operations. Based on the longest common subsequence, the edit distance between the two sequences can be calculated.
[0165] Step 406: Based on the difference tags and the difference distances, in combination with a preset graph convolutional neural network, determine the code difference degree.
[0166] In some embodiments, after obtaining the difference distances and the difference tags, the present disclosure can calculate the node difference degree by using a large model and the GCN algorithm. That is, taking the difference tags and the difference distances as the inputs of the preset graph convolutional neural network, and using the first hidden layer and the second hidden layer in the preset graph convolutional neural network to determine the code difference degree.
[0167] The present disclosure can input the difference tags corresponding to the difference elements and the difference distances into the large model, and calculate the difference degree of each node vi (i.e., the difference element) through the preset graph convolutional neural network (GCN) algorithm.
[0168] The input feature of the preset graph convolutional neural network in the present disclosure is Hvi(0). Hvi(0) is the initial feature vector of the difference element, and this vector contains the difference tags and the difference distances.
[0169] The graph structure of the preset graph convolutional neural network in the present disclosure:
[0170] Is the adjacency matrix of the graph data with self-connections added, usually defined as =A + I, where A is the original adjacency matrix and I is the identity matrix. D is the degree matrix, that is, a diagonal matrix, and its diagonal elements are the degrees of each node (i.e., the number of edges directly connected to the node).
[0171] The GCN layer includes a first hidden layer using the ReLU activation function; a second hidden layer using the Sigmoid activation function.
[0172] For each difference element, the calculation method of its detection result is as follows:
[0173] The first hidden layer is Formula 1:
[0174] Formula 1
[0175] Where, Is the adjacency matrix of the graph data with self-connections added, D is the degree matrix, Is the normalized adjacency matrix; W(0) is the weight matrix of the first hidden layer.
[0176] The second hidden layer is Formula 2:
[0177] Formula 2
[0178] Where, Is the adjacency matrix of the graph data with self-connections added, D is the degree matrix, is a normalized adjacency matrix, and W(1) is the weight matrix of the second hidden layer.
[0179] In the present disclosure, the output result of the preset graph convolutional neural network can be a certain value in Hvi(2) or a certain further processed output (for example, taking the value of a specific dimension as the difference degree).
[0180] Through the above method, the present disclosure can input the difference label and the difference distance into the GCN model, and calculate the difference degree of each difference element through the algorithm of the model.
[0181] In summary, the present disclosure determines the code difference degree between the original code and the corrected code, evaluates the corrected code level of the corrected code based on the code difference degree, realizes the evaluation of the code level by using the code difference degree, reduces the influence of subjectivity on the evaluation result, and improves the accuracy of the evaluation. At the same time, the present disclosure uses the code difference degree to evaluate the code level of the corrected code to realize the dual evaluation of the code level, further reduces the influence of subjectivity, and more objectively evaluates the quality of the original code.
[0182] Corresponding to the above code level evaluation method, the present invention also proposes a code level evaluation device. Since the device embodiment of the present invention corresponds to the above method embodiment, for the details not disclosed in the device embodiment, reference may be made to the above method embodiment, and the present invention will not be elaborated herein.
[0183] Figure 5 is a schematic structural diagram of a code level evaluation device provided by an embodiment of the present disclosure, as Figure 5 shown, the device includes:
[0184] An optimization unit 510, configured to optimize the original code of the first object to obtain a corrected code corresponding to the original code;
[0185] A determination unit 520, configured to determine the code difference degree between the original code and the corrected code;
[0186] An evaluation unit 530, configured to determine the corrected code level of the corrected code based on the code difference degree, and push the corrected code level to the first object.
[0187] In some embodiments of the present disclosure, the code level evaluation device further includes: an acquisition unit, configured to acquire the real-time input code of the first object before optimizing the original code of the first object to obtain a corrected code corresponding to the original code; determine the abnormal code in the real-time input code; determine the initial correction suggestion corresponding to the abnormal code, and give an initial correction prompt to the first object, so that the first object corrects the real-time input code based on the initial correction prompt to obtain the original code.
[0188] In some embodiments of the present disclosure, the optimization unit 510 is configured to: determine the evaluation results of the original code under multiple evaluation metrics, where the multiple evaluation metrics include code complexity, code duplication rate, code coverage rate, code style inconsistency ratio, code review feedback score, code security rate, and code team collaboration score; determine the comprehensive evaluation result of the original code based on the evaluation results and the preset weights corresponding to each evaluation metric; compare the comprehensive evaluation result with a preset scoring threshold, and based on the comparison result, determine the original code level of the original code, where the original code level includes an excellent level, a medium level, and a poor level; optimize the original code of the first object based on the original code level of the original code to obtain a corrected code.
[0189] In some embodiments of the present disclosure, the optimization unit 510 is configured to: when the original code level is the medium level or the poor level, detect the pre-annotated weak content in the original code to determine the area to be corrected; generate a first correction suggestion based on the area to be corrected, and optimize the original code based on the first correction suggestion to obtain a corrected code.
[0190] In some embodiments of the present disclosure, the determination unit 520 is configured to: perform decomposition operations on the original code and the corrected code respectively to construct a first abstract syntax network corresponding to the original code and a second abstract syntax network corresponding to the corrected code, where the first abstract syntax network includes first code elements corresponding to the original code, and the second abstract syntax network includes second code elements corresponding to the corrected code; construct a dynamic programming table based on the first code elements and the second code elements; determine the longest common subsequence based on the dynamic programming table; determine the different elements in the first code elements and the second code elements based on the longest common subsequence, and mark the different elements to obtain different labels; determine the difference distance between the first code elements and the second code elements; determine the code difference degree based on the different labels and the difference distance in combination with a preset graph convolutional neural network.
[0191] In some embodiments of the present disclosure, the determination unit 520 is configured to: use the different labels and the difference distance as the input of a preset graph convolutional neural network, and use the first hidden layer and the second hidden layer in the preset graph convolutional neural network to determine the code difference degree;
[0192] The first hidden layer is Formula 1:
[0193] Formula 1
[0194] Where is the adjacency matrix of the graph data with self-connections added, D is the degree matrix, is the normalized adjacency matrix; W(0) is the weight matrix of the first hidden layer.
[0195] The second hidden layer is Formula 2:
[0196] Formula 2
[0197] Wherein, is the adjacency matrix of the graph data with self-connections added, D is the degree matrix, is the normalized adjacency matrix, and W(1) is the weight matrix of the second hidden layer.
[0198] In some embodiments of the present disclosure, the evaluation unit 530 is configured to: compare the code difference degree with a preset difference threshold, and based on the comparison result, determine the correction code level of the corrected code, where the correction code level includes an excellent level, a medium level, and a poor level.
[0199] It should be noted that the foregoing explanation of the method embodiments also applies to the apparatus in this embodiment. The principle is the same and will not be limited in this embodiment.
[0200] Based on the above method as Figures 1 to 4 shown, correspondingly, this embodiment also provides a computer program product, including a computer program, which when executed by a processor implements the above method as Figures 1 to 4 shown.
[0201] Based on the above method as Figures 1 to 4 shown, correspondingly, this embodiment also provides a computer-readable storage medium, on which a computer program is stored, and the computer program when executed by a processor implements the above method as Figures 1 to 4 shown.
[0202] Based on such an understanding, the technical solution of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of various implementation scenarios of this application.
[0203] As Figure 6 shown is a schematic hardware structure diagram of an electronic device according to the present invention, including:
[0204] At least one processor 601; and,
[0205] A memory 602 communicatively connected to at least one of the processors 601; wherein,
[0206] The memory 602 stores instructions executable by at least one of the processors, and the instructions are executed by at least one of the processors so that at least one of the processors can execute the code level evaluation method as described above.
[0207] Figure 6 Take a processor 601 as an example.
[0208] The electronic device may further include: an input device 603 and a display device 604.
[0209] The processor 601, the memory 602, the input device 603, and the display device 604 may be connected through a bus or other means. In the figure, the connection through the bus is taken as an example.
[0210] As a non-volatile computer-readable storage medium, the memory 602 can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as the program instructions / modules corresponding to the review content generation method in the embodiments of the present application. For example, Figures 1 to 4 the method flow shown. The processor 601 executes various functional applications and data processing by running the non-volatile software programs, instructions, and modules stored in the memory 602, that is, implements the code level evaluation method in the above embodiments.
[0211] The memory 602 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the review content generation method, etc. In addition, the memory 602 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 602 may optionally include a memory remotely set relative to the processor 601, and these remote memories can be connected to the device for executing the review content generation method through a network. Examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0212] The input device 603 can receive input user clicks and generate signal inputs related to user settings and function controls of the review content generation method. The display device 604 may include a display screen and other display devices.
[0213] When the one or more modules are stored in the memory 602 and run by the one or more processors 601, the code level evaluation method in any of the above method embodiments is executed.
[0214] Optionally, the above-mentioned physical device may further include a user interface, a network interface, a camera, a Radio Frequency (RF) circuit, sensors, an audio circuit, a WI-FI module, and so on. The user interface may include a display, an input unit such as a keyboard, etc. Optionally, the user interface may further include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.
[0215] Those skilled in the art can understand that the structure of the above-mentioned physical device provided in this embodiment does not constitute a limitation on the physical device, and it may include more or fewer components, or combine certain components, or have different component arrangements.
[0216] The storage medium may further include an operating system and a network communication module. The operating system is a program for managing the hardware and software resources of the above-mentioned physical device, and supports the operation of information processing programs and other software and / or programs. The network communication module is used to implement communication between components inside the storage medium, as well as communication between other hardware and software in the information processing physical device.
[0217] Through the description of the above embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus a necessary general hardware platform, or can also be implemented by hardware. By applying the solution of this embodiment, compared with the current prior art, in this embodiment, the original code of the first object is optimized to obtain a corrected code corresponding to the original code; the code difference degree between the original code and the corrected code is determined; based on the code difference degree, the correction code level of the corrected code is determined, and the correction code level is pushed to the first object. The code quality assessment is carried out through the code difference degree, reducing the influence of subjective factors and improving the accuracy and efficiency of the code quality assessment.
[0218] It should be noted that in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover a non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the phrase "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0219] The above are only specific embodiments of the present application, enabling those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments described herein, but rather will be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A code level evaluation method, characterized in that: The method comprises: Optimizing the original code of the first object to obtain a modified code corresponding to the original code; determining a code difference between the original code and the revised code; determining a correction code level of the correction code based on the code difference, and pushing the correction code level to the first object; The determining of the code difference between the original code and the revised code comprises: Decomposing the original code and the revised code respectively, constructing a first abstract syntax network corresponding to the original code and a second abstract syntax network corresponding to the revised code, wherein the first abstract syntax network includes a first code element corresponding to the original code, and the second abstract syntax network includes a second code element corresponding to the revised code; Constructing a dynamic programming table based on the first code element and the second code element; Based on the dynamic programming table, determining the longest common subsequence; Based on the longest common subsequence, determining a difference element between the first code element and the second code element, and marking the difference element to obtain a difference label; determining a difference distance between the first code element and the second code element; Based on the difference label and the difference distance, combined with a preset graph convolutional neural network, the code difference degree is determined.
2. The method according to claim 1, characterized in that Before optimizing the original code of the first object to obtain the corrected code corresponding to the original code, the method includes: Obtaining a real-time input code of the first object; Determining an abnormal code in the real-time input code; An initial correction suggestion corresponding to the abnormal code is determined, and an initial correction prompt is given to the first object, so that the first object corrects the real-time input code based on the initial correction prompt to obtain the original code.
3. The method according to claim 1, characterized in that The optimizing the original code of the first object to obtain the corrected code corresponding to the original code includes: Determine the evaluation results of the original code under multiple evaluation indicators, wherein the multiple evaluation indicators include code complexity, code repetition rate, code coverage rate, code style inconsistency ratio, code review feedback score, code safety rate, and code team assistance score; Determine a comprehensive evaluation result of the original code based on the evaluation result and the preset weight corresponding to each evaluation indicator; Comparing the comprehensive evaluation result with a preset scoring threshold, and determining an original code grade of the original code based on the comparison result, wherein the original code grade includes an excellent grade, a medium grade, and a poor grade; Based on the original code level of the original code, the original code of the first object is optimized to obtain the modified code.
4. The method according to claim 1, characterized in that: The step of optimizing the original code of the first object based on the original code level of the original code to obtain the corrected code includes: If the original code level is medium or poor, detect the pre-marked weak content in the original code to determine the area to be corrected; Based on the area to be corrected, a first correction suggestion is generated, and based on the first correction suggestion, the original code is optimized to obtain the corrected code.
5. The method according to claim 1, characterized in that The determining of the code difference based on the difference label and the difference distance in combination with a preset graph convolutional neural network includes: Using the difference label and the difference distance as inputs of the preset graph convolutional neural network, and using the first hidden layer and the second hidden layer in the preset graph convolutional neural network to determine the code difference degree; The first hidden layer is Formula 1: Formula 1 in, is the adjacency matrix of the graph data with self-connection, D is the degree matrix, is the normalized adjacency matrix; W(0) is the weight matrix of the first hidden layer; The second hidden layer is Formula 2: Formula 2 in, is the adjacency matrix of the graph data with self-connection, D is the degree matrix, is the normalized adjacency matrix, and W(1) is the weight matrix of the second hidden layer.
6. The method according to claim 1, characterized in that The determining of the correction code level of the correction code based on the code difference comprises: The code difference degree is compared with a preset difference threshold, and based on the comparison result, a correction code grade of the correction code is determined, wherein the correction code grade includes an excellent grade, a medium grade, and a poor grade.
7. A code level evaluation device, characterized in that: The device comprises: An optimization unit, configured to optimize an original code of the first object to obtain a modified code corresponding to the original code; A determination unit, configured to determine a code difference between the original code and the revised code; an evaluation unit, configured to determine a correction code level of the correction code based on the code difference, and push the correction code level to the first object; The determining unit is used to perform decomposition operations on the original code and the revised code respectively, to construct a first abstract syntax network corresponding to the original code and a second abstract syntax network corresponding to the revised code, wherein the first abstract syntax network includes a first code element corresponding to the original code, and the second abstract syntax network includes a second code element corresponding to the revised code; Constructing a dynamic programming table based on the first code element and the second code element; Based on the dynamic programming table, determining the longest common subsequence; Based on the longest common subsequence, determining a difference element between the first code element and the second code element, and marking the difference element to obtain a difference label; determining a difference distance between the first code element and the second code element; Based on the difference label and the difference distance, combined with a preset graph convolutional neural network, the code difference degree is determined.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
9. An electronic device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Version code quality portrait construction method and device based on multi-level labels
CN117472739A
Code quality evaluation model training method and device and code quality evaluation method and device
CN118093385A