Code quality evaluation method and device based on multiple dimensions and medium

Through the comprehensive evaluation method of multi-dimensional indicator acquisition and machine learning models, the single-dimensional problem of traditional code evaluation is solved, accurate and efficient evaluation of code quality is achieved, and development costs are reduced.

CN120448240APending Publication Date: 2025-08-08SHANDONG INSPUR ULTRA HD INTELLIGENT TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510540528.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-27
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

Traditional code evaluation methods are mainly based on single-dimensional static analysis, which is difficult to cover the quality requirements of the entire life cycle, and cannot capture the dynamic characteristics of the program when it is run, resulting in low accuracy of code evaluation.

Method used

Multi-dimensional indicators are used to collect static, dynamic and process indicator data, regularly update indicator weights through machine learning models, comprehensive quality scores are performed in combination with preset benchmark scales, and code optimization suggestions are provided.

Benefits of technology

It realizes a comprehensive evaluation of code quality, improves the accuracy and timeliness of evaluation, reduces the time cost of post-debugging and repair, and saves project development costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448240A_ABST
    Figure CN120448240A_ABST
Patent Text Reader

Abstract

The invention discloses a code quality evaluation method and device based on multiple dimensions and a medium, and relates to the field of software engineering.The method comprises the steps that index data and result data corresponding to preset multi-dimensional indexes of source codes are collected in the target system development process based on a preset time period; obtaining an initial index weight corresponding to a preset multi-dimensional index, and regularly updating the initial index weight based on the index data and the result data through a trained machine learning model; and determining a quantitative score of the latest index data based on a preset reference scale, and weighting the quantitative score according to the updated index weight to obtain a comprehensive quality score of the source code. According to the method, the index data of the source code of the target system is collected based on the multi-dimensional index, meanwhile, the static code quality, the performance during dynamic operation and the efficiency of the development process are evaluated, the one-sidedness that a traditional method only depends on single dimension is solved, and more potential codes can be found.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software engineering technology, and in particular to a multi-dimensional code quality assessment method, device, and medium. Background Art

[0002] As software demand grows, the scale and complexity of software systems are also increasing. As software systems evolve from monolithic architectures to distributed architectures such as microservices, cloud native, and edge computing, the code size is growing exponentially. The amount of code in large systems can reach tens of millions of lines, and the complexity of dependencies between modules is increasing rapidly. Code quality assessment, as a core link to ensure the stability and security of software systems, is becoming increasingly important.

[0003] Traditional code evaluation methods primarily analyze code statically, using lexical analysis, syntax parsing, and control flow analysis to assess static metrics such as cyclomatic complexity, code compliance, and annotation coverage. For example, SonarQube identifies code smells through static scanning, while Checkstyle focuses on code formatting and standardization verification. While this static analysis approach can ensure code maintainability and consistency to a certain extent, it relies on a single dimension and struggles to cover quality requirements throughout the entire lifecycle. Furthermore, the analysis focuses solely on the code text itself, making it difficult to capture dynamic runtime features, resulting in low accuracy in assessing system code. Summary of the Invention

[0004] To solve the above problems, this application proposes a multi-dimensional code quality assessment method, including:

[0005] Based on a preset time period, indicator data and result data corresponding to preset multi-dimensional indicators of the source code are collected during the development process of the target system;

[0006] Obtaining initial indicator weights corresponding to the preset multidimensional indicators, and regularly updating the initial indicator weights based on the indicator data and the result data using a trained machine learning model;

[0007] A quantitative score of the latest indicator data is determined based on a preset benchmark scale, and the quantitative score is weighted according to the updated indicator weight to obtain a comprehensive quality score of the source code.

[0008] On the other hand, the present application also proposes a multi-dimensional code quality assessment device, comprising:

[0009] at least one processor; and,

[0010] a memory communicatively connected to the at least one processor; wherein,

[0011] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute a multi-dimensional code quality assessment method as described in the above example.

[0012] On the other hand, the present application also proposes a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured as: a multi-dimensional code quality assessment method as described in the above example.

