CN118093385A - Training of code quality evaluation model, and code quality evaluation method and device - Google Patents

Training of code quality evaluation model, and code quality evaluation method and device Download PDF

Info

Publication number
CN118093385A
CN118093385A CN202410155821.6A CN202410155821A CN118093385A CN 118093385 A CN118093385 A CN 118093385A CN 202410155821 A CN202410155821 A CN 202410155821A CN 118093385 A CN118093385 A CN 118093385A
Authority
CN
China
Prior art keywords
code
quality evaluation
index
training
rule
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410155821.6A
Other languages
Chinese (zh)
Inventor
欧建斌
何晓
李学优
何韶兴
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202410155821.6A priority Critical patent/CN118093385A/en
Publication of CN118093385A publication Critical patent/CN118093385A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/30Computing systems specially adapted for manufacturing

Landscapes

  • Stored Programmes (AREA)

Abstract

The application relates to a training method, a training device, a training computer device, a training storage medium and a training computer program product of a code quality assessment model. The method comprises the following steps: acquiring index data corresponding to the training sample codes under each code quality evaluation index; training sample codes are application program codes of the repaired code problems; the repaired code problem is a code problem detected by a sample application program by adopting a preset code scanning rule and repaired; the code quality evaluation index comprises a problem difficulty index and a problem repair cost index; and acquiring the actual repair time corresponding to the repaired code problem, and training the code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index to obtain an object code quality evaluation model for predicting the code technology liability corresponding to the application program to be tested. By adopting the method, the accuracy of code quality evaluation can be improved.

Description

