Code generation method and device based on big data, and electronic device

By using a big data-based code generation method, leveraging public code repositories and pre-defined rating strategies to generate and review code, the problems of low code writing efficiency and high bug rates have been solved, resulting in more efficient and rigorous code generation.

CN115421725BActive Publication Date: 2026-03-10INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-30
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

Existing technologies suffer from low code writing efficiency and high bug rates, and manual review cannot effectively reduce code defects.

Method used

The big data-based code generation method receives code generation requests, retrieves public code repositories, generates and reviews initial code, adds it to the public code repository, and optimizes the code's logical rigor using preset rating strategies and machine learning.

Benefits of technology

It improved coding efficiency, reduced the code bug rate, and enhanced the rigor and reliability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115421725B_ABST
    Figure CN115421725B_ABST
Patent Text Reader

Abstract

The application discloses a code generation method and device based on big data and electronic equipment, and relates to the field of big data, and the generation method comprises the following steps: receiving a code generation request, searching a pre-established public code library, determining a target scene matched with a function requirement scene, and acquiring a reference code of the target scene, generating an initial code based on the generation logic of the reference code and the function requirement scene, and in the case that the initial code is audited and passed, determining that the initial code is a target code, and adding the target code to the public code library. The application solves the technical problems of low coding efficiency and inability to reduce the BUG rate of the code in the related art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of big data, and more specifically, to a code generation method, apparatus, and electronic device based on big data. Background Technology

[0002] Currently, due to the varying skill levels of developers and their insufficient understanding of code, the code they write is prone to bugs, leading to problems during runtime and preventing the achievement of desired results.

[0003] In related technologies, developers typically submit code after it has been written and undergone a manual review process. However, relying solely on manual review not only leads to low coding efficiency but also means that the code may still contain memory overflows or other bugs after deployment.

[0004] There is currently no effective solution to the above problems. Summary of the Invention

[0005] This invention provides a code generation method, apparatus, and electronic device based on big data, to at least solve the technical problems of low coding efficiency and inability to reduce the bug rate of code in related technologies.

[0006] According to one aspect of the present invention, a code generation method based on big data is provided, comprising: receiving a code generation request, wherein the code generation request includes at least: a functional requirement scenario; retrieving a pre-established public code library, determining a target scenario that matches the functional requirement scenario, and obtaining reference code for the target scenario; generating initial code based on the generation logic of the reference code and the functional requirement scenario; and, if the initial code passes the review, determining the initial code as target code and adding the target code to the public code library.

[0007] Optionally, before receiving the code generation request, the method further includes: using a preset rating strategy to rate the existing code in the public code repository and obtain a rating result, wherein the preset rating strategy includes at least one of the following: rating based on the code's running status, rating based on the code's problem situation, rating based on the impact level of the problem in the code, rating based on the code's logical level, rating based on the code's code status, rating based on the code's logging status, and rating based on the code's handling of exceptions.

[0008] Optionally, before receiving the code generation request, the method further includes: determining the code level of the code block, and adding weights to the code block based on the code level to obtain a weight value for each code block; if the weight value matches a preset scenario value, determining that the code scenario of the code block indicated by the weight value is a scenario corresponding to the preset scenario value, wherein each preset scenario value is pre-associated with the scenario; performing an analysis operation on the code block to obtain an analysis result, wherein the analysis operation includes at least one of the following: code analysis, performance analysis, and vulnerability analysis; if the analysis result indicates that the code block passes the analysis verification, including the code block in the public code repository.

[0009] Optionally, after determining that the code scenario of the code block indicated by the weight value corresponds to the scenario value of the preset scenario, the method further includes: determining the scenario level corresponding to the code scenario of the code block based on the weight value; verifying the code scenario of the code block if the scenario level is a preset level; classifying and analyzing the code logic of the code block if the verification passes; and including the code block in the public code library if the classification and analysis pass.

[0010] Optionally, after generating initial code based on the generation logic of the reference code and the functional requirement scenario, the method further includes: determining whether the initial code is a first type of code; if the initial code is a first type of code, reviewing the first type of code through a first code library in the public code library; if the review passes, performing a first preset review on the first type of code; if the first preset review passes, determining whether the code type of the first type of code is a modified existing code type; if the code type of the first type of code is the modified existing code type, determining the code level of the existing code indicated by the modified existing code type based on the rating result; if the code level of the first type of code is greater than the code level of the existing code, modifying the existing code based on the first type of code, and identifying the modified existing code.

[0011] Optionally, after determining whether the code situation of the first type of code is a modified existing code type, the method further includes: if the code situation of the first type of code is an incremental code type, using the preset rating strategy to rate the first type of code and obtain the initial level of the first type of code.

