Artificial Intelligence-Based Code Metrics Method, Device, Equipment and Storage Medium
Through the AI-based code measurement method, the metric library and trend prediction model are used to solve the problem of not considering code trends in traditional code measurement technology, and more accurate and flexible measurement analysis is achieved.
Patent Information
- Application Number
- CN202210281710.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-21
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2042-03-21
AI Technical Summary
Traditional code metrics fail to effectively consider the trend of code, resulting in low accuracy of metric analysis results.
Using an artificial intelligence-based method, by obtaining code metric requests, using preset metric databases and project code libraries, combined with trend prediction models, code metric results are generated, including metric configuration interfaces and keyword definition interfaces, to improve the accuracy of metric analysis.
The measurement analysis based on the code-based trend prediction value is realized, which improves the accuracy and flexibility of the results of the measurement analysis and meets the personalized needs of users.
Smart Images

Figure CN114595157B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to an artificial intelligence-based code measurement method, apparatus, device, and storage medium. Background Art
[0002] Code metrics are a set of software measurements that allow developers to better understand the code they are developing. Traditional code metrics techniques simply analyze the code's standard and actual metrics without considering code trends, resulting in inaccurate results. Summary of the Invention
[0003] The main purpose of this application is to provide an artificial intelligence-based code measurement method, device, equipment and storage medium, aiming to solve the technical problem that code measurement technology does not take into account the trend of the code, resulting in low accuracy of the measurement analysis results.
[0004] In order to achieve the above-mentioned invention objectives, the present application proposes a code measurement method based on artificial intelligence, which includes:
[0005] Obtaining a code measurement request, wherein the code measurement request carries a target indicator identifier;
[0006] According to the target indicator identifier, a metric indicator is obtained from a preset metric indicator library as the target metric indicator;
[0007] According to the target measurement indicators, the project code is obtained from a preset project code library to obtain the code to be measured;
[0008] Measuring the code to be measured according to the target measurement indicator to obtain the target measurement actual value;
[0009] A code measurement result is generated according to the target measurement indicator, the target measurement actual value and the measurement prediction value corresponding to the target measurement indicator.
[0010] Furthermore, the step of obtaining a code metrics request includes:
[0011] The code measurement request sent by the target application through a preset measurement service interface is obtained, wherein the measurement service interface is an interface encapsulated by a Python microservice framework based on FastApi.
[0012] Furthermore, before the step of obtaining a metric from a preset metric library according to the target metric identifier and using it as the target metric, the step further includes:
[0013] Get indicator configuration request;
[0014] In response to the metric configuration request, display a metric configuration interface according to a preset common keyword library and a preset method interface library;
[0015] Obtain the metric index input by the user according to the metric configuration interface as the metric index to be stored;
[0016] Update the metric index library according to the metric index to be stored.
[0017] Further, before the step of obtaining the metric configuration request, it further includes:
[0018] Obtain a keyword definition request;
[0019] In response to the keyword definition request, display a keyword definition interface according to the method interface library and a preset user script library;
[0020] Obtain the keyword input by the user according to the keyword definition interface as the personalized keyword to be stored;
[0021] Update the to-be-stored personalized keyword to a preset personalized keyword library;
[0022] The step of displaying a metric configuration interface according to a preset common keyword library and a preset method interface library includes:
[0023] Display the metric configuration interface according to the personalized keyword library, the common keyword library, and the method interface library.
[0024] Further, the step of generating a code metric result according to the target metric index, the target metric actual value, and the metric prediction value corresponding to the target metric index includes:
[0025] Obtain the metric prediction value corresponding to the target metric index;
[0026] Subtract the metric prediction value corresponding to the target metric index from the target metric actual value to obtain a metric difference;
[0027] Determine whether the metric difference meets the requirements of the fluctuation configuration in the target metric index;
[0028] If so, determine that the code metric result is normal;
[0029] If not, determine that the code metric result is abnormal.
[0030] Further, the step of obtaining the metric prediction value corresponding to the target metric index includes:
[0031] Obtain the actual metric values within a preset duration from a preset actual metric value library according to the target metric and the actual target metric value, as the historical actual metric value set;
[0032] Input the historical actual metric value set into a preset trend prediction model for prediction to obtain the metric prediction value corresponding to the target metric.
[0033] Further, before the step of inputting the historical actual metric value set into a preset trend prediction model for prediction to obtain the metric prediction value corresponding to the target metric, it further includes:
[0034] Obtain a training sample set and an initial model, where the initial model is a model obtained based on the ARIMA model;
[0035] Randomly divide each of the training samples in the training sample set into two sets to obtain a training set and a validation set;
[0036] Use the training set to train the initial model, and use the trained initial model as the model to be verified;
[0037] Use the validation set to verify the model to be verified to obtain a verification result;
[0038] If the verification result is a failure, use the model to be verified as the initial model, and repeat the step of randomly dividing each of the training samples in the training sample set into two sets to obtain a training set and a validation set;
[0039] If the verification result is a success, use the model to be verified as the trend prediction model.
[0040] This application also proposes an artificial intelligence-based code metric device, and the device includes:
[0041] ]>A request acquisition module, configured to acquire a code metric request, where the code metric request carries a target index identifier;
[0042] A target metric determination module, configured to obtain a metric according to the target index identifier from a preset metric library as the target metric;
[0043] A code to be measured determination module, configured to obtain project code from a preset project code library according to the target metric to obtain the code to be measured;
[0044] A target metric actual value determination module, configured to measure the code to be measured according to the target metric to obtain the target metric actual value;
[0045] A code metric result determination module, configured to generate a code metric result according to the target metric indicator, the target metric actual value, and the metric prediction value corresponding to the target metric indicator.
[0046] The present application also provides a computer device, including a memory and a processor, where the memory stores a computer program, and when the processor executes the computer program, the steps of the method described in any one of the above are implemented.
[0047] The present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method described in any one of the above are implemented.
[0048] The code metric method, device, equipment, and storage medium based on artificial intelligence of the present application. The method obtains a code metric request, where the code metric request carries a target metric identifier; according to the target metric identifier, a metric indicator is obtained from a preset metric indicator library as the target metric indicator; according to the target metric indicator, project code is obtained from a preset project code library to obtain the code to be metric; according to the target metric indicator, the code to be metric is metric to obtain the target metric actual value; a code metric result is generated according to the target metric indicator, the target metric actual value, and the metric prediction value corresponding to the target metric indicator. By generating the code metric result through the target metric actual value and the metric prediction value corresponding to the target metric indicator, it realizes metric analysis based on the predicted value of the code trend, and improves the accuracy of the metric analysis result. Description of the Drawings
[0049] Figure 1 It is a schematic flowchart of the code metric method based on artificial intelligence according to an embodiment of the present application;
[0050] Figure 2 It is a schematic block diagram of the structure of the code metric device based on artificial intelligence according to an embodiment of the present application;
[0051] Figure 3 It is a schematic block diagram of the structure of a computer device according to an embodiment of the present application.
[0052] The realization, functional features, and advantages of the purpose of the present application will be further described with reference to the embodiments and the drawings. Detailed Embodiments
[0053] In order to make the purpose, technical solution, and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0054] Refer to Figure 1, in an embodiment of the present application, a code measurement method based on artificial intelligence is provided, and the method includes:
[0055] S1: Obtain a code measurement request, where the code measurement request carries a target metric identifier;
[0056] S2: According to the target metric identifier, obtain a metric from a preset metric library as the target metric;
[0057] S3: According to the target metric, obtain project code from a preset project code library to obtain the code to be measured;
[0058] S4: Measure the code to be measured according to the target metric to obtain the actual value of the target measurement;
[0059] S5: Generate a code measurement result according to the target metric, the actual value of the target measurement, and the predicted measurement value corresponding to the target metric.
[0060] In this embodiment, the code measurement result is generated by the actual value of the target measurement and the predicted measurement value corresponding to the target metric, realizing the measurement analysis based on the predicted value of the code trend and improving the accuracy of the measurement analysis result.
[0061] For S1, the code measurement request sent by the target application can be obtained, or the code measurement request actively triggered by the program implementing the present application can also be obtained.
[0062] The code measurement request is a request for measuring and analyzing the code.
[0063] The target metric identifier is the identifier of the metric that the code measurement request wants to analyze. The metric identifier can be data such as a metric name, metric ID, etc. that uniquely identifies a metric.
[0064] For S2, the target metric identifier is used to obtain a metric from a preset metric library, and the found metric is used as the target metric.
[0065] The metric library includes: one or more metrics. The metric includes: metric identifier, project identifier, metric algorithm, and fluctuation configuration. The project identifier can be data such as a project name, project ID, etc. that uniquely identifies a project..
[0066] Optionally, the metric indicators further include: indicator trigger configuration. The indicator trigger configuration includes: direct trigger, interval first duration trigger, and periodic trigger. The direct trigger is to directly trigger the execution of steps S2 to S5 when a code metric request is obtained. The interval first duration trigger is to wait for the first duration after obtaining the code metric request and then trigger the execution of steps S2 to S5. The periodic trigger is to start from the time when the code metric request is obtained and perform periodic triggering to execute steps S2 to S5 at a preset period.
[0067] For S3, according to the item identifier in the target metric indicator, obtain the project code from the project code library, and use the obtained code as the code to be measured.
[0068] The project code library includes: project identifier and project code. The project code is all the code corresponding to a project.
[0069] For S4, use a code parser to perform lexical and syntactic analysis on the code to be measured, extract information from the parsed data, and represent the extracted information in the form of an abstract syntax tree; use the indicator algorithm in the target metric indicator to traverse the abstract syntax tree generated from the code to be measured, measure the traversed data, and use the measured data as the actual value of the target metric.
[0070] For S5, compare the actual value of the target metric with the predicted metric value corresponding to the target metric indicator; if the comparison result meets the requirements of the fluctuation configuration of the target metric indicator, determine that the code metric result is normal; if the comparison result does not meet the requirements of the fluctuation configuration of the target metric indicator, determine that the code metric result is abnormal.
[0071] The predicted metric value corresponding to the target metric indicator is a predicted value obtained by trend prediction based on the historical actual metric values corresponding to the target metric indicator.
[0072] Optionally, the code metric request also carries a chart configuration method; after the step of measuring the code to be measured according to the target metric indicator to obtain the actual value of the target metric, it further includes: storing the actual value of the target metric in a preset actual metric value library; generating a chart according to the chart configuration method and the actual metric value library to obtain a chart to be displayed; displaying the chart to be displayed on the interface. Thus, the visualization of the actual metric value is realized, and the user experience is improved.
[0073] In one embodiment, the step of obtaining the code metric request includes:
[0074] S11: Obtain the code measurement request sent by the target application through a preset measurement service interface, where the measurement service interface is an interface encapsulated based on the Python microservice framework of FastApi.
[0075] In this embodiment, the measurement service interface encapsulated based on the Python microservice framework of FastApi is used to obtain the code measurement request sent by the target application, so as to provide the measurement service to other applications through the network.
[0076] FastApi is a high-performance Web framework.
[0077] The Python (computer programming language) microservice framework is a microservice framework based on Python.
[0078] For S11, the target application generates the code measurement request according to the preset requirements and sends the code measurement request to the measurement service interface. Thus, code measurement is achieved by calling the measurement service interface.
[0079] In one embodiment, before the step of obtaining the measurement index from the preset measurement index library as the target measurement index according to the target index identifier, the following steps are further included:
[0080] S011: Obtain an index configuration request;
[0081] S012: Respond to the index configuration request and display the index configuration interface according to the preset common keyword library and preset method interface library;
[0082] S013: Obtain the measurement index input by the user according to the index configuration interface as the measurement index to be stored;
[0083] S014: Update the measurement index library according to the measurement index to be stored.
[0084] In this embodiment, the index configuration interface is displayed according to the preset common keyword library and preset method interface library, and the measurement index input by the user is obtained through the index configuration interface, so that the configurator of the measurement index does not require a lot of code skills, reducing the threshold and cost of measuring index configuration.
[0085] For S011, the user clicks the index configuration button in the system implementing this application; when the index configuration button is clicked, an index configuration request will be generated.
[0086] The index configuration request is a request for configuring the measurement index.
[0087] For S012, when receiving the metric configuration request, display the metric configuration interface according to the public keyword library and method interface library in the database. Thus, the public keywords in the public keyword library and the method interfaces in the method interface library can be quickly referenced on the metric configuration interface.
[0088] The public keyword library includes one or more public keywords. A public keyword is a method or class encapsulated by code.
[0089] The method interface library includes one or more method interfaces. Using the code development method, this method uses a method interface to receive calls. When calling a method interface, input parameters need to be entered.
[0090] For example, use a method interface to receive the call time and date conversion method.
[0091] For another example, use a method interface to receive the call database connection query method.
[0092] For S013, the user configures the metric indicators on the metric configuration interface by referencing the public keywords in the public keyword library and / or the method interfaces in the method interface library, and clicks the submit button after the configuration is completed; when the submit button is clicked, the metric indicators to be stored will be generated according to the metric indicators in the metric configuration interface.
[0093] It can be understood that the metric algorithm of the metric indicator is an algorithm obtained based on public keywords and / or method interfaces.
[0094] For S014, use the metric indicator to be stored to replace and update the metric indicator library.
[0095] In one embodiment, before the step of obtaining the metric configuration request, it further includes:
[0096] S0111: Obtain the keyword definition request;
[0097] S0112: Respond to the keyword definition request, and display the keyword definition interface according to the method interface library and the preset user script library;
[0098] S0113: Obtain the keyword input by the user according to the keyword definition interface, and use it as the personalized keyword to be stored;
[0099] S0114: Update the personalized keyword to be stored to the preset personalized keyword library;
[0100] The step of displaying the metric configuration interface according to the preset public keyword library and preset method interface library includes:
[0101] S0121: Display the metric configuration interface according to the personalized keyword library, the common keyword library, and the method interface library.
[0102] In this embodiment, the keyword definition interface is displayed according to the method interface library and the user script library. The personalized keywords to be stored are determined based on the keyword definition interface. Then, the metric configuration interface is displayed according to the personalized keyword library, the common keyword library, and the method interface library, realizing the configuration of metric indicators based on the user-defined personalized keyword library, improving the flexibility of metric indicator configuration, and meeting the user's personalized metric indicator generation requirements.
[0103] For S0111, the user clicks the keyword definition button in the system implementing this application; when the keyword definition button is clicked, a keyword definition request is generated.
[0104] The keyword definition request is a request to define personalized keywords.
[0105] For S0112, when the keyword definition request is received, the keyword definition interface is displayed according to the method interface library and the preset user script library. Thus, the method interfaces in the method interface library and / or the user scripts in the user script library can be quickly referenced in the keyword definition interface for keyword definition.
[0106] The user script library includes user scripts. User scripts are methods for customization. User scripts are scripts developed using Python or Java.
[0107] For S0113, the user configures keywords in the keyword definition interface by referencing the method interfaces in the method interface library and / or the user scripts in the user script library. After the configuration is completed, the save button is clicked; when the save button is clicked, the keywords in the keyword definition interface are used as the personalized keywords to be stored.
[0108] For S0114, the personalized keyword library is replaced and updated using the personalized keywords to be stored.
[0109] The personalized keyword library includes: one or more personalized keywords. Personalized keywords are keywords defined by users.
[0110] For S0121, the metric configuration interface is displayed according to the personalized keyword library, the common keyword library, and the method interface library. Thus, the personalized keywords in the personalized keyword library, the common keywords in the common keyword library, and the method interfaces in the method interface library can be quickly referenced in the metric configuration interface.
[0111] It can be understood that the index algorithm of the metric index is an algorithm obtained based on at least one of personalized keywords, common keywords, and method interfaces.
[0112] In one embodiment, the step of generating a code metric result according to the target metric index, the actual value of the target metric, and the metric prediction value corresponding to the target metric index includes:
[0113] S51: Obtain the metric prediction value corresponding to the target metric index;
[0114] S52: Subtract the metric prediction value corresponding to the target metric index from the actual value of the target metric to obtain a metric difference;
[0115] S53: Determine whether the metric difference meets the requirements of the fluctuation configuration in the target metric index;
[0116] S54: If so, determine that the code metric result is normal;
[0117] S55: If not, determine that the code metric result is abnormal.
[0118] In this embodiment, by determining whether the difference obtained by subtracting the metric prediction value corresponding to the target metric index from the actual value of the target metric meets the requirements of the fluctuation configuration in the target metric index, the code metric result is determined, thereby realizing metric analysis based on the predicted value of the code trend and improving the accuracy of the metric analysis result.
[0119] For S51, the metric prediction value corresponding to the target metric index can be obtained from a database.
[0120] For S52, subtract the metric prediction value corresponding to the target metric index from the actual value of the target metric, and use the obtained difference as the metric difference.
[0121] For S53, when the fluctuation configuration in the target metric is range data, if the metric difference is within the range corresponding to the fluctuation configuration in the target metric, it is determined that the metric difference meets the requirements of the fluctuation configuration in the target metric; if the metric difference is outside the range corresponding to the fluctuation configuration in the target metric, it is determined that the metric difference does not meet the requirements of the fluctuation configuration in the target metric. When the fluctuation configuration in the target metric is greater than a first preset value, if the metric difference is greater than the first preset value, it is determined that the metric difference meets the requirements of the fluctuation configuration in the target metric; if the metric difference is less than or equal to the first preset value, it is determined that the metric difference does not meet the requirements of the fluctuation configuration in the target metric. When the fluctuation configuration in the target metric is less than a second preset value, if the metric difference is less than the second preset value, it is determined that the metric difference meets the requirements of the fluctuation configuration in the target metric; if the metric difference is greater than or equal to the second preset value, it is determined that the metric difference does not meet the requirements of the fluctuation configuration in the target metric.
[0122] For S54, if so, that is, the metric difference meets the requirements of the fluctuation configuration in the target metric, which means the metric difference is reasonable, so it is determined that the code metric result is normal.
[0123] For S55, if not, that is, the metric difference does not meet the requirements of the fluctuation configuration in the target metric, which means the metric difference is unreasonable, so it is determined that the code metric result is abnormal.
[0124] In one embodiment, the step of obtaining the metric prediction value corresponding to the target metric includes:
[0125] S511: Obtain the metric actual values within a preset duration from a preset metric actual value library according to the target metric and the target metric actual value as a historical metric actual value set.
[0126] S512: Input the historical metric actual value set into a preset trend prediction model for prediction to obtain the metric prediction value corresponding to the target metric.
[0127] In this embodiment, the metric actual values within the preset duration before the target metric are input into a preset trend prediction model for prediction, realizing the determination of the metric prediction value corresponding to the target metric based on artificial intelligence, improving the accuracy of the determined metric prediction value corresponding to the target metric, and improving the accuracy of the determined code metric result.
[0128] For S511, according to the index identifier in the target metric index, obtain the actual metric value from the actual metric value library as the candidate actual metric value set; obtain each actual metric value within a preset duration before the target actual metric value from the candidate actual metric value set, and use the obtained actual metric values as the historical actual metric value set, where the interval duration between the earliest generation time of the actual metric value in the historical actual metric value set and the generation time of the target actual metric value is less than or equal to the preset duration.
[0129] For S512, input the historical actual metric value set into a preset trend prediction model for prediction, and use the first predicted value in the predicted sequence as the metric predicted value corresponding to the target metric index.
[0130] In one embodiment, before the step of inputting the historical actual metric value set into a preset trend prediction model for prediction to obtain the metric predicted value corresponding to the target metric index, the following steps are further included:
[0131] S5121: Obtain a training sample set and an initial model, where the initial model is a model obtained based on the ARIMA model;
[0132] S5122: Randomly divide each training sample in the training sample set into two sets to obtain a training set and a validation set;
[0133] S5123: Use the training set to train the initial model, and use the trained initial model as the model to be verified;
[0134] S5124: Use the validation set to verify the model to be verified to obtain a verification result;
[0135] S5125: If the verification result is a failure, use the model to be verified as the initial model, and repeat the step of randomly dividing each training sample in the training sample set into two sets to obtain a training set and a validation set;
[0136] S5126: If the verification result is a success, use the model to be verified as the trend prediction model.
[0137] In this embodiment, by randomly dividing each training sample in the training sample set into two sets to obtain a training set and a validation set, and if the verification result is a failure, using the model to be verified as the initial model and repeating the step of randomly dividing each training sample in the training sample set into two sets to obtain a training set and a validation set, cross-validation is realized, which is beneficial to improving the efficiency of model training.
[0138] For S5121, the training sample set can be obtained from a database, or the training sample set input by a user can be obtained, or the training sample set can be obtained from a third-party application.
[0139] The training sample set includes multiple training samples. A training sample includes: a metric actual value sample sequence and a metric predicted value calibration result. The metric actual value sequence is a plurality of metric actual values arranged in time for the same metric. The metric actual value sequence is divided into two segments. The first segment of the two segments is used as the metric actual value sample sequence, and the second segment of the two segments is used as the metric predicted value calibration result. That is to say, the generation time corresponding to the metric predicted value calibration result is later than the generation time corresponding to the metric actual value sample sequence.
[0140] The initial model can be obtained from a database, or the initial model input by a user can be obtained, or the initial model can be obtained from a third-party application.
[0141] The ARIMA model, Autoregressive Integrated Moving Average model, also known as the integrated moving average autoregressive model (moving can also be called sliding), is one of the time series prediction analysis methods.
[0142] For S5122, each of the training samples in the training sample set is randomly divided into two sets. The first set obtained by the division is used as the training set, and the second set obtained by the division is used as the validation set.
[0143] Optionally, using a preset division ratio, each of the training samples in the training sample set is randomly divided into two sets. The first set obtained by the division is used as the training set, and the second set obtained by the division is used as the validation set.
[0144] Optionally, the number of training samples in the training set is four times the number of training samples in the validation set.
[0145] For S5123, using the training set, the initial model is trained until a preset model training condition is reached, and the initial model that reaches the model training condition is used as the model to be verified.
[0146] The preset model training condition is that the loss value of the initial model reaches the minimum.
[0147] Among them, the method of training the initial model using the training set will not be elaborated here.
[0148] For S5124, calculate the accuracy rate of the model to be verified's prediction on the verification set as the target accuracy rate. If the target accuracy rate is greater than the preset accuracy rate threshold, the verification result is successful; if the target accuracy rate is less than or equal to the preset accuracy rate threshold, the verification result is failed.
[0149] For S5125, if the verification result is failed, it means that the accuracy rate of the model to be verified does not meet the requirements yet. Therefore, take the model to be verified as the initial model and repeat steps S5122 to S5125 until the verification result is successful.
[0150] For S5126, if the verification result is successful, it means that the accuracy rate of the model to be verified meets the requirements, then take the model to be verified as the trend prediction model.
[0151] Refer to Figure 2 , this application also proposes an artificial intelligence-based code measurement device, which includes:
[0152] A request acquisition module 100, configured to acquire a code measurement request, where the code measurement request carries a target metric identifier;
[0153] A target metric determination module 200, configured to acquire a metric from a preset metric library according to the target metric identifier as the target metric;
[0154] A code to be measured determination module 300, configured to acquire project code from a preset project code library according to the target metric to obtain the code to be measured;
[0155] A target metric actual value determination module 400, configured to measure the code to be measured according to the target metric to obtain the actual value of the target metric;
[0156] A code measurement result determination module 500, configured to generate a code measurement result according to the target metric, the actual value of the target metric, and the metric prediction value corresponding to the target metric.
[0157] In this embodiment, by generating a code measurement result based on the actual value of the target metric and the metric prediction value corresponding to the target metric, it realizes the measurement analysis based on the predicted value of the code trend, and improves the accuracy of the measurement analysis result.
[0158] In one embodiment, the above request acquisition module 100 includes:
[0159] Request acquisition sub-module, used to acquire the code measurement request sent by the target application through a preset measurement service interface, where the measurement service interface is an interface encapsulated based on the Python microservice framework of FastApi.
[0160] In one embodiment, the above device further includes:
[0161] Metric index configuration module, used to acquire an index configuration request, respond to the index configuration request, display an index configuration interface according to a preset common keyword library and a preset method interface library, acquire the metric index input by the user from the index configuration interface as the metric index to be stored, and update the metric index library according to the metric index to be stored.
[0162] In one embodiment, the above metric index configuration module further includes:
[0163] Keyword definition sub-module, used to acquire a keyword definition request, respond to the keyword definition request, display a keyword definition interface according to the method interface library and a preset user script library, acquire the keyword input by the user from the keyword definition interface as the personalized keyword to be stored, and update the preset personalized keyword library with the personalized keyword to be stored;
[0164] Index configuration interface display sub-module, used to display the index configuration interface according to the personalized keyword library, the common keyword library, and the method interface library.
[0165] In one embodiment, the above code measurement result determination module 500 includes:
[0166] Metric prediction value acquisition sub-module, used to acquire the metric prediction value corresponding to the target metric index;
[0167] Code measurement result determination sub-module, used to subtract the metric prediction value corresponding to the target metric index from the target metric actual value to obtain a metric difference, and determine whether the metric difference meets the requirements of the fluctuation configuration in the target metric index. If so, determine that the code measurement result is normal; if not, determine that the code measurement result is abnormal.
[0168] In one embodiment, the above metric prediction value acquisition sub-module includes:
[0169] Historical metric actual value set acquisition unit, used to acquire the metric actual values within a preset time period from a preset metric actual value library according to the target metric index and the target metric actual value as the historical metric actual value set;
[0170] A metric prediction value determination unit, configured to input the set of historical metric actual values into a preset trend prediction model for prediction, so as to obtain the metric prediction value corresponding to the target metric indicator.
[0171] In one embodiment, the above device further includes:
[0172] A model training module, configured to obtain a training sample set and an initial model, where the initial model is a model obtained based on the ARIMA model; randomly divide each of the training samples in the training sample set into two sets to obtain a training set and a validation set; use the training set to train the initial model, and use the trained initial model as a model to be verified; use the validation set to verify the model to be verified to obtain a verification result; if the verification result is a failure, use the model to be verified as the initial model, and repeat the step of randomly dividing each of the training samples in the training sample set into two sets to obtain a training set and a validation set; if the verification result is a success, use the model to be verified as the trend prediction model.
[0173] Refer to Figure 3 , in an embodiment of the present application, a computer device is further provided. The computer device may be a server, and its internal structure may be as Figure 3 shown. The computer device includes a processor, a memory, a network interface, and a database connected through a system bus. Among them, the processor of the computer design is used 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, a computer program, and a database. The memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as a code metric method based on artificial intelligence. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a code metric method based on artificial intelligence. The code metric method based on artificial intelligence includes: obtaining a code metric request, where the code metric request carries a target metric identifier; according to the target metric identifier, obtaining a metric indicator from a preset metric indicator library as a target metric indicator; according to the target metric indicator, obtaining project code from a preset project code library to obtain code to be metric; according to the target metric indicator, metric the code to be metric to obtain a target metric actual value; generating a code metric result according to the target metric indicator, the target metric actual value, and the metric prediction value corresponding to the target metric indicator.
[0174] In this embodiment, the code metric result is generated by the actual value of the target metric and the metric prediction value corresponding to the target metric indicator, realizing the metric analysis based on the predicted value of the code trend and improving the accuracy of the metric analysis result.
[0175] In one embodiment, the step of obtaining the code metric request described above includes: obtaining the code metric request sent by the target application through a preset metric service interface, where the metric service interface is an interface encapsulated based on the FastApi Python microservice framework.
[0176] In one embodiment, before the step of obtaining the metric indicator from the preset metric indicator library according to the target indicator identifier as the target metric indicator, it further includes: obtaining an indicator configuration request; in response to the indicator configuration request, displaying an indicator configuration interface according to the preset common keyword library and preset method interface library; obtaining the metric indicator input by the user according to the indicator configuration interface as the metric indicator to be stored; and updating the metric indicator library according to the metric indicator to be stored.
[0177] In one embodiment, before the step of obtaining the indicator configuration request, it further includes: obtaining a keyword definition request; in response to the keyword definition request, displaying a keyword definition interface according to the method interface library and the preset user script library; obtaining the keyword input by the user according to the keyword definition interface as the personalized keyword to be stored; updating the preset personalized keyword library with the personalized keyword to be stored; the step of displaying the indicator configuration interface according to the preset common keyword library and preset method interface library includes: displaying the indicator configuration interface according to the personalized keyword library, the common keyword library, and the method interface library.
[0178] In one embodiment, the step of generating the code metric result according to the target metric indicator, the target metric actual value, and the metric prediction value corresponding to the target metric indicator includes: obtaining the metric prediction value corresponding to the target metric indicator; subtracting the metric prediction value corresponding to the target metric indicator from the target metric actual value to obtain a metric difference; determining whether the metric difference meets the requirements of the fluctuation configuration in the target metric indicator; if so, determining that the code metric result is normal; if not, determining that the code metric result is abnormal.
[0179] In one embodiment, the step of obtaining the metric prediction value corresponding to the target metric includes: obtaining the actual metric values within a preset time period from a preset actual metric value library according to the target metric and the actual target metric value as a historical actual metric value set; inputting the historical actual metric value set into a preset trend prediction model for prediction to obtain the metric prediction value corresponding to the target metric.
[0180] In one embodiment, before the step of inputting the historical actual metric value set into a preset trend prediction model for prediction to obtain the metric prediction value corresponding to the target metric, it further includes: obtaining a training sample set and an initial model, where the initial model is a model obtained based on the ARIMA model; randomly dividing each training sample in the training sample set into two sets to obtain a training set and a validation set; using the training set to train the initial model, and taking the trained initial model as a model to be verified; using the validation set to verify the model to be verified to obtain a verification result; if the verification result is a failure, taking the model to be verified as the initial model, and repeating the step of randomly dividing each training sample in the training sample set into two sets to obtain a training set and a validation set; if the verification result is a success, taking the model to be verified as the trend prediction model.
[0181] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements a code metric method based on artificial intelligence, including the steps of: obtaining a code metric request, where the code metric request carries a target metric identifier; obtaining a metric according to the target metric identifier from a preset metric library as a target metric; obtaining project code from a preset project code library according to the target metric to obtain code to be measured; measuring the code to be measured according to the target metric to obtain an actual target metric value; generating a code metric result according to the target metric, the actual target metric value, and the metric prediction value corresponding to the target metric.
[0182] The above-executed code metric method based on artificial intelligence generates a code metric result through the actual target metric value and the metric prediction value corresponding to the target metric, realizes metric analysis based on the predicted value of the code trend, and improves the accuracy of the metric analysis result.
[0183] In one embodiment, the step of obtaining the code metric request includes: obtaining the code metric request sent by a target application through a preset metric service interface, where the metric service interface is an interface encapsulated based on the Python microservice framework of FastApi.
[0184] In one embodiment, before the step of obtaining a metric as a target metric from a preset metric library according to the target metric identifier, the method further includes: obtaining an index configuration request; in response to the index configuration request, displaying an index configuration interface according to a preset common keyword library and a preset method interface library; obtaining a metric input by a user according to the index configuration interface as a metric to be stored; and updating the metric library according to the metric to be stored.
[0185] In one embodiment, before the step of obtaining the index configuration request, the method further includes: obtaining a keyword definition request; in response to the keyword definition request, displaying a keyword definition interface according to the method interface library and a preset user script library; obtaining a keyword input by a user according to the keyword definition interface as a personalized keyword to be stored; updating the preset personalized keyword library with the personalized keyword to be stored; the step of displaying the index configuration interface according to the preset common keyword library and the preset method interface library includes: displaying the index configuration interface according to the personalized keyword library, the common keyword library, and the method interface library.
[0186] In one embodiment, the step of generating a code metric result according to the target metric, the target metric actual value, and the metric prediction value corresponding to the target metric includes: obtaining the metric prediction value corresponding to the target metric; subtracting the metric prediction value corresponding to the target metric from the target metric actual value to obtain a metric difference; determining whether the metric difference meets the requirements of the fluctuation configuration in the target metric; if so, determining that the code metric result is normal; if not, determining that the code metric result is abnormal.
[0187] In one embodiment, the step of obtaining the metric prediction value corresponding to the target metric includes: obtaining metric actual values within a preset time period from a preset metric actual value library as a historical metric actual value set according to the target metric and the target metric actual value; inputting the historical metric actual value set into a preset trend prediction model for prediction to obtain the metric prediction value corresponding to the target metric.
[0188] In one embodiment, before the step of inputting the set of actual historical metric values into a preset trend prediction model to obtain the metric prediction value corresponding to the target metric indicator, the method further includes: obtaining a training sample set and an initial model, where the initial model is a model obtained based on the ARIMA model; randomly dividing each of the training samples in the training sample set into two sets to obtain a training set and a validation set; using the training set to train the initial model, and taking the initial model after the training is completed as the model to be validated; using the validation set to validate the model to be validated to obtain a validation result; if the validation result is a failure, taking the model to be validated as the initial model, and repeating the step of randomly dividing each of the training samples in the training sample set into two sets to obtain a training set and a validation set; if the validation result is a success, taking the model to be validated as the trend prediction model.
[0189] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the above method embodiments. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0190] It should be noted that in this text, the term "including", "comprising", or any other variation thereof is intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that includes a series of elements not only includes those elements but also includes other elements not explicitly listed, or further includes elements inherent to such a process, apparatus, article, or method. Without further limitation, an element defined by the statement "including one..." does not exclude the presence of additional identical elements in the process, apparatus, article, or method that includes such an element.
[0191] The above are only the preferred embodiments of the present application, and do not limit the patent scope of the present application accordingly. Any equivalent structural or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present application.
Claims
1. An artificial intelligence-based code measurement method, characterized in that, The method includes: Obtaining a code metric request, where the code metric request carries a target metric identifier; According to the target metric identifier, obtaining a metric from a preset metric library as the target metric; According to the target metric, obtaining project code from a preset project code library to obtain the code to be measured; Measuring the code to be measured according to the target metric to obtain the actual value of the target metric; Generating a code metric result according to the target metric, the actual value of the target metric, and the predicted metric value corresponding to the target metric; Before the step of obtaining a metric from a preset metric library as the target metric according to the target metric identifier, it further includes: Obtaining an index configuration request; Responding to the index configuration request, and displaying an index configuration interface according to a preset common keyword library and a preset method interface library; Obtaining the metric input by the user according to the index configuration interface as the metric to be stored; Updating the metric library according to the metric to be stored; The step of generating a code metric result according to the target metric, the actual value of the target metric, and the predicted metric value corresponding to the target metric includes: Obtaining the predicted metric value corresponding to the target metric; Subtracting the predicted metric value corresponding to the target metric from the actual value of the target metric to obtain a metric difference; Judging whether the metric difference meets the requirements of the fluctuation configuration in the target metric; If so, determining that the code metric result is normal; If not, determining that the code metric result is abnormal; According to the project identifier in the target metric, obtaining project code from the project code library, and using the obtained code as the code to be measured; The step of obtaining the predicted metric value corresponding to the target metric includes: According to the target metric and the actual value of the target metric, obtaining the actual metric values within a preset time period from a preset actual metric value library as the historical actual metric value set; Inputting the historical actual metric value set into a preset trend prediction model for prediction to obtain the predicted metric value corresponding to the target metric; Before the step of inputting the historical actual metric value set into a preset trend prediction model for prediction to obtain the predicted metric value corresponding to the target metric, it further includes: Obtaining a training sample set and an initial model, where the initial model is a model based on the ARIMA model; Randomly dividing each training sample in the training sample set into two sets to obtain a training set and a validation set; Using the training set to train the initial model, and using the initial model after training as the model to be verified; Using the validation set to verify the model to be verified to obtain a verification result; If the verification result is a failure, using the model to be verified as the initial model, and repeating the step of randomly dividing each training sample in the training sample set into two sets to obtain a training set and a validation set; If the verification result is successful, use the model to be verified as the trend prediction model.
2. The code measurement method based on artificial intelligence according to claim 1, wherein The step of obtaining the code metric request includes: Obtain the code metric request sent by the target application through a preset metric service interface, where the metric service interface is an interface encapsulated based on the FastApi Python microservice framework.
3. The code measurement method based on artificial intelligence according to claim 1, wherein Before the step of obtaining the metric configuration request, it further includes: Obtain a keyword definition request; In response to the keyword definition request, display a keyword definition interface according to the method interface library and a preset user script library; According to the keyword definition interface, obtain the keywords input by the user as personalized keywords to be stored; Update the personalized keyword library with the personalized keywords to be stored; The step of displaying a metric configuration interface according to a preset common keyword library and a preset method interface library includes: Display the metric configuration interface according to the personalized keyword library, the common keyword library, and the method interface library.
4. An artificial intelligence-based code measurement device, characterized in that The device includes: A request acquisition module for obtaining a code metric request, where the code metric request carries a target metric identifier; A target metric determination module for obtaining a metric from a preset metric library according to the target metric identifier as the target metric; A code to be measured determination module for obtaining project code from a preset project code library according to the target metric to obtain the code to be measured; A target metric actual value determination module for measuring the code to be measured according to the target metric to obtain the target metric actual value; A code metric result determination module for generating a code metric result according to the target metric, the target metric actual value, and the metric prediction value corresponding to the target metric; Before the step of obtaining a metric from a preset metric library according to the target metric identifier as the target metric, it further includes: Obtain a metric configuration request; In response to the metric configuration request, display a metric configuration interface according to a preset common keyword library and a preset method interface library; Obtain the metric input by the user according to the metric configuration interface as the metric to be stored; Update the metric library according to the metric to be stored; The step of generating a code metric result according to the target metric, the target metric actual value, and the metric prediction value corresponding to the target metric includes: Obtain the metric prediction value corresponding to the target metric; Subtract the metric prediction value corresponding to the target metric from the target metric actual value to obtain a metric difference; Determine whether the metric difference meets the requirements of the fluctuation configuration in the target metric; If so, determine that the code metric result is normal; If not, determine that the code metric result is abnormal; Obtain project code from the project code library according to the project identifier in the target metric, and use the obtained code as the code to be measured; The step of obtaining the metric prediction value corresponding to the target metric includes: According to the target metric and the actual value of the target metric, obtain the actual metric values within a preset duration from a preset actual metric value library as the historical actual metric value set; Input the historical actual metric value set into a preset trend prediction model for prediction to obtain the metric prediction value corresponding to the target metric; Before the step of inputting the historical actual metric value set into a preset trend prediction model for prediction to obtain the metric prediction value corresponding to the target metric, it further includes: Obtain a training sample set and an initial model, where the initial model is a model obtained based on the ARIMA model; Randomly divide each training sample in the training sample set into two sets to obtain a training set and a validation set; Use the training set to train the initial model, and use the initial model after the training ends as the model to be verified; Use the validation set to verify the model to be verified to obtain a verification result; If the verification result is a failure, use the model to be verified as the initial model, and repeat the step of randomly dividing each training sample in the training sample set into two sets to obtain a training set and a validation set; If the verification result is a success, use the model to be verified as the trend prediction model.
5. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 3.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Code quality improving method and system based on machine learning
CN114116469A
Data metric resolution prediction system and method
US20140095422A1