Training of code quality evaluation model, and code quality evaluation method and device
Technical Field
The present application relates to the field of artificial intelligence technology, and in particular, to a method, an apparatus, a computer device, a storage medium, and a computer program product for training a code quality evaluation model.
Background
Code is text composed of characters, symbols, etc. written in accordance with a certain programming language specification. With the development of program projects becoming larger and more complex, one program project often consists of a large amount of codes, meanwhile, the writing of the codes of the program project is usually completed by the cooperation of a plurality of program developers, and many factors affecting the quality of the codes exist, such as the connection problem of functions of the codes written by different program developers, the unification problem of writing styles and the like.
In the process of software development, the code quality often directly affects the maintainability, performance and security of the software. How to evaluate the quality of written code becomes a problem. In the related art, a test script of a full amount of codes is often tested in sequence, and then the code quality is estimated according to the test results of all the test scripts, so that the code quality cannot be estimated accurately.
Therefore, there is a problem in the related art that the code quality evaluation is inaccurate.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a training of a code quality assessment model, a code quality assessment method, an apparatus, a computer device, a computer-readable storage medium, and a computer program product, which are capable of improving accuracy of code quality assessment.
In a first aspect, the present application provides a training method of a code quality assessment model, including:
Acquiring index data corresponding to the training sample codes under each code quality evaluation index; the training sample code is an application program code of the repaired code problem; the repaired code problem is a code problem detected by a sample application program by adopting a preset code scanning rule and repaired;
Each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the code scanning rule and rule average repair time of the code scanning rule for the code problems in the sample application program;
Acquiring the actual repair time corresponding to the repaired code problem, and training a code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index to obtain a target code quality evaluation model; the target code quality evaluation model is used for predicting the code technology liability rate corresponding to the application program to be tested.
In one embodiment, the training the code quality evaluation model to be trained according to the actual repair time and the index data corresponding to the training sample code under each code quality evaluation index to obtain a target code quality evaluation model includes:
Inputting each index data into the code quality evaluation model to be trained, and predicting the code problem repair time of the repaired code problem under the code scanning rule through the code quality evaluation model to be trained to obtain the corresponding predicted repair time of the repaired code problem under the code scanning rule;
And training the code quality evaluation model to be trained according to the difference between the predicted repair time and the actual repair time to obtain the target code quality evaluation model.
In one embodiment, the training the code quality assessment model to be trained according to the difference between the predicted repair time and the actual repair time to obtain the target code quality assessment model includes:
Updating model parameters of the code quality evaluation model to be trained according to the difference; the model parameters comprise weights corresponding to the code quality evaluation indexes;
retraining the code quality assessment model with updated model parameters until the trained code quality assessment model meets the preset training ending condition, so as to obtain the target code quality assessment model.
In one embodiment, the rule repair evaluation time is a pre-evaluated average repair time of code problems detected in the sample application using the code scanning rule;
The obtaining the corresponding index data of the training sample codes under each code quality evaluation index comprises the following steps:
Acquiring the number of repaired code problems and the number of unrepaired code problems corresponding to the sample application program under the code scanning rule, and the actual average repair time corresponding to the repaired code problems;
and obtaining the rule average repair time according to the product result of the number of repaired code problems and the actual average repair time, the product result of the number of unrepaired code problems and the rule repair evaluation time, and the total number of code problems.
In one embodiment, there are at least two code scanning rules and at least two sample applications; training the code quality evaluation model to be trained to obtain an object code quality evaluation model, comprising the following steps:
Taking index data and actual repair time corresponding to each sample application program under the same code scanning rule as a training unit;
And training the code quality evaluation model to be trained according to the training units corresponding to the code scanning rules to obtain the target code quality evaluation model.
In a second aspect, the present application also provides a code quality assessment method, the method comprising:
Code problems scanned in test program codes corresponding to an application program to be tested according to target code scanning rules are solved, and index data corresponding to the test program codes under each code quality evaluation index are obtained;
Each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the target code scanning rule and rule average repair time of the target code scanning rule for code problems in the test program code;
Inputting index data corresponding to each code quality evaluation index into a target code quality evaluation model, and predicting the repair time of an unrepaired code problem in the test program code through the target code quality evaluation model to obtain a code technology liability rate corresponding to the application program to be tested; the code technology liability rate is used for evaluating the code quality of the application program to be tested; the object code quality assessment model is obtained according to the training method of the code quality assessment model according to any one of claims 1 to 5.
In one embodiment, there are a plurality of the object code scanning rules; the unrepaired code problems include unrepaired code problems detected in the test program code by each of the target code scanning rules;
Inputting the corresponding index data under each code quality evaluation index into an object code quality evaluation model, predicting the repair time of the unrepaired code problem in the test program code through the object code quality evaluation model, and obtaining the code technology liability rate corresponding to the application program to be tested, wherein the method comprises the following steps:
Inputting index data corresponding to each code quality evaluation index under each target code scanning rule into a target code quality evaluation model, and predicting the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule;
And obtaining the code technology liability rate corresponding to the application program to be tested according to the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule and the code writing cost time corresponding to the test program code.
In a third aspect, the present application further provides a training device for a code quality assessment model, including:
The training data acquisition module is used for acquiring index data corresponding to the training sample codes under the quality evaluation indexes of the codes; the training sample code is an application program code of the repaired code problem; the repaired code problem is a code problem detected by a sample application program by adopting a preset code scanning rule and repaired;
The code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the code scanning rule and rule average repair time of the code scanning rule for the code problems in the sample application program;
The training module is used for collecting the actual repair time corresponding to the repaired code problem, and training the code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index to obtain an object code quality evaluation model; the target code quality evaluation model is used for predicting the code technology liability rate corresponding to the application program to be tested.
In a fourth aspect, the present application also provides a code quality evaluation apparatus, including:
the system comprises a to-be-tested data acquisition module, a code analysis module and a code analysis module, wherein the to-be-tested data acquisition module is used for acquiring index data corresponding to test program codes corresponding to an application program to be tested according to code problems scanned in the test program codes according to target code scanning rules;
Each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the target code scanning rule and rule average repair time of the target code scanning rule for code problems in the test program code;
The prediction module is used for inputting the corresponding index data under each code quality evaluation index into a target code quality evaluation model, and predicting the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the code technology liability rate corresponding to the application program to be tested; the code technology liability rate is used for evaluating the code quality of the application program to be tested; the target code quality evaluation model is obtained according to the training method of the code quality evaluation model.
In a fifth aspect, the present application also provides a computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the steps of the training method of the code quality assessment model according to the first aspect or any one of the possible implementations of the first aspect and/or the steps of the code quality assessment method according to the second aspect or any one of the possible implementations of the second aspect when the computer program is executed.
In a sixth aspect, the present application also provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the training method of the code quality assessment model according to the first aspect or any of the possible implementations of the first aspect, and/or the steps of the code quality assessment method according to the second aspect or any of the possible implementations of the second aspect.
In a seventh aspect, the present application also provides a computer program product comprising a computer program which, when executed by a processor, implements the steps of the training method of the code quality assessment model as described in the first aspect or any of the possible implementations of the first aspect, and/or the steps of the code quality assessment method as described in the second aspect or any of the possible implementations of the second aspect.
The training method, the device, the computer equipment, the storage medium and the computer program product of the code quality evaluation model are characterized in that index data corresponding to the training sample codes under each code quality evaluation index are obtained; training sample codes are application program codes of the repaired code problems; the repaired code problem is a code problem detected by a sample application program by adopting a preset code scanning rule and repaired; each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the code scanning rule and rule average repair time of the code scanning rule for the code problem in the sample application program; acquiring actual repair time corresponding to the repaired code problem, and training a code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index to obtain a target code quality evaluation model; the target code quality evaluation model is used for predicting the code technology liability rate corresponding to the application program to be tested.
In this way, by setting a plurality of measurable code quality evaluation indexes related to code quality evaluation, index data corresponding to the training sample codes under each code quality evaluation index is obtained; the code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to a code scanning rule and rule average repair time of the code scanning rule for code problems in a sample application program, then, the actual repair time corresponding to the repaired code problems in a training sample code and the index data corresponding to each code quality evaluation index are adopted to train a code quality evaluation model to be trained, so that the code technical liability rate corresponding to the application program to be tested can be quantized more accurately through the index data of multiple dimensions by the target code quality evaluation model obtained after training, the code quality of the application program to be tested can be represented more accurately by the predicted code technical liability rate, and the accuracy of code quality evaluation is effectively improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the related art, the drawings that are required to be used in the embodiments or the related technical descriptions will be briefly described, and it is apparent that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to the drawings without inventive effort for those skilled in the art.
FIG. 1 is a flow chart of a training method of a code quality assessment model in one embodiment;
FIG. 2 is a block diagram of a BP neural network in one embodiment;
FIG. 3 is a flow chart of a code quality assessment method in one embodiment;
FIG. 4 is a flow chart of another code quality assessment method in one embodiment;
FIG. 5 is a block diagram of a training device of a code quality assessment model in one embodiment;
FIG. 6 is a block diagram of a code quality assessment apparatus in one embodiment;
fig. 7 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the foregoing figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the disclosure described herein may be capable of operation in sequences other than those illustrated or described herein. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present disclosure as detailed in the accompanying claims.
In one embodiment, as shown in fig. 1, a training method of a code quality assessment model is provided, and this embodiment is applied to a terminal for illustration by using the method, it is understood that the method may also be applied to a server, and may also be applied to a system including the terminal and the server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the steps of:
Step S110, index data corresponding to the training sample codes under each code quality evaluation index is obtained.
The training sample code is application program code of the repaired code problem.
The repaired code problem is a code problem detected by a sample application program and repaired by adopting a preset code scanning rule.
Wherein the code quality evaluation index is an index for evaluating the code quality.
The application program code is the code of the problem which is already solved by the sample application program, namely the application program code is the code of the problem of the repaired code of the sample application program.
Wherein the sample application is an application whose code can be the training sample code.
In a specific implementation, the terminal can acquire application program codes of the repaired code problem corresponding to the sample application program as training sample codes, and acquire index data corresponding to the training sample codes under each code quality evaluation index. Specifically, the terminal may obtain, according to a preset code scanning rule, code problems detected by an application program code corresponding to the sample application program, and index data corresponding to the training sample code under each code quality evaluation index.
Specifically, by performing static code scanning on the application program codes corresponding to the sample application program, the code problems in the application program codes corresponding to the sample application program and the problem repair states corresponding to the code problems can be determined, so that the repaired code problems in the application program codes corresponding to the sample application program can be determined, and the application program codes with the repaired code problems can be obtained as training sample codes. Therefore, the repaired code problem detected by the application program code corresponding to the sample application program according to the preset code scanning rule can be obtained, and index data corresponding to the training sample code under each code quality evaluation index can be obtained.
In practical application, the terminal may perform static code scanning on the application code corresponding to the application program by using a static code scanning tool, and a preset code scanning rule is defined in the static code scanning tool, so that a code problem in the application code corresponding to the sample application program can be detected through the preset code scanning rule.
Wherein if the detected code problem has changed to a repaired state relative to a previously saved problem repair state, the code problem is determined to be a repaired code problem.
The code quality evaluation index comprises a problem difficulty index and a problem repair cost index.
The problem difficulty index is an index for describing code problem repair difficulty, and may include, but is not limited to, at least one of code complexity, repeatability, line coverage rate and call depth.
The code complexity is the complexity of the method in which the code problem is located; the repeatability is the repeatability of the line where the code problem is located; the line coverage rate is the coverage rate of the line where the code problem is located; the call depth is the method call depth of the line where the code problem exists. Wherein, the code problem is located in the code row where the code problem is located.
The problem repair cost index is an index for describing code problem repair time.
The index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to a preset code scanning rule and rule average repair time of the preset code scanning rule for code problems in the sample application program.
The rule repairing evaluation time may be a problem repairing time estimated in advance by a rule developer and/or a rule requirement proposer for the code scanning rule. In practical applications, the rule repair evaluation time may be specifically an average repair time of a rule developer and/or a rule requirement for evaluating a code problem detected by a code scanning rule.
The rule average repair time may be an average repair time of a code problem calculated for a code problem detected by a code scanning rule in an application code corresponding to a sample application.
Step S120, collecting the actual repair time corresponding to the repaired code problem, and training the code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index to obtain the target code quality evaluation model.
The target code quality evaluation model is used for predicting the code technology liability rate corresponding to the application program to be tested.
The code quality evaluation model is a neural network model capable of evaluating code quality, such as a deep learning model; in a practical scenario, the network structure of the code quality assessment model may employ a BP (Back Propagation) neural network.
In a specific implementation, the terminal can train the code quality assessment model to be trained according to index data corresponding to the training sample codes under each code quality assessment index, and when the trained code quality assessment model meets a preset training ending condition, an object code quality assessment model is obtained.
Further, the terminal can collect the actual repair time of the repaired code problem of the sample application program, and train the code quality evaluation model to be trained according to the actual repair time of the repaired code problem and the index data corresponding to the training sample code under each code quality evaluation index.
Specifically, index data corresponding to the training sample codes under each code quality evaluation index can be input into a code quality evaluation model to be trained, the code quality evaluation model to be trained can predict the repair time of the repaired code problem, and the terminal can train the code quality evaluation model to be trained based on the predicted repair time corresponding to the repaired code problem output by the code quality evaluation model to be trained and the corresponding actual repair time.
In this way, the terminal can predict the code technology liability rate corresponding to the application program to be tested by adopting the target code quality evaluation model so as to evaluate the code quality of the application program code corresponding to the application program to be tested.
In practical application, the terminal can be used for collecting the repair time of each code problem by setting a buried point in the IDE (INTEGRATED DEVELOPMENT ENVIRONMENT ) in the process of collecting the actual repair time corresponding to the repaired code problem.
Specifically, when the application code corresponding to the sample application is scanned, the change (new or modified) time of each line may be read from the source code control software, and the change line and the change time of the current version may be identified. By setting a buried point in the IDE of each developer development environment, the repair time for each code problem is collected. After an application program code file corresponding to a sample application program is opened at the IDE, triggering static code scanning is started, and when a developer performs space code entry or line feed operation each time, the static code scanning is automatically triggered, and if the scanned code problem is changed into a repaired state relative to a state stored before, the repair time of the repaired problem is calculated. The problem repair start time may be the time when the IDE opens the application code file on the same day, and the line development where the problem is located is displayed in the edit view page; the problem repair end time is the time when the code problem was successfully repaired. When a developer stores the code, the repair time of the code problem is prompted to display the problem which appears at the beginning, the time for starting the repair and the time for solving the problem, and the developer can adjust the problem repair starting time to more accurately judge the actual repair time of the code problem.
In the training method of the code quality evaluation model, the corresponding index data of the training sample codes under each code quality evaluation index is obtained; training sample codes are application program codes of the repaired code problems; the repaired code problem is a code problem detected by a sample application program by adopting a preset code scanning rule and repaired; each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the code scanning rule and rule average repair time of the code scanning rule for the code problem in the sample application program; acquiring actual repair time corresponding to the repaired code problem, and training a code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index to obtain a target code quality evaluation model; the target code quality evaluation model is used for predicting the code technology liability rate corresponding to the application program to be tested.
In this way, by setting a plurality of measurable code quality evaluation indexes related to code quality evaluation, index data corresponding to the training sample codes under each code quality evaluation index is obtained; the code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to a code scanning rule and rule average repair time of the code scanning rule for code problems in a sample application program, then, the actual repair time corresponding to the repaired code problems in a training sample code and the index data corresponding to each code quality evaluation index are adopted to train a code quality evaluation model to be trained, so that the code technical liability rate corresponding to the application program to be tested can be quantized more accurately through the index data of multiple dimensions by the target code quality evaluation model obtained after training, the code quality of the application program to be tested can be represented more accurately by the predicted code technical liability rate, and the accuracy of code quality evaluation is effectively improved.
In one embodiment, training a code quality evaluation model to be trained according to an actual repair time and index data corresponding to a training sample code under each code quality evaluation index to obtain an object code quality evaluation model, including: inputting each index data into a code quality evaluation model to be trained, and predicting the code problem repair time of the repaired code problem under the code scanning rule through the code quality evaluation model to be trained to obtain the corresponding predicted repair time of the repaired code problem under the code scanning rule; and training the code quality evaluation model to be trained according to the difference between the predicted repair time and the actual repair time to obtain the target code quality evaluation model.
In the specific implementation, the terminal trains the code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index, so that in the process of obtaining the target code quality evaluation model, the terminal can input each index data into the code quality evaluation model to be trained, and predicts the code problem repair time of the repaired code problem under the code scanning rule through the code quality evaluation model to be trained, so as to obtain the predicted repair time corresponding to the repaired code problem under the code scanning rule. Therefore, the terminal can calculate the difference between the predicted repair time and the actual repair time corresponding to the repaired code problem, and train the code quality evaluation model to be trained according to the difference to obtain the target code quality evaluation model.
In practical application, because the code styles of each application program are different, the time required for repairing the problem is also different, wherein the ring complexity of the code (the number of test cases which are used for covering all possible branching situations least) and the repetition degree of the code are influenced by indexes, the modification difficulty of the code row where the problem exists in the present code is correspondingly increased in a method with high complexity, and the difficulty of the problem modification is also increased when the code row exists in the repeated code block. Therefore, when predicting the repair time of each code problem, the complexity of the method in which the code line is located, whether the code line is in a repeated block or not, the coverage rate condition, the code call depth, the rule repair evaluation time and the rule average repair time can be judged, so that the weighting calculation is performed when the problem repair time is predicted.
Correspondingly, the index data corresponding to the training sample codes under the code quality evaluation indexes comprise index acquisition data and index coefficient data corresponding to the code quality evaluation indexes.
The index collection data are numerical data actually collected under the code quality evaluation index. The index coefficient data is a normalization coefficient corresponding to the index acquisition data.
For the problem repair cost index, the rule repair evaluation time is index acquisition data corresponding to the problem repair cost index, and the rule average repair time is index coefficient data corresponding to the problem repair cost index.
The problem difficulty index may include, among other things, code complexity, repetition, line coverage, and call depth.
In practical application, the description is given by taking the example that the problem difficulty index comprises code complexity, repeatability, row coverage rate and calling depth: the index data corresponding to the training sample codes under the code complexity index comprises the complexity of the method in which the repaired code problem is located and the corresponding complexity coefficient; the index data corresponding to the training sample codes under the repeatability index comprises the repeatability of the row where the repaired code problem is located and the corresponding repeatability coefficient; the corresponding index data of the training sample code under the row coverage index comprises the row coverage of the row where the repaired code problem is located and a corresponding coverage coefficient; the index data corresponding to the training sample code under the index of the calling depth comprises the calling depth of the method where the repaired code problem exists and the corresponding calling depth coefficient.
The terminal can acquire the mapping relation between the index acquisition data corresponding to each code quality evaluation index and the index coefficient data, and after the index acquisition data are obtained, the index coefficient data corresponding to the index acquisition data are determined according to the corresponding mapping relation.
Wherein:
1. Code complexity
When the complexity of the method of the code problem exceeds 15, mapping the complexity of 15 to 100 to 1 to 2 as a complexity coefficient; the complexity factor is 1 when the complexity does not exceed 15.
2. Degree of repetition
When the line where the code problem is located is a repeated block, the repeated lines 10 to 100 are mapped to 1 to 2 as the repetition degree coefficients.
3. Line coverage
When the code problem is covered by the existing automatic test case, the coverage coefficient is 0.8, and when the code problem is uncovered, the coverage coefficient is 0.
4. Depth of call
When the call depth of the method of the line where the code problem exists is larger than 3, mapping the call depth to be between 1 and 2 as a call depth coefficient. Wherein use is made of(3 < = X < = 100) where X is the call depth and Y is the call depth coefficient, as a normalization function. Y=2 when the call depth is greater than 100.
In this way, in the process of inputting each index data into the code quality evaluation model to be trained, the terminal can input the index acquisition data and the index coefficient data corresponding to each code quality evaluation index into the code quality evaluation model to be trained. Specifically, as an alternative embodiment of the present application, the complexity of the method in which the repaired code problem of the training sample code exists, and the corresponding complexity coefficient may be set; the complexity of the row where the repaired code problem is located and the corresponding complexity coefficient; the row coverage rate of the row where the repaired code problem is located and the corresponding coverage rate coefficient; the method call depth of the line where the repaired code problem exists, and the corresponding call depth coefficient; and inputting the rule repair evaluation time and the rule average repair time into a code quality evaluation model to be trained. The code quality evaluation model to be trained can multiply the index acquisition data with corresponding index coefficient data to predict the code problem repair time of the repaired code problem.
According to the technical scheme, the code quality evaluation model to be trained is used for predicting the code problem repair time of the repaired code problem under the code scanning rule by inputting the index data to the code quality evaluation model to be trained, so that the predicted repair time of the repaired code problem corresponding to the code scanning rule is obtained; and training the code quality evaluation model to be trained according to the difference between the predicted repair time and the actual repair time to obtain the target code quality evaluation model. In this way, the code quality assessment model to be trained can predict the repair time of the repaired code problem through the multidimensional index data, obtain the predicted repair time corresponding to the repaired code problem, train the code quality assessment model to be trained according to the difference between the predicted repair time and the actual repair time, and can help the model to continuously identify and correct the deviation in prediction, so that the accuracy and reliability of model output are improved.
In one embodiment, training a code quality assessment model to be trained according to the difference between the predicted repair time and the actual repair time to obtain an object code quality assessment model, including: updating model parameters of the code quality evaluation model to be trained according to the difference; the model parameters comprise weights corresponding to the code quality evaluation indexes; retraining the code quality assessment model after model parameter updating until the trained code quality assessment model meets the preset training ending condition, and obtaining the target code quality assessment model.
In the specific implementation, the terminal trains the code quality assessment model to be trained according to the difference between the predicted repair time and the actual repair time, and in the process of obtaining the target code quality assessment model, the terminal can update the model parameters of the code quality assessment model to be trained according to the difference; the model parameters comprise weights corresponding to the code quality evaluation indexes; and then retraining the code quality assessment model with updated model parameters until the trained code quality assessment model meets the preset training ending condition to obtain the target code quality assessment model.
In practical application, the network structure of the code quality evaluation model to be trained can adopt a BP neural network. The BP neural network is a multi-layer feedforward neural network trained according to an error back propagation algorithm, as shown in a BP neural network structure diagram in fig. 2, the BP neural network is composed of an input layer, a hidden layer and an output layer, and the hidden layer can be one or more layers. And the BP neural network continuously adjusts the index weight corresponding to each code quality evaluation index through the transfer function and the error anti-transfer function until the error function value reaches the minimum, and the training is completed.
As shown in fig. 2, the method uses index data corresponding to the training sample codes under each code quality evaluation index as input, and the index data comprises indexes such as code complexity, repeatability, row coverage, calling depth, problem repairing cost and the like. The error function may be a difference between an output value of the predicted repair time corresponding to the repaired problem and an actual repair time corresponding to the repaired problem.
It can be understood that, in practical application, the difference between the predicted repair time corresponding to the repaired problem and the corresponding actual repair time may be the difference between the predicted average repair time corresponding to the repaired problem and the actual average repair time corresponding to the repaired problem. In some embodiments, the difference between the predicted repair time corresponding to the repaired problem and the corresponding actual repair time may also include the difference between the predicted repair time corresponding to each repaired problem and the corresponding actual repair time. The present invention is not particularly limited herein.
According to the technical scheme of the embodiment, model parameters of a code quality evaluation model to be trained are updated according to the difference; the model parameters comprise weights corresponding to the code quality evaluation indexes; retraining the code quality assessment model after model parameter updating until the trained code quality assessment model meets the preset training ending condition, and obtaining the target code quality assessment model. Therefore, the iterative training process can help the code quality assessment model to continuously adjust parameters according to actual conditions so as to reduce prediction errors and improve the accuracy and reliability of the code quality assessment model, and the iterative training process is helpful for the code quality assessment model to continuously improve, so that the performance and the prediction capability of the code quality assessment model are improved.
In one embodiment, obtaining index data corresponding to the training sample codes under each code quality assessment index includes: acquiring the number of repaired code problems and the number of unrepaired code problems corresponding to a sample application program under a code scanning rule, and the actual average repair time corresponding to the repaired code problems; and obtaining the regular average repair time according to the product result of the number of repaired code problems and the actual average repair time, the product result of the number of unrepaired code problems and the regular repair evaluation time, and the total number of code problems.
The rule repairing evaluation time is the average repairing time of the code problems detected by the code scanning rule, which is evaluated in advance. The rule repair evaluation time may be evaluated by a rule developer and/or a rule requirement proposer.
The number of the repaired code problems is the number of the repaired code problems detected by the code scanning rule in the application program codes corresponding to the sample application programs.
The number of unrepaired code problems is the number of unrepaired code problems detected by the code scanning rule in the application program codes corresponding to the sample application program.
The total number of the code questions is the total number of the code questions detected by the code scanning rule in the application program codes corresponding to the sample application program.
The actual average repair time corresponding to the repaired code problems is an average value calculated according to the actual repair time corresponding to each repaired code problem.
In a specific implementation, in a process of acquiring index data corresponding to each code quality evaluation index of a training sample code, specifically, in a process of acquiring rule average repair time of a code scanning rule for a code problem in a sample application program, aiming at a certain preset code scanning rule and a certain sample application program, the terminal can acquire the number of repaired code problems and the number of unrepaired code problems corresponding to the application program code corresponding to the sample application program under the code scanning rule and actual average repair time corresponding to the repaired code problems, and obtain rule average repair time of the code scanning rule for the code problem in the sample application program according to a product result of the number of repaired code problems and the actual average repair time and a product result of the number of unrepaired code problems and rule repair evaluation time and a total number of code problems.
Specifically, the terminal can obtain the total repair time of the repaired code problem according to the product result of the number of the repaired code problems and the actual average repair time; predicting the total repair time of the unrepaired code problems according to the product result of the number of unrepaired code problems and the rule repair evaluation time; obtaining the total time for repairing all code problems detected by the code scanning rule according to the sum of the total repairing time of the repaired code problems and the total repairing time of the unrepaired code problems, and obtaining the rule average repairing time of the code scanning rule aiming at the code problems in the sample application program according to the ratio of the total time of all code problems detected by the code scanning rule to the total number of the code problems.
For ease of understanding by those skilled in the art, the calculation formula for the regular average repair time is as follows:
rule average repair time = (rule repair evaluation time × number of unrepaired code problems + coefficient × actual average repair time × number of repaired code problems)/total number of code problems.
The coefficient may be a ratio of the counted actual average repair time, and the more the counted time ratio is, the closer the counted time ratio is to the real value.
According to the technical scheme, the rule repairing evaluation time is the average repairing time of the code problems detected by the code scanning rule, which is evaluated in advance; obtaining the number of repaired code problems and the number of unrepaired code problems corresponding to a sample application program under a code scanning rule, and the actual average repair time corresponding to the repaired code problems; obtaining regular average repair time according to the product result of the number of repaired code problems and the actual average repair time, the product result of the number of unrepaired code problems and the regular repair evaluation time, and the total number of code problems; in this way, the rule average repair time of the code scanning rule for the code problem in the sample application program can be effectively calculated, so that the rule average repair time is utilized to predict the repair time of the code problem.
In one embodiment, there are at least two code scan rules and at least two sample applications; training the code quality evaluation model to be trained to obtain an object code quality evaluation model, comprising: taking index data and actual repair time corresponding to each sample application program under the same code scanning rule as a training unit; and training the code quality evaluation model to be trained according to the training units corresponding to the code scanning rules to obtain the target code quality evaluation model.
In the specific implementation, at least two preset code scanning rules exist, at least two sample application programs exist, and in the process that a terminal trains a code quality evaluation model to be trained to obtain a target code quality evaluation model, index data and actual repair time corresponding to each sample application program under the same code scanning rule can be used as a training unit; and training the code quality evaluation model to be trained according to the training units corresponding to the code scanning rules to obtain the target code quality evaluation model.
For ease of understanding by those skilled in the art, table 1 provides index data corresponding to each sample application under each preset code scan rule.
Table 1 index data for different sample applications without code scanning rules
As shown in table 1, a row is a record of a sample application under a rule. As the number of code problem repairs increases, so too does training sample data, so that continuous learning can be performed.
The error function of the BP neural network is determined through a predicted value and an actual value, wherein the predicted value is the predicted repair time of the BP neural network for the repaired code problem detected by the sample application program under the code scanning rule, the actual value is the actual repair time of the repaired code problem detected by the sample application program collected in the real environment under the code scanning rule, and the difference value between the predicted value and the actual value is used as the error function. And reflecting and transmitting the error value to the previous layer, and training the parameters of the BP neural network through multiple iterations. I.e., the weights and thresholds for each neuron (i.e., the weights and thresholds for each code quality assessment indicator).
Therefore, the method can realize the construction of the code quality evaluation model to be trained through the BP neural network, adjusts the weight corresponding to each code quality evaluation index through the training of training sample data, and dynamically carries out self-adaptive adjustment on the weight corresponding to each code quality evaluation index by combining with the training sample data which is updated in an actual and continuous mode, so that the repair time pre-test can be carried out more effectively for the problem of unrepaired codes.
According to the technical scheme of the embodiment, at least two code scanning rules exist, and at least two sample application programs exist; the index data and the actual repair time corresponding to each sample application program under the same code scanning rule are used as a training unit; and training the code quality evaluation model to be trained according to the training units corresponding to the code scanning rules to obtain the target code quality evaluation model. Therefore, the index data and the actual repair time corresponding to the sample application program under the same rule are used as a training unit, and the model can be trained more finely to adapt to different rule and application program conditions. The method for training the code quality evaluation model according to the different code scanning rule sub-units is beneficial to improving the accuracy and applicability of the code quality evaluation model, is beneficial to the model to better understand the corresponding sample data under different rules, so that the model can better adapt to different rules and application program characteristics, and the accuracy of the model in predicting the repair time of the code problems scanned by different code scanning rules in different program codes is effectively improved.
In one embodiment, as shown in fig. 3, a code quality evaluation method is provided, and the method is applied to a terminal for illustration, and includes the following steps:
Step S310, according to the code problems scanned by the target code scanning rule in the test program codes corresponding to the application program to be tested, the index data corresponding to the test program codes under each code quality evaluation index is obtained.
The application program to be tested is an application program to be subjected to code quality evaluation.
The target code scanning rule is a code scanning rule for scanning the test program code.
Wherein, each code quality evaluation index comprises a problem difficulty index and a problem repair cost index.
The index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the target code scanning rule and rule average repair time of the target code scanning rule for testing code problems in the program code.
In a specific implementation, for an application program to be tested, the terminal may perform static code scanning on an application program code corresponding to the application program to be tested, so as to scan out a code problem in the application program to be tested. Meanwhile, the terminal can acquire index data corresponding to the test program codes corresponding to the application program to be tested under the quality evaluation indexes of the codes according to the scanned code problems.
In order to predict repair time corresponding to an unrepaired code problem in the test program code, the terminal may determine index data corresponding to the test program code under each problem difficulty index according to the scanned unrepaired code problem.
In practical applications, the problem difficulty index may include code complexity, repeatability, line coverage, and call depth. The terminal can obtain index data corresponding to the test program code under the code complexity index according to the complexity of the method where the unrepaired code problem exists in the test program code; the terminal can obtain index data corresponding to the test program code under the index of the repeatability according to the repeatability of the line where the unrepaired code problem is located in the test program code; the terminal can obtain index data corresponding to the test program code under the index of the line coverage according to the line coverage of the unrepaired code problem in the test program code; the terminal can obtain index data corresponding to the test program code under the index of the calling depth according to the calling depth of the method where the unrepaired code problem exists in the test program code. The specific index data obtaining method may refer to description of the embodiment in the training method of the code quality assessment model, which is not described herein.
In addition, the index data corresponding to the test program code under the problem repair cost index includes a rule repair evaluation time corresponding to the target code scanning rule, and a rule average repair time of the target code scanning rule for the code problem in the test program code. The method for calculating the rule average repair time of the target code scanning rule for the code problem in the test program code can be referred to the method for calculating the rule average repair time of the code scanning rule for the code problem in the sample application program, and will not be described herein.
Wherein, when the file modification frequency and maintenance personnel of the detected code problem are more, the repair cost is increased. After calculating the average repair time of the rule corresponding to the application program to be tested, the terminal can continuously adjust the average repair time of the rule corresponding to the application program to be tested according to the actual repair time of the currently detected unrepaired code problem in subsequent repair.
Step S320, inputting the corresponding index data under each code quality evaluation index into the target code quality evaluation model, and predicting the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the code technology liability rate corresponding to the application program to be tested.
Wherein the code technology liability is used to evaluate the code quality of the application under test.
The target code quality assessment model is obtained according to the training method of the code quality assessment model.
In a specific implementation, the terminal can input index data corresponding to the test program code under each code quality evaluation index into the target code quality evaluation model, and predict the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the code technology liability rate corresponding to the application program to be tested.
According to the code quality evaluation method, through the code problems scanned in the test program codes corresponding to the application program to be tested according to the target code scanning rule, index data corresponding to the test program codes under each code quality evaluation index are obtained; each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the target code scanning rule and rule average repair time of the target code scanning rule for testing code problems in the program code; inputting corresponding index data under each code quality evaluation index into a target code quality evaluation model, and predicting the repair time of unrepaired code problems in the test program code through the target code quality evaluation model to obtain the code technology liability rate corresponding to the application program to be tested; the code technology liability rate is used for evaluating the code quality of the application program to be tested; the target code quality assessment model is obtained according to the training method of the code quality assessment model.
In this way, by setting a plurality of measurable code quality evaluation indexes related to code quality evaluation, and acquiring index data corresponding to the test program code under each code quality evaluation index, the index data is input into the target code quality evaluation model, so that the target code quality evaluation model can more accurately quantify the code technology liability corresponding to the target application program through the multi-dimensional index data, the predicted code technology liability can more accurately represent the code quality of the target application program, and the accuracy of code quality evaluation is effectively improved.
In one embodiment, there are multiple object code scan rules; the unrepaired code problems include unrepaired code problems detected in the test program code by each target code scanning rule;
Inputting corresponding index data under each code quality evaluation index into an object code quality evaluation model, predicting the repair time of an unrepaired code problem in the test program code through the object code quality evaluation model, and obtaining the code technology liability rate corresponding to the application program to be tested, wherein the method comprises the following steps: inputting index data corresponding to each code quality evaluation index under each target code scanning rule into a target code quality evaluation model, and predicting the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule; and according to the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule, the code writing cost time corresponding to the test program code, and the code technology liability rate corresponding to the application program to be tested is obtained.
In a specific implementation, a plurality of target code scanning rules exist; the unrepaired code problems include unrepaired code problems detected in the test program code by each target code scanning rule; the terminal inputs the corresponding index data under each code quality evaluation index into the target code quality evaluation model, predicts the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model, and obtains the code technology liability rate corresponding to the application program to be tested; thus, the terminal can obtain the code technology liability rate corresponding to the application program to be tested according to the predicted repair time corresponding to the unrepaired code problem detected by each target code scanning rule and the code writing cost time corresponding to the test program code.
Specifically, the terminal may obtain the repair time required by all code problems detected by all target code scanning rules in the test program code according to the predicted repair time corresponding to the unrepaired code problems detected by each target code scanning rule and the actual repair time corresponding to the repaired code problems detected by each target code scanning rule, and obtain the code technology liability rate corresponding to the application program to be tested according to the repair time required by all code problems and the code writing cost time corresponding to the test program code.
Further, the terminal may aggregate repair time required for all code problems detected by all target code scanning rules according to the target code scanning rules, and calculate a code technology liability rate based on a ratio of repair time required for all code problems and time cost required for developing all code lines of the stock code according to an effective code line number scanned in the test program code. The time cost required for developing all code lines of the stock code is determined according to the time required for developing each line of the effective code and the product result of the number of the effective code lines.
In practical application, the code technology liability rate=the repair time required by all code problems/the time cost required by all code lines of the development stock code (i.e. the code writing cost time), wherein the time cost required by all code lines of the development stock code scans the effective code lines by a code scanning tool, and removes invalid codes such as notes, blank lines, separators and the like in the code to count the effective code lines. According to the number of effective code lines, a time cost of 20 minutes (other time may be set, not specifically limited herein) required for developing each line of effective code is set, and the product of the total number of effective code lines and the development time of each line of effective code is taken as a time cost required for developing all code lines of the stock code.
According to the technical scheme of the embodiment, a plurality of target code scanning rules exist; the unrepaired code problems include unrepaired code problems detected in the test program code by each target code scanning rule; inputting index data corresponding to each code quality evaluation index under each target code scanning rule into a target code quality evaluation model, and predicting the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule; and according to the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule, the code writing cost time corresponding to the test program code, and the code technology liability rate corresponding to the application program to be tested is obtained. Therefore, the repair time required by all unrepaired code problems detected in the test program codes by all target code scanning rules can be predicted according to all target code scanning rules, and the repair cost time according to the code problems in the test program codes and the write cost time of the test program codes can be realized by combining the code write cost time required by the test program codes, so that the code technology liability rate of the test program codes can be quantized more accurately, and the code quality of the test degree codes can be estimated more accurately.
Fig. 4 provides a flow chart of another code quality assessment method, as shown in fig. 4, comprising the steps of:
Step S402, index data corresponding to the training sample codes under each code quality evaluation index is obtained.
Step S404, inputting each index data into a code quality evaluation model to be trained, and predicting the code problem repair time of the repaired code problem under the code scanning rule by the code quality evaluation model to be trained to obtain the corresponding predicted repair time of the repaired code problem under the code scanning rule.
Step S406, collecting the actual repair time corresponding to the repaired code problem, and updating the model parameters of the code quality evaluation model to be trained according to the difference between the predicted repair time and the actual repair time.
Step S408, retraining the code quality assessment model with updated model parameters until the trained code quality assessment model meets the preset training ending condition, and obtaining the target code quality assessment model.
Step S410, according to the code problems scanned by the target code scanning rule in the test program codes corresponding to the application program to be tested, the index data corresponding to the test program codes under each code quality evaluation index is obtained.
Step S412, inputting index data corresponding to each code quality evaluation index under each target code scanning rule into the target code quality evaluation model, and predicting the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule.
Step S414, according to the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule, the code writing cost time corresponding to the test program code is obtained, and the code technology liability rate corresponding to the application program to be tested is obtained.
It should be noted that, the specific limitation of the above steps may refer to the specific limitation of the training of a code quality evaluation model and the specific limitation of a code quality evaluation method, which are not described herein.
It should be understood that, although the steps in the flowcharts related to the embodiments described above are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides a training device of the code quality evaluation model for realizing the training method of the code quality evaluation model. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in the embodiments of the training device for one or more code quality assessment models provided below may be referred to the limitation of the training method for the code quality assessment model hereinabove, and will not be described herein.
In an exemplary embodiment, as shown in fig. 5, there is provided a training apparatus of a code quality evaluation model, including: a training data acquisition module 510 and a training module 520, wherein:
The training data obtaining module 510 is configured to obtain index data corresponding to the training sample codes under each code quality evaluation index; the training sample code is an application program code of the repaired code problem; the repaired code problem is a code problem detected by a sample application program by adopting a preset code scanning rule and repaired;
The code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the code scanning rule and rule average repair time of the code scanning rule for the code problems in the sample application program.
The training module 520 is configured to collect an actual repair time corresponding to the repaired code problem, and train the code quality assessment model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality assessment index, so as to obtain an object code quality assessment model; the target code quality evaluation model is used for predicting the code technology liability rate corresponding to the application program to be tested.
In one embodiment, the training module 520 is specifically configured to input each index data into the code quality assessment model to be trained, predict, by using the code quality assessment model to be trained, a code problem repair time of the repaired code problem under the code scanning rule, and obtain a predicted repair time of the repaired code problem corresponding to the code scanning rule;
And training the code quality evaluation model to be trained according to the difference between the predicted repair time and the actual repair time to obtain the target code quality evaluation model.
In one embodiment, the training module 520 is specifically configured to update model parameters of the code quality assessment model to be trained according to the difference; the model parameters comprise weights corresponding to the code quality evaluation indexes; retraining the code quality assessment model with updated model parameters until the trained code quality assessment model meets the preset training ending condition, so as to obtain the target code quality assessment model.
In one embodiment, the rule repairing evaluation time is an average repairing time of a code problem detected by using the code scanning rule, which is evaluated in advance; the training data obtaining module 510 is specifically configured to obtain the number of repaired code problems and the number of unrepaired code problems corresponding to the sample application program under the code scanning rule, and an actual average repair time corresponding to the repaired code problems; and obtaining the rule average repair time according to the product result of the number of repaired code problems and the actual average repair time, the product result of the number of unrepaired code problems and the rule repair evaluation time, and the total number of code problems.
In one embodiment, there are at least two code scanning rules and at least two sample applications; the training module 520 is specifically configured to use, as a training unit, index data and actual repair time corresponding to each sample application program under the same code scanning rule; and training the code quality evaluation model to be trained according to the training units corresponding to the code scanning rules to obtain the target code quality evaluation model.
The respective modules in the training device of the code quality evaluation model described above may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
Based on the same inventive concept, the embodiment of the application also provides a code quality evaluation device for realizing the above related code quality evaluation method. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in the embodiments of the code quality assessment device or devices provided below may refer to the limitation of the code quality assessment method hereinabove, and will not be repeated here.
In an exemplary embodiment, as shown in fig. 6, there is provided a code quality evaluation apparatus including: a data to be measured acquisition module 610 and a prediction module 620, wherein:
The to-be-tested data obtaining module 610 is configured to obtain, according to a code problem scanned in a test program code corresponding to an application program to be tested by using an object code scanning rule, index data corresponding to the test program code under each code quality evaluation index;
Each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the target code scanning rule and rule average repair time of the target code scanning rule for code problems in the test program code.
The prediction module 620 is configured to input index data corresponding to each code quality evaluation index to a target code quality evaluation model, and predict, by using the target code quality evaluation model, a repair time of an unrepaired code problem in the test program code, thereby obtaining a code technology liability corresponding to the application program to be tested; the code technology liability rate is used for evaluating the code quality of the application program to be tested; the target code quality assessment model is obtained according to the training method of the code quality assessment model.
In one embodiment, there are a plurality of the object code scanning rules; the unrepaired code problems include unrepaired code problems detected in the test program code by each of the target code scanning rules; the prediction module 620 is specifically configured to input index data corresponding to each code quality evaluation index under each target code scanning rule into a target code quality evaluation model, and predict repair time of an unrepaired code problem in the test program code through the target code quality evaluation model to obtain predicted repair time corresponding to the unrepaired code problem under each target code scanning rule; and obtaining the code technology liability rate corresponding to the application program to be tested according to the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule and the code writing cost time corresponding to the test program code.
The respective modules in the above-described code quality evaluation apparatus may be implemented in whole or in part by software, hardware, and a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one exemplary embodiment, a computer device is provided, which may be a terminal, and an internal structure diagram thereof may be as shown in fig. 7. The computer device includes a processor, a memory, an input/output interface, a communication interface, a display unit, and an input means. The processor, the memory and the input/output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input/output interface. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless mode can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement a training of a code quality assessment model and/or a code quality assessment method. The display unit of the computer device is used for forming a visual picture, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, can also be a key, a track ball or a touch pad arranged on the shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the structure shown in FIG. 7 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In an embodiment, there is also provided a computer device comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the method embodiments described above when the computer program is executed.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, carries out the steps of the method embodiments described above.
In an embodiment, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the steps of the method embodiments described above.
It should be noted that, the user information (including but not limited to user equipment information, user personal information, etc.) and the data (including but not limited to data for analysis, stored data, presented data, etc.) related to the present application are both information and data authorized by the user or sufficiently authorized by each party, and the collection, use and processing of the related data are required to meet the related regulations.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (ReRAM), magneto-resistive random access Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (PHASE CHANGE Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in various forms such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The databases referred to in the embodiments provided herein may include at least one of a relational database and a non-relational database. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processor referred to in the embodiments provided in the present application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, or the like, but is not limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing examples illustrate only a few embodiments of the application and are described in detail herein without thereby limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of the application should be assessed as that of the appended claims.

Claims (12)

1. A method of training a code quality assessment model, the method comprising:
Acquiring index data corresponding to the training sample codes under each code quality evaluation index; the training sample code is an application program code of the repaired code problem; the repaired code problem is a code problem detected by a sample application program by adopting a preset code scanning rule and repaired;
The code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the code scanning rule and rule average repair time of the code scanning rule for the code problems in the sample application program;
Acquiring the actual repair time corresponding to the repaired code problem, and training a code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index to obtain a target code quality evaluation model; the target code quality evaluation model is used for predicting the code technology liability rate corresponding to the application program to be tested.
2. The method according to claim 1, wherein training the code quality assessment model to be trained according to the actual repair time and the index data corresponding to the training sample code under each code quality assessment index to obtain an object code quality assessment model includes:
Inputting each index data into the code quality evaluation model to be trained, and predicting the code problem repair time of the repaired code problem under the code scanning rule through the code quality evaluation model to be trained to obtain the corresponding predicted repair time of the repaired code problem under the code scanning rule;
And training the code quality evaluation model to be trained according to the difference between the predicted repair time and the actual repair time to obtain the target code quality evaluation model.
3. The method of claim 2, wherein training the code quality assessment model to be trained based on the difference between the predicted repair time and the actual repair time results in the target code quality assessment model, comprising:
Updating model parameters of the code quality evaluation model to be trained according to the difference; the model parameters comprise weights corresponding to the code quality evaluation indexes;
retraining the code quality assessment model with updated model parameters until the trained code quality assessment model meets the preset training ending condition, so as to obtain the target code quality assessment model.
4. The method of claim 1, wherein the rule fix evaluation time is a pre-evaluated average fix time of code problems detected using the code scanning rule;
The obtaining the corresponding index data of the training sample codes under each code quality evaluation index comprises the following steps:
Acquiring the number of repaired code problems and the number of unrepaired code problems corresponding to the sample application program under the code scanning rule, and the actual average repair time corresponding to the repaired code problems;
and obtaining the rule average repair time according to the product result of the number of repaired code problems and the actual average repair time, the product result of the number of unrepaired code problems and the rule repair evaluation time, and the total number of code problems.
5. The method of claim 1, wherein there are at least two code scanning rules and at least two sample applications; training the code quality evaluation model to be trained to obtain an object code quality evaluation model, comprising the following steps:
Taking index data and actual repair time corresponding to each sample application program under the same code scanning rule as a training unit;
And training the code quality evaluation model to be trained according to the training units corresponding to the code scanning rules to obtain the target code quality evaluation model.
6. A method of code quality assessment, the method comprising:
Code problems scanned in test program codes corresponding to an application program to be tested according to target code scanning rules are solved, and index data corresponding to the test program codes under each code quality evaluation index are obtained;
Each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the target code scanning rule and rule average repair time of the target code scanning rule for code problems in the test program code;
Inputting index data corresponding to each code quality evaluation index into a target code quality evaluation model, and predicting the repair time of an unrepaired code problem in the test program code through the target code quality evaluation model to obtain a code technology liability rate corresponding to the application program to be tested; the code technology liability rate is used for evaluating the code quality of the application program to be tested;
The object code quality assessment model is obtained according to the training method of the code quality assessment model according to any one of claims 1 to 5.
7. The method of claim 6, wherein there are a plurality of the object code scanning rules; the unrepaired code problems include unrepaired code problems detected in the test program code by each of the target code scanning rules;
Inputting the corresponding index data under each code quality evaluation index into an object code quality evaluation model, predicting the repair time of the unrepaired code problem in the test program code through the object code quality evaluation model, and obtaining the code technology liability rate corresponding to the application program to be tested, wherein the method comprises the following steps:
Inputting index data corresponding to each code quality evaluation index under each target code scanning rule into a target code quality evaluation model, and predicting the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule;
And obtaining the code technology liability rate corresponding to the application program to be tested according to the predicted repair time corresponding to the unrepaired code problem under each target code scanning rule and the code writing cost time corresponding to the test program code.
8. A training device for a code quality assessment model, the device comprising:
The training data acquisition module is used for acquiring index data corresponding to the training sample codes under the quality evaluation indexes of the codes; the training sample code is an application program code of the repaired code problem; the repaired code problem is a code problem detected by a sample application program by adopting a preset code scanning rule and repaired;
The code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the code scanning rule and rule average repair time of the code scanning rule for the code problems in the sample application program;
The training module is used for collecting the actual repair time corresponding to the repaired code problem, and training the code quality evaluation model to be trained according to the actual repair time and index data corresponding to the training sample code under each code quality evaluation index to obtain an object code quality evaluation model; the target code quality evaluation model is used for predicting the code technology liability rate corresponding to the application program to be tested.
9. A code quality assessment apparatus, the apparatus comprising:
the system comprises a to-be-tested data acquisition module, a code analysis module and a code analysis module, wherein the to-be-tested data acquisition module is used for acquiring index data corresponding to test program codes corresponding to an application program to be tested according to code problems scanned in the test program codes according to target code scanning rules;
Each code quality evaluation index comprises a problem difficulty index and a problem repair cost index; the index data corresponding to the problem repair cost index comprises rule repair evaluation time corresponding to the target code scanning rule and rule average repair time of the target code scanning rule for code problems in the test program code;
the prediction module is used for inputting the corresponding index data under each code quality evaluation index into a target code quality evaluation model, and predicting the repair time of the unrepaired code problem in the test program code through the target code quality evaluation model to obtain the code technology liability rate corresponding to the application program to be tested; the code technology liability rate is used for evaluating the code quality of the application program to be tested;
The object code quality assessment model is obtained according to the training method of the code quality assessment model according to any one of claims 1 to 5.
10. Computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the method of any one of claims 1 to 5 and/or the steps of the method of any one of claims 6 to 7.
11. A computer-readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any one of claims 1 to 5 and/or the steps of the method of any one of claims 6 to 7.
12. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any one of claims 1 to 5 and/or the steps of the method according to any one of claims 6 to 7.
CN202410155821.6A 2024-02-04 2024-02-04 Training of code quality evaluation model, and code quality evaluation method and device Pending CN118093385A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410155821.6A CN118093385A (en) 2024-02-04 2024-02-04 Training of code quality evaluation model, and code quality evaluation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410155821.6A CN118093385A (en) 2024-02-04 2024-02-04 Training of code quality evaluation model, and code quality evaluation method and device

Publications (1)

Publication Number Publication Date
CN118093385A true CN118093385A (en) 2024-05-28

Family

ID=91152208

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410155821.6A Pending CN118093385A (en) 2024-02-04 2024-02-04 Training of code quality evaluation model, and code quality evaluation method and device

Country Status (1)

Country Link
CN (1) CN118093385A (en)

Similar Documents

Publication Publication Date Title
CN110442516A (en) Information processing method, equipment and computer readable storage medium
CN110286938B (en) Method and apparatus for outputting evaluation information for user
CN112199293A (en) Software quality evaluation method and device, terminal equipment and storage medium
CN113487019A (en) Circuit fault diagnosis method and device, computer equipment and storage medium
CN116010226A (en) Software system reliability simulation evaluation method and device and computer equipment
CN117033039A (en) Fault detection method, device, computer equipment and storage medium
CN115841046A (en) Accelerated degradation test data processing method and device based on wiener process
CN117454668B (en) Method, device, equipment and medium for predicting failure probability of parts
CN116626504A (en) Power battery performance determining method, apparatus, computer device and storage medium
CN114363004B (en) Risk assessment method, risk assessment device, computer equipment and storage medium
CN118093385A (en) Training of code quality evaluation model, and code quality evaluation method and device
CN117827668A (en) Test coverage rate improving device, computer equipment and storage medium
CN113159100B (en) Circuit fault diagnosis method, circuit fault diagnosis device, electronic equipment and storage medium
CN117891566B (en) Reliability evaluation method, device, equipment, medium and product of intelligent software
CN112799913B (en) Method and device for detecting abnormal operation of container
CN117473327B (en) Regional population model training method and regional population prediction method
CN116610906B (en) Equipment fault diagnosis method and device, computer equipment and storage medium thereof
CN117078236B (en) Intelligent maintenance method and device for complex equipment, electronic equipment and storage medium
CN118227463A (en) Test data generation method, device, computer equipment, storage medium and product
CN115622894B (en) Dynamic network topology prediction method and system based on historical data probability analysis
CN117631682A (en) Method and system for determining inspection route of unmanned aerial vehicle of power grid
CN116418552A (en) Method and device for detecting false data invasion of power grid and computer equipment
CN118338337A (en) Reliability detection method, apparatus, computer device and storage medium
CN117762810A (en) Model ring test method, device, computer equipment and storage medium
CN118132318A (en) Log error reporting positioning method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination