Scenario-based Code Generation Strategy Optimization Method

By analyzing project requirements and specific scenarios, optimizing code generation strategies, and dynamically generating code using dynamic programming algorithms and template engine technology, the problems of insufficient flexibility and high coupling of traditional code generation methods are solved, and the efficiency and quality of code generation are significantly improved.

CN119847496BActive Publication Date: 2025-06-13TAIJI COMPUTER CORPORATION LIMITED
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510338287.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-06-13
Estimated Expiration
2045-03-21

AI Technical Summary

Technical Problem

Traditional code generation methods lack flexibility and are difficult to adapt to diverse project needs and specific scenarios. The coupling degree and inefficiency in the code generation process are high.

Method used

The target code template is determined based on the analysis of project requirements, and an optimized code generation strategy is provided for specific scenarios; the coupling degree between different code segments is analyzed by using a preset dynamic programming algorithm to generate reference code generation order; the reference code generation order is combined with the key factors of the code to dynamically generate the actual code part, and the actual code part is tested and optimized.

Benefits of technology

It realizes the accurate generation of code that meets the requirements based on different project requirements and specific scenarios, improving the efficiency and quality of software development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847496B_ABST
    Figure CN119847496B_ABST
Patent Text Reader

Abstract

The present invention provides a method for optimizing a scenario-based code generation strategy, which relates to the technical field of software development. The method includes determining a target code template based on the analysis of project requirements; analyzing the coupling degree between different code segments to generate a reference code generation order; dynamically generating corresponding actual code parts by combining the reference code generation order with code key factors; testing the actual code parts and optimizing according to the test results. By determining a target code template based on the analysis of project requirements and providing an optimized code generation strategy for specific scenarios; analyzing the coupling degree between different code segments to generate a reference code generation order; generating corresponding actual code parts by combining the reference code generation order with code key factors; testing the actual code parts and optimizing according to the test results, code that meets the requirements can be accurately generated according to different project requirements and specific scenarios, improving the software development efficiency and quality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a scenario-based code generation strategy optimization method. Background Art

[0002] In the process of software development, code generation technology has been widely used. However, traditional code generation methods often lack flexibility and are difficult to adapt to diverse project requirements and specific scenarios. In addition, problems such as high coupling and low efficiency in the code generation process also limit its further development. Therefore, how to design a reasonable code generation strategy according to specific scenarios and achieve efficient and accurate code generation has become a technical problem that needs to be solved in the current software development field.

[0003] Therefore, the present invention provides a scenario-based code generation strategy optimization method. Summary of the invention

[0004] The present invention provides a scenario-based code generation strategy optimization method, which is used to determine the target code template based on the analysis of project requirements and provide an optimized code generation strategy for a specific scenario; analyze the coupling degree between different code fragments to generate a reference code generation sequence; combine the reference code generation sequence with code key factors to generate a corresponding actual code part; test the actual code part and optimize it according to the test results, so as to accurately generate code that meets the requirements according to different project requirements and specific scenarios, thereby improving software development efficiency and quality.

[0005] The present invention provides a scenario-based code generation strategy optimization method, comprising:

[0006] Step 1: Based on the analysis of project requirements, determine the target code template and provide optimized code generation strategies for specific scenarios involved;

[0007] Step 2: Analyze the coupling between different code fragments by using a preset dynamic programming algorithm to generate a reference code generation sequence;

[0008] Step 3: combining the reference code generation sequence with the code key factors to dynamically generate the corresponding actual code part;

[0009] Step 4: Perform performance analysis on the actual code and make corresponding optimizations based on the analysis results.

[0010] Preferably, based on the analysis of project requirements, the target code template is determined, and an optimized code generation strategy is provided for the specific scenarios involved, including:

[0011] Input the currently obtained target project into the pre-established project recognition model for recognition and analysis to obtain the corresponding project objectives, specific scenarios, and project constraints;

[0012] Use the obtained project objectives and specific scenarios as matching conditions to screen and obtain the desired template from the preset code template library and output it as the target code template;

