Report automatic generation method, device, electronic device and computer-readable storage medium
By analyzing the conversion request, the key data in the JSON form data is extracted, and the template engine is called to process the report template to generate an output report that conforms to the set output format, which solves the problem of cumbersome, time-consuming and error-prone reporting output in the existing technology. Automatic report generation and efficiency improvement have been achieved.
Patent Information
- Application Number
- CN202411660067.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-11-20
AI Technical Summary
In the prior art, the report output requires manual data collection and processing, the use of static templates, and manual generation and distribution, resulting in cumbersome, time-consuming, error-prone and inefficient.
Provides an automatic report generation method. By receiving conversion requests, analyzing the set output format, JSON form data and report templates, extracting key data, and calling the template engine to process key data and report templates, generating output that conforms to the set output format Report.
It realizes automatic generation of reports, saves manpower, and improves the efficiency and accuracy of report generation.
Smart Images

Figure CN119150817B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for automatically generating a report, an electronic device, and a computer-readable storage medium. Background Art
[0002] Report output is a common task encountered by many people in their daily work. People usually write and output reports completely manually, including the following steps:
[0003] (1) Manual data collection and processing: Manually collect data from various data sources (such as various databases, etc.), and perform data cleaning and analysis through manual operations;
[0004] (2) Use of static templates: Report templates are usually static Word files, and the placeholders and other contents need to be replaced manually;
[0005] (3) Manual generation and distribution: The generated reports need to be manually saved and distributed to relevant personnel.
[0006] However, the manual data collection and processing process is cumbersome, time-consuming and prone to errors. At the same time, manually replacing the content in the template requires a lot of manpower, which is inefficient and prone to errors. Summary of the invention
[0007] The object of the present invention is to provide a method, device, electronic device and computer-readable storage medium for automatically generating a report, so as to improve the problems existing in the prior art.
[0008] The embodiments of the present invention can be implemented as follows:
[0009] In a first aspect, the present invention provides a method for automatically generating a report, which is applied to a server, and the method comprises:
[0010] Receiving a conversion request, and parsing the conversion request to obtain a set output format, JSON form data, and a report template; the report template predefines the format, style, and content layout of the report;
[0011] Extract key data from the JSON form data;
[0012] The template engine is called to process the key data and the report template to obtain an output report that complies with the set output format.
[0013] Optionally, the key data includes first key data and second key data;
[0014] The step of extracting key data from the JSON form data includes:
[0015] Parsing the JSON form data to obtain parsed data; the parsed data includes text data and / or image data;
[0016] Extracting text data from the parsed data to obtain the first key data;
[0017] Extracting picture data from the parsed data;
[0018] If the picture data includes a local picture path, acquiring a target local picture based on the local picture path and storing the target local picture in a local cache of the server to obtain a first temporary storage path;
[0019] If the picture data includes an online picture URL, then downloading a target online picture based on the online picture URL and storing the target online picture in the local cache to obtain a second temporary storage path;
[0020] If the image data includes a Base64 encoded image, converting the Base64 encoded image into a preset image format and storing it in the local cache to obtain a third temporary storage path;
[0021] The second key data includes the first temporary storage path and / or the second temporary storage path and / or the third temporary storage path.
[0022] Optionally, the step of calling the template engine to process the key data and the report template to obtain an output report conforming to the set output format includes:
[0023] Calling the template engine to process the key data and the report template to obtain a word document report;
[0024] If the set output format belongs to the word file format, the word document report is used as the output report;
[0025] If the set output format is PDF format, the word document report is converted into a PDF document report, and the PDF document report is used as the output report.
[0026] Optionally, after the step of calling the template engine to process the key data and the report template to obtain an output report conforming to the set output format, the method further includes:
[0027] Based on the second key data, clear the pictures stored in the local cache.
[0028] Optionally, if the conversion request further includes a summary extraction instruction and a keyword extraction instruction, the method further includes:
[0029] Extracting summary information from the output report using an extractive summary algorithm; extracting at least one keyword from the output report using a keyword extraction algorithm;
[0030] The summary information and the at least one keyword are inserted into the beginning or the end of the output report to obtain a target output report.
[0031] Optionally, the method further includes:
[0032] The target output report is returned to the requesting end that issued the conversion request.
[0033] Optionally, the method further includes:
[0034] The output report is returned to the requesting end that issued the conversion request.
[0035] In a second aspect, the present invention provides a report automatic generation device, which is applied to a server, and the device comprises:
[0036] A receiving module, used for receiving a conversion request, and parsing the conversion request to obtain a set output format, JSON form data and a report template; the report template predefines the format, style and content layout of the report;
[0037] An extraction module, used to extract key data from the JSON form data;
[0038] The processing module is used to call the template engine to process the key data and the report template to obtain an output report that complies with the set output format.
[0039] In a third aspect, the present invention provides an electronic device, comprising: a memory and a processor, wherein the memory stores a software program, and when the electronic device is running, the processor executes the software program to implement the automatic report generation method as described in the first aspect above.
[0040] In a fourth aspect, the present invention provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the method for automatically generating a report as described in the first aspect.
[0041] Compared with the prior art, the embodiment of the present invention provides a method, device, electronic device and computer-readable storage medium for automatic report generation, which first receives a conversion request and parses the conversion request to obtain a set output format, JSON form data and a report template; the report template predefines the format, style and content layout of the report; then, extracts key data from the JSON form data; finally, calls a template engine to process the key data and the report template to obtain an output report that conforms to the set output format. In this way, the automatic generation of the report is realized, saving manpower. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0043] Figure 1 One of the flowcharts of a method for automatically generating a report provided by an embodiment of the present invention.
[0044] Figure 2 The second flowchart of a method for automatically generating a report provided by an embodiment of the present invention.
[0045] Figure 3 The third flowchart of a method for automatically generating a report provided by an embodiment of the present invention.
[0046] Figure 4 A schematic diagram of a report template provided by an embodiment of the present invention.
[0047] Figure 5 A schematic diagram of the structure of an automatic report generation device provided by an embodiment of the present invention.
[0048] Figure 6 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0050] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0052] In the description of the present invention, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. appear to indicate an orientation or position relationship, they are based on the orientation or position relationship shown in the accompanying drawings, or are the orientation or position relationship in which the product of the invention is usually placed when used. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.
[0053] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.
[0054] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.
[0055] Please refer to Figure 1 , Figure 1 A flowchart of a method for automatically generating a report is provided in an embodiment of the present invention. The execution subject of the method for automatically generating a report may be a server. The method for automatically generating a report includes the following steps S101 to S103.
[0056] S101, receiving a conversion request, and parsing the conversion request to obtain a set output format, JSON form data, and a report template.
[0057] In this embodiment, the conversion request can be initiated by the client based on the request page. The request page may include a form to be filled in, a file upload button (supporting uploading files), multiple format selection boxes, multiple template selection boxes and a conversion button. The user can fill in relevant information, upload files, select the output format, select the required report template, etc. in the form to be filled in the request page, and then click the conversion button. The client can generate a conversion request and send it to the server.
[0058] The server parses the conversion request and obtains the output format, JSON form data and report template number selected by the user. Based on the report template number, the report template selected by the user can be determined. The report template predefines the format, style and content layout of the report. The report template uses placeholders to represent dynamic content (content to be replaced), and the report template can also support advanced functions such as conditional statements and loop statements, and can dynamically adjust the report content according to different data.
[0059] S102. Extract key data from the JSON form data.
[0060] S103, calling the template engine to process key data and report templates to obtain an output report that complies with the set output format.
[0061] Optionally, the server can be containerized and deployed with a Web service and a template engine, wherein the Web service can be implemented based on a Tornado framework. The Web service provides a Web service interface that supports high-concurrency request processing, can receive user-submitted data in real time, and generate corresponding reports.
[0062] The data request sent by the client is sent to the Web service. The Web service first verifies and parses the data to ensure that the data format meets the requirements; then the Web service passes the parsed JSON form data to the preset Python script, which is responsible for extracting key data from the JSON form data. The template engine is then responsible for processing the key data and the report template to obtain an output report that meets the set output format.
[0063] The automatic report generation method provided by the embodiment of the present invention first receives a conversion request, and parses the conversion request to obtain a set output format, JSON form data and a report template; the report template predefines the format, style and content layout of the report; then, key data is extracted from the JSON form data; finally, the template engine is called to process the key data and the report template to obtain an output report that conforms to the set output format. In this way, the automatic generation of the report is realized, saving manpower.
[0064] In an optional implementation, the key data includes first key data and second key data. Figure 1 Based on Figure 2 , the sub-steps of the above step S102 may include S1021~S1026:
[0065] S1021, parsing the JSON form data to obtain parsed data;
[0066] The parsed data may include text data and / or image data;
[0067] S1022, extracting text data from the parsed data to obtain first key data;
[0068] S1023, extracting image data from the parsed data;
[0069] S1024: If the image data includes a local image path, a target local image is acquired based on the local image path and the target local image is stored in a local cache of the server to obtain a first temporary storage path;
[0070] S1025: If the image data includes an online image URL, download the target online image based on the online image URL and store the target online image in a local cache to obtain a second temporary storage path;
[0071] S1026. If the image data includes a Base64-encoded image, convert the Base64-encoded image into a preset image format and store it in a local cache to obtain a third temporary storage path;
[0072] The second key data includes the first temporary storage path and / or the second temporary storage path and / or the third temporary storage path. Optionally, the Base64 encoded image can be converted into PNG format and then stored in the local cache.
[0073] In an optional implementation, Figure 1 Based on Figure 3 The sub-steps of the above step S103 may include S1031~S1033.
[0074] S1031, calling the template engine to process key data and report templates to obtain a word document report;
[0075] S1032, if the output format is set to be a word file format, the word document report is used as the output report;
[0076] The word file format may include a docx format or a doc format.
[0077] S1033. If the output format is set to PDF format, the word document report is converted into a PDF document report, and the PDF document report is used as the output report.
[0078] In this embodiment, the server may also be containerized and deployed with a LibreOffice service, which supports the document conversion function and is responsible for converting a word document report into a pdf document report. That is, the server calls the command line interface of the LibreOffice service to convert the word document report in the specified path into a pdf format. This process is run in isolation in the container to ensure the stability and consistency of the conversion process.
[0079] It can be understood that after the output report is obtained, the output report can be returned to the requesting end that issued the conversion request for the user to view.
[0080] In an optional implementation, after obtaining the output report, it is also necessary to clean up the local cache in time. Therefore, after the above step S103, it also includes S103a:
[0081] S103a. Based on the second key data, clear the pictures stored in the local cache.
[0082] In an optional implementation, in order to enhance the content quality of the report, the conversion request may also include a summary extraction instruction and a keyword extraction instruction, so that summary extraction and keyword extraction are required after obtaining the output report. Correspondingly, the report automatic generation method may also include the following steps S104 to S106.
[0083] S104, extracting summary information from the output report using an extractive summary algorithm;
[0084] S105, extracting at least one keyword from the output report using a keyword extraction algorithm;
[0085] S106: Insert the summary information and at least one keyword into the beginning or the end of the output report to obtain a target output report.
[0086] After the target output report is obtained, the target output report can be returned to the requesting end that issued the conversion request for the user to view.
[0087] Optionally, the keyword extraction algorithm may be, but is not limited to: TF-IDF (Term Frequency-Inverse Document Frequency), TextRank (a keyword extraction method), LexRank (a graph-based ranking algorithm), Luhn's Algorithm (a classic text summarization algorithm), LSA (Latent Semantic Analysis), K-Means Clustering (a distance-based clustering algorithm), MMR (Maximal Marginal Relevance), SentencePosition-Based Extraction (a simple keyword extraction method), etc. These algorithms are used to identify and extract the most representative keywords from the text for subsequent report indexing and searching.
[0088] In the optional example, please refer to Figure 4 , Figure 4 which is a schematic diagram of a report template provided by an embodiment of the present invention. In Figure 4 , {{……}} represents a variable placeholder, and during the conversion process, …… will be replaced with specific data, text, or pictures.
[0089] Among them, {%if municipality %}: This is the start of a conditional statement used to check whether the variable "municipality" is true (usually a boolean value). If the city is a municipality, the content within the conditional statement will be included in the final report.
[0090] {%endif %}: This is the end marker of a conditional statement, indicating that if the "municipality" variable is false, all the content within this conditional statement will not appear in the final report.
[0091] The {%if municipality %} in the second paragraph: This is the start of a conditional statement used to check whether the "municipality" variable is true. If it is true, the following content will be displayed.
[0092] This example is only for illustration, and the content of the report template in the embodiments of the present invention is not limited.
[0093] It should be noted that the execution order of each step in the above method embodiments is not limited by the figures shown, and the execution order of each step is subject to the actual application situation.
[0094] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0095] The present invention automates data processing and report generation through Python scripts, greatly improving the efficiency and accuracy of report generation. By using Tornado to implement Web services to provide standard API tool processing interfaces to facilitate system-level calls, using template engines to implement template file replacement generation, and using NLP technology to automatically generate report summaries and keywords, the readability and professionalism of reports are improved. The above centralized technologies realize full automation and intelligence of data processing and report generation, meeting the needs of high-frequency and real-time report generation;
[0096] The present invention adopts modular design, can easily adapt to different data sources and report formats, has good scalability, and supports hot-swappable plug-ins, such as supporting the output of multiple report formats, realizing Word to PDF conversion through LibreOffice, supporting default .docx format and .pdf format files, etc. In addition, the automated data processing process reduces manual operations, improves data consistency and security, and reduces the risk of data leakage.
[0097] In order to execute the corresponding steps in the above method embodiment and various possible implementation modes, an implementation method of an automatic report generation device is provided below.
[0098] See also Figure 5 , Figure 5 The structure diagram of the automatic report generation device provided by the embodiment of the present invention is shown. The automatic report generation device 200 is applied to a server, and the automatic report generation device 200 includes: a receiving module 210 , an extracting module 220 and a processing module 230 .
[0099] The receiving module 210 is used to receive the conversion request and parse the conversion request to obtain the set output format, JSON form data and report template; the report template predefines the format, style and content layout of the report;
[0100] An extraction module 220, used to extract key data from JSON form data;
[0101] The processing module 230 is used to call the template engine to process key data and report templates to obtain an output report that complies with the set output format.
[0102] Optionally, the key data includes first key data and second key data. When the extraction module 220 is used to extract key data from JSON form data, it can be specifically used to: parse the JSON form data to obtain parsed data; the parsed data includes text data and / or image data; extract the text data in the parsed data to obtain the first key data; extract the image data in the parsed data; if the image data includes a local image path, then based on the local image path, the target local image is obtained and stored in the local cache of the server to obtain a first temporary storage path; if the image data includes an online image URL, then based on the online image URL, the target online image is downloaded and stored in the local cache to obtain a second temporary storage path; if the image data includes a Base64 encoded image, then the Base64 encoded image is converted into a preset image format and stored in the local cache to obtain a third temporary storage path; wherein the second key data includes the first temporary storage path and / or the second temporary storage path and / or the third temporary storage path.
[0103] Optionally, the processing module 230 is used to call the template engine to process key data and report templates to obtain an output report that conforms to the set output format. Specifically, it can be used to: call the template engine to process key data and report templates to obtain a word document report; if the set output format is a word file format, then the word document report is used as the output report; if the set output format is a pdf format, then the word document report is converted into a pdf document report, and the pdf document report is used as the output report.
[0104] Optionally, after the processing module 230 is used to call the template engine to process the key data and the report template to obtain an output report that complies with the set output format, it can also be used to: clean up images stored in the local cache based on the second key data.
[0105] Optionally, if the conversion request also includes summary extraction instructions and keyword extraction instructions, the processing module 230 can also be used to: extract summary information from the output report using an extractive summary algorithm; extract at least one keyword from the output report using a keyword extraction algorithm; insert the summary information and at least one keyword into the beginning or end of the output report to obtain a target output report.
[0106] Optionally, the processing module 230 may also be configured to return the target output report to the requesting end that issued the conversion request.
[0107] Optionally, the processing module 230 may also be configured to return the output report to the requesting end that issued the conversion request.
[0108] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the automatic report generation device 200 described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0109] See also Figure 6 , Figure 6 The electronic device 300 includes a processor 310 , a memory 320 , and a bus 330 , wherein the processor 310 is connected to the memory 320 via the bus 330 .
[0110] The memory 320 may be used to store software programs, for example, software programs corresponding to the automatic report generation device 200 provided in the embodiment of the present invention. The processor 310 executes various functional applications and data processing to implement the automatic report generation method provided in the embodiment of the present invention by running the software programs stored in the memory 320.
[0111] Among them, the memory 320 can be but is not limited to: RAM (Random Access Memory), ROM (Read Only Memory), FLASH (Flash Memory), PROM (Programmable Read-Only Memory), EPROM (Erasable Programmable Read-Only Memory), EEPROM (Electric Erasable Programmable Read-Only Memory), etc.
[0112] The processor 310 may be an integrated circuit chip with signal processing capability. The processor 310 may be a general-purpose processor, including: CPU (Central Processing Unit), NP (Network Processor), etc.; it may also be: DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0113] Understandably, Figure 6The structure shown is for illustration only. The electronic device 300 may also include Figure 6 More or fewer components as shown, or with Figure 6 Different configurations are shown. Figure 6 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0114] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method for automatically generating a report disclosed in the above embodiment is implemented. The computer-readable storage medium can be, but is not limited to, various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a PROM, an EPROM, an EEPROM, a FLASH disk, or an optical disk.
[0115] In summary, the embodiments of the present invention provide a method, device, electronic device and computer-readable storage medium for automatic report generation. First, a conversion request is received, and the conversion request is parsed to obtain a set output format, JSON form data and a report template; the report template predefines the format, style and content layout of the report; then, key data is extracted from the JSON form data; finally, a template engine is called to process the key data and the report template to obtain an output report that conforms to the set output format. In this way, automatic report generation is achieved, saving manpower.
[0116] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A method for automatically generating a report, characterized in that: Applied to a server, the method comprises: Receiving a conversion request, and parsing the conversion request to obtain a set output format, JSON form data, and a report template; the report template predefines the format, style, and content layout of the report; the report template is a word template; Parsing the JSON form data to obtain parsed data; the parsed data includes text data and / or image data; Extracting text data from the parsed data to obtain first key data; Extract the image data from the parsed data; if the image data includes a local image path, obtain a target local image based on the local image path and store the target local image in the local cache of the server to obtain a first temporary storage path; if the image data includes an online image URL, download a target online image based on the online image URL and store the target online image in the local cache to obtain a second temporary storage path; if the image data includes a Base64 encoded image, convert the Base64 encoded image into a preset image format and store it in the local cache to obtain a third temporary storage path; Wherein, the second key data includes the first temporary storage path and / or the second temporary storage path and / or the third temporary storage path; the key data includes the first key data and the second key data; The template engine is called to process the key data and the report template to obtain an output report that complies with the set output format.
2. The method for automatically generating a report according to claim 1, characterized in that: The step of calling the template engine to process the key data and the report template to obtain an output report conforming to the set output format includes: Calling the template engine to process the key data and the report template to obtain a word document report; If the set output format belongs to the word file format, the word document report is used as the output report; If the set output format is PDF format, the word document report is converted into a PDF document report, and the PDF document report is used as the output report.
3. The method for automatically generating a report according to claim 1, characterized in that: After the step of calling the template engine to process the key data and the report template to obtain an output report conforming to the set output format, the method further includes: Based on the second key data, clear the pictures stored in the local cache.
4. The method for automatically generating a report according to claim 1, characterized in that: If the conversion request further includes a summary extraction instruction and a keyword extraction instruction, the method further includes: Extracting summary information from the output report using an extractive summary algorithm; extracting at least one keyword from the output report using a keyword extraction algorithm; The summary information and the at least one keyword are inserted into the beginning or the end of the output report to obtain a target output report.
5. The method for automatically generating a report according to claim 4, characterized in that: The method further comprises: The target output report is returned to the requesting end that issued the conversion request.
6. The method for automatically generating a report according to claim 1, characterized in that: The method further comprises: The output report is returned to the requesting end that issued the conversion request.
7. A report automatic generation device, characterized in that: Applied to a server, the device comprises: A receiving module, used for receiving a conversion request, and parsing the conversion request to obtain a set output format, JSON form data and a report template; the report template predefines the format, style and content layout of the report; the report template is a word template; Extraction module for: Parsing the JSON form data to obtain parsed data; the parsed data includes text data and / or image data; Extracting text data from the parsed data to obtain first key data; Extract the image data from the parsed data; if the image data includes a local image path, obtain a target local image based on the local image path and store the target local image in the local cache of the server to obtain a first temporary storage path; if the image data includes an online image URL, download a target online image based on the online image URL and store the target online image in the local cache to obtain a second temporary storage path; if the image data includes a Base64 encoded image, convert the Base64 encoded image into a preset image format and store it in the local cache to obtain a third temporary storage path; Wherein, the second key data includes the first temporary storage path and / or the second temporary storage path and / or the third temporary storage path; the key data includes the first key data and the second key data; The processing module is used to call the template engine to process the key data and the report template to obtain an output report that conforms to the set output format.
8. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a software program, and when the electronic device is running, the processor executes the software program to implement the automatic report generation method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for automatically generating a report according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Method for generating PDF (Portable Document Format) in rich text form based on template technology
CN114742026A
Property report information issuing method and device, equipment and medium
CN117172218A