[0013] This application proposes a multi-dimensional code quality assessment method that can bring the following beneficial effects:

[0014] Based on multi-dimensional indicators, the indicator data of the target system source code is collected, and the static code quality, dynamic runtime performance and development process efficiency are evaluated at the same time. This solves the one-sidedness of traditional methods that only rely on a single dimension and can discover more potential code problems.

[0015] Regularly updating indicator weights through trained machine learning models ensures that evaluations are more aligned with project realities and development needs, making code evaluations more accurate and providing developers with more precise improvement strategies. Furthermore, timely data collection and evaluation during the development process can quickly identify code issues, reducing the time required for later debugging and remediation, and saving both time and money on project development. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0017] Figure 1 This is a flowchart of a multi-dimensional code quality assessment method according to an embodiment of the present application;

[0018] Figure 2 This is a schematic diagram of a multi-dimensional code quality assessment device in an embodiment of the present application. DETAILED DESCRIPTION

[0019] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0020] The following describes in detail the technical solutions provided by various embodiments of the present application in conjunction with the accompanying drawings.

[0021] like Figure 1 As shown, the embodiment of the present application provides a multi-dimensional code quality assessment method, including:

[0022] S101: Based on a preset time period, indicator data and result data corresponding to preset multi-dimensional indicators of source code are collected during the development process of the target system.

[0023] Specifically, a preset time period is set, and multi-dimensional indicator data and result data of the target system are regularly collected during the development process of the target system based on the preset multi-dimensional indicators. Among them, the preset time period can be set according to the iteration cycle or version release cycle of the target system. The preset multi-dimensional indicators include static indicators, dynamic indicators and process indicators. Static indicators usually refer to indicators analyzed without running the code, including code complexity, annotation rate, code specification compliance, etc.; dynamic indicators are data collected when the program is running, including test coverage, response time, memory usage; process indicators may involve data during the development process, including code submission frequency, code review time, defect repair time, etc.

[0024] Furthermore, indicator data is collected through static analysis, dynamic analysis, and the development process. Specifically, the source code is determined to be in an uncompiled state, the source code is scanned, and static indicator data of the source code is collected. The source code is compiled and run, and program monitoring events are triggered to collect dynamic indicator data of the source code during compilation and run. The original log data of the target system is obtained, and within the original log data, process indicator data and result data associated with the source code within a preset time period are collected.

[0025] Collecting static metrics requires using static code analysis tools, such as SonarQube and Checkstyle, to scan source code and obtain data. Static code analysis tools analyze the code structure and extract static metric data, primarily including cyclomatic complexity (CC), code duplication rate (CDR), and style violations (SV). The corresponding result data includes complexity scores and violation warnings.

[0026] It should be noted that the calculation formula for cyclomatic complexity is: CC = E-N+2P, where E is the number of edges in the control flow graph, N is the number of nodes, and P is the number of connected components (usually 1, or the number of separate modules if the code has separate modules). Code repetition rate uses string hashing and AST (abstract syntax tree) to detect code similarity, and the calculation formula is: The number of violations is calculated by the rule engine, which counts the number of violations of the preset coding standards and then weights them by severity. The calculation formula is: Among them, w i is the weight of the i-th violation, which is predefined and can be adjusted during use, such as error = 0.8, warning = 0.3; c i is the number of times the i-th violation occurs.

[0027] The collection of dynamic indicators requires running test cases, using performance analysis tools such as JProfiler, or monitoring runtime logs, mainly including average response time (ART), memory leak rate (MLR), thread safety violations (TSV), etc. The corresponding result data includes test case pass rate, performance bottleneck report, etc.

[0028] It should be noted that the average response time is calculated by collecting the time taken by multiple requests during the stress test and taking the average value. The calculation formula is: Where n is the total number of requests for collecting data, T i is the time taken for the i-th request. The memory leak rate is calculated by monitoring the heap memory usage and calculating the memory growth per unit time. The calculation formula is: Among them, Δ M is in the time window Δ t Thread safety violations are calculated by using dynamic instrumentation tools to detect race conditions or unsynchronized shared resource accesses.