[0013] Use the template type, project objectives, and project constraints of the current target code template as matching conditions to screen and obtain the desired code generation rule document from the preset code template library and output it as the target code generation rule;

[0014] Utilize a tool framework adapted to the specific domain of the current target project service to develop the corresponding first code generation tool;

[0015] Integrate the dependencies of the target library and the target framework into the first code generation tool.

[0016] Preferably, analyze the coupling degree between different code segments by using a preset dynamic programming algorithm to generate a reference code generation order, including:

[0017] Evaluate the current code segment by using a set coupling evaluation index to obtain the coupling degree evaluation index value;

[0018] Perform a weighted average on all the obtained coupling degree evaluation index values to calculate the coupling degree evaluation coefficient of the current code segment;

[0019] Construct a code segment dependency graph based on the coupling degree evaluation coefficients of all code segments;

[0020] Select the first preset dynamic programming algorithm from the current preset planning algorithm list to analyze the code segment dependency graph and obtain the reference code generation order;

[0021] Adjust the current code generation order according to the reference code generation order.

[0022] Preferably, in the code segment dependency graph, each node represents a code segment, and the edge between nodes represents the coupling degree between code segments.

[0023] Preferably, it further includes:

[0024] Regularly obtain the historical adjustment data of the code generation order within the first preset time period;

[0025] According to the historical adjustment data, obtain the historical usage frequency, historical adjustment duration, and adjustment accuracy of each preset dynamic programming algorithm in the preset planning algorithm table;

[0026] Calculate the applicability coefficient of the current preset dynamic programming algorithm according to the obtained historical usage frequency, historical adjustment duration, and adjustment accuracy;

[0027] Among them, the calculation formula of the applicability coefficient is as follows:

[0028] ; In the formula, represents the applicability coefficient of the current preset dynamic programming algorithm; represents the adjustment accuracy of the current preset dynamic programming algorithm; represents the historical usage frequency of the current preset dynamic programming algorithm; represents the contribution weight of the historical usage frequency to the applicability of the analysis algorithm; represents the historical adjustment duration of the current preset dynamic programming algorithm; represents the average value of the historical adjustment durations of all preset dynamic programming algorithms; represents the contribution weight of the adjustment duration to the applicability of the analysis algorithm;

[0029] After sorting the preset dynamic programming algorithms in descending order according to the applicability coefficient, output them as a preset planning algorithm list.

[0030] Preferably, combine the reference code generation order with the code key factors to dynamically generate the corresponding actual code part, including:

[0031] Identify the key factors by identifying the project requirements and target code templates of the target project;

[0032] Based on the identified key factors, establish a key mapping relationship between the code generation logic and the key factors;

[0033] Based on the key mapping relationship, determine the first code snippet that matches the key factors;

[0034] Based on the template engine technology, dynamically generate the corresponding actual code part according to the reference code generation order and the matched first code snippet, and integrate the generated actual code part into the target project.

[0035] Preferably, perform performance analysis on the actual code part and perform corresponding optimization according to the analysis results, including:

[0036] Combine test cases and test-driven development methods to ensure the synchronous generation of test code and implementation code;

[0037] Input the currently obtained actual code part into different types of pre-established target satisfaction analysis models in sequence to perform corresponding target satisfaction analysis and obtain the first satisfaction analysis score;

[0038] If the corresponding first satisfaction analysis scores of all types of project objectives in the current actual code part are greater than the set satisfaction score threshold, it is determined that the current actual code part does not need to be optimized;

[0039] If there is a corresponding first satisfaction analysis score of a project objective in the current actual code part that is not greater than the set satisfaction score threshold, it is determined that the current actual code part needs to be optimized and marked as the code part to be optimized;

[0040] According to the project objective whose first satisfaction analysis score in the code part to be optimized is not greater than the set satisfaction score threshold, determine the first optimization objective of the current code part to be optimized;

[0041] Using the obtained first optimization objective as a matching condition, determine the matching first review index from the preset review analysis list;

