Code workload measurement method and device, electronic equipment and program product
Patent Information
- Application Number
- CN202610863882.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-15
- Publication Date
- 2026-10-30
AI Technical Summary
[0004]本发明实施例提供了一种代码工作量的度量方法及装置、电子设备及程序产品,以至少解决相关技术中基于代码行数的工作量评估方式,准确性低,且降低开发效率的技术问题
[0022]在本公开中,对代码源文件和目标代码文件分别进行分析,生成源文件抽象语法树和目标文件抽象语法树;计算源文件抽象语法树与目标文件抽象语法树之间的最短编辑距离以及对应的编辑路径;基于编辑路径生成包含所有操作记录的差异文件,并结合差异文件计算每项编辑操作的工作量;累加所有编辑操作的工作量,输出本次提交的总代码工作量值。
Smart Images

Figure CN123011297A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of financial technology or other related fields, and more specifically, to a method and apparatus for measuring coding workload, electronic devices, and program products. Background Technology
[0002] In software development, it's crucial to assess developers' workload. In many technologies, this is primarily done by evaluating lines of code. While this data is more intuitive, relying solely on lines of code to evaluate workload has significant drawbacks. Firstly, line counts are easily influenced by non-semantic factors such as coding style, line breaks, comments, and formatting. It also fails to identify actual code modifications; simple copy-pasting or moving code blocks can generate numerous line additions and deletions. Secondly, using only lines of code to assess workload leads to an increase in redundant code, reducing developer efficiency, delaying project progress, producing lower-quality code, and wasting team resources.
[0003] There is currently no effective solution to the above problems. Summary of the Invention
[0004] This invention provides a method, apparatus, electronic device, and program product for measuring code workload, to at least solve the technical problems of low accuracy and reduced development efficiency in related technologies that use workload assessment methods based on lines of code.
[0005] To achieve the above objectives, according to one aspect of this application, a method for measuring code workload is provided, comprising: analyzing source code files and target code files respectively to generate source file abstract syntax trees and target file abstract syntax trees; calculating the shortest edit distance and corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree; generating a difference file containing all operation records based on the edit path, and calculating the workload of each edit operation in conjunction with the difference file; summing the workload of all the edit operations, and outputting the total code workload value of this submission.
[0006] Optionally, the steps of analyzing the source code file and the target code file separately to generate the source file abstract syntax tree and the target file abstract syntax tree include: responding to a code commit operation and obtaining the two most recent commit records of the committed code file through the project source code system; downloading the code files corresponding to the two most recent commit records from the project source code repository to obtain the source code file of the previous commit and the target code file of the current commit; performing lexical analysis and syntax analysis on the source code file of the previous commit to generate the source file abstract syntax tree; and performing lexical analysis and syntax analysis on the target code file of the current commit to generate the target file abstract syntax tree.
[0007] Optionally, the step of performing lexical and syntactic analysis on the previously submitted source code file to generate the source file abstract syntax tree includes: performing lexical analysis on the source code file, scanning and segmenting the lexical units in the source code file to generate a sequence of lexical units; performing syntactic analysis on the sequence of lexical units based on the grammar rules and production rules of the target programming language to construct an initial parse tree; and simplifying the initial parse tree by removing redundant syntactic nodes while preserving the semantic structure to generate the source file abstract syntax tree, wherein redundant nodes include at least one of the following: semicolon nodes, bracket nodes, and indentation symbol nodes.
[0008] Optionally, the step of calculating the shortest edit distance and edit path between the source file abstract syntax tree and the target file abstract syntax tree includes: extracting the number of operations corresponding to each operation type in the source file abstract syntax tree and the target file abstract syntax tree, wherein the operation type includes at least one of the following: add operation, delete operation, update operation, move operation; based on the source file abstract syntax tree and the target file abstract syntax tree, using a tree edit distance algorithm, calculating the minimum number of operations required to move from the source file abstract syntax tree to the target file abstract syntax tree, to obtain the shortest edit distance; based on the source file abstract syntax tree and the target file abstract syntax tree, determining the starting point, intermediate nodes, and ending point traversed by the shortest edit distance, to obtain the edit path.
[0009] Optionally, the step of generating a difference file containing all operation records based on the editing path includes: identifying the operation type and operation object type of each editing operation based on the start and end points of the editing path; merging each identified operation type and its corresponding operation object type into one operation record; and writing all the operation records into a predetermined file to generate the difference file containing all operation records.
[0010] Optionally, the step of calculating the workload of each editing operation in conjunction with the difference file includes: reading the difference file to obtain all the operation records; assigning a first weight parameter to the operation type in each operation record according to a preset operation type weight table, and assigning a second weight parameter to each operation object type according to a preset node type weight table; for each editing operation, performing a weighted calculation based on the operation type and the corresponding first weight parameter, the operation object type and the corresponding second weight parameter, to obtain the weighted workload corresponding to the editing operation.
[0011] Optionally, the method for measuring code workload also includes storing the source file abstract syntax tree and the target file abstract syntax tree in JSON format.
[0012] According to another aspect of the present invention, a code workload measurement device is also provided, comprising: a syntax tree generation unit, configured to analyze source code files and target code files respectively, and generate source file abstract syntax trees and target file abstract syntax trees; an edit path generation unit, configured to calculate the shortest edit distance between the source file abstract syntax tree and the target file abstract syntax tree and the corresponding edit path; a difference file generation unit, configured to generate a difference file containing all operation records based on the edit path, and calculate the workload of each edit operation in conjunction with the difference file; and a code workload measurement unit, configured to accumulate the workload of all the edit operations and output the total code workload value of this submission.
[0013] Optionally, the syntax tree generation unit includes: a commit record acquisition module, used to respond to code commit operations and acquire the two most recent commit records of the committed code file through the project source code system; a code file download module, used to download the code files corresponding to the two most recent commit records from the project source code repository, to obtain the code source file of the previous commit and the target code file of the current commit; a first syntax tree generation module, used to perform lexical analysis and syntax analysis on the code source file of the previous commit, and generate the source file abstract syntax tree; and a second syntax tree generation module, used to perform lexical analysis and syntax analysis on the target code file of the current commit, and generate the target file abstract syntax tree.
[0014] Optionally, the first syntax tree generation module includes: a lexical analysis submodule, used to perform lexical analysis on the code source file, scan and segment the lexical units in the code source file, and generate a lexical unit sequence; a syntax analysis submodule, used to perform syntax analysis on the lexical unit sequence based on the grammar rules and production rules of the target programming language, and construct an initial parse tree; and a simplification submodule, used to simplify the initial parse tree, remove redundant grammatical nodes, retain the semantic structure, and generate the source file abstract syntax tree, wherein the redundant nodes include at least one of the following: semicolon nodes, bracket nodes, and indentation symbol nodes.
[0015] Optionally, the edit path generation unit includes: an operand extraction module, used to extract operands corresponding to each operation type in the source file abstract syntax tree and the target file abstract syntax tree, wherein the operation type includes at least one of the following: add operation, delete operation, update operation, move operation; an edit distance calculation module, used to calculate the minimum number of operations required to move from the source file abstract syntax tree to the target file abstract syntax tree using a tree edit distance algorithm based on the source file abstract syntax tree and the target file abstract syntax tree, to obtain the shortest edit distance; and an edit path generation module, used to determine the starting point, intermediate nodes, and ending point traversed by the shortest edit distance based on the source file abstract syntax tree and the target file abstract syntax tree, to obtain the edit path.
[0016] Optionally, the difference file generation unit includes: an operation type identification module, used to identify the operation type and operation object type of each editing operation based on the start and end points of the editing path; an operation record merging module, used to merge each identified operation type and its corresponding operation object type into an operation record; and a difference file generation module, used to write all the operation records into a predetermined file to generate the difference file containing all the operation records.
[0017] Optionally, the difference file generation unit includes: an operation record reading module, used to read the difference file and obtain all the operation records; a weight parameter assignment module, used to assign a first weight parameter to the operation type in each operation record according to a preset operation type weight table, and assign a second weight parameter to each operation object type according to a preset node type weight table; and a weighting module, used to perform a weighted calculation for each editing operation based on the operation type and the corresponding first weight parameter, the operation object type and the corresponding second weight parameter, to obtain the weighted workload corresponding to the editing operation.
[0018] Optionally, the code workload measurement device further includes: storing the source file abstract syntax tree and the target file abstract syntax tree in JSON format.
[0019] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored computer program, wherein a method for measuring the amount of code work required to control the device where the computer-readable storage medium is located to perform any of the above-mentioned tasks is provided when the computer program is executed.
[0020] 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 implement a method for measuring the amount of code work required by any of the above-mentioned methods.
[0021] According to another aspect of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements the steps of the code workload measurement method described in any one of the above embodiments.
[0022] In this disclosure, the source code file and the target code file are analyzed separately to generate the source file abstract syntax tree and the target file abstract syntax tree; the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree are calculated; a difference file containing all operation records is generated based on the edit path, and the workload of each edit operation is calculated in combination with the difference file; the workload of all edit operations is accumulated, and the total code workload value of this submission is output.
[0023] Based on the aforementioned publicly available information, source code can be parsed into an abstract syntax tree (AST), replacing the counting of lines of text with semantic changes in syntax structure. This eliminates the interference of non-semantic factors such as code style, comments, blank lines, and formatting on workload assessment. Simultaneously, by calculating the shortest edit distance and corresponding edit path between the source file AST and the target file AST, the editing operations in code changes can be accurately identified. By comparing the ASTs of the previous and current versions, no manual intervention or code instrumentation is required, achieving non-intrusive and automated workload measurement. This effectively improves code development efficiency and solves the technical problem of low accuracy and reduced development efficiency of workload assessment methods based on lines of code 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 1A hardware block diagram of a computer terminal (or mobile device) for implementing a method for measuring code workload is shown.
[0026] Figure 2 This is a flowchart of an optional method for measuring code workload according to an embodiment of the present invention;
[0027] Figure 3 This is a schematic diagram of an optional code workload assessment method according to an embodiment of the present invention;
[0028] Figure 4 This is a schematic diagram of an optional code workload measurement process according to an embodiment of the present invention;
[0029] Figure 5 This is a schematic diagram of an optional code workload measurement device according to an embodiment of the present invention;
[0030] Figure 6 This is a structural block diagram of an electronic device for measuring the amount of code execution work according to an embodiment of this application. Detailed Implementation
[0031] 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.
[0032] 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.
[0033] To facilitate understanding of the present invention by those skilled in the art, some terms or nouns involved in the various embodiments of the present invention are explained below:
[0034] An Abstract Syntax Tree (AST) is a tree-like data structure used to represent the syntactic structure of source code. Each node corresponds to a syntactic element in the code. An AST is a tree-like representation of the abstract syntactic structure of source code. Each node in the tree represents a structure in the source code, which does not depend on the specific grammar or the details of the language.
[0035] Tree edit distance is an algorithm that measures the minimum number of operations required between two abstract syntax trees and is used to calculate the structural differences in code changes.
[0036] Operation types refer to the four basic change behaviors that occur in the abstract syntax tree difference analysis: insert, delete, update, and move.
[0037] The type of the operation object refers to the semantic category of the syntax node being operated on, such as variable, method, conditional statement, expression, etc., and is used to distinguish whether data or logical structure is being modified.
[0038] The difference file is a structured file that records all changes made from the source abstract syntax tree to the target abstract syntax tree, including the operation type, node type, and node content.
[0039] It should be noted that the code workload measurement method and apparatus in this disclosure can be used in the fintech field when code workload measurement is implemented based on abstract syntax trees, and can also be used in any field other than fintech when code workload measurement is implemented based on abstract syntax trees. This disclosure does not limit the application field of the code workload measurement method and apparatus.
[0040] It should be noted that the information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, and displayed data, etc.) collected in this public disclosure are information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of related data are handled with corresponding access points, allowing users to choose to authorize or refuse. For example, this system has interfaces with relevant users or organizations. Before obtaining relevant information, a request to obtain the information needs to be sent to the aforementioned user or organization through the interface, and the relevant information is obtained only after receiving consent from the aforementioned user or organization.
[0041] It should be noted that in this disclosure, customer information is collected and analyzed, and users are provided with corresponding operation entry points to choose whether to agree to or reject the automated decision results; if the user chooses to reject, the process will proceed to the expert decision-making process.
[0042] The following embodiments of the present invention can be applied to various systems / applications / devices for measuring code workload. The present invention is applicable to scenarios such as financial system development and code quality management; specifically, it can, for example, quantify code submission workload and automate code review.
[0043] This invention achieves precise measurement of the semantic workload of code changes through abstract syntax tree structure difference analysis, eliminates interference from non-semantic factors such as code style, comments, and formatting, accurately identifies logical modifications and data modifications, effectively distinguishes between valid development behaviors and invalid changes, and improves the objectivity, fairness, and auditability of workload assessment.
[0044] The present invention will now be described in detail with reference to various embodiments.
[0045] Example 1
[0046] According to an embodiment of the present invention, an embodiment of a method for measuring code workload 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.
[0047] The code workload measurement method provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1 A hardware block diagram of a computer terminal (or mobile device) for implementing a method to measure code workload is shown. Figure 1 As shown, computer terminal 10 (or mobile device) may include one or more ( Figure 1 The processor 102 (which may include, but is not limited to, a microprocessor MCU (Microcontroller Unit) or a programmable logic device FPGA (Field Programmable Gate Array)) is illustrated using 102a, 102b, ..., 102n. It also includes a memory 104 for storing data and a transmission device 106 for communication functions. 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 a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1The different configurations shown.
[0048] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0049] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the code workload measurement method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the aforementioned code workload measurement method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0050] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0051] The display can be, for example, a touchscreen liquid crystal display (LCD), which allows the user to interact with the user interface of the computer terminal 10 (or mobile device).
[0052] Under the aforementioned operating environment, this application provides the following: Figure 2 The method shown is for measuring code workload. Figure 2 This is a flowchart of an optional method for measuring code workload according to an embodiment of the present invention, such as... Figure 2As shown, the method includes the following steps:
[0053] Step S201: Analyze the source code file and the target code file respectively to generate the source file abstract syntax tree and the target file abstract syntax tree.
[0054] It should be noted that in step S201, the source code file and the target code file are analyzed separately to generate the source file abstract syntax tree and the target file abstract syntax tree. By converting the source code text into a structured tree representation, the syntactic structure of the code can be expressed in a unified way, free from specific character forms.
[0055] Optionally, the steps of analyzing the source code file and the target code file separately to generate the source file abstract syntax tree and the target file abstract syntax tree include: responding to the code commit operation and obtaining the two most recent commit records of the committed code file through the project source code system; downloading the code files corresponding to the two most recent commit records from the project source code repository to obtain the source code file of the previous commit and the target code file of the current commit; performing lexical analysis and syntax analysis on the source code file of the previous commit to generate the source file abstract syntax tree; and performing lexical analysis and syntax analysis on the target code file of the current commit to generate the target file abstract syntax tree.
[0056] In this embodiment of the invention, the two most recent commit records of submitted code files can be obtained through the project source code system. This operation relies on the commit history recorded in the version control system and can locate the previous and current versions of a specified file. The code files corresponding to the two most recent commit records are downloaded from the project source code repository, obtaining the source code file of the previous commit and the target code file of the current commit. This process obtains a file snapshot under a specified commit hash by calling the interface of the version control tool, giving the input data a clear time sequence relationship. Then, lexical and syntactic analysis are performed on the source code file of the previous commit to generate an abstract syntax tree (AST) for the source file, providing a reference benchmark for change comparison; simultaneously, lexical and syntactic analysis are performed on the target code file of the current commit to generate an AST for the target file, serving as an expression of the changed structure. This process ensures that the generation of the AST is entirely based on the actual commit content, enabling automated tracking of the code evolution path.
[0057] Optionally, the steps of performing lexical and syntactic analysis on the previously submitted code source file to generate an abstract syntax tree for the source file include: performing lexical analysis on the code source file, scanning and segmenting the lexical units in the code source file to generate a sequence of lexical units; performing syntactic analysis on the sequence of lexical units based on the grammar rules and production rules of the target programming language to construct an initial parse tree; and simplifying the initial parse tree by removing redundant syntactic nodes while preserving the semantic structure to generate an abstract syntax tree for the source file, wherein redundant nodes include at least one of the following: semicolon nodes, bracket nodes, and indentation symbol nodes.
[0058] It should be noted that lexical analysis is performed on the previously submitted source code file. This includes scanning and segmenting the character sequences in the source code file, identifying lexical units with types and values, such as identifiers, keywords, operators, and constants, according to the lexical rules of the programming language. This forms an ordered sequence of lexical units, transforming the raw text into structured input. Further, syntactic analysis is performed on the sequence of lexical units. Using top-down or bottom-up parsing algorithms, lexical units are gradually combined according to grammatical rules to construct an initial parse tree reflecting the complete grammatical derivation process. This initial parse tree contains all grammatical details, such as explicit delimiters, bracket levels, and statement boundaries, providing a complete grammatical basis for the generation of the abstract syntax tree. Specifically, the lexical analysis stage decomposes the source code into a sequence of lexical units with types and values, such as keywords, identifiers, operators, and constants. The syntactic analysis stage parses the sequence of lexical units into a grammatical structure according to the grammatical rules of the programming language. Finally, by simplifying redundant symbols in the parse tree and preserving the core grammatical relationships, an abstract syntax tree is formed.
[0059] Specifically, the first stage of compilation is the lexical analysis stage, which scans, segments, and identifies the source code text to obtain a sequence of lexical units (tokens). The token sequence is represented as...<type,value> A tuple of types, where `type` represents the category of a word and `value` represents the attribute value, as shown in the following Java statement:
[0060] int result = 2 + (3 4);
[0061] The character "2" has a constant type and a value of 2, which represents a tuple.<CONST,2> The character "+" has the type "operator" and the value "+", representing a tuple.<OPT,+> .
[0062] After the lexical analysis phase, a sequence of lexical units is obtained, which then proceeds to the syntax analysis phase. Further, in the syntax analysis phase, the lexical unit sequence passes through the parser, which outputs a parse tree based on the grammar rules. In the syntax analysis phase, first, let's explain the production rules. A production rule is usually denoted as A->a, meaning that the left-hand side symbol A generates the right-hand side symbol string a. If A->a and A->b, it can be written as A->a|b. Production rules consist of terminal symbols and non-terminal symbols. Non-terminal symbols are defined as symbols on the left-hand side of the production rule; terminal symbols are defined as symbols that are not non-terminal symbols. Non-terminal symbols can appear on both the left-hand and right-hand sides of a production rule. Terminal symbols can only appear on the right-hand side of a production rule. Non-terminal symbols are usually represented by uppercase letters.
[0063] Grammar rules can be defined as a non-empty finite set of production rules, formally expressed as a quadruple: G=(T,N,P,S). Here, T represents the set of terminal symbols; N represents the set of non-terminal symbols; P represents the set of production rules; and S is the start symbol, from which the defined language is identified (S is a child element of N and is a special non-terminal symbol). It should be noted that in this embodiment, it is not necessary to explicitly represent the quadruple; only the set of production rules of the grammar needs to be given.
[0064] Scanning each word of the expression from left to right, and applying the set of production rules given the grammar rules, generates a parse tree for the expression. This parse tree is then simplified to obtain an abstract syntax tree (AST). It's important to note that the initial parse tree is simplified by removing semantically irrelevant redundant nodes, such as semicolons, parentheses, and indentation symbols, while retaining core nodes expressing semantic relationships, such as variable references, method calls, conditional statements, and expression combinations. This process focuses the grammatical structure on the program logic itself, rather than the grammatical implementation details, which helps improve the accuracy and efficiency of subsequent tree structure comparisons.
[0065] Step S202: Calculate the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree.
[0066] It should be noted that in step S202, calculating the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree can formally model the structural differences between the two trees, so as to abstract the code change into a series of quantifiable tree operation behaviors.
[0067] Optionally, the steps of calculating the shortest edit distance and edit path between the source file abstract syntax tree and the target file abstract syntax tree include: extracting the number of operations corresponding to each operation type in the source file abstract syntax tree and the target file abstract syntax tree, wherein the operation type includes at least one of the following: add operation, delete operation, update operation, move operation; based on the source file abstract syntax tree and the target file abstract syntax tree, using a tree edit distance algorithm, calculating the minimum number of operations required to move from the source file abstract syntax tree to the target file abstract syntax tree, and obtaining the shortest edit distance; based on the source file abstract syntax tree and the target file abstract syntax tree, determining the starting point, intermediate nodes, and ending point traversed by the shortest edit distance, and obtaining the edit path.
[0068] It should be noted that this embodiment identifies nodes that exist only in the target tree as objects of addition operations, nodes that exist only in the source tree as objects of deletion operations, nodes that exist in both trees but have different structures or attributes as objects of update operations, and nodes that have moved in position but have the same semantics as objects of move operations, thereby classifying code changes into identifiable structural behaviors. Further, based on the source file's abstract syntax tree and the target file's abstract syntax tree, the tree edit distance algorithm is used to calculate the minimum number of operations required to move from the source file's abstract syntax tree to the target file's abstract syntax tree, obtaining the shortest edit distance. It should be noted that the shortest edit distance is determined by the minimum number of operation steps; this shortest edit distance can be understood as the minimum number of execution editing steps required to move from the source file's abstract syntax tree to the target file's abstract syntax tree. Through dynamic programming or recursive backtracking, all possible operation sequences are enumerated and the path with the lowest cost is selected to minimize the total number of operations in the change process, thus reflecting the minimum cost expression of semantic changes.
[0069] Furthermore, embodiments of the present invention can determine the starting point, intermediate nodes, and ending point of the shortest editing distance based on the source file's abstract syntax tree and the target file's abstract syntax tree, thus obtaining an editing path. This editing path records the node positions and operation types involved in each step of the operation, forming a complete transformation sequence from the source tree to the target tree, making the difference analysis traceable and interpretable. This process can decompose complex code modification behaviors into atomic-level structural operations, enabling comparisons of changes of different scales and complexities within a unified measurement framework.
[0070] Step S203: Generate a difference file containing all operation records based on the editing path, and calculate the workload of each editing operation based on the difference file.
[0071] It should be noted that in step S203, a difference file containing all operation records is generated based on the edit path. By converting the path information output by the tree edit distance algorithm into structured records, the process of changing the abstract syntax tree can be persistently stored in a readable and parsable format.
[0072] Optionally, the step of generating a difference file containing all operation records based on the editing path includes: identifying the operation type and operation object type of each editing operation based on the start and end points of the editing path; merging each identified operation type and its corresponding operation object type into one operation record; and writing all operation records into a predetermined file to generate a difference file containing all operation records.
[0073] The operation types include add, delete, update, and move, while the operation object types are node categories in the abstract syntax tree, such as variable declarations, method calls, conditional expressions, and constant values. This identification process matches nodes based on their existence status and structural change characteristics in the source and target trees, helping to distinguish the essential attributes of the operations. Furthermore, each identified operation type and its corresponding operation object type are merged into an operation record. Each record encapsulates the operation behavior and semantic object in key-value pairs. This structured format facilitates program parsing and subsequent weight mapping, and can uniformly express semantic changes across different programming languages.
[0074] It should be noted that all operation records are written to a predefined file, generating a difference file containing all operation records. This file uses a standard data format such as JSON, which has good scalability and cross-platform compatibility, facilitating transfer and integration between different systems, while also supporting log archiving and audit traceability. This process can transform complex tree structure changes into discrete, quantifiable behavioral units.
[0075] Optionally, the step of calculating the workload of each editing operation in conjunction with the difference file includes: reading the difference file to obtain all operation records; assigning a first weight parameter to the operation type in each operation record according to a preset operation type weight table, and assigning a second weight parameter to each operation object type according to a preset node type weight table; for each editing operation, performing a weighted calculation based on the operation type and the corresponding first weight parameter, the operation object type and the corresponding second weight parameter, to obtain the weighted workload corresponding to the editing operation.
[0076] It should be noted that reading the difference file to obtain all operation records provides structured input for subsequent weighted calculations. This reading process supports standard data parsing mechanisms and can adapt to file reading interfaces in different language environments. Furthermore, a first weight parameter is assigned to the operation type in each operation record according to a preset operation type weight table. This table defines baseline values for four types of operations: add, delete, update, and move, reflecting the relative differences in semantic complexity among different operations. Simultaneously, a second weight parameter is assigned to each operation object type according to a preset node type weight table. This node type weight table assigns values based on the semantic complexity of the syntactic structure represented by the node. For example, logical nodes such as method calls, conditional branches, and loop structures are given higher weights, while data nodes such as variable references and constant assignments are given lower weights, which helps to distinguish the levels of semantic influence.
[0077] Furthermore, the embodiments of the present invention perform weighted calculations to obtain the weighted workload corresponding to the editing operation. By multiplying the two types of weight parameters, a fine-grained workload value is formed for each change. This calculation method allows for combined evaluation of different types of changes, making the workload result closer to the complexity of the actual semantic modification.
[0078] Optionally, methods for measuring code workload also include storing the source file's abstract syntax tree and the target file's abstract syntax tree in JSON format. Storing the source file's abstract syntax tree and the target file's abstract syntax tree in JSON format offers good readability, structured expression, and cross-platform compatibility, and can fully preserve syntactic information such as node types, attributes, and child node relationships.
[0079] Step S204: Accumulate the workload of all editing operations and output the total code workload value for this submission.
[0080] By iterating through the weighted workload values corresponding to each operation record in the difference file, these values are added sequentially to form the overall workload value for this code commit. This accumulation process does not distinguish between the order or position of the operations; it only aggregates based on the numerical superposition relationship. Furthermore, the accumulated result is returned to the calling interface in structured or numerical form. This process can transform semantic-level fine-grained changes into a single, comparable quantifiable value, enabling horizontal comparison of code commits of different scales and complexities on a unified scale. This helps to achieve standardized measurement of development workload based on semantics rather than text.
[0081] Through the above steps, the source code file and the target code file can be analyzed separately to generate the source file abstract syntax tree and the target file abstract syntax tree; the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree are calculated; a difference file containing all operation records is generated based on the edit path, and the workload of each edit operation is calculated in combination with the difference file; the workload of all edit operations is accumulated, and the total code workload value of this submission is output. In this embodiment, by parsing the source code into an abstract syntax tree, the semantic-level changes in the syntax structure are used instead of the text line count, eliminating the interference of non-semantic factors such as code style, comments, blank lines, and formatting on workload assessment. At the same time, by calculating the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree, the edit operations in the code change are accurately identified, and the abstract syntax trees of the previous and current versions are compared. Without manual intervention or code instrumentation, non-intrusive and automated workload measurement is achieved, effectively improving code development efficiency. This solves the technical problem of low accuracy and reduced development efficiency of workload assessment methods based on code lines in related technologies.
[0082] The following describes in detail another optional implementation method.
[0083] The embodiments of the present invention overcome the shortcomings of existing code workload assessment schemes and provide a code workload assessment method.
[0084] Figure 3 This is a schematic diagram of an optional code workload assessment method according to an embodiment of the present invention, such as... Figure 3 As shown, the submitted source code is input into the source code parsing module, the abstract syntax tree output by the source code parsing module is input into the code analysis module, and then the difference file obtained from the analysis is input into the workload calculation module to obtain the code workload. The following is a detailed explanation of each module.
[0085] The first one is the source code parsing module.
[0086] Input: The source code file submitted this time.
[0087] Output: The abstract syntax tree of the source code in this submission, and the abstract syntax tree of the source code in the previous submission.
[0088] Processing procedure:
[0089] The first step is that when the source code is submitted, the source code parsing module traces the two most recent submissions of the code file (i.e., the current submission and the previous submission) through the code storage system's submission records, and downloads the source files of these two submissions from the code storage repository.
[0090] The second step involves the source file being the file submitted last time and the target file being the file submitted this time. The source code parsing module parses the source file and the target file respectively, and generates a parse tree after lexical analysis and syntax analysis. The parse tree is then simplified to generate an abstract syntax tree for the source file and an abstract syntax tree for the target file.
[0091] Figure 4 This is a schematic diagram of an optional code workload measurement process according to an embodiment of the present invention, such as... Figure 4 As shown, after parsing the source and target files, two abstract syntax trees are generated. Then, a tree edit distance algorithm (such as...) is used... Figure 4 The Tree Edit Distance algorithm in the database generates the difference file.
[0092] For example, include the following in the code file:
[0093] if x > 0:
[0094] print(x)
[0095] else:
[0096] print(0)
[0097] After analysis, an abstract syntax tree is generated. The nodes in the abstract syntax tree are described as follows:
[0098] Root node +: indicates an addition operation.
[0099] Left child node 3: constant. Right child node : Indicates a multiplication operation. Left child node 4: Constant.
[0100] Right child node 2: constant.
[0101] The second is the code analysis module.
[0102] Input: Source file abstract syntax tree and target file abstract syntax tree.
[0103] Output: Abstract syntax tree difference file.
[0104] Processing procedure:
[0105] The first step is to abstract a syntax tree based on the source and target files, and then use the tree edit distance algorithm to calculate the shortest edit distance and edit path between the two trees.
[0106] The second step is to determine the shortest edit distance, which is the minimum number of operations required to move from the source file's abstract syntax tree to the target file's abstract syntax tree. There are four types of operations: add, delete, update, and move.
[0107] The third step is to identify the operation type and operation object type of each editing operation based on the start and end points of the editing path. An operation type and its corresponding operation object type are merged into an operation record.
[0108] The fourth step is to write all the operation records into a file, which records all the operation records from the source abstract syntax tree to the target abstract syntax tree, i.e., the difference file.
[0109] like Figure 4 As shown, the tree edit distance algorithm can generate a difference file containing multiple operation records, including edit1, edit2...editn.
[0110] Each element in the difference file can contain:
[0111] `actionName`: Indicates the operation performed between the source and target syntax trees, such as adding, updating, or moving. `nodeType`: Indicates the type of the specific node, such as a variable or method. `nodeLabel`: Indicates the content of the specific node.
[0112] The difference file is a JSON file, as follows: [
[0114] {
[0115] "actionName": "update",
[0116] "nodeType": "method",
[0117] "nodeLabel": "getTotalNum
[0118] },
[0119] {
[0120] "actionName": "insert",
[0121] "nodeType": "variable",
[0122] "nodeLabel": "num
[0123] } ]
[0125] The third module is the workload calculation module.
[0126] Input: Difference file.
[0127] Output: The amount of code work done in this submission.
[0128] Processing procedure:
[0129] The first step is to parse the difference file and obtain all the edit records.
[0130] The second step is to assign weights to each operation type and also to each operation object type.
[0131] The third step is to calculate the editing workload for each edit record as the weight of the operation type multiplied by the weight of the operation object type.
[0132] The fourth step is to sum up the editing workload of each edit record, and the final sum is the total code workload for this submission.
[0133] like Figure 4 As shown, the code workload value is obtained by parsing the difference file and then performing weighted calculations. The weight parameters corresponding to each operation record are determined, and then weighted calculations are performed.
[0134] The embodiments of the present invention convert the source code into an abstract syntax tree structure, eliminating the interference of non-semantic factors such as code style, comments, blank lines, indentation, and formatting on workload assessment, so that the measurement of code changes focuses on the semantic changes of the syntax structure, and improves the correlation between assessment results and actual development behavior.
[0135] Meanwhile, the embodiments of the present invention identify four types of operations—addition, deletion, update, and movement—based on the tree edit distance algorithm. This allows for accurate differentiation between logical restructuring and data adjustment, assigning higher weights to operations with high semantic complexity, such as method call changes and control structure modifications, and assigning lower weights to operations with low semantic impact, such as variable renaming and constant value adjustment. This enables fine-grained semantic differentiation of development behaviors.
[0136] Furthermore, the embodiments of the present invention calculate the workload of each change by weighted product of operation type and node type, so that the workload assessment matches the semantic depth of the code's syntax structure, avoiding the "quantity over quality" problem caused by simply counting the number of character lines, and helping to guide developers to focus on logic optimization rather than code quantity.
[0137] The following is a detailed description with reference to another embodiment.
[0138] Example 2
[0139] The code workload measurement device provided in this embodiment includes multiple implementation units, each of which corresponds to a specific implementation step in the above embodiment one. The specific implementation method and beneficial effects can be referred to the foregoing method embodiment, and will not be repeated here.
[0140] Figure 5This is a schematic diagram of an optional code workload measurement device according to an embodiment of the present invention, such as... Figure 5 As shown, the code workload measurement device may include: a syntax tree generation unit 51, an edit path generation unit 52, a difference file generation unit 53, and a code workload measurement unit 54.
[0141] The syntax tree generation unit 51 is used to analyze the source code file and the target code file respectively, and generate the source file abstract syntax tree and the target file abstract syntax tree.
[0142] The edit path generation unit 52 is used to calculate the shortest edit distance between the source file abstract syntax tree and the target file abstract syntax tree, as well as the corresponding edit path.
[0143] The difference file generation unit 53 is used to generate a difference file containing all operation records based on the editing path, and to calculate the workload of each editing operation by combining the difference file.
[0144] Code workload metric unit 54 is used to accumulate the workload of all editing operations and output the total code workload value for this submission.
[0145] The aforementioned code workload measurement device can analyze the source code file and the target code file separately through the syntax tree generation unit 51 to generate the source file abstract syntax tree and the target file abstract syntax tree; calculate the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree through the edit path generation unit 52; generate a difference file containing all operation records based on the edit path through the difference file generation unit 53, and calculate the workload of each edit operation in combination with the difference file; and accumulate the workload of all edit operations through the code workload measurement unit 54 to output the total code workload value of this submission. In this embodiment, source code can be parsed into an abstract syntax tree, replacing the counting of lines of text with semantic changes in syntax structure. This eliminates the interference of non-semantic factors such as code style, comments, blank lines, and formatting on workload assessment. At the same time, by calculating the shortest edit distance and corresponding edit path between the source file's abstract syntax tree and the target file's abstract syntax tree, the editing operations in code changes can be accurately identified. By comparing the abstract syntax trees of the previous and current versions, no manual intervention or code instrumentation is required, achieving non-intrusive and automated workload measurement. This effectively improves code development efficiency and solves the technical problem of low accuracy and reduced development efficiency of workload assessment methods based on lines of code in related technologies.
[0146] Optionally, the syntax tree generation unit includes: a commit record acquisition module, used to respond to code commit operations and obtain the two most recent commit records of the committed code files through the project source code system; a code file download module, used to download the code files corresponding to the two most recent commit records from the project source code repository, obtaining the source code file of the previous commit and the target code file of the current commit; a first syntax tree generation module, used to perform lexical analysis and syntax analysis on the source code file of the previous commit, generating an abstract syntax tree for the source file; and a second syntax tree generation module, used to perform lexical analysis and syntax analysis on the target code file of the current commit, generating an abstract syntax tree for the target file.
[0147] Optionally, the first syntax tree generation module includes: a lexical analysis submodule, used to perform lexical analysis on the code source file, scan and segment the lexical units in the code source file, and generate a sequence of lexical units; a syntax analysis submodule, used to perform syntax analysis on the sequence of lexical units based on the grammar rules and production rules of the target programming language, and construct an initial parse tree; and a simplification submodule, used to simplify the initial parse tree, remove redundant grammatical nodes, preserve the semantic structure, and generate an abstract syntax tree of the source file, wherein the redundant nodes include at least one of the following: semicolon nodes, bracket nodes, and indentation symbol nodes.
[0148] Optionally, the edit path generation unit includes: an operand extraction module, used to extract operands corresponding to each operation type in the source file abstract syntax tree and the target file abstract syntax tree, wherein the operation type includes at least one of the following: add operation, delete operation, update operation, move operation; an edit distance calculation module, used to calculate the minimum number of operations required to move from the source file abstract syntax tree to the target file abstract syntax tree using a tree edit distance algorithm, based on the source file abstract syntax tree and the target file abstract syntax tree, to obtain the shortest edit distance; and an edit path generation module, used to determine the starting point, intermediate nodes, and ending point traversed by the shortest edit distance based on the source file abstract syntax tree and the target file abstract syntax tree, to obtain the edit path.
[0149] Optionally, the difference file generation unit includes: an operation type identification module, used to identify the operation type and operation object type of each editing operation based on the start and end points of the editing path; an operation record merging module, used to merge each identified operation type and its corresponding operation object type into one operation record; and a difference file generation module, used to write all operation records into a predefined file to generate a difference file containing all operation records.
[0150] Optionally, the difference file generation unit includes: an operation record reading module, used to read the difference file and obtain all operation records; a weight parameter assignment module, used to assign a first weight parameter to the operation type in each operation record according to a preset operation type weight table, and to assign a second weight parameter to each operation object type according to a preset node type weight table; and a weighting module, used to perform weighted calculations for each editing operation based on the operation type and the corresponding first weight parameter, the operation object type and the corresponding second weight parameter, to obtain the weighted workload corresponding to the editing operation.
[0151] Optionally, the code workload measurement device also includes: storing the source file abstract syntax tree and the target file abstract syntax tree in JSON format.
[0152] The aforementioned code workload measurement device may also include a processor and a memory. The syntax tree generation unit 51, the edit path generation unit 52, the difference file generation unit 53, the code workload measurement unit 54, 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.
[0153] The processor described above contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and kernel parameters can be adjusted to implement code workload measurement based on the abstract syntax tree.
[0154] 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.
[0155] Example 3
[0156] Embodiments of this application may provide an electronic device. Figure 6 This is a structural block diagram of an electronic device for measuring the workload of executing code, according to an embodiment of this application. Figure 6 As shown, the electronic device may include: one or more ( Figure 6 (Only one is shown) Processor 602, memory 604, memory controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0157] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the code workload measurement method and apparatus in this application embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the aforementioned code workload measurement method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0158] The processor can access information and applications stored in memory via a transmission device to perform the following steps: analyze the source code file and the target code file respectively, and generate the source file abstract syntax tree and the target file abstract syntax tree; calculate the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree; generate a difference file containing all operation records based on the edit path, and calculate the workload of each edit operation based on the difference file; sum up the workload of all edit operations, and output the total code workload value of this submission.
[0159] Those skilled in the art will understand that Figure 6 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones, tablets, handheld computers, mobile internet devices (MIDs), PADs, and other terminal devices. Figure 6 This does not limit the structure of the aforementioned electronic device. For example, electronic devices may also include components that are more... Figure 6 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 6 The different configurations shown.
[0160] Those skilled in the art will understand that all or part of the steps in the various code workload measurement methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0161] Example 4
[0162] Embodiments of this application also provide a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the code workload measurement method provided in Embodiment 1.
[0163] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored computer program, wherein a method for measuring the amount of code work required to control the device where the computer-readable storage medium is located to execute any one of the above embodiments is provided when the computer program is running.
[0164] Optionally, in this embodiment, the storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0165] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the code workload measurement method described in various embodiments of this application.
[0166] This application also provides a computer program product, including a non-volatile computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the code workload measurement method described in various embodiments of this application.
[0167] 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.
[0168] 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.
[0169] 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.
[0170] 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.
[0171] 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.
[0172] 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.
[0173] 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 method for measuring code workload, characterized in that, include: The source code file and the target code file are analyzed separately to generate the source file abstract syntax tree and the target file abstract syntax tree; Calculate the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree; A difference file containing all operation records is generated based on the edit path, and the workload of each edit operation is calculated based on the difference file. Add up the workload of all the aforementioned editing operations and output the total code workload value for this submission.
2. The method for measuring code workload according to claim 1, characterized in that, The steps involved in analyzing source and object code files separately to generate abstract syntax trees (ASTs) for the source and object files include: In response to code commit operations, retrieve the two most recent commit records of the committed code files from the project source code system; Download the code files corresponding to the two most recent commits from the project source code repository to obtain the source code file of the previous commit and the target code file of the current commit; Lexical and syntactic analysis are performed on the previously submitted source code file to generate an abstract syntax tree for the source file; Lexical and syntactic analysis were performed on the target code file submitted in this paper to generate an abstract syntax tree for the target file.
3. The method for measuring code workload according to claim 2, characterized in that, The steps of performing lexical and syntactic analysis on the previously submitted source code file to generate an abstract syntax tree for the source file include: Lexical analysis is performed on the source code file, and the lexical units in the source code file are scanned and segmented to generate a sequence of lexical units; Based on the grammar rules and production rules of the target programming language, the lexical unit sequence is subjected to syntactic analysis to construct an initial parse tree; The initial parse tree is simplified by removing redundant syntactic nodes while preserving the semantic structure, thereby generating the source file abstract syntax tree. The redundant nodes include at least one of the following: semicolon nodes, bracket nodes, and indentation symbol nodes.
4. The method for measuring code workload according to claim 1, characterized in that, The steps for calculating the shortest edit distance and edit path between the source file abstract syntax tree and the target file abstract syntax tree include: Extract the operands corresponding to each operation type in the source file abstract syntax tree and the target file abstract syntax tree, wherein the operation type includes at least one of the following: add operation, delete operation, update operation, move operation; Based on the source file abstract syntax tree and the target file abstract syntax tree, the minimum number of operations required to move from the source file abstract syntax tree to the target file abstract syntax tree is calculated using the tree edit distance algorithm, and the shortest edit distance is obtained. Based on the source file abstract syntax tree and the target file abstract syntax tree, the starting point, intermediate nodes and the ending point of the shortest editing distance are determined to obtain the editing path.
5. The method for measuring code workload according to claim 1, characterized in that, The step of generating a difference file containing all operation records based on the edit path includes: Based on the start and end points of the editing path, identify the operation type and operation object type of each editing operation; Each identified operation type and its corresponding operation object type are merged into one operation record; Write all the operation records to a predefined file to generate the difference file containing all the operation records.
6. The method for measuring code workload according to claim 1, characterized in that, The steps for calculating the workload of each editing operation based on the aforementioned difference file include: Read the difference file to obtain all the operation records; According to the preset operation type weight table, a first weight parameter is assigned to the operation type in each operation record, and a second weight parameter is assigned to each operation object type according to the preset node type weight table; For each editing operation, a weighted calculation is performed based on the operation type and its corresponding first weight parameter, the operation object type and its corresponding second weight parameter, to obtain the weighted workload corresponding to the editing operation.
7. The method for measuring code workload according to any one of claims 1 to 6, characterized in that, Also includes: The source file abstract syntax tree and the target file abstract syntax tree are stored in JSON format.
8. A device for measuring coding workload, characterized in that, include: The syntax tree generation unit is used to analyze source code files and object code files separately, and generate abstract syntax trees for the source files and object files respectively; The edit path generation unit is used to calculate the shortest edit distance and the corresponding edit path between the source file abstract syntax tree and the target file abstract syntax tree; The difference file generation unit is used to generate a difference file containing all operation records based on the editing path, and to calculate the workload of each editing operation based on the difference file; The code workload metric unit is used to accumulate the workload of all the aforementioned editing operations and output the total code workload value for this submission.
9. An electronic device, characterized in that, It includes one or more processors and a memory for storing 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 code workload measurement method according to any one of claims 1 to 7.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the code workload measurement method according to any one of claims 1 to 7.