[0029] Process indicators are collected from version control systems such as Git, project management tools such as Jira, and CI / CD pipelines, mainly including test coverage (TC), code review pass rate (CRPR), defect repair cycle, etc. The corresponding result data includes team efficiency reports, problem tracking records, etc.

[0030] It should be noted that the test coverage calculation formula is: The formula for calculating the code review pass rate is: The defect repair cycle refers to tracking the defect tickets in the defect tracking system and calculating the average time from discovery to repair.

[0031] S102: Obtain initial indicator weights corresponding to the preset multi-dimensional indicators, and regularly update the initial indicator weights based on the indicator data and the result data through a trained machine learning model.

[0032] Specifically, the weight matrix of the project type corresponding to the target system is obtained, the initial indicator weights corresponding to the preset multidimensional indicators are determined, and the initial indicator weights are regularly updated within a preset time period based on the indicator data and result data through the trained machine learning model.

[0033] Prior to this, it also includes: determining the project type of the target system, obtaining the key quality objectives corresponding to the project type, setting the key quality objectives as the top-level objectives, setting the preset multidimensional indicators as the criterion layer, setting the indicator data corresponding to the preset multidimensional indicators as the sub-criterion layer, setting the project type as the solution layer, building a hierarchical model, and generating the initial indicator weights corresponding to the preset multidimensional indicators through the hierarchical model.

[0034] Specifically, through the expert rule engine, the importance of the preset multidimensional indicators is determined according to the key quality objectives, and an importance judgment matrix is generated. Through the hierarchical model, the importance judgment matrix is normalized, and the initial indicator weights corresponding to the preset multidimensional indicators are calculated.

[0035] It should be noted that before system development, project types were categorized based on business domain (e.g., web applications, embedded systems, financial systems), scale, and quality priorities (security, performance, maintainability). Domain experts were invited to compare the importance of indicators for different project types, determine their importance, generate a judgment matrix, and build an expert rule judgment library. The expert rule engine then determined the corresponding importance judgment matrix.

[0036] Furthermore, based on the result data, quality labels are generated and added to the indicator data, and the indicator data is normalized to obtain standard feature vectors. Based on the standard feature vectors and the corresponding initial indicator weights, input features are generated and input into the trained machine learning model. Through the machine learning model, the initial indicator weights are redistributed to obtain the optimized weights corresponding to the indicator weights.

[0037] In the embodiment of the present application, first, define the project type feature vector: P = [p1, p2, p3...p k ], where performance-sensitive is defined as p1, safety-critical is defined as p2, data-intensive is defined as p3, etc. The initial weight matrix W ini , this matrix can be generated through expert experience or historical data:

[0038]

[0039] Among them, w ijis the weight of the i-th category item on the j-th indicator. Secondly, weight optimization is performed through machine learning, dynamically optimizing weights based on historical evaluation data to improve scoring accuracy. Using a random forest or gradient boosted tree (GBDT) model, with historical scoring data as the training set, the weight distribution is optimized to obtain the optimized weight matrix. The model's objective function is to minimize the mean squared error between the predicted and actual scores: Among them, min is the minimum function, is the minimum predicted score, is the actual rating.

[0040] S103: Determine a quantitative score of the latest indicator data based on a preset benchmark scale, and weight the quantitative score according to the updated indicator weight to obtain a comprehensive quality score of the source code.

[0041] Specifically, the latest indicator data of the target system within the current preset time period is obtained, and the quantitative scores of the latest indicator data are calculated according to the preset benchmark scales corresponding to the preset multi-dimensional indicators. The quantitative scores are weighted according to the updated indicator weights to obtain the comprehensive quality score of the source code.

[0042] Furthermore, the quality score threshold corresponding to the key quality target is obtained to determine whether the comprehensive quality score is higher than the quality score threshold. If not, code optimization suggestions for the source code are generated based on the latest indicator data through the rule engine.