[0042] Adopt a preset performance analysis tool to perform a performance evaluation of the first review index for the current code part to be optimized, and obtain the first performance analysis value;

[0043] Compare the first performance analysis value with the corresponding preset index performance threshold range, and calculate the performance deviation coefficient of each first review index;

[0044] Using the performance deviation coefficient as a matching condition, extract the key optimization strategies from the preset optimization strategy library;

[0045] Perform a summary analysis on all the obtained key optimization strategies. If there are conflicts among the key optimization strategies, regard the conflicting key optimization strategies as the strategies to be analyzed;

[0046] Perform an optimization effect evaluation of the optimization effect index on the strategies to be analyzed, and obtain the first effect index value;

[0047] Calculate the optimization effect evaluation coefficient of the current strategy to be analyzed using the first effect index value;

[0048] Obtain the historical average execution duration of the current strategy to be analyzed within a preset time period;

[0049] After performing a weighted average calculation on the historical average execution duration and the optimization effect evaluation coefficient, obtain the strategy execution coefficient of the strategy to be analyzed;

[0050] Regard the strategy to be analyzed with the largest strategy execution coefficient as the target optimization strategy;

[0051] Use the target optimization strategy and the remaining key optimization strategies other than the strategies to be analyzed to optimize and adjust the current code part to be optimized.

[0052] Preferably, the calculation formula of the performance deviation coefficient is as follows:

[0053] ; wherein, is expressed as the performance deviation coefficient of the i-th first review index; is expressed as the first performance analysis value of the i-th first review index; is expressed as the upper limit of the preset index performance threshold range of the i-th first review index; is expressed as the lower limit of the preset index performance threshold range of the i-th first review index; ln represents the natural logarithm; e represents a constant with a value of 2.7.

[0054] Compared with the prior art, the beneficial effects of the present application are as follows:

[0055] By determining the target code template based on the analysis of project requirements, providing an optimized code generation strategy for specific scenarios; analyzing the coupling degree between different code segments to generate a reference code generation order; combining the reference code generation order with code key factors to generate the corresponding actual code part; testing the actual code part and optimizing according to the test results, it is possible to accurately generate code that meets the requirements according to different project requirements and specific scenarios, improving the software development efficiency and quality.

[0056] Other features and advantages of the present invention will be described in the following specification, and, in part, will be obvious from the specification, or will be understood by implementing the present invention. The objectives and other advantages of the present invention can be achieved and obtained by the structures specifically pointed out in the written specification and the drawings.

[0057] The technical solution of the present invention will be further described in detail below through the drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] The drawings are used to provide a further understanding of the present invention, and constitute a part of the specification, and are used to explain the present invention together with the embodiments of the present invention, and do not constitute a limitation to the present invention. In the drawings:

[0059] Figure 1 is a flowchart of a method for optimizing a code generation strategy based on scenarios in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0060] The following describes the preferred embodiments of the present invention with reference to the drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0061] An embodiment of the present invention provides a method for optimizing a code generation strategy based on scenarios, as Figure 1 shown, including:

[0062] Step 1: Based on the analysis of project requirements, determine the target code template and provide an optimized code generation strategy for the specific scenarios involved;

[0063] Step 2: Analyze the coupling degree between different code segments by adopting a preset dynamic programming algorithm to generate a reference code generation order;

[0064] Step 3: Combine the reference code generation order with code key factors to dynamically generate the corresponding actual code part;

[0065] Step 4: Conduct a performance analysis on the actual code part and perform corresponding optimization according to the analysis results.

[0066] In this embodiment, the target project refers to the actual project that needs to be analyzed and developed currently; the preset dynamic programming algorithm is an algorithm used to solve optimization problems, which is used to analyze the code segment dependency graph to find the optimal code generation order; the reference code generation order refers to the code generation order obtained based on the analysis results of the code segment dependency graph by the dynamic programming algorithm, aiming to minimize the dependency conflicts between code segments and improve the code generation efficiency and quality; the code key factors include input parameters, API calls, context environment and other factors.

