Code statistics method, code statistics device and medium
Through monitoring code submission and storing statistics in the database, the code statistics in existing technology are prone to obstructive problems and low real -time problems, and real -time stable statistics and efficient feedback of the code are realized.
Patent Information
- Application Number
- CN202111383865.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-22
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2041-11-22
AI Technical Summary
Existing code management tools are prone to blocking problems when stating the amount of code, and the real-time performance of statistical results is low. Users need to wait until the statistics are completed before obtaining the results, which is less efficient.
Through the submission of the listening code, obtain the unique submission identification number to determine whether there are corresponding statistical records in the database. If there is no existence, the code statistics are performed and the results are stored in the database.
The real -time statistics of the code have been realized, and the stability is high. It can timely feedback the statistical results to the user, which improves the statistical efficiency and real -time nature of code.
Smart Images

Figure CN114115970B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to a code statistics method, a code statistics device and a medium. Background Art
[0002] Existing code management tools such as git and svn provide the functions of client-side code pulling and server-side code saving. The code saved on the server can be divided into multiple projects created by users and stored in different groups and user directories. Conventional code statistics solutions are to count the amount of code at regular intervals, and count the code accumulated over a period of time at one time. The statistical tools need to be executed for a long time, are more likely to encounter blocking problems, and once a blocking problem occurs, the impact is greater. Because it is a scheduled statistics, users can only obtain the statistical results after the statistics are completed, which is inefficient.
[0003] The present disclosure is proposed to solve one or more problems existing in the prior art. Summary of the invention
[0004] A brief overview of the disclosure is given below in order to provide a basic understanding of some aspects of the disclosure. However, it should be understood that this overview is not an exhaustive overview of the disclosure. It is not intended to identify the key or important parts of the disclosure, nor is it intended to limit the scope of the disclosure. Its purpose is simply to give some concepts of the disclosure in a simplified form as a prelude to a more detailed description given later.
[0005] According to one aspect of the present disclosure, there is provided a code statistics method, comprising: monitoring submissions for code; when monitoring submissions for code, obtaining a unique submission identification number of the submitted code; determining whether there is a statistical record corresponding to the submission identification number in a database for storing code statistics information; when there is no statistical record corresponding to the submission identification number in the database, performing statistics on the submitted code; and storing the statistical results in the database.
[0006] According to another aspect of the present disclosure, a code statistics device is provided, comprising: a memory on which instructions are stored; and a processor configured to execute the instructions stored in the memory to perform the method as described above.
[0007] According to another aspect of the present disclosure, a computer-readable storage medium is provided, which includes computer-executable instructions. When the computer-executable instructions are executed by one or more processors, the one or more processors execute the method according to the above aspects of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] The accompanying drawings, which constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0009] The present disclosure may be more clearly understood from the following detailed description with reference to the accompanying drawings, in which:
[0010] Figure 1 A flowchart of a code statistics method according to an embodiment of the present disclosure is shown;
[0011] Figure 2 An exemplary configuration of a computing device that can implement an embodiment according to the present disclosure is shown. DETAILED DESCRIPTION
[0012] The following detailed description is made with reference to the accompanying drawings, and the following detailed description is provided to assist in a comprehensive understanding of the various exemplary embodiments of the present disclosure. The following description includes various details to assist in understanding, but these details are considered to be examples only and not to limit the present disclosure, which is defined by the appended claims and their equivalents. The words and phrases used in the following description are only used to enable a clear and consistent understanding of the present disclosure. In addition, for the sake of clarity and brevity, descriptions of well-known structures, functions, and configurations may be omitted. Those of ordinary skill in the art will recognize that various changes and modifications may be made to the examples described herein without departing from the spirit and scope of the present disclosure.
[0013] Existing code statistics methods, such as daily scheduled statistics, count the amount of code for a day at, for example, 0:00 a.m. Each script needs to scan a large amount of code, which may encounter problems such as process blocking, resulting in unstable functions. In addition, users submit code on the same day, and the statistical results can only be obtained the next day after the statistics are completed at midnight, for example. This has low real-time performance and poor user experience.
[0014] The present disclosure proposes a method for real-time code quantity statistics, which can count codes in real time in small quantities and multiple times, has high stability, and can feed back the statistical results to users in a timely manner, with good timeliness. Therefore, the present disclosure can improve code statistics efficiency, improve real-time performance and stability.
[0015] Figure 1 A flowchart of a code statistics method according to an embodiment of the present disclosure is shown.
[0016] According to an embodiment of the present disclosure, a code statistics method is proposed, comprising: monitoring submissions for code; when a submission for code is monitored, obtaining a unique submission identification number (commit ID, Figure 1Determine whether there is a statistical record corresponding to the commit identification number in a database for storing code statistical information; when there is no statistical record corresponding to the commit identification number in the database, perform statistics on the submitted code; and store the statistical results in the database.
[0017] Specifically, whenever code is submitted, the trigger mechanism is triggered, thereby the submission (submission message) for the code can be monitored. In one embodiment, the submission message can be monitored by, for example, a message listener, thereby monitoring the submission for the code.
[0018] The above code statistics method can be performed by, for example, a code management device. In one embodiment, one or more users can edit the code on the client, and the client sends and saves the code to the server. The user can obtain the code from the server to continue editing the code the next time he edits. In this case, the server is the code management device. Of course, the above code statistics method can also be performed by another server or computing device independent of the server that saves the code. In this case, the other server or computing device is the code management device.
[0019] In another embodiment, one or more users can edit the code on the same computing device, and the computing device not only saves the code edited by the one or more users, but also performs code statistics on the code. In this case, the computing device is the code management device.
[0020] Alternatively, one or more users can edit and save the code on the same computing device, but perform code statistics on the code through another computing device connected to the computing device. In this case, the other computing device is the code management device.
[0021] Each time a code is submitted, a unique submission identification number can be assigned to the submitted code (which corresponds to a submission message). In one embodiment, the unique submission identification number can be generated by a code management device.
[0022] In the client and server architecture, the unique submission identification number can be generated by the server or the client. In this case, when multiple clients respectively generate the unique submission identification number, a unified generation method is required to generate the same submission identification number for the same submission content.
[0023] In one embodiment, for example, a hash value may be calculated based on the submitted code and used as a unique submission identification number.
[0024] After obtaining the unique submission identification number, an existence check can be performed in the database for storing code statistics to determine whether there is a statistical record corresponding to the unique submission identification number. The database for storing code statistics can be located anywhere, that is, it can be located in the code management device, or on other servers, or in the cloud.
[0025] If there is no record of the unique submission identification number in the database, the relevant indicators of the submitted code can be counted. For example, the amount of new and deleted code can be counted. The dimensions to be counted are not limited in any way. For example, the statistical dimensions can be any one or more of the following dimensions:
[0026] Code statistics: total number of files, lines, commits, authors, by date, by extension, etc.
[0027] Activity: number of commits per hour per day, per day per week, per hour per week, per month per year, and per year.
[0028] Number of authors: Lists all authors (number of commits, first commit date, latest commit date), broken down by month and year.
[0029] After the statistics are completed, the statistical results can be stored in a database, thereby achieving real-time statistics of the code.
[0030] In one embodiment, the above-mentioned code statistics method may also include: determining whether there is a parent submission identification number of the submission identification number; when the parent submission identification number exists, determining whether there is a statistical record corresponding to the parent submission identification number in the database; when there is no statistical record corresponding to the parent submission identification number in the database, performing statistics on the code corresponding to the parent submission identification number; and storing the statistical results of the code corresponding to the parent submission identification number in the database.
[0031] Thus, backtracking can be performed based on the parent commit ID (i.e., parent commitid) to determine whether the code associated with the parent commit ID has been counted and recorded in the database. If it has not been counted and recorded, additional counting and recording can be performed. Thus, the problem that the historical commit records that may exist in the prior art have not been counted can be solved.
[0032] In one embodiment, the above-mentioned code statistics method may also include: replacing the submission identification number with the parent submission identification number; re-executing each step as described above (that is, determining whether there is a parent submission identification number of the submission identification number; when the parent submission identification number exists, determining whether there is a statistical record corresponding to the parent submission identification number in the database; when there is no statistical record corresponding to the parent submission identification number in the database, performing statistics on the code corresponding to the parent submission identification number; and storing the statistical results of the code corresponding to the parent submission identification number in the database); and iteratively executing the above-mentioned replacement steps and re-execution steps until there is no parent submission identification number of the submission identification number or there is a statistical record corresponding to the parent submission identification number in the database.
[0033] In this way, you can continuously use the parent commit identification number of the current commit identification number to continuously backtrack along the version line to supplement the statistics and records of all the codes upstream of the version line that have not yet been counted and recorded.
[0034] In one embodiment, if there is a parent submission identification number of the submitted code, for example, a hash value may be calculated based on at least the submitted code and the parent submission identification number, and the hash value may be used as the unique submission identification number.
[0035] In one embodiment, in the above code statistics method, counting the submitted code includes: counting the amount of newly added and deleted code.
[0036] In one embodiment, the code statistics method may further include: presenting the code statistics results according to one or more statistical dimensions corresponding to the user request. Thus, the code statistics results may be displayed in the interface according to different dimensions according to user needs, which is easy to read.
[0037] In one embodiment, the code statistics method of the present disclosure can be implemented on the basis of any existing code statistics tool. For example, the git hooks script provided by gitlab can be modified to realize the real-time collection of submission information, thereby realizing the above-mentioned code statistics method of the present disclosure. Furthermore, the submission information can be pushed to the platform interface through, for example, kafka to feedback to the user, realizing the function of automatic statistics.
[0038] Compared with the prior art, the code statistics method disclosed in the present invention can count the code changes in real time, has stable functions, high statistical efficiency, and can be directly displayed to users through the platform interface. In addition, in the method disclosed in the present invention, backtracking can be performed based on the parent submission identification number, thereby solving the problem of stock code not being counted, and no repeated statistics are made, which is highly efficient.
[0039] Figure 2An exemplary configuration of a computing device 1200 capable of implementing embodiments according to the present disclosure is shown.
[0040] The computing device 1200 is an example of a hardware device to which the above aspects of the present disclosure can be applied. The computing device 1200 can be any machine configured to perform processing and / or computing. The computing device 1200 can be, but is not limited to, a workstation, a server, a desktop computer, a laptop computer, a tablet computer, a personal data assistant (PDA), a smart phone, a vehicle-mounted computer, or a combination thereof.
[0041] like Figure 2 As shown, the computing device 1200 may include one or more elements that can be connected or communicated with the bus 1202 via one or more interfaces. The bus 1202 may include, but is not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MCA) bus, an Enhanced ISA (EISA) bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus, etc. The computing device 1200 may include, for example, one or more processors 1204, one or more input devices 1206, and one or more output devices 1208. The one or more processors 1204 may be any kind of processor, and may include, but is not limited to, one or more general-purpose processors or special-purpose processors (such as special-purpose processing chips). The processor 1204 may be configured to implement the above-mentioned code statistics method, for example. The input device 1206 may be any type of input device capable of inputting information to the computing device, and may include, but is not limited to, a mouse, a keyboard, a touch screen, a microphone, and / or a remote controller. The output device 1208 may be any type of device capable of presenting information, and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer.
[0042] The computing device 1200 may also include or be connected to a non-transitory storage device 1214, which may be any non-transitory storage device that can implement data storage, and may include, but is not limited to, a disk drive, an optical storage device, a solid-state memory, a floppy disk, a flexible disk, a hard disk, a tape, or any other magnetic medium, a compressed disk or any other optical medium, a cache memory, and / or any other storage chip or module, and / or any other medium from which a computer can read data, instructions, and / or code. The computing device 1200 may also include a random access memory (RAM) 1210 and a read-only memory (ROM) 1212. The ROM 1212 may store programs, utilities, or processes to be executed in a non-volatile manner. The RAM 1210 may provide volatile data storage and store instructions related to the operation of the computing device 1200. The computing device 1200 may also include a network / bus interface 1216 coupled to a data link 1218. The network / bus interface 1216 may be any type of device or system capable of enabling communication with an external device and / or a network, and may include but is not limited to a modem, a network card, an infrared communication device, a wireless communication device, and / or a chipset (such as a Bluetooth TM equipment, 802.11 equipment, WiFi equipment, WiMax equipment, cellular communication facilities, etc.).
[0043] The present disclosure may be implemented as any combination of an apparatus, a system, an integrated circuit, and a computer program on a non-transitory computer-readable medium. One or more processors may be implemented as an integrated circuit (IC), an application specific integrated circuit (ASIC), or a large scale integrated circuit (LSI), a system LSI, a super LSI, or a super LSI component that performs some or all of the functions described in the present disclosure.
[0044] The present disclosure includes the use of software, applications, computer programs, or algorithms. The software, applications, computer programs, or algorithms may be stored on a non-transitory computer-readable medium to enable a computer such as one or more processors to perform the above steps and the steps described in the accompanying drawings. For example, one or more memories store the software or algorithm in executable instructions, and one or more processors may associate a set of instructions to execute the software or algorithm to provide various functions according to the embodiments described in the present disclosure.
[0045] Software and computer programs (which may also be referred to as programs, software applications, applications, components or code) include machine instructions for a programmable processor and may be implemented in a high-level procedural language, an object-oriented programming language, a functional programming language, a logic programming language, or an assembly language or a machine language. The term "computer-readable medium" refers to any computer program product, apparatus or device for providing machine instructions or data to a programmable data processor, such as magnetic disks, optical disks, solid-state storage devices, memories and programmable logic devices (PLDs), including computer-readable media that receive machine instructions as computer-readable signals.
[0046] For example, computer readable media may include dynamic random access memory (DRAM), random access memory (RAM), read-only memory (ROM), electrically erasable read-only memory (EEPROM), compact disk read-only memory (CD-ROM) or other optical disk storage devices, magnetic disk storage devices or other magnetic storage devices, or any other medium that can be used to carry or store the desired computer readable program code in the form of instructions or data structures and can be accessed by a general or special purpose computer or a general or special purpose processor. As used herein, disk or disc includes compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, where disks usually reproduce data magnetically, while discs reproduce data optically by laser. Combinations of the above are also included in the scope of computer readable media.
[0047] The subject matter of the present disclosure is provided as an example of devices, systems, methods and programs for performing the features described in the present disclosure. However, in addition to the above-mentioned features, other features or variations may also be expected. It is expected that the implementation of the components and functions of the present disclosure may be completed with any emerging technology that may replace any of the above-mentioned implementation technologies.
[0048] In addition, the above description provides examples without limiting the scope, applicability or configuration set forth in the claims. Without departing from the spirit and scope of the present disclosure, the functions and arrangements of the elements discussed may be changed. Various embodiments may appropriately omit, replace or add various processes or components. For example, features described with respect to certain embodiments may be combined in other embodiments.
[0049] In addition, in the description of the present disclosure, the terms “first”, “second”, “third”, etc. are used for descriptive purposes only and cannot be understood as indicating or implying relative importance and order.
[0050] Similarly, while operations are depicted in a particular order in the drawings, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order, or that all illustrated operations be performed to achieve desired results. In certain circumstances, multitasking and parallel processing can be advantageous.
Claims
1. A code statistics method, comprising: Listen for code submissions; When a submission for the code is monitored, the unique submission identification number of the submitted code is obtained; Determining whether there is a statistical record corresponding to the submission identification number in a database for storing code statistical information; When there is no statistical record corresponding to the submission identification number in the database, performing statistics on the submitted code; as well as storing the statistical results in the database, The method further includes the following operations: Determine whether there is a parent commit identification number of the commit identification number, When the parent submission identification number exists, determining whether there is a statistical record corresponding to the parent submission identification number in the database, When there is no statistical record corresponding to the parent submission identification number in the database, statistics are collected on the code corresponding to the parent submission identification number. storing the statistical results of the codes corresponding to the parent submission identification number in the database, Wherein, the method further comprises: Replace the commit identification number with the parent commit identification number, Re-execute the above operation. The steps of replacing the commit identification number with the parent commit identification number and re-performing the operation are iterated until there is no parent commit identification number of the commit identification number or there is a statistical record corresponding to the parent commit identification number in the database.
2. The method according to claim 1, wherein: Statistics of submitted code include: statistics of the amount of new and deleted code.
3. The method according to claim 1, further comprising: The code statistics results are presented according to one or more statistical dimensions corresponding to the user request.
4. The method according to claim 1, further comprising: A hash value is calculated based on the submitted code, and the hash value is used as the unique submission identification number.
5. A code statistics device, comprising: a memory having instructions stored therein; as well as A processor configured to execute instructions stored on the memory to perform the method according to any one of claims 1 to 4.
6. A computer-readable storage medium comprising computer-executable instructions, which, when executed by one or more processors, cause the one or more processors to perform the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Project information query method and device based on multiple code warehouses
CN113342392A