A code quality improvement method and system based on machine learning
By using machine learning algorithms on the code quality management platform to predict the number of potential problems and convergence time after code submission, the problem of inability to improve code quality is solved and the code quality is improved.
Patent Information
- Application Number
- CN202111364980.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-17
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2041-11-17
AI Technical Summary
It is difficult for the existing technology to effectively predict the number of problems that may arise in the future in the improvement of code quality and the convergence time of problem, resulting in the problem of inability to improve code quality.
By obtaining the training data formed by the code quality management platform's inspection items and the code inspection results submitted by developers, the training model is trained using machine learning algorithms, predicting the number of potential problems and convergence time in subsequent submitted codes, and quantitatively comparing them with the actual inspection results to the developers.
By quantizing and comparing data, developers can actively conduct static checks and unit tests of code, reducing the number of problems and thus improving code quality.
Smart Images

Figure CN114116469B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of information processing technology, and more specifically, relates to a code quality improvement method and system based on machine learning. Background Art
[0002] Software developers often have potential problems in their code due to programming habits and other reasons. Some of these problems can be found in the code compilation stage, some problems need to be found in the debugging and testing stages, and some hidden problems can only be gradually discovered in the actual operation of the software. No matter at which stage the problem is found, it will bring certain cost losses to solve it, and the later the problem is found, the higher the cost of solving it will be. Therefore, more and more strategies and tools are applied in the software development stage, aiming to find problems as early as possible and minimize costs. Currently commonly used methods include code walkthrough, code static checking, unit testing, etc.
[0003] The existing patent publication number is CN111382443A, which proposes a method, device and electronic device for determining code quality improvement suggestions. The method includes: obtaining evaluation information of the target code automatically generated by the code quality evaluation system, wherein the code quality evaluation system is used to automatically generate evaluation information of the target code including at least one of vulnerability detection information, code repetition rate detection information and code complexity information, and then determining corresponding quality improvement suggestion information based on the obtained evaluation information of the target code. This patent only gives suggestions for improving code quality based on the results of code vulnerability detection, code repetition rate, complexity and other aspects, but does not predict the number of problems that may arise in the future and the time for problem convergence, so that the quantitative prediction results cannot be compared with the actual number of problems generated by the developer's subsequent new development code. Developers often do not reduce the number of their own code problems through various means, so the problem of code quality not being improved will arise. Summary of the invention
[0004] The present invention proposes a code quality improvement method and system based on machine learning, which obtains the inspection items of the code quality management platform and the training data formed by the inspection results of the code submitted by the developer, and trains the training model through a machine learning algorithm. After the training is completed, the training model is used to predict the subsequent submitted code, and the prediction results are quantitatively compared with the actual inspection results and displayed to the developer, so that the developer can improve the code quality through the quantitative comparison data to solve the problem that the code quality cannot be improved.
[0005] To achieve the above object, the technical solution of the present invention is as follows:
[0006] A code quality improvement method based on machine learning, comprising:
[0007] Step S1, obtaining sample data through a code quality management platform, wherein the sample data includes check items obtained according to the code quality management platform, and the number of problems matching each check item in the code currently submitted by the developer;
[0008] Step S2, drawing a scatter plot according to the sample data, taking part of the data of the scatter plot as training data and inputting it into the model to be trained, until the model to be trained meets the preset convergence condition, thereby obtaining a target model;
[0009] Step S3, using the target model to predict the number of potential problems and convergence time corresponding to the unit number of lines in the code subsequently submitted by the developer, to obtain a prediction result;
[0010] Step S4, quantitatively comparing the prediction result with the actual inspection result of the code quality management platform in a visual manner and graphically presenting the result to the developer.
[0011] Preferably, step S1 comprises the following steps:
[0012] Step S11, generating a check vector from the check result corresponding to each of the check items, wherein each element of the check vector represents one of the check items;
[0013] Step S12, recording the inspection results corresponding to the code submitted by the developer each time in chronological order and generating an inspection result list;
[0014] Step S13, matching the inspection vector with the data in the inspection result list one by one to generate a matching vector, wherein each element of the matching vector represents the number of times a problem matching each inspection item occurs in this inspection.
[0015] Preferably, step S2 comprises the following steps:
[0016] Step S21, defining a number of lines as a unit line number, and calculating the number of problems corresponding to the unit line number in the current submitted code according to the number of problems included in the sample data;
[0017] Step S22, using the number of problems and the number of problems that occur in each inspection item corresponding to the unit number of rows as horizontal and vertical axes, respectively, to draw a scatter plot;
[0018] Step S23, taking part of the data of the scatter plot as training data and inputting it into the model to be trained, until the model to be trained meets a preset convergence condition, thereby obtaining a target model.
[0019] Preferably, the step S2 further includes: using other data of the scatter plot except the training data to input into the model to be trained, and cross-validating the model to be trained.
[0020] Preferably, the preset convergence condition includes: adjusting the mean square error between the predicted value and the actual value by adjusting parameters, and the adjustment parameters include a preset threshold.
[0021] The present invention provides a code quality improvement system based on machine learning, which implements the above-mentioned code quality improvement method based on machine learning, including:
[0022] An acquisition module, the acquisition module is used to acquire sample data through a code quality management platform, the sample data including check items acquired according to the code quality management platform, and the number of problems matching each check item in the code currently submitted by the developer;
[0023] A training module, the training module is connected to the acquisition module, and is used to draw a scatter plot according to the sample data, take part of the data of the scatter plot as training data and input it into the model to be trained, until the model to be trained meets the preset convergence condition, thereby obtaining a target model;
[0024] A prediction module, the prediction module is connected to the training module and is used to use the target model to predict the number of potential problems and convergence time corresponding to the unit number of lines in the subsequent submitted code to obtain a prediction result;
[0025] A display module is connected to the prediction module and is used to compare the prediction results with the actual inspection results in a quantitative manner in a visual manner and present them graphically to the developer.
[0026] Preferably, the acquisition module includes:
[0027] a first generating unit, the first generating unit being configured to generate a check vector from the check result corresponding to each of the check items, wherein each element of the check vector represents one of the check items;
[0028] A second generating unit, the second generating unit is used to record the inspection results corresponding to the code submitted by the developer each time in chronological order and generate an inspection result list;
[0029] A matching unit, wherein the matching unit is connected to the first generating unit and the second generating unit respectively, and is used to match the inspection vector with the data in the inspection result list one by one to generate a matching vector, wherein each element of the matching vector represents the number of times a problem matching each of the inspection items occurs in this inspection.
[0030] Preferably, the training module includes:
[0031] A calculation unit, the calculation unit is used to calculate the number of problems corresponding to a unit number of lines in the current submitted code; wherein a number of lines is defined as the unit number of lines;
[0032] A drawing unit, the drawing unit is connected to the calculation unit, and is used to draw a scatter plot by taking the number of questions and the number of questions corresponding to the number of unit rows as horizontal and vertical coordinate axes respectively;
[0033] A training unit is connected to the drawing unit and is used to take part of the data of the scatter plot as training data and input it into the model to be trained until the model to be trained meets a preset convergence condition to obtain a target model.
[0034] Preferably, the training module further includes:
[0035] A verification unit, wherein the verification unit is respectively connected to the drawing unit and the training unit, and is used to use the data of the scatter plot other than the training data to be input into the model to be trained, and to perform cross-validation on the model to be trained.
[0036] Preferably, the preset convergence condition includes: adjusting the mean square error between the predicted value and the actual value by adjusting parameters, and the adjustment parameters include a preset threshold.
[0037] The beneficial effects of the technical solution of the present invention are:
[0038] The training model is trained through a machine learning algorithm by obtaining the inspection items of the code quality management platform and the training data formed by the inspection results of the code submitted by the developer. After the training is completed, the training model is used to predict the subsequent submitted code, and the prediction results are quantitatively compared with the actual inspection results and displayed to the developer. The developer compares the data quantitatively. In order to ensure that the actual number of problems is not greater than the predicted value, the developer will actively perform static inspection and unit testing of the code in the daily coding process to reduce the number of problems, thereby achieving the purpose of improving code quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The above and other objects, features and advantages of the present invention will become more apparent through a more detailed description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components throughout the exemplary embodiments of the present invention.
[0040] Figure 1 A flowchart of a method for improving code quality based on machine learning provided by the present invention;
[0041] Figure 2A flowchart of step S1 of a method for improving code quality based on machine learning provided by the present invention;
[0042] Figure 3 A flowchart of step S2 of a method for improving code quality based on machine learning provided by the present invention;
[0043] Figure 4 A schematic diagram of the structure of a code quality improvement system based on machine learning provided by the present invention;
[0044] Figure 5 A schematic diagram of the structure of an acquisition module of a code quality improvement system based on machine learning provided by the present invention;
[0045] Figure 6 A structural schematic diagram of a training module of a code quality improvement system based on machine learning provided by the present invention.
[0046] Description of reference numerals:
[0047] 1. Acquisition module; 11. First generation unit; 12. Second generation unit; 13. Matching unit; 2. Training module; 21. Calculation unit; 22. Drawing unit; 23. Training unit; 24. Verification unit; 3. Prediction module; 4. Display module. DETAILED DESCRIPTION
[0048] The preferred embodiments of the present invention will be described in more detail below. Although the preferred embodiments of the present invention are described below, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to make the present invention more thorough and complete, and to fully convey the scope of the present invention to those skilled in the art.
[0049] Reference Figure 1 As shown, a code quality improvement method based on machine learning includes:
[0050] Step S1, obtaining sample data through the code quality management platform, the sample data including the check items obtained from the code quality management platform, and the number of problems matching each check item in the code currently submitted by the developer;
[0051] Step S2, draw a scatter plot based on the sample data, take part of the data in the scatter plot as training data and input it into the model to be trained until the model to be trained meets the preset convergence condition, thereby obtaining the target model;
[0052] Step S3, using the target model to predict the number of potential problems and convergence time corresponding to the number of lines in the code subsequently submitted by the developer, and obtain a prediction result;
[0053] Step S4, quantitatively comparing the prediction results with the actual inspection results of the code quality management platform in a visual manner and graphically displaying them to the developers.
[0054] Specifically, the code quality management platform takes the sonar platform as an example, and the unit line number is taken as every hundred lines. According to the multiple submissions of code by developers after submitting to the code base, the inspection results for each inspection item on the sonar platform are obtained, that is, the number of problems that occur for each inspection item, so as to form sample data, and a scatter plot is drawn through the sample data. Part of the data in the scatter plot is taken as training data and input into the model to be trained for machine learning until the model to be trained meets the preset convergence conditions, and the target model is obtained. The target model is used to predict the number of potential problems and the convergence time of the number of problems in the subsequent code submissions by developers, that is, the number of potential problems per hundred lines of code in the subsequent code submissions. The number of problems and the estimated convergence time are calculated to obtain the prediction result, and the actual inspection results on the sonar platform after each subsequent code submission by the developer are recorded, and quantitatively compared with the prediction results. The difference between the number of problems actually checked each time and the predicted value of the previous day is calculated, and displayed through visual charts and quantitative comparison data. According to the quantitative comparison data, in order to make the actual number of problems in the code not greater than the predicted value, the developer will be more cautious in the daily coding process, and reduce the number of problems through various methods such as static inspection and unit testing of the code before submitting it to the code base. This method allows developers to improve the quality of their code through various channels.
[0055] Reference Figure 2 As shown in a preferred example, step S1 includes the following steps:
[0056] Step S11, generating a check vector from the check result corresponding to each check item, where each element of the check vector represents a check item;
[0057] Step S12, recording the inspection results corresponding to the code submitted by the developer each time in chronological order and generating an inspection result list;
[0058] Step S13, matching the inspection vector with the data in the inspection result list one by one to generate a matching vector, wherein each element of the matching vector represents the number of times a problem matching each inspection item occurs in this inspection.
[0059] Specifically, first, the inspection results corresponding to each inspection item of the sonar platform are combined into an inspection vector of length M, and each element of the vector represents an inspection item; then, the inspection results of the new code on the sonar platform after a developer has submitted the code to the code base N times since entering the project team are recorded in chronological order, and a list is generated for each inspection result. After this operation, N lists will be generated; then, the inspection vector is matched with the data in the result list one by one to generate a new matching vector. The length of the matching vector is M, and the initial value of the matching vector is 0. If the i-th element in the inspection vector appears once in the result list, the i-th element in the inspection vector is added by 1. Through this method, N matching vectors of length M will be generated, and each element in the matching vector represents the number of problems corresponding to this inspection item in this inspection. The inspection results of the code are matched with the inspection vector and then a matching vector is generated. The sample data formed in this way is used as training data to be more real and accurate.
[0060] Reference Figure 3 As shown in a preferred example, step S2 includes the following steps:
[0061] Step S21, defining a number of lines as unit lines, and calculating the number of problems corresponding to the unit lines in the current submitted code according to the number of problems included in the sample data;
[0062] Step S22, using the number of problems and the number of problems corresponding to the number of rows of each inspection item as the horizontal and vertical axes, respectively, to draw a scatter plot;
[0063] Step S23, taking part of the data of the scatter plot as training data and inputting it into the model to be trained, until the model to be trained meets the preset convergence condition, thereby obtaining the target model.
[0064] Specifically, the average number of times each problem occurs per 100 lines of code in the submitted code is calculated based on the number of lines of code submitted each time, and then a scatter plot is drawn with the number of problems and the number of problems that occur per 100 lines of the corresponding single check item as the horizontal and vertical axes, and 75% of the data is taken as training data. The logistic algorithm is used for fitting until the model to be trained meets the preset convergence condition and the target model is obtained. The preset convergence condition often has a preset threshold, and the preset threshold is passed to make the training model reach the ideal state.
[0065] In a preferred example, step S2 further includes: using other scatter plot data other than the training data to input into the model to be trained, and performing cross-validation on the model to be trained.
[0066] Specifically, the trained model is used to cross-validate the remaining 25% of the data to confirm the effectiveness of the model and avoid major deviations in the prediction results.
[0067] In a preferred example, the preset convergence condition includes: adjusting the mean square error between the predicted value and the actual value by adjusting a parameter, and the adjustment parameter includes a preset threshold.
[0068] Specifically, the preset convergence condition is achieved by calculating the mean square error between the predicted value and the actual value, and then adjusting the parameters continuously to minimize the loss of the mean square error so that the training model can achieve the optimal effect.
[0069] Reference Figure 4 As shown, the present invention also provides a code quality improvement system based on machine learning, which implements the above-mentioned code quality improvement method based on machine learning, including:
[0070] Acquisition module 1, which is used to acquire sample data through the code quality management platform. The sample data includes check items acquired according to the code quality management platform, and the number of problems matching each check item in the code currently submitted by the developer;
[0071] The training module 2 is connected to the acquisition module 1 and is used to draw a scatter plot according to the sample data, take part of the data of the scatter plot as training data and input it into the model to be trained until the model to be trained meets the preset convergence condition, thereby obtaining a target model;
[0072] Prediction module 3, which is connected to training module 2 and is used to use the target model to predict the number of potential problems and convergence time that may occur in the corresponding unit number of lines in the subsequently submitted code, and obtain a prediction result;
[0073] Display module 4, which is connected to prediction module 3, is used to compare the prediction results with the actual inspection results in a quantitative manner in a visual way and present them graphically to developers.
[0074] Reference Figure 5 As shown in a preferred example, the acquisition module 1 includes:
[0075] A first generating unit 11, the first generating unit 11 is used to generate a check vector from the check result corresponding to each check item, each element of the check vector represents a check item;
[0076] A second generating unit 12, the second generating unit 12 is used to record the inspection results corresponding to the code submitted by the developer each time in chronological order and generate an inspection result list;
[0077] The matching unit 13 is connected to the first generating unit 11 and the second generating unit 12 respectively, and is used to match the inspection vector with the data in the inspection result list one by one to generate a matching vector, each element of which represents the number of problems matching each inspection item in this inspection.
[0078] Reference Figure 6 As shown in a preferred example, the training module 2 includes:
[0079] A calculation unit 21, the calculation unit 21 is used to calculate the number of problems corresponding to a unit number of lines in the current submitted code; wherein a number of lines is defined as the unit number of lines;
[0080] A drawing unit 22, the drawing unit 22 is connected to the calculation unit 21, and is used to draw a scatter plot by taking the number of questions and the number of questions corresponding to the number of rows as horizontal and vertical coordinate axes respectively;
[0081] The training unit 23 is connected to the drawing unit 22 and is used to take part of the data of the scatter plot as training data and input it into the model to be trained until the model to be trained meets the preset convergence condition to obtain the target model.
[0082] In a preferred example, the training module 2 further includes:
[0083] The verification unit 24 is connected to the drawing unit 22 and the training unit 23 respectively, and is used to use the data of other scatter plots except the training data to input into the model to be trained, and perform cross-validation on the model to be trained.
[0084] In a preferred example, the preset convergence condition includes: adjusting the mean square error between the predicted value and the actual value by adjusting parameters, and the adjustment parameters include a preset threshold.
[0085] Specifically, the code quality management platform takes the sonar platform as an example, and the unit line number is taken as every hundred lines. First, in the acquisition module 1, the first generation unit 11 forms an inspection vector with a length of M with the inspection results corresponding to each inspection item of the sonar platform, and each element of the vector represents an inspection item; then the second generation unit 12 will record the inspection results of the new code on the sonar platform after a developer has submitted the code to the code base N times since entering the project team in chronological order, and generate a list for each inspection result, so that N lists will be generated after this operation; then the matching unit 13 will match the inspection vector with the data in the list one by one to generate a new matching vector, and the length of the matching vector is M, wherein each element in the matching vector represents the number of problems corresponding to this inspection item in this inspection.
[0086] In the training module 2, the calculation unit 21 calculates the average number of times each type of problem appears per hundred lines of code in the submitted code based on the number of lines of code submitted each time; then the drawing unit 22 draws a scatter plot with the number of problems and the number of problems that appear per hundred lines of the corresponding single check item as the horizontal and vertical axes, and the training unit 23 takes 75% of the data as training data and uses the logistic algorithm for fitting until the model to be trained meets the preset convergence condition to obtain the target model. The preset convergence condition is often set with a preset threshold, and the preset threshold allows the training model to reach an ideal state; the verification unit 24 uses the trained model to cross-validate the remaining 25% of the data to confirm the effect of the model.
[0087] In prediction module 3, the trained target model is used to predict the number of potential problems and convergence time of the code submitted by subsequent developers to obtain prediction results.
[0088] In display module 4, the number of potential problems and the estimated problem convergence time included in the prediction results are displayed in a visual chart and quantitative value, and in the following time, after each sonar platform inspection, the actual inspection results of each time are compared with the predicted results and displayed together. Through the target model, the number of potential problems and the convergence time of the number of problems in the subsequent code submitted by the developer are predicted, that is, the number of potential problems and the estimated convergence time per hundred lines of code in the subsequent code submission, so as to obtain the prediction results, and the actual inspection results of the developer on the sonar platform after each subsequent code submission are recorded, and compared quantitatively with the prediction results, and the difference between the number of problems actually checked each time and the predicted value of the previous day is calculated, and the visual chart and quantitative comparison data are displayed. According to the quantitative comparison data, in order to make the actual number of problems in the code not larger than the predicted value, the developer will be more cautious in the daily coding process, and reduce the number of problems by various means such as static inspection and unit testing of the code before submitting it to the code base. This method allows the developer to improve the code quality through various channels.
[0089] Furthermore, the preset convergence condition is achieved by calculating the mean square error between the predicted value and the actual value, and then adjusting the parameters continuously to minimize the loss of the mean square error so that the training model can achieve the optimal effect.
[0090] Example 1
[0091] Reference Figure 1-Figure 3 As shown, a code quality improvement method based on machine learning includes:
[0092] Step S1, obtaining sample data through the code quality management platform, the sample data including the check items obtained from the code quality management platform, and the number of problems matching each check item in the code currently submitted by the developer;
[0093] Step S2, draw a scatter plot based on the sample data, take part of the data in the scatter plot as training data and input it into the model to be trained until the model to be trained meets the preset convergence condition, thereby obtaining the target model;
[0094] Step S3, using the target model to predict the number of potential problems and convergence time corresponding to the number of lines in the code subsequently submitted by the developer, and obtain a prediction result;
[0095] Step S4, quantitatively comparing the prediction results with the actual inspection results of the code quality management platform in a visual manner and graphically displaying them to the developers.
[0096] In this embodiment, step S1 includes the following steps:
[0097] Step S11, generating a check vector from the check result corresponding to each check item, where each element of the check vector represents a check item;
[0098] Step S12, recording the inspection results corresponding to the code submitted by the developer each time in chronological order and generating an inspection result list;
[0099] Step S13, matching the inspection vector with the data in the inspection result list one by one to generate a matching vector, wherein each element of the matching vector represents the number of times a problem matching each inspection item occurs in this inspection.
[0100] In this embodiment, step S2 includes the following steps:
[0101] Step S21, defining a number of lines as unit lines, and calculating the number of problems corresponding to the unit lines in the current submitted code according to the number of problems included in the sample data;
[0102] Step S22, using the number of problems and the number of problems corresponding to the number of rows of each inspection item as the horizontal and vertical axes, respectively, to draw a scatter plot;
[0103] Step S23, taking part of the data of the scatter plot as training data and inputting it into the model to be trained, until the model to be trained meets the preset convergence condition, thereby obtaining the target model.
[0104] In this embodiment, step S2 also includes: using other scatter plot data other than the training data to input into the model to be trained, and performing cross-validation on the model to be trained.
[0105] In this embodiment, the preset convergence condition includes: adjusting the mean square error between the predicted value and the actual value by adjusting parameters, and the adjustment parameters include a preset threshold.
[0106] Example 2
[0107] Reference Figure 4-Figure 6 As shown, this embodiment provides a code quality improvement system based on machine learning, including:
[0108] Acquisition module 1, which is used to acquire sample data through the code quality management platform. The sample data includes check items acquired according to the code quality management platform, and the number of problems matching each check item in the code currently submitted by the developer;
[0109] The training module 2 is connected to the acquisition module 1 and is used to draw a scatter plot according to the sample data, take part of the data of the scatter plot as training data and input it into the model to be trained until the model to be trained meets the preset convergence condition, thereby obtaining a target model;
[0110] Prediction module 3, which is connected to training module 2 and is used to use the target model to predict the number of potential problems and convergence time that may occur in the corresponding unit number of lines in the subsequently submitted code, and obtain a prediction result;
[0111] Display module 4, which is connected to prediction module 3, is used to compare the prediction results with the actual inspection results in a quantitative manner in a visual way and present them graphically to developers.
[0112] In this embodiment, the acquisition module 1 includes:
[0113] A first generating unit 11, the first generating unit 11 is used to generate a check vector from the check result corresponding to each check item, each element of the check vector represents a check item;
[0114] A second generating unit 12, the second generating unit 12 is used to record the inspection results corresponding to the code submitted by the developer each time in chronological order and generate an inspection result list;
[0115] The matching unit 13 is connected to the first generating unit 11 and the second generating unit 12 respectively, and is used to match the inspection vector with the data in the inspection result list one by one to generate a matching vector, each element of which represents the number of problems matching each inspection item in this inspection.
[0116] In this embodiment, the training module 2 includes:
[0117] A calculation unit 21, the calculation unit 21 is used to calculate the number of problems corresponding to a unit number of lines in the current submitted code; wherein a number of lines is defined as the unit number of lines;
[0118] A drawing unit 22, the drawing unit 22 is connected to the calculation unit 21, and is used to draw a scatter plot by taking the number of questions and the number of questions corresponding to the number of rows as horizontal and vertical coordinate axes respectively;
[0119] The training unit 23 is connected to the drawing unit 22 and is used to take part of the data of the scatter plot as training data and input it into the model to be trained until the model to be trained meets the preset convergence condition to obtain the target model.
[0120] In this embodiment, the training module 2 also includes:
[0121] The verification unit 24 is connected to the drawing unit 22 and the training unit 23 respectively, and is used to use the data of other scatter plots except the training data to input into the model to be trained, and perform cross-validation on the model to be trained.
[0122] In this embodiment, the preset convergence condition includes: adjusting the mean square error between the predicted value and the actual value by adjusting parameters, and the adjustment parameters include a preset threshold.
[0123] In summary, the present invention obtains the inspection items of the code quality management platform and the training data formed by the inspection results of the code submitted by the developer to train the training model through a machine learning algorithm. After the training is completed, the training model is used to predict the subsequent submitted code, and the prediction results are quantitatively compared with the actual inspection results and displayed to the developer. By quantitatively comparing the data, in order to ensure that the actual number of problems is not greater than the predicted value, the developer will actively perform static inspection and unit testing of the code in the daily coding process to reduce the number of problems, thereby achieving the purpose of improving the code quality.
[0124] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments.
Claims
1. A code quality improvement method based on machine learning, characterized in that: The following steps are involved: Step S1, obtaining sample data through a code quality management platform, wherein the sample data includes check items obtained according to the code quality management platform, and the number of problems matching each check item in the code currently submitted by the developer; Step S2, drawing a scatter plot according to the sample data, taking part of the data of the scatter plot as training data and inputting it into the model to be trained, until the model to be trained meets the preset convergence condition, thereby obtaining a target model; Step S3, using the target model to predict the number of potential problems and convergence time corresponding to the number of lines in the code subsequently submitted by the developer, to obtain a prediction result; Step S4, quantitatively comparing the prediction result with the actual inspection result of the code quality management platform in a visual manner and graphically displaying it to the developer.
2. The method for improving code quality according to claim 1, characterized in that: The step S1 comprises the following steps: Step S11, generating a check vector from the check result corresponding to each of the check items, wherein each element of the check vector represents one of the check items; Step S12, recording the inspection results corresponding to the code submitted by the developer each time in chronological order and generating an inspection result list; Step S13, matching the inspection vector with the data in the inspection result list one by one to generate a matching vector, wherein each element of the matching vector represents the number of times a problem matching each inspection item occurs in this inspection.
3. The code quality improvement method according to claim 1 is characterized in that: The step S2 comprises the following steps: Step S21, defining a number of lines as a unit line number, and calculating the number of problems corresponding to the unit line number in the current submitted code according to the number of problems included in the sample data; Step S22, using the number of problems and the number of problems that occur in each inspection item corresponding to the unit number of rows as horizontal and vertical axes, respectively, to draw a scatter plot; Step S23, taking part of the data of the scatter plot as training data and inputting it into the model to be trained, until the model to be trained meets a preset convergence condition, thereby obtaining a target model.
4. The method for improving code quality according to claim 1, characterized in that: The step S2 further includes: using other data of the scatter plot except the training data to input into the model to be trained, and cross-validating the model to be trained.
5. The method for improving code quality according to claim 1, characterized in that: The preset convergence condition includes: adjusting a mean square error between a predicted value and an actual value by adjusting a parameter, wherein the adjustment parameter includes a preset threshold.
6. A code quality improvement system based on machine learning, implementing the code quality improvement method based on machine learning as described in any one of claims 1 to 5, characterized in that: include: An acquisition module, the acquisition module is used to acquire sample data through a code quality management platform, the sample data including check items acquired according to the code quality management platform, and the number of problems matching each check item in the code currently submitted by the developer; A training module, the training module is connected to the acquisition module, and is used to draw a scatter plot according to the sample data, take part of the data of the scatter plot as training data and input it into the model to be trained, until the model to be trained meets the preset convergence condition, thereby obtaining a target model; A prediction module, the prediction module is connected to the training module and is used to use the target model to predict the number of potential problems and convergence time corresponding to the unit number of lines in the subsequent submitted code to obtain a prediction result; A display module is connected to the prediction module and is used to compare the prediction results with the actual inspection results in a quantitative manner in a visual manner and present them graphically to the developer.
7. The code quality improvement system according to claim 6, characterized in that: The acquisition module comprises: a first generating unit, the first generating unit being configured to generate a check vector from the check result corresponding to each of the check items, wherein each element of the check vector represents one of the check items; A second generating unit, the second generating unit is used to record the inspection results corresponding to the code submitted by the developer each time in chronological order and generate an inspection result list; A matching unit, wherein the matching unit is connected to the first generating unit and the second generating unit respectively, and is used to match the inspection vector with the data in the inspection result list one by one to generate a matching vector, wherein each element of the matching vector represents the number of times a problem matching each of the inspection items occurs in this inspection.
8. The code quality improvement system according to claim 6, characterized in that: The training module includes: A calculation unit, the calculation unit is used to calculate the number of problems corresponding to a unit number of lines in the current submitted code; wherein a number of lines is defined as the unit number of lines; A drawing unit, connected to the calculation unit, for drawing a scatter plot by taking the number of questions and the number of questions corresponding to the number of unit rows as horizontal and vertical coordinate axes respectively; A training unit is connected to the drawing unit and is used to take part of the data of the scatter plot as training data and input it into the model to be trained until the model to be trained meets a preset convergence condition to obtain a target model.
9. The code quality improvement system according to claim 8, characterized in that: The training module also includes: A verification unit, wherein the verification unit is respectively connected to the drawing unit and the training unit, and is used to use the data of the scatter plot other than the training data to be input into the model to be trained, and to perform cross-validation on the model to be trained.
10. The code quality improvement system according to claim 6, characterized in that: The preset convergence condition includes: adjusting a mean square error between a predicted value and an actual value by adjusting a parameter, wherein the adjustment parameter includes a preset threshold.
Citation Information
Patent Citations
Code quality improvement suggestion determination method and device and electronic equipment
CN111382443A
Code quality evaluation method, device and system and storage medium
CN110858176A
Code risk prediction method and system based on machine learning
CN112711530A