[0067] The beneficial effects of the above technical solution are: by determining the target code template based on the analysis of project requirements and providing an optimized code generation strategy for specific scenarios; analyzing the coupling degree between different code segments to generate a reference code generation order; combining the reference code generation order with code key factors to generate the corresponding actual code part; testing the actual code part and performing optimization according to the test results, it is possible to accurately generate code that meets the requirements according to different project requirements and specific scenarios, and improve the software development efficiency and quality.

[0068] The embodiment of the present invention provides a method for optimizing a scenario-based code generation strategy. Based on the analysis of project requirements, determine the target code template and provide an optimized code generation strategy for the specific scenarios involved, including:

[0069] Input the currently obtained target project into a pre-established project recognition model for recognition and analysis to obtain the corresponding project objectives, specific scenarios and project constraint conditions;

[0070] Use the obtained project objectives and specific scenarios as matching conditions to screen out the desired template from the preset code template library and output it as the target code template;

[0071] Use the template type, project objectives and project constraint conditions of the current target code template as matching conditions to screen out the desired generation rule document from the preset code template library and output it as the target code generation rule;

[0072] Develop a corresponding first code generation tool using a tool framework adapted to the specific domain served by the current target project.

[0073] Integrate the dependencies of the target library and the target framework into the first code generation tool.

[0074] In this embodiment, the target project refers to the actual project that needs to be analyzed and developed currently; the project identification model refers to the key element model established in advance for identifying and analyzing projects; project objectives include functional requirements, performance requirements, security, scalability, etc.; specific scenarios include high concurrency, big data processing, real-time communication, etc., and these scenarios may have special requirements for code templates and generation rules; project constraint conditions include technology stack, development cycle, budget, etc.

[0075] In this embodiment, the preset code template library refers to a collection that stores various types of code templates; the expected template refers to the template obtained from the template library that best matches the target project; the expected generation rule document refers to the generation rule document obtained from the preset code template library that matches the target code template, project objectives, and constraint conditions; the specific domain refers to the professional or business category where the target project is located, such as e-commerce; the first code generation tool refers to a software tool specifically used to automatically generate code according to templates and generation rules; the target library refers to a database used to store and manage various library files, modules, or components required for a specific project or system during software development; the target framework refers to a software architecture that provides a set of structured solutions and development environments for a specific domain or project, including a set of predefined classes, components, interfaces, and rules, as well as the interaction methods and constraint conditions between them.

[0076] The beneficial effects of the above technical solution are: By analyzing project requirements, determining the target code template, and providing optimized code generation strategies for the specific scenarios involved, it can accurately match requirements, significantly improve development efficiency, improve code quality, and enhance the adaptability and scalability of the project.

[0077] An embodiment of the present invention provides a method for optimizing a scenario-based code generation strategy. By using a preset dynamic programming algorithm to analyze the coupling degree between different code fragments, a reference code generation order is generated, including:

[0078] Evaluate the current code fragment using a set coupling evaluation index to obtain a coupling degree evaluation index value;

[0079] Perform a weighted average on all the obtained coupling degree evaluation index values to calculate the coupling degree evaluation coefficient of the current code fragment;

[0080] Based on the coupling degree evaluation coefficients of all code fragments, construct a code fragment dependency graph;

[0081] Select the first preset dynamic programming algorithm from the current preset planning algorithm list, analyze the code snippet dependency graph, and obtain the reference code generation order;

[0082] Adjust the current code generation order according to the reference code generation order.

[0083] In this embodiment, the coupling evaluation index refers to an index used to quantify the tightness of the dependency relationship between code snippets, including the number of calls, the degree of data sharing, interface dependency relationships, etc.; the coupling degree evaluation index value refers to the value obtained by evaluating the current code snippet according to the coupling evaluation index, which reflects the coupling degree between the code snippet and other snippets; the coupling degree evaluation coefficient refers to the coefficient obtained by weighted averaging all the coupling degree evaluation index values, which is used to comprehensively reflect the coupling degree of the code snippet; in the code snippet dependency graph, each node represents a code snippet, and the edges between the nodes represent the coupling degree between the code snippets; the preset dynamic programming algorithm is an algorithm used to solve optimization problems, which is used to analyze the code snippet dependency graph to find the optimal code generation order; the reference code generation order refers to the code generation order obtained based on the analysis result of the code snippet dependency graph by the dynamic programming algorithm, aiming to minimize the dependency conflicts between code snippets and improve the code generation efficiency and quality.

[0084] The beneficial effects of the above technical solution are: by using the preset dynamic programming algorithm to analyze the coupling degree between different code snippets and generate the reference code generation order, it can help improve the code multiplication efficiency and code quality.

[0085] The embodiment of the present invention provides a method for optimizing a code generation strategy based on scenarios, which further includes:

[0086] Regularly obtain the historical adjustment data of the code generation order within the first preset time period;

[0087] According to the historical adjustment data, obtain the historical usage frequency, historical adjustment duration, and adjustment accuracy of each preset dynamic programming algorithm in the preset planning algorithm table;

[0088] Calculate the applicability coefficient of the current preset dynamic programming algorithm according to the obtained historical usage frequency, historical adjustment duration, and adjustment accuracy;

[0089] Among them, the calculation formula of the applicability coefficient is as follows:

[0090] ; in the formula, represents the applicability coefficient of the current preset dynamic programming algorithm; represents the adjustment accuracy of the current preset dynamic programming algorithm; Represented as the historical usage frequency of the current preset dynamic programming algorithm; Represented as the contribution weight of the historical usage frequency to the applicability analysis of the algorithm; Represented as the historical adjustment duration of the current preset dynamic programming algorithm; Represented as the average value of the historical adjustment durations of all preset dynamic programming algorithms; Represented as the contribution weight of the adjustment duration to the applicability analysis of the algorithm;

[0091] After sorting the preset dynamic programming algorithms in descending order according to the applicability coefficient, output them as a list of preset planning algorithms.

[0092] In this embodiment, the first preset time period refers to a specific time period for regularly collecting and analyzing the historical adjustment data of the code generation order; the historical adjustment data refers to the records and data of the code generation order being adjusted within the first preset time period, including the time of adjustment, the order before and after adjustment, the reason for adjustment, etc.; the preset planning algorithm table refers to a table or list containing multiple preset dynamic programming algorithms, and the algorithms are used to analyze the dependencies between code segments and generate an optimized code generation order; the historical usage frequency refers to the number of times or frequency of each preset dynamic programming algorithm being used in the historical adjustment data; the historical adjustment duration refers to the time length required to use a certain preset dynamic programming algorithm for adjustment; the adjustment accuracy refers to the improvement degree or accuracy of the code generation order after using a certain preset dynamic programming algorithm for adjustment, and the index is evaluated by comparing the performance and error rate before and after adjustment; the applicability coefficient is used to comprehensively reflect the applicability of the preset dynamic programming algorithm.

[0093] The beneficial effects of the above technical solution are: By performing applicability analysis on the preset dynamic programming algorithm and dynamically updating the list of preset planning algorithms according to the applicability analysis results, the scientificity of algorithm selection is improved, which in turn helps to optimize the code generation order.

[0094] The embodiment of the present invention provides a method for optimizing a code generation strategy based on scenarios, which combines the reference code generation order with code key factors to dynamically generate corresponding actual code parts, including:

[0095] Identify key factors for the project requirements and target code templates of the target project;

[0096] Based on the identified key factors, establish a key mapping relationship between the code generation logic and the key factors;

[0097] Based on the key mapping relationship, determine the first code segment that matches the key factors;

[0098] Based on the template engine technology, according to the reference code generation order and the first code snippet after matching, dynamically generate the corresponding actual code part, and integrate the generated actual code part into the target project.

[0099] In this embodiment, the key factors refer to factors such as input parameters, API calls, and context environment; establishing a mapping relationship between the code generation logic and the identified key factors aims to guide how to transform project requirements into specific code implementations; the first code snippet refers to the code segment that matches the identified key factors and is used to implement specific functions or logics; the template engine technology refers to an automated tool for generating text based on templates and data, which is used to dynamically generate actual code according to the reference code generation order and the matched code snippets; the actual code part refers to the actual code generated by the template engine technology that meets the project requirements, and these codes are integrated into the target project to achieve specific functions.

[0100] The beneficial effects of the above technical solution are: by combining the reference code generation order with the code key factors, dynamically generating the corresponding actual code part, it can ensure the code quality, enhance the code maintainability, support rapid iteration, and reduce the development cost, which has a significant promoting effect on the software development process.

[0101] An embodiment of the present invention provides a method for optimizing a scenario-based code generation strategy, which performs performance analysis on the actual code part and performs corresponding optimization according to the analysis results, including:

[0102] Combining test cases and test-driven development methods to ensure the synchronous generation of test code and implementation code;

[0103] Input the currently obtained actual code part into different types of pre-established target satisfaction analysis models in sequence for corresponding target satisfaction analysis to obtain the first satisfaction analysis score;

[0104] If the corresponding first satisfaction analysis scores of all types of project goals of the current actual code part are greater than the set satisfaction score threshold, it is determined that the current actual code part does not need to be optimized;

[0105] If there is a corresponding first satisfaction analysis score of a project goal of the current actual code part that is not greater than the set satisfaction score threshold, it is determined that the current actual code part needs to be optimized and is marked as the code part to be optimized;

[0106] According to the project goals for which the first satisfaction analysis score of the code part to be optimized is not greater than the set satisfaction score threshold, determine the first optimization goal of the current code part to be optimized;

[0107] Using the obtained first optimization goal as a matching condition, determine the matching first review index from the pre-set review analysis list;

[0108] Use a preset performance analysis tool to perform a performance evaluation of the first review metric for the current code section to be optimized, and obtain a first performance analysis value;

[0109] Compare the first performance analysis value with the corresponding preset metric performance threshold range, and calculate the performance deviation coefficient for each first review metric;

[0110] Use the performance deviation coefficient as a matching condition to extract key optimization strategies from the preset optimization strategy library;

[0111] Summarize and analyze all the obtained key optimization strategies. If there are conflicts among the key optimization strategies, regard the conflicting key optimization strategies as strategies to be analyzed;

[0112] Perform an optimization effect evaluation of the optimization effect metric on the strategies to be analyzed, and obtain a first effect metric value;

[0113] Calculate the optimization effect evaluation coefficient of the current strategy to be analyzed using the first effect metric value;

[0114] Obtain the historical average execution duration of the current strategy to be analyzed within a preset time period;

[0115] After performing a weighted average calculation on the historical average execution duration and the optimization effect evaluation coefficient, obtain the strategy execution coefficient of the strategy to be analyzed;

[0116] Regard the strategy to be analyzed with the largest strategy execution coefficient as the target optimization strategy;

[0117] Use the target optimization strategy and the remaining key optimization strategies other than the strategies to be analyzed to optimize and adjust the current code section to be optimized.

[0118] In this embodiment, the target satisfaction analysis model refers to a model for evaluating whether the actual code part meets the preset criteria or rules of the project objectives; the first satisfaction analysis score refers to the score obtained by evaluating the current actual code part through the target satisfaction analysis model, reflecting the degree of satisfaction of the code with specific objectives; the set satisfaction score threshold refers to the score boundary for determining whether the actual code part meets the project objectives; the code part to be optimized refers to the code part that does not meet the set threshold in the target satisfaction analysis; the preset review analysis list refers to a list containing different review metrics, used for the preparatory work before performance evaluation; the preset performance analysis tool refers to a software tool for performing performance evaluation; the performance deviation coefficient refers to a coefficient reflecting the deviation degree between the first performance analysis value and the preset index performance threshold range; the preset optimization strategy library refers to a database containing various optimization strategies, used to guide the code optimization work; the optimization effect evaluation coefficient refers to a coefficient calculated based on the optimization effect metrics, reflecting the actual effect of the optimization strategy; the target optimization strategy refers to the optimization strategy with the largest strategy execution coefficient among the strategies to be analyzed.