[0043] The latest indicator data is input into the rule engine, and the optimization rule database is traversed through the rule engine to obtain multiple optimization rules corresponding to the latest indicator data. Based on the priority of the optimization rules, multiple optimization rules are used in turn to generate code optimization suggestions for the corresponding source code.

[0044] It should be noted that in order to eliminate the dimensional differences of different indicators and make them comparable, the indicators need to be normalized. Min-Max normalization is used to eliminate dimensional differences. The specific calculation formula is: Among them, max is the maximum value function, min is the minimum value function, M i is the value of the i-th indicator. Based on the time series model ARIMA, the quality trend is predicted and the predicted value is recorded as T r , the final weighted comprehensive score calculation formula is as follows: Where α is the trend attenuation factor (usually 0.1 to 0.3). Predefine optimization rules in the "IF-condition THEN-recommendation" format, and then use the rule engine to match triggered rules in real time. An example optimization rule is as follows: IF the memory leak rate is > 2MB / s AND the project type is microservices, THEN recommends checking the database connection pool configuration or adding resource release logic.

[0045] In addition, in the embodiment of the present application, a knowledge graph is constructed and data mining is performed to generate a high-level repair strategy. The nodes of the knowledge graph are code defects (such as NullPointerException, memory leak), optimization measures (such as using a connection pool, adding a synchronization lock), etc. The edges of the knowledge graph are the associations between defects and measures (such as "memory leak → check resource release"). Then, frequent item sets are extracted and rules with a confidence level > 70% are retained. The confidence calculation formula is as follows: Among them, S(A) is the support of rule A, and S(A∪B) is the support of rule "A and B".

[0046] For example, when evaluating microservice system code, the metrics are cyclomatic complexity (CC) = 18, code duplication rate (CDR) = 10%, average response time (ART) = 250ms, memory leak rate (MLR) = 1.8MB / s, test coverage (TC) = 88%, and review pass rate (CRPR) = 92%. The initial weights are 0.5 for performance, 0.2 for security, and 0.3 for maintainability. After optimization, the weights are 0.55 for performance, 0.15 for security, and 0.3 for maintainability. Normalized metrics: ART' = 0.75, MLR' = 0.36, CC' = 0.35. The resulting overall quality score is: Score = 0.75 × 0.55 + 0.36 × 0.55 + 0.35 × 0.3 + 0.2 × 0.85 = 78 / 100. Rule trigger: "Memory leak rate > 1.5 MB / s → Check connection pool configuration." Knowledge graph association: "Memory leak → Use try-with-resources to release resources."

[0047] This application collects indicator data of the target system source code based on multi-dimensional indicators, and simultaneously evaluates static code quality, dynamic runtime performance and development process efficiency. It solves the one-sidedness of traditional methods that rely only on a single dimension and can discover more potential code problems.

[0048] Regularly updating indicator weights through trained machine learning models ensures that evaluations are more aligned with project realities and development needs, making code evaluations more accurate and providing developers with more precise improvement strategies. Furthermore, timely data collection and evaluation during the development process can quickly identify code issues, reducing the time required for later debugging and remediation, and saving both time and money on project development.

[0049] like Figure 2 As shown, the embodiment of the present application also proposes a multi-dimensional code quality assessment device, including:

[0050] at least one processor; and,

[0051] a memory communicatively connected to the at least one processor; wherein,

[0052] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute a multi-dimensional code quality assessment method as described in any of the above embodiments.

[0053] An embodiment of the present application further provides a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured to be: a multi-dimensional code quality assessment method as described in any of the above embodiments.

[0054] The various embodiments in this application are described in a progressive manner. Similar portions between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the device and medium embodiments are generally similar to the method embodiments, so their descriptions are relatively simple. For relevant portions, refer to the descriptions of the method embodiments.

[0055] The devices and media provided in the embodiments of the present application correspond one-to-one to the methods. Therefore, the devices and media also have similar beneficial technical effects to their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.

[0056] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0057] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.

[0058] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0059] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0060] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0061] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0062] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0063] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0064] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application should be included within the scope of the claims of the present application.

Claims