[0012] Optionally, after determining whether the initial code is a first type of code, the method further includes: if the initial code is a second type of code, reviewing the second type of code through a second code library in the public code library; if the review passes, performing a second preset review on the second type of code; and if the second preset review passes, adding the second type of code to the public code library.

[0013] Optionally, it further includes: adjusting the code level of existing code in the public code library based on a first preset interval period; adjusting the code level of incremental code based on a second preset interval period; and retrieving other code scenarios that match the code scenario of the existing code indicated by the existing code modification type based on a third preset interval period, and modifying the code corresponding to the other code scenarios based on the first type of code corresponding to the existing code modification type.

[0014] According to another aspect of the present invention, a code generation apparatus based on big data is also provided, comprising: a receiving unit for receiving a code generation request, wherein the code generation request includes at least a functional requirement scenario; a retrieval unit for retrieving a pre-established public code library, determining a target scenario that matches the functional requirement scenario, and obtaining reference code for the target scenario; a generation unit for generating initial code based on the generation logic of the reference code and the functional requirement scenario; and a determining unit for determining the initial code as target code and adding the target code to the public code library if the initial code passes the review.

[0015] Optionally, the generation device further includes: a first rating module, used to rate the existing code in the public code library using a preset rating strategy before receiving the code generation request, and obtain a rating result, wherein the preset rating strategy includes at least one of the following: rating based on the code's running status, rating based on the code's problem situation, rating based on the impact level of the problem in the code, rating based on the code's logical level, rating based on the code's code status, rating based on the code's log recording situation, and rating based on the code's handling of exceptions.

[0016] Optionally, the generation device further includes: a first adding module, configured to determine the code level of a code block before receiving a code generation request, and add weights to the code block based on the code level to obtain a weight value for each code block; a first determining module, configured to determine, when the weight value matches a preset scenario value, that the code scenario of the code block indicated by the weight value is a scenario corresponding to the preset scenario value, wherein each preset scenario value is pre-associated with the scenario; a first analysis module, configured to perform analysis operations on the code block to obtain analysis results, wherein the analysis operations include at least one of the following: code analysis, performance analysis, vulnerability analysis; and a first inclusion module, configured to include the code block in the public code library when the analysis results indicate that the code block has passed analysis verification.

[0017] Optionally, the generation device further includes: a second determining module, configured to determine a scene level corresponding to the code scene of the code block based on the weight value after determining that the code scene of the code block indicated by the weight value is a scene corresponding to the preset scene value; a first verification module, configured to verify the code scene of the code block when the scene level is a preset level; and a second analysis module, configured to classify and analyze the code logic of the code block when the verification passes, and to include the code block in the public code library when the classification and analysis pass.

[0018] Optionally, the generation device further includes: a first judgment module, configured to determine whether the initial code is a first type of code after generating initial code based on the generation logic of the reference code and the functional requirement scenario; a first review module, configured to review the first type of code through a first code library in the public code library if the initial code is a first type of code; a second review module, configured to perform a first preset review on the first type of code if the review passes; a second judgment module, configured to determine whether the code type of the first type of code is a modified existing code type if the first preset review passes; a third determination module, configured to determine the code level of the existing code indicated by the modified existing code type based on the rating result if the code type of the first type of code is the modified existing code type; and a first modification module, configured to modify the existing code based on the first type of code if the code level of the first type of code is greater than the code level of the existing code, and to identify the modified existing code.

[0019] Optionally, the generation device further includes: a second rating module, used to, after determining whether the code situation of the first type of code is a modified existing code type, and if the code situation of the first type of code is an incremental code type, to use the preset rating strategy to rate the first type of code and obtain the initial level of the first type of code.

[0020] Optionally, the generation device further includes: a third review module, used to review the second type of code through a second code library in the public code library if the initial code is a second type of code after determining whether the initial code is a first type of code; a fourth review module, used to perform a second preset review on the second type of code if the review passes; and a second addition module, used to add the second type of code to the public code library if the second preset review passes.

[0021] Optionally, the generation device further includes: a first adjustment module, configured to adjust the code level of existing code in the public code library based on a first preset interval period; a second adjustment module, configured to adjust the code level of incremental code based on a second preset interval period; and a first retrieval module, configured to retrieve other code scenarios that match the code scenario of the existing code indicated by the existing code modification type based on a third preset interval period, and modify the code corresponding to the other code scenarios based on the first type of code corresponding to the existing code modification type.

[0022] According to another aspect of the present invention, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the above-described big data-based code generation method.

[0023] In this disclosure, a code generation request is received, a pre-established public code library is retrieved, a target scenario matching the functional requirements is identified, and reference code for the target scenario is obtained. Based on the generation logic of the reference code and the functional requirements scenario, initial code is generated. If the initial code passes review, it is identified as the target code and added to the public code library. This disclosure utilizes big data to retrieve target scenarios matching the functional requirements scenario carried in the code generation request from the public code library. Then, based on the generation logic of the reference code for the target scenario and the functional requirements scenario, initial code is generated. After the initial code passes review, it is added to the public code library. By referencing the code logic of similar scenarios, the rigor of the code can be increased, the number of bugs can be reduced, and the coding efficiency can be improved. This solves the technical problems of low coding efficiency and the inability to reduce the bug rate in related technologies. Attached Figure Description

[0024] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:

[0025] Figure 1 This is a flowchart of an optional code generation method based on big data according to an embodiment of the present invention;

[0026] Figure 2 This is a schematic diagram of an optional code generation process according to an embodiment of the present invention;

[0027] Figure 3 This is a schematic diagram of an optional system program monitoring according to an embodiment of the present invention;

[0028] Figure 4 This is a schematic diagram of an optional big data-based code generation device according to an embodiment of the present invention;

[0029] Figure 5 This is a hardware structure block diagram of an electronic device (or mobile device) for a code generation method based on big data according to an embodiment of the present invention. Detailed Implementation

[0030] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0031] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0032] It should be noted that the code generation method and apparatus based on big data in this disclosure can be used in the field of big data for code generation based on big data, and can also be used in any field other than the field of big data for code generation based on big data. This disclosure does not limit the application field of the code generation method and apparatus based on big data.

[0033] It should be noted that all information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are information and data authorized by the user or fully authorized by all parties. For example, this system has an interface with relevant users or organizations. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain the relevant information after receiving consent information from the aforementioned user or organization.

[0034] The following embodiments of the present invention can be applied to various systems / applications / devices based on big data for code generation. This invention can leverage big data recommendations and machine learning to provide code retrieval functionality. Based on existing use cases (such as activity lotteries, points redemption, financial management, etc.), it performs statistical analysis on all existing non-encrypted libraries, methods, functions, packages, etc. Each time new production code is added, machine learning is applied to that production code and the code is saved to the database. Simultaneously, it can autonomously learn from modifications to existing code. Developers can search for corresponding code based on certain conditions / use cases to refer to when writing code for those scenarios, increasing code rigor and reducing bugs. Furthermore, machine learning, through comparisons of new and old code in terms of standardization and logical rigor, can increase the weight of recommended code.

[0035] The present invention will now be described in detail with reference to various embodiments.

[0036] Example 1

[0037] According to an embodiment of the present invention, an embodiment of a code generation method based on big data is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0038] Figure 1 This is a flowchart of an optional code generation method based on big data according to an embodiment of the present invention, such as... Figure 1 As shown, the method includes the following steps:

[0039] Step S101: Receive code generation request, wherein the code generation request includes at least: functional requirement scenario.

[0040] Step S102: Search the pre-established public code library, determine the target scenario that matches the functional requirement scenario, and obtain the reference code of the target scenario.

[0041] Step S103: Generate initial code based on the generation logic of the reference code and the functional requirement scenario.

[0042] Step S104: If the initial code passes the review, the initial code is identified as the target code, and the target code is added to the public code repository.

[0043] Through the above steps, a code generation request can be received, a pre-established public code library can be retrieved, a target scenario matching the functional requirement scenario can be determined, and reference code for the target scenario can be obtained. Based on the generation logic of the reference code and the functional requirement scenario, initial code is generated. If the initial code passes the review, it is determined as the target code and added to the public code library. In this embodiment of the invention, based on big data, a target scenario matching the functional requirement scenario carried in the code generation request can be retrieved from the public code library. Then, based on the generation logic of the reference code for the target scenario and the functional requirement scenario, initial code is generated. After the initial code passes the review, it is added to the public code library. By referring to the code logic of similar scenarios, the rigor of the code can be increased, the number of bugs can be reduced, and the coding efficiency can be improved. This solves the technical problems of low coding efficiency and inability to reduce the bug rate in related technologies.

[0044] The embodiments of the present invention will now be described in detail with reference to the steps described above.

[0045] In one embodiment of the present invention, optionally, before receiving a code generation request, the method further includes: using a preset rating strategy to rate the existing code in the public code repository and obtain a rating result, wherein the preset rating strategy includes at least one of the following: rating based on the code's running status, rating based on the code's problem situation, rating based on the impact level of the problem in the code, rating based on the code's logical level, rating based on the code's code status, rating based on the code's log recording situation, and rating based on the code's handling of exceptions.

[0046] In this embodiment of the invention, the program backend can rate the existing code (i.e., currently existing code) in the public code repository according to a preset rating strategy (e.g., the rating result can be in the form of S (Excellent), A (Good), B (Average), C (Pass), etc.). The preset rating strategy can be: rating based on the code's running status (e.g., rating based on the code's continuous and stable running status, such as rating based on interface response speed, interface stability, etc.), or rating based on the code's problem situation (e.g., rating based on the occurrence of problems / bugs in the code; it can also collect problem and bug solutions for later use). The rating system is based on several factors: the impact level of the code issues (e.g., rating based on the severity of the issues (including: severe / moderate / minor), the logical level of the code (e.g., rating based on the logical rigor of the code), the code status (e.g., rating based on whether the code is core code, whether there is low cohesion, high coupling, etc., with core code having a higher rating and code with lower cohesion and higher coupling having a lower rating), the logging status of the code (i.e., rating based on the logging status corresponding to the code), and the handling of exceptions by the code.

[0047] Optionally, before receiving the code generation request, the method further includes: determining the code level of the code block, and adding weights to the code block based on the code level to obtain a weight value for each code block; if the weight value matches a preset scenario value, determining that the code scenario of the code block indicated by the weight value is the scenario corresponding to the preset scenario value, wherein each preset scenario value is pre-associated with a scenario; performing analysis operations on the code block to obtain analysis results, wherein the analysis operations include at least one of the following: code analysis, performance analysis, vulnerability analysis; and if the analysis results indicate that the code block passes the analysis verification, including the code block in the public code repository.

[0048] In this embodiment of the invention, code blocks can first be rated to obtain their code levels. Then, weights are added to the code blocks based on their code levels (i.e., the higher the code level, the greater the weight), resulting in a weight value for each code block. Next, based on the weight value of each code block, the code scenarios (such as activity lotteries, points redemption, financial management, etc.) of the code blocks are divided. Specifically, a preset scenario value matching the weight value of a code block can be found (this preset scenario value is calculated based on the code of existing scenarios, and each preset scenario value is pre-associated with a scenario). The scenario corresponding to the preset scenario value is then the code scenario of the code block indicated by the weight value. Afterwards, code blocks can be analyzed, including but not limited to code analysis, performance analysis, and vulnerability analysis, to identify code blocks that meet the standards. These code blocks are then included in the public code repository and, after a second review, submitted to the public code repository (i.e., if the analysis results indicate that the code block passes the analysis verification, it is included in the public code repository).

[0049] Optionally, after determining that the code scenario of the code block indicated by the weight value corresponds to the scenario value of the preset scenario, the method further includes: determining the scenario level corresponding to the code scenario of the code block based on the weight value; verifying the code scenario of the code block if the scenario level is the preset level; classifying and analyzing the code logic of the code block if the verification passes; and including the code block in the public code library if the classification and analysis pass.

[0050] In this embodiment of the invention, the scenario level corresponding to the code scenario of the code block can be determined according to the weight value. When the scenario level is a preset level (i.e., the scenario involves specific sensitive functions and the level is relatively high, such as scenarios involving money, points, etc.), the code scenario of the code block is verified. After the verification is passed, the code logic can be classified and analyzed, and after passing the classification and analysis, it is included and submitted to the public code library. In addition, the included logic code can be improved through subsequent iterations.

[0051] In this embodiment, subsequent operations can determine whether the system (or public code repository) inclusion rules are review standards. For scenario code that has passed the review standards, it can be directly checked after a new scenario code is submitted in the system (or public code repository), and an overall analysis can be performed through inclusion dimensions.

[0052] Step S101: Receive code generation request, wherein the code generation request includes at least: functional requirement scenario.

[0053] In this embodiment of the invention, a code generation request may be received first. The code generation request includes information such as functional requirement scenarios, so as to generate corresponding code according to the functional requirement scenarios.

[0054] Step S102: Search the pre-established public code library, determine the target scenario that matches the functional requirement scenario, and obtain the reference code of the target scenario.

[0055] In this embodiment of the invention, after receiving a code generation request, a pre-established public code library can be searched to determine whether there is a target scenario (i.e., a similar scenario) that matches the functional requirement scenario. If so, the reference code of the target scenario can be obtained to learn from the code logic of the reference code and generate code, thereby improving the logical rigor of the generated code.

[0056] Step S103: Generate initial code based on the generation logic of the reference code and the functional requirement scenario.

[0057] In this embodiment of the invention, initial code suitable for the functional requirement scenario can be generated based on the generation logic of the reference code and the functional requirement scenario.

[0058] Optionally, after generating the initial code based on the generation logic and functional requirements of the reference code, the process further includes: determining whether the initial code is a first-type code; if the initial code is a first-type code, reviewing the first-type code through the first code library in the public code library; if the review passes, performing a first pre-review on the first-type code; if the first pre-review passes, determining whether the code type of the first-type code is a modified existing code type; if the code type of the first-type code is a modified existing code type, determining the code level of the existing code indicated by the modified existing code type based on the rating result; if the code level of the first-type code is greater than the code level of the existing code, modifying the existing code based on the first-type code, and identifying the modified existing code.

[0059] In this embodiment of the invention, it can be first determined whether the generated initial code is core code (i.e., the first type of code) or non-core code (i.e., the second type of code). If the initial code is the first type of code, it is reviewed by the first code library in the public code library (i.e., if it is core code, it can be automatically reviewed by the first code library (i.e., the core code library) in the public code library to determine whether the core code has hidden defects or unknown bugs, and whether the logic is rigorous, etc.). If the core code has hidden defects or unknown bugs, or the logic is not rigorous (i.e., the review fails), the initial code can be modified by a preset adjustment plan, and then reviewed again after modification. If the review passes, the first type of code is subject to a first preset review (i.e., multi-party review (e.g., review by multiple professionals)). If the first pre-defined review is passed, it is determined whether the code type of the first type of code is a modified existing code type (i.e., whether the core code is a modified existing code or a newly added incremental code). If the code type of the first type of code is a modified existing code type, the code level of the existing code indicated by the modified existing code type is determined according to the rating result. If the code level of the first type of code is greater than the code level of the existing code, the existing code is modified based on the first type of code, and the modified existing code is marked (i.e., if the review level of the core code is higher than the review level of the existing code, it indicates that the core code is more complete than the existing code, and the existing code can be optimized through the core code, and the mark of the optimized existing code is added).

[0060] Optionally, after determining whether the code situation of the first type of code is a modified existing code type, the method further includes: if the code situation of the first type of code is an incremental code type, adopting a preset rating strategy to rate the first type of code and obtain the initial level of the first type of code.

[0061] In this embodiment of the invention, if the code of the first type of code is an incremental code type (i.e., the core code is newly added incremental code), a preset rating strategy can be adopted to rate the first type of code and obtain the initial level of the first type of code.

[0062] Optionally, after determining whether the initial code is the first type of code, the method further includes: if the initial code is the second type of code, reviewing the second type of code through the second code library in the public code library; if the review passes, performing a second preset review on the second type of code; and if the second preset review passes, adding the second type of code to the public code library.

[0063] In this embodiment of the invention, if the initial code is a modification or addition to non-core code (i.e., in the case of the initial code being the second type of code), the second type of code can first be reviewed through the second code library in the public code library (i.e., if it is non-core code, it can be automatically reviewed through the second code library (i.e., the non-core code library) in the public code library to determine whether the non-core code has hidden defects or unknown bugs, and whether the logic is rigorous, etc.). If the non-core code has hidden defects or unknown bugs, or the logic is not rigorous (i.e., the review fails), the initial code can be modified through a preset adjustment scheme, and then reviewed again after the modification is completed. If the review passes, the second type of code can be subject to a second preset review (i.e., it can be reviewed by the designer who submitted the code generation request). If the second preset review passes, the second type of code is added to the public code library.

[0064] Step S104: If the initial code passes the review, the initial code is identified as the target code, and the target code is added to the public code repository.

[0065] In this embodiment of the invention, after the initial code review (i.e., if the initial code is core code, it needs to undergo automatic review and a first preset review; if the initial code is non-core code, it needs to undergo automatic review and a second preset review) is passed, the initial code can be determined to be target code, and the target code is added to the public code library for continued use in the future.

[0066] Figure 2 This is a schematic diagram of an optional code generation process according to an embodiment of the present invention, such as... Figure 2 As shown, after designers complete the function design, they initiate a code generation request. The system searches for scenarios similar to the functional requirements carried in the code generation request. If a similar scenario exists, the system reviews the code for that scenario. If the code fits the functional requirements, it is recommended to the developers. Otherwise, the developers write the code based on the code generation request. After the code is written, it is determined whether it is core code. If it is core code, it is automatically reviewed through the core code library in the public code repository to determine whether there are hidden defects or unknown bugs, and whether the logic is rigorous. If the core code has hidden defects or unknown bugs, or the logic is not rigorous, the code is modified according to a preset adjustment plan. After the modification, the review continues. If the review passes, the core code is reviewed by multiple parties. After the review, it is determined whether the code is an existing code modification or an incremental code modification. If it is an existing code modification, the existing code is optimized, and the optimized code is marked in the system. If it is an incremental code, the system adds the code to the list of key areas for monitoring.

[0067] If it is non-core code, it will be automatically reviewed through the non-core code repository in the public codebase to determine whether there are hidden defects or unknown bugs, and whether the logic is rigorous. If the non-core code has hidden defects or unknown bugs, or the logic is not rigorous, the code will be modified according to the preset adjustment plan. After the modification, it will be reviewed again. If the review passes, the designer will review the code. After the review, it will be determined whether the code is an existing code modification or an incremental code modification. If it is an existing code modification, the existing code will be optimized and the optimized code will be marked in the system. If it is an incremental code, the system will add the code to focus on.

[0068] In this embodiment, the code can be automatically reviewed by directly calling the public code library during the development process, and the review process can be directly synchronized in the development editor. For code that fails the review, prompts can be given directly, and preliminary review can be carried out based on the code segmentation and inspection principle.

[0069] In this embodiment, for the development of certain specific scenarios (i.e. frequently used scenarios where relatively complete code already exists, such as currency trading scenarios and points trading scenarios), during the development process, complete code snippets from public code libraries can be directly recommended during code review. These code snippets can then be optimized and selected to improve coding efficiency.

[0070] Optionally, it also includes: adjusting the code level of existing code in the public code repository based on a first preset interval period; adjusting the code level of incremental code based on a second preset interval period; and retrieving other code scenarios that match the code scenario of the existing code indicated by the existing code modification type based on a third preset interval period, and modifying the code corresponding to the other code scenarios based on the first type of code corresponding to the existing code modification type.

[0071] In this embodiment of the invention, the system program can monitor the code and continuously adjust the code level of existing code in the public code repository based on a first preset interval (e.g., adjusting the existing code level once a year). Incremental code can be monitored intensively, and its code level can be adjusted based on a second preset interval (e.g., adjusting the incremental code level weekly). Furthermore, based on a third preset interval, other code scenarios matching the code scenario indicated by the existing code modification type can be retrieved, and code corresponding to other code scenarios can be modified based on the first type of code corresponding to the existing code modification type (e.g., modifications to existing code can be monitored intensively, and it can be retrieved whether there are other existing codes with similar scenarios, allowing for optimization of existing code based on more complete code).

[0072] Figure 3This is a schematic diagram of an optional system program monitoring according to an embodiment of the present invention, such as... Figure 3 As shown, the system program monitoring includes the following: continuous rating of existing code, monitoring of core incremental code, monitoring of modifications to core existing code, monitoring of non-core incremental code, and monitoring of bugs in existing code. Specifically, continuous rating of existing code involves readjusting the code level of existing code every period (e.g., one year); monitoring of core incremental code involves focusing on core incremental code and readjusting its code level every period (e.g., one week); monitoring of modifications to core existing code involves searching for existing code that has been modified from core existing code, and optimizing similar existing code if found; monitoring of non-core incremental code involves normal monitoring of non-core incremental code, and readjusting its code level every period (e.g., one month); and monitoring of bugs in existing code involves searching for code snippets with problems or bugs, and processing the corresponding existing code to reduce risk if a similar scenario is found.

[0073] In this embodiment of the invention, based on big data recommendation and machine learning, machine learning can be performed on the production code each time a production code is added. It can also learn autonomously from modifications to existing code. Furthermore, by searching for usage scenarios to obtain corresponding code for reference when writing code for those scenarios, the rigor of the code can be increased, coding efficiency and coding level can be improved, and code bugs can be reduced.

[0074] The following is a detailed description with reference to another embodiment.

[0075] Example 2

[0076] The code generation device based on big data provided in this embodiment includes multiple implementation units, each of which corresponds to a specific implementation step in Embodiment 1 above.

[0077] Figure 4 This is a schematic diagram of an optional big data-based code generation apparatus according to an embodiment of the present invention, such as... Figure 4 As shown, the generating device may include: a receiving unit 40, a retrieving unit 41, a generating unit 42, and a determining unit 43, wherein...

[0078] The receiving unit 40 is used to receive code generation requests, wherein the code generation requests include at least: functional requirement scenarios;

[0079] The retrieval unit 41 is used to retrieve a pre-established public code library, determine the target scenario that matches the functional requirement scenario, and obtain the reference code of the target scenario;

[0080] Generation unit 42 is used to generate initial code based on the generation logic of the reference code and the functional requirement scenario;

[0081] Unit 43 is used to determine that the initial code is the target code if the initial code has passed the review, and to add the target code to the public code library.

[0082] The aforementioned generation device can receive a code generation request through a receiving unit 40, retrieve a pre-established public code library through a retrieval unit 41, determine a target scenario matching the functional requirement scenario, and obtain reference code for the target scenario. The generation unit 42 generates initial code based on the generation logic of the reference code and the functional requirement scenario. The determining unit 43, if the initial code passes review, determines the initial code as the target code and adds it to the public code library. In this embodiment of the invention, based on big data, a target scenario matching the functional requirement scenario carried in the code generation request can be retrieved from the public code library. Then, based on the generation logic of the reference code for the target scenario and the functional requirement scenario, initial code is generated. After the initial code passes review, it is added to the public code library. By referencing the code logic of similar scenarios, the rigor of the code can be increased, the number of bugs can be reduced, and the coding efficiency can be improved, thereby solving the technical problems of low coding efficiency and inability to reduce the bug rate in related technologies.