[0119] The beneficial effects of the above technical solution are: By performing performance analysis on the actual code part and corresponding optimization according to the analysis results, the code quality can be significantly improved, the optimization requirements can be accurately positioned, the optimization strategy can be scientifically selected, the code performance can be enhanced, and the maintenance cost can be reduced.

[0120] The embodiment of the present invention provides a method for optimizing a code generation strategy based on scenarios, and the calculation formula of the performance deviation coefficient is as follows:

[0121] ; In the formula, represents the performance deviation coefficient of the i-th first review metric; represents the first performance analysis value of the i-th first review metric; represents the upper limit of the preset index performance threshold range of the i-th first review metric; represents the lower limit of the preset index performance threshold range of the i-th first review metric; ln represents the natural logarithm; e represents a constant with a value of 2.7.

[0122] The beneficial effects of the above technical solution are: By calculating the performance deviation coefficient, a strong data basis can be provided for selecting effective optimization strategies to accurately optimize the code part, which in turn helps to scientifically select optimization strategies to improve the code performance and reduce the maintenance cost.

[0123] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalent technologies, the present invention also intends to include these changes and modifications.

Claims

1. A scenario-based code generation strategy optimization method, characterized in that: include: Step 1: Based on the analysis of project requirements, determine the target code template and provide optimized code generation strategies for specific scenarios involved; Step 2: Analyze the coupling between different code fragments by using a preset dynamic programming algorithm to generate a reference code generation sequence; Step 3: combining the reference code generation sequence with the code key factors to dynamically generate the corresponding actual code part; Step 4: Perform performance analysis on the actual code and make corresponding optimizations based on the analysis results; Wherein, step 2 includes: Use the set coupling evaluation index to evaluate the current code snippet and obtain the coupling evaluation index value; Take a weighted average of all the obtained coupling evaluation index values ​​and calculate the coupling evaluation coefficient of the current code snippet; Based on the coupling evaluation coefficients of all code snippets, a code snippet dependency graph is constructed; A first preset dynamic programming algorithm is selected from the current preset programming algorithm list, and the code snippet dependency graph is analyzed to obtain a reference code generation sequence.

2. The scenario-based code generation strategy optimization method according to claim 1, characterized in that: Based on the analysis of project requirements, determine the target code template and provide optimized code generation strategies for specific scenarios involved, including: Input the currently acquired target project into the pre-established project identification model for identification and analysis to obtain the corresponding project goals, specific scenarios and project constraints; Using the acquired project goals and specific scenarios as matching conditions, the desired template is screened from the preset code template library and output as the target code template; Taking the template type, project target and project constraint of the current target code template as matching conditions, the expected generation rule document is screened from the preset code template library and output as the target code generation rule; Develop a corresponding first code generation tool using a tool framework adapted to the specific field served by the current target project; Integrate the target library and the target framework's dependencies into the first code generation tool.

3. The scenario-based code generation strategy optimization method according to claim 1, characterized in that: In the code snippet dependency graph, each node represents a code snippet, and the edges between the nodes represent the degree of coupling between the code snippets.

4. The scenario-based code generation strategy optimization method according to claim 1, characterized in that: Also includes: Regularly obtain historical adjustment data of the code generation sequence within a first preset time period; According to the historical adjustment data, the historical usage frequency, historical adjustment duration and adjustment accuracy of each preset dynamic programming algorithm in the preset planning algorithm table are obtained; Calculate the applicability coefficient of the current preset dynamic programming algorithm based on the acquired historical usage frequency, historical adjustment duration, and adjustment accuracy; The calculation formula of the applicable coefficient is as follows: ; In the formula, It is represented as the applicable coefficient of the current preset dynamic programming algorithm; It represents the adjustment accuracy of the current preset dynamic programming algorithm; It represents the historical usage frequency of the current preset dynamic programming algorithm; It is expressed as the contribution weight of historical usage frequency to the applicability of the analysis algorithm; Indicates the historical adjustment time of the current preset dynamic programming algorithm; It is expressed as the average of the historical adjustment durations of all preset dynamic programming algorithms; It is expressed as the contribution weight of the adjustment duration to the applicability of the analysis algorithm; The preset dynamic programming algorithms are sorted from large to small according to their applicable coefficients and output as a preset planning algorithm list.