1. A multi-dimensional code quality assessment method, characterized in that: include: Based on a preset time period, indicator data and result data corresponding to preset multi-dimensional indicators of the source code are collected during the development process of the target system; Obtaining initial indicator weights corresponding to the preset multidimensional indicators, and regularly updating the initial indicator weights based on the indicator data and the result data using a trained machine learning model; A quantitative score of the latest indicator data is determined based on a preset benchmark scale, and the quantitative score is weighted according to the updated indicator weight to obtain a comprehensive quality score of the source code.

2. A multi-dimensional code quality assessment method according to claim 1, characterized in that: The preset multi-dimensional indicators include static indicators, dynamic indicators and process indicators; The target system development process includes collecting indicator data and result data corresponding to preset multi-dimensional indicators of the source code respectively, specifically including: determining that the source code is in an uncompiled state, scanning the source code, and collecting static indicator data of the source code; Compile and run the source code, trigger a program monitoring event, and collect dynamic indicator data of the source code during compilation and operation; Original log data of the target system is acquired, and process indicator data and result data associated with the source code within the preset time period are collected from the original log data.

3. A multi-dimensional code quality assessment method according to claim 2, characterized in that: The periodic updating of the initial indicator weights based on the indicator data and the result data by the trained machine learning model specifically includes: Based on the result data, a quality label is generated and added to the indicator data, and the indicator data is normalized to obtain a standard feature vector; Generate input features based on the standard feature vector and the corresponding initial indicator weights, and input them into the trained machine learning model; The initial indicator weights are redistributed through the machine learning model to obtain optimized weights corresponding to the indicator weights.

4. A multi-dimensional code quality assessment method according to claim 1, characterized in that: Before obtaining the initial indicator weight corresponding to the preset multi-dimensional indicator, the method further includes: Determine the project type of the target system and obtain key quality objectives corresponding to the project type; Building a hierarchical structure model based on the key quality objectives and the preset multidimensional indicators; The initial indicator weights corresponding to the preset multi-dimensional indicators are generated through the hierarchical structure model.

5. A multi-dimensional code quality assessment method according to claim 4, characterized in that: Generating the initial indicator weights corresponding to the preset multi-dimensional indicators through the hierarchical structure model specifically includes: By using an expert rule engine, the importance of the preset multi-dimensional indicators is determined according to the key quality objectives, and an importance judgment matrix is generated; The importance judgment matrix is normalized through the hierarchical structure model, and the initial indicator weights corresponding to the preset multidimensional indicators are calculated.

6. A multi-dimensional code quality assessment method according to claim 5, characterized in that: After weighting the quantitative score according to the update indicator weight to obtain the comprehensive quality score of the source code, the method further includes: Obtaining a quality score threshold corresponding to the key quality objective, and determining whether the comprehensive quality score is higher than the quality score threshold; If not, a code optimization suggestion for the source code is generated based on the latest indicator data through a rule engine.

7. A multi-dimensional code quality assessment method according to claim 6, characterized in that: Generating code optimization suggestions for the source code based on the latest indicator data through a rule engine specifically includes: Inputting the latest indicator data into a rule engine, and traversing an optimization rule database through the rule engine to obtain a plurality of optimization rules corresponding to the latest indicator data; Based on the priorities of the optimization rules, code optimization suggestions corresponding to the source code are generated by sequentially applying the multiple optimization rules.

8. A multi-dimensional code quality assessment method according to claim 1, characterized in that: Determining the quantitative score of the latest indicator data based on the preset benchmark scale specifically includes: Obtain the latest indicator data of the target system within the current preset time period; Calculate the quantitative scores of the latest indicator data according to the preset benchmark scales corresponding to the preset multidimensional indicators.

9. A multi-dimensional code quality assessment device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute a multi-dimensional code quality assessment method as described in any one of claims 1 to 8.

10. A non-volatile computer storage medium storing computer executable instructions, characterized in that: The computer executable instructions are configured as: a multi-dimensional code quality assessment method as described in any one of claims 1 to 8.

Citation Information

Cited By

  • Software delivery automatic evaluation method and system

    CN121880204A