[0083] Optionally, the generation device further includes: a first rating module, used to rate the existing code in the public code repository using a preset rating strategy before receiving the code generation request, and obtain a rating result, wherein the preset rating strategy includes at least one of the following: rating based on the code's running status, rating based on the code's problem status, rating based on the impact level of the problem in the code, rating based on the code's logical level, rating based on the code's code status, rating based on the code's log recording status, and rating based on the code's handling of exceptions.

[0084] Optionally, the generation device further includes: a first adding module, configured to determine the code level of the code block before receiving the code generation request, and add weights to the code block based on the code level to obtain a weight value for each code block; a first determining module, configured to determine that the code scenario of the code block indicated by the weight value is the scenario corresponding to the preset scenario value when the weight value matches the preset scenario value, wherein each preset scenario value is pre-associated with a scenario; a first analysis module, configured to perform analysis operations on the code block to obtain analysis results, wherein the analysis operations include at least one of the following: code analysis, performance analysis, vulnerability analysis; and a first inclusion module, configured to include the code block in a public code repository when the analysis results indicate that the code block has passed the analysis verification.

[0085] Optionally, the generation device further includes: a second determining module, used to determine the scene level corresponding to the code scene of the code block based on the weight value after determining that the code scene of the code block indicated by the weight value is the scene corresponding to the preset scene value; a first verification module, used to verify the code scene of the code block when the scene level is the preset level; and a second analysis module, used to classify and analyze the code logic of the code block when the verification is passed, and to include the code block in the public code library when the classification and analysis is passed.

[0086] Optionally, the generation device further includes: a first judgment module, used to determine whether the initial code is a first type of code after generating the initial code based on the generation logic and functional requirements scenario of the reference code; a first review module, used to review the first type of code through a first code library in the public code library if the initial code is a first type of code; a second review module, used to perform a first preset review on the first type of code if the review passes; a second judgment module, used to determine whether the code type of the first type of code is a modified type of existing code if the first preset review passes; a third determination module, used to determine the code level of the existing code indicated by the modified type of existing code based on the rating result if the code type of the first type of code is a modified type of existing code; and a first modification module, used to modify the existing code based on the first type of code if the code level of the first type of code is greater than the code level of the existing code, and to identify the modified existing code.

[0087] Optionally, the generating device further includes: a second rating module, used to, after determining whether the code situation of the first type of code is a modified existing code type, and if the code situation of the first type of code is an incremental code type, to rate the first type of code using a preset rating strategy to obtain the initial level of the first type of code.

[0088] Optionally, the generation device further includes: a third review module, used to review the second type of code through a second code library in a public code library after determining whether the initial code is the first type of code, if the initial code is the second type of code; a fourth review module, used to perform a second preset review on the second type of code if the review passes; and a second addition module, used to add the second type of code to the public code library if the second preset review passes.

[0089] Optionally, the generation device further includes: a first adjustment module, used to adjust the code level of existing code in the public code library based on a first preset interval period; a second adjustment module, used to adjust the code level of incremental code based on a second preset interval period; and a first retrieval module, used to retrieve other code scenarios that match the code scenario of the existing code indicated by the existing code modification type based on a third preset interval period, and modify the code corresponding to the other code scenarios based on the first type of code corresponding to the existing code modification type.

[0090] The aforementioned generating apparatus may further include a processor and a memory. The receiving unit 40, the retrieval unit 41, the generating unit 42, the determining unit 43, etc., are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to realize the corresponding functions.

[0091] The aforementioned processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured; by adjusting kernel parameters, the initial code is determined to be object code after initial code review and is then added to the public codebase.

[0092] The aforementioned memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0093] This application also provides a computer program product that, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: receiving a code generation request, retrieving a pre-established public code library, determining a target scenario that matches the functional requirement scenario, obtaining reference code for the target scenario, generating initial code based on the generation logic of the reference code and the functional requirement scenario, and, if the initial code passes the review, determining the initial code as the target code and adding the target code to the public code library.

[0094] According to another aspect of the present invention, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the above-described big data-based code generation method.

[0095] Figure 5 This is a hardware structure block diagram of an electronic device (or mobile device) for a code generation method based on big data, according to an embodiment of the present invention. Figure 5As shown, the electronic device may include one or more processors 502 (shown as 502a, 502b, ..., 502n in the figure) 502 (processor 502 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 504 for storing data. In addition, it may include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 5 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device described above. For example, the electronic device may also include... Figure 5 The more or fewer components shown, or having the same Figure 5 The different configurations shown.

[0096] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0097] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0098] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.

[0099] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0100] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0101] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0102] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A big data based code generation method, characterized by, The method comprises the following steps: receiving a code generation request, wherein the code generation request at least comprises a functional requirement scenario; retrieving a pre-established public code library, determining a target scenario matching the functional requirement scenario, and obtaining a reference code of the target scenario; generating an initial code based on the generation logic of the reference code and the functional requirement scenario; in the case where the initial code passes the audit, determining the initial code as a target code, and adding the target code to the public code library; wherein, before receiving the code generation request, the inventory codes in the public code library are rated using a preset rating strategy to obtain a rating result; after generating the initial code based on the generation logic of the reference code and the functional requirement scenario: judging whether the initial code is a first type of code; in the case where the initial code is a first type of code, reviewing the first type of code through a first code library in the public code library; in the case where the review passes, performing a first preset review on the first type of code; in the case where the first preset review passes, judging whether the code type of the first type of code is an inventory code modification type; in the case where the code type of the first type of code is the inventory code modification type, determining the code level of the inventory code indicated by the inventory code modification type according to the rating result; in the case where the code level of the first type of code is greater than the code level of the inventory code, modifying the inventory code based on the first type of code, and marking the modified inventory code.

2. The generation method of claim 1, wherein, Further comprising: The preset rating strategy comprises at least one of the following: rating according to the running status of the code, rating according to the problem situation of the code, rating according to the influence level of the problem of the code, rating according to the logic level of the code, rating according to the code state of the code, rating according to the log recording situation of the code, rating according to the processing situation of the code to the exception.

3. The generation method of claim 1, wherein, Before receiving the code generation request, further comprising: determining the code level of a code block, and adding a weight to the code block based on the code level to obtain a weight value of each code block; in the case where the weight value matches a preset scenario value, determining that the code scenario of the code block indicated by the weight value is the scenario corresponding to the preset scenario value, wherein each preset scenario value is pre-associated with the scenario; performing an analysis operation on the code block to obtain an analysis result, wherein the analysis operation comprises at least one of the following: code analysis, performance analysis, vulnerability analysis; in the case where the analysis result indicates that the code block passes the analysis verification, including the code block in the public code library.

4. The generation method of claim 3, wherein, After determining that the code scenario of the code block indicated by the weight value is the scenario corresponding to the preset scenario value, further comprising: determining a scenario level corresponding to the code scenario of the code block based on the weight value; in the case where the scenario level is a preset level, verifying the code scenario of the code block; In the case of passing the verification, the code logic of the code block is classified and analyzed, and in the case of passing the classification analysis, the code block is included in the public code library.

5. The generation method of claim 1, wherein, After judging whether the code situation of the first type of code is the stock code modification type, further comprising: In the case that the code situation of the first type of code is the incremental code type, the first type of code is rated by using the preset rating strategy to obtain the initial level of the first type of code.

6. The generation method of claim 1, wherein, After judging whether the initial code is the first type of code, further comprising: In the case that the initial code is the second type of code, the second type of code is reviewed by the second code library in the public code library; In the case of passing the review, the second type of code is subjected to a second preset review; In the case of passing the second preset review, the second type of code is added to the public code library.

7. The generation method of claim 6, wherein, Further comprising: Based on a first preset interval period, the code level of the stock code in the public code library is adjusted; Based on a second preset interval period, the code level of the incremental code is adjusted; Based on a third preset interval period, other code scenarios matching the code scenario of the stock code modification type are retrieved, and the code corresponding to the other code scenarios is modified based on the first type of code corresponding to the stock code modification type. 8.A big data based code generation apparatus, characterized by, Comprising: The receiving unit is configured to receive a code generation request, wherein the code generation request at least includes a functional requirement scenario; The retrieval unit is configured to retrieve a pre-established public code library, determine a target scenario matching the functional requirement scenario, and obtain a reference code of the target scenario; The generation unit is configured to generate an initial code based on the generation logic of the reference code and the functional requirement scenario; The determination unit is configured to determine the initial code as a target code in the case of passing the review of the initial code, and add the target code to the public code library; The first rating module is configured to rate the stock code in the public code library by using a preset rating strategy to obtain a rating result before receiving the code generation request; The first judging module is configured to judge whether the initial code is a first type of code after the initial code is generated based on the generation logic of the reference code and the functional requirement scene; the first review module is configured to review the first type of code by a first code base in the public code base when the initial code is the first type of code; the second review module is configured to perform a first preset review on the first type of code when the review is passed; the second judging module is configured to judge whether a code type of the first type of code is a stock code modification type when the first preset review is passed; the third determining module is configured to determine a code level of stock code indicated by the stock code modification type according to the rating result when the code type of the first type of code is the stock code modification type; and the first modifying module is configured to modify the stock code based on the first type of code and mark the modified stock code when the code level of the first type of code is greater than the code level of the stock code.

9. An electronic device, comprising: The one or more processors and the memory are configured to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the big data-based code generation method in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Code automatic generation method, code automatic generation device and electronic equipment

    CN107729003A

  • Business demand form publishing method and device, electronic equipment and storage medium

    CN113282282A