5. The scenario-based code generation strategy optimization method according to claim 1, characterized in that: The reference code generation sequence is combined with the code key factors to dynamically generate the corresponding actual code parts, including: Identify the factors of the project requirements and target code template of the target project and obtain the key factors; Based on the identified key factors, a key mapping relationship between the code generation logic and the key factors is established; Based on the key mapping relationship, determining a first code fragment matching the key factor; Based on the template engine technology, the corresponding actual code part is dynamically generated according to the reference code generation order and the matched first code fragment, and the generated actual code part is integrated into the target project.

6. The scenario-based code generation strategy optimization method according to claim 1, characterized in that: Perform performance analysis on the actual code and make corresponding optimizations based on the analysis results, including: Combine test cases and test-driven development methods to ensure that test code and implementation code are generated synchronously; Inputting the currently acquired actual code part into different types of pre-established target satisfaction analysis models in sequence, performing corresponding target satisfaction analysis, and obtaining a first satisfaction analysis score; If the first satisfaction analysis scores corresponding to all types of project goals of the current actual code part are greater than the set satisfaction score threshold, it is determined that the current actual code part does not need to be optimized; If the first satisfaction analysis score corresponding to the project goal in the current actual code part is not greater than the set satisfaction score threshold, it is determined that the current actual code part needs to be optimized and marked as the code part to be optimized; Determining a first optimization target of the current code portion to be optimized according to the project target that the first satisfaction analysis score of the code portion to be optimized is not greater than a set satisfaction score threshold; Using the obtained first optimization target as a matching condition, determining a matching first review indicator from a preset review analysis list; Using a preset performance analysis tool, a performance evaluation of a first review indicator is performed on the current code portion to be optimized to obtain a first performance analysis value; Compare the first performance analysis value with the corresponding preset indicator performance threshold range to calculate the performance deviation coefficient of each first review indicator; Taking the performance deviation coefficient as the matching condition, the key optimization strategy is extracted from the preset optimization strategy library; Summarize and analyze all key optimization strategies obtained. If there is a conflict in key optimization strategies, the conflicting key optimization strategies will be regarded as strategies to be analyzed. Performing optimization effect evaluation of the optimization effect index on the strategy to be analyzed to obtain a first effect index value; Calculate the optimization effect evaluation coefficient of the current strategy to be analyzed using the first effect indicator value; Get the historical average execution time of the current strategy to be analyzed within the preset time period; After weighted average calculation of the historical average execution time and the optimization effect evaluation coefficient, the strategy execution coefficient of the strategy to be analyzed is obtained; The strategy to be analyzed with the largest strategy execution coefficient is taken as the target optimization strategy; The target optimization strategy and the remaining key optimization strategies except the strategy to be analyzed are used to optimize and adjust the current code portion that needs to be optimized.

7. The scenario-based code generation strategy optimization method according to claim 6, characterized in that: The performance deviation coefficient is calculated as follows: ; In the formula, It is expressed as the performance deviation coefficient of the i-th first review indicator; It is represented as the first performance analysis value of the i-th first review indicator; is represented as the upper limit of the preset indicator performance threshold range of the i-th first review indicator; It is represented as the lower limit of the preset indicator performance threshold range of the i-th first review indicator; ln is represented as the natural logarithm; e is represented as a constant with a value of 2.7.

Citation Information

Patent Citations

  • Code analysis and generation method and system based on large model

    CN119396400A