A formula engine calculation method, device and medium based on database configuration
By building a formula index table and a rule table in the database, and combining the tree data structure and the bidirectional queue, the applicability problem of complex formula calculation scenarios is solved, and a flexible and convenient formula calculation method is implemented, which is applicable to a variety of calculation scenarios and improves calculation efficiency and compatibility.
Patent Information
- Application Number
- CN202310469895.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-27
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2043-04-27
AI Technical Summary
The existing formula engine calculation method is difficult to adapt to complex formula calculation scenarios, especially the lack of applicability caused by the complexity of formulas and the diversity of calculation requirements in calculation scenarios in different industries.
A database configuration-based method is adopted to build a formula index table and a rule table, establish a nonlinear tree data structure, combine bidirectional queues and linked lists, use the priority of operator symbols and the symmetry of brackets to judge the validity of formula rules, perform traversal and calculation, and realize flexible and universal formula measurement.
It realizes flexible, general and convenient formula calculation, can adapt to a variety of calculation scenarios, improves calculation speed and compatibility, simplifies the formula calculation process, is easy to operate and highly practical.
Smart Images

Figure CN116775644B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data structure and data calculation technology, and in particular to a formula engine calculation method, device and medium based on database configuration. Background Art
[0002] The formulas used in formula engine calculations are extremely complex, containing multiple operators, multiple nested calculation logics, etc., and the formulas are different in different calculation scenarios in the industry. Therefore, it is necessary to provide a formula engine calculation method that is highly applicable and can be used in complex formula calculation scenarios.
[0003] A universal formula calculation table, configured based on a bidirectional queue and tree structure, calculates complex formulas containing multiple operators and nested calculation logic. Formula input is abstracted into a unified code, allowing for the extraction of abstract formulas. This is suitable for complex industry formula calculation scenarios. Bidirectional queues support the insertion and removal of elements at both ends, enabling fast and complete parsing of formula calculations. Using the tree structure to create indexes accelerates formula queries.
[0004] A double-ended queue (Deque) is a linear list that can be stored in two ways: sequentially, using an array, or linked, using a linked list. Both support inserting and removing elements at both ends. Most Deque implementations have no fixed limit on the number of elements they can contain. A double-ended queue provides methods for accessing elements from both ends, including methods for inserting, removing, and inspecting elements.
[0005] A tree is a data structure consisting of a hierarchical set of n (n ≥ 1) nodes. It's called a "tree" because it resembles an upside-down tree, with the root pointing upward and the leaves facing downward. The tree structure stores results, and its most powerful feature is query storage. Using the tree structure to create indexes can speed up queries. Summary of the Invention
[0006] The present invention aims to address the deficiencies of the prior art and provide a formula engine calculation method, device, and medium based on database configuration. The formula engine calculation method of the present invention is flexible, versatile, convenient, easy to operate, highly compatible, and practical.
[0007] The object of the present invention is achieved through the following technical solutions: In a first aspect, an embodiment of the present invention provides a formula engine calculation method based on database configuration, comprising the following steps:
[0008] (1) Constructing a database configuration table, the database configuration table including a formula index table and a formula rule table; the formula index table including an index number, an index name, and a parent index number field name; the formula rule table including an index number, a rule name, a formula code identifier, a formula type, a formula rule, and a formula description field name; an index column in the formula index table corresponding to a plurality of formula rules in the formula rule table, the index column being an index number column;
[0009] (2) reading the index column of the formula index table, and constructing a one-to-many nonlinear tree data structure based on the index number of the index column and its corresponding upper index number;
[0010] (3) performing indexing according to the tree data structure obtained in step (2) to obtain an index number, and querying the input value number of the corresponding formula rule according to the index number;
[0011] (4) According to the index number and input value number passed in step (3), the corresponding formula rule in the formula rule table is searched, the validity of the formula rule is judged according to the symmetry of the multiple brackets of the formula, the formula rule is traversed using the queue and the linked list, and the value corresponding to the input value number is calculated to obtain the measurement result.
[0012] Furthermore, the format of the index number is XYZ; the format of the input value number is letters+numbers.
[0013] Furthermore, if the current index number has no upper-level index number, the upper-level index number corresponding to the current index number is configured as 0 or NULL.
[0014] Furthermore, the formula types include formula input and formula output.
[0015] Furthermore, the step (2) is specifically as follows: reading the index column of the formula index table, determining the corresponding upper-level index number according to the index number of the index column, selecting the index number without an upper-level index number as the root node, traversing the formula index table, and searching for all index numbers corresponding to the root node as child nodes until all index numbers are traversed, so as to construct a one-to-many nonlinear tree data structure.
[0016] Furthermore, the step (4) includes the following sub-steps:
[0017] (4.1) Query the corresponding formula rule in the formula rule table according to the index number passed in step (3), and create a bidirectional queue and a linked list for storing the parsed formula rules;
[0018] (4.2) Establishing priorities for different operator symbols, traversing the formula rules retrieved in step (4.1), adding the input value numbers and operator symbols of the formula rules retrieved in step (3) to the queue and linked list created in step (4.1) in order of their priorities, and judging the validity of the formula rules based on the symmetry of the multiple brackets of the formula rules;
[0019] (4.3) Create a queue for calculation, traverse the formula rules in the linked list obtained at the end of step (4.2), and substitute the JSON format value corresponding to the input value number into the corresponding formula rule for calculation to obtain the measurement result.
[0020] Furthermore, the step (4.2) includes the following sub-steps:
[0021] (4.2.1) Establish priorities for different operators;
[0022] (4.2.2) Traverse the formula rules retrieved in step (4.1): when traversing to a left bracket, add the left bracket to the queue; when traversing to a right bracket, remove the left bracket corresponding to the right bracket from the queue; when traversing to the input value number of the formula rule, directly add the input value number to the linked list; when traversing to an operator, query whether there is an operator with a priority greater than or equal to the operator in the current queue; if so, remove the operator in the queue and add it to the linked list in descending order of priority, and add the currently traversed operator to the queue; otherwise, add the operator to the queue; finally, add the remaining operators in the queue to the linked list in descending order of priority;
[0023] (4.2.3) Determine whether there is a left bracket in the queue finally obtained in step (4.2.2). If so, the formula rule is invalid; otherwise, the formula rule is valid.
[0024] Furthermore, the step (4.3) of traversing the formula rules in the linked list finally obtained in the step (4.2) specifically includes: when traversing to the input value number of the formula rule, directly adding the input value number to the queue; when traversing to the operator symbol, taking out the first two input value numbers at the head of the queue, and calculating according to the input parameter assignment based on the principle of proximity to the operator symbol, and then pushing the calculation result back into the queue.
[0025] A second aspect of an embodiment of the present invention provides a formula engine calculation device based on database configuration, comprising one or more processors for implementing the above-mentioned formula engine calculation method based on database configuration.
[0026] A third aspect of an embodiment of the present invention provides a computer-readable storage medium having a program stored thereon. When the program is executed by a processor, it is used to implement the above-mentioned formula engine calculation method based on database configuration.
[0027] The beneficial effects of the present invention are that, based on the database configuration file, the present invention can not only flexibly configure and customize the formula engine calculation, but also import different calculation rules into the database according to different data business requirements; the present invention uses a tree data structure and a queue stack, which can be compatible with a variety of computer languages, speed up the calculation speed, and simplify the formula calculation process, making it easy to understand, highly versatile, suitable for a variety of formula calculation scenarios, simple to operate, highly practical, and easy to promote. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 It is a flow chart of the formula engine calculation method based on database configuration of the present invention;
[0029] Figure 2 1 is a schematic structural diagram of a formula index table according to an embodiment of the present invention;
[0030] Figure 3 It is a schematic structural diagram of a formula rule table according to an embodiment of the present invention;
[0031] Figure 4 1 is a tree structure diagram of a formula index table according to an embodiment of the present invention;
[0032] Figure 5 This is a diagram showing interface formula rules according to an embodiment of the present invention;
[0033] Figure 6 This is a diagram showing an example of inputting a formula calculation interface according to an embodiment of the present invention;
[0034] Figure 7 This is an example diagram of the output results displayed on the formula calculation interface of one embodiment of the present invention;
[0035] Figure 8 It is a structural diagram of the formula engine calculation device based on database configuration of the present invention. DETAILED DESCRIPTION
[0036] Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. In the following description, when referring to the drawings, like numbers in different figures represent like or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all possible embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present invention, as detailed in the appended claims.
[0037] The terms used in this invention are for the purpose of describing specific embodiments only and are not intended to limit the invention. The singular forms "a," "the," and "the" used in this invention and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0038] It should be understood that although the terms "first," "second," "third," etc. may be used in the present invention to describe various information, such information should not be limited to these terms. These terms are merely used to distinguish information of the same type from one another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present invention. Depending on the context, the term "if" as used herein may be interpreted as "when," "when," or "in response to determining."
[0039] The present invention will be described in detail below with reference to the accompanying drawings. Unless there is any conflict, the features of the following embodiments and implementations may be combined with each other.
[0040] join Figure 1 The formula engine calculation method based on database configuration of the present invention includes the following steps:
[0041] (1) Construct a database configuration table, which includes a formula index table and a formula rule table. The formula index table includes multiple field names such as index number (INDEX_ID), index name (INDEX_NAME), and parent index number (PARENT_INDEX_ID); the formula rule table includes multiple field names such as index number (INDEX_ID), rule name (RULE_CLASS), formula code identifier (VALUE_CODE), formula type (VALUE_TYPE), formula rule (VALUE_RULE), and formula description (DESC).
[0042] The rule name (RULE_CLASS) is the name of the rule represented by the formula; the formula code identifier (VALUE_CODE) is the formula input parameter code identifier.
[0043] It should be understood that the field names included in the formula index table and the formula rule table are not limited to the above-mentioned multiple field names. For example, the formula index table also includes formula index levels (LEVEL) for marking formula index levels, etc.; the formula rule table also includes formula calculation units (UNIT), etc., which can be specifically configured according to actual conditions to construct the formula index table and the formula rule table.
[0044] In this embodiment, the format of the index number is XYZ, for example, 1.2.3. In addition, if the current index number has no upper-level index number, the upper-level index number corresponding to the index number can be configured as 0 or NULL; it should be understood that NULL means no upper-level index number is filled.
[0045] In this embodiment, the formula type includes formula input (INPUT, indicating the input parameter type) and formula output (OUTPUT, indicating the output parameter type).
[0046] Furthermore, the index column in the formula index table corresponds to the formula rules in the plurality of formula rule tables, wherein the index column in the formula index table is an index number (INDEX_ID) column.
[0047] (2) Read the index column of the formula index table, and construct a one-to-many nonlinear tree data structure based on the index number of the index column and its corresponding upper index number.
[0048] It should be understood that by constructing a one-to-many nonlinear tree data structure, it is possible to quickly index and query formula rules on the front-end page.
[0049] Specifically, the index column of the formula index table is read, and the corresponding upper index number is determined according to the index number of the index column. The index number without an upper index number is selected as the root node, and the formula index table is traversed to find all the index numbers corresponding to the root node as child nodes until all the index numbers are traversed to construct a one-to-many nonlinear tree data structure. For example, the constructed nonlinear tree data structure of the formula index table is as follows: Figure 4 As shown, the corresponding front-end interface formula rule display diagram is as follows Figure 5 shown.
[0050] (3) Indexing is performed according to the tree data structure obtained in step (2) to obtain an index number, and the input value number of the corresponding formula rule is queried according to the index number.
[0051] Specifically, according to the tree data structure obtained in step (2), the main node can be quickly indexed to the child node, such as from the main node 2. to its corresponding child node 2.1.1.1.1. In this way, the index number (INDEX_ID) can be obtained, and then the input value number of the corresponding formula rule can be queried by the index number (INDEX_ID), where the number format is defined as: letter + number, such as: A1. It should be understood that when assigning a value to the input value number, it is represented as a value in JSON format, and its format is "input value number: value", for example, A1:100; B1:200; C1:300.
[0052] (4) Query the corresponding formula rule in the formula rule table according to the index number and input value number passed in step (3), judge the validity of the formula rule according to the symmetry of the formula's multiple brackets, use the queue and linked list to traverse the formula rule and calculate according to the value corresponding to the input value number to obtain the measurement result.
[0053] (4.1) Query the corresponding formula rule in the formula rule table according to the index number passed in step (3), and create a bidirectional queue and a linked list for storing the re-parsed formula rules.
[0054] For example, the formula rules found are such as (A1+B1) / 100+C1, [A6*B6*341.215-276.3*B6]*H / I, etc., where A1, A6, etc. are input value numbers.
[0055] (4.2) Establish priorities for different operator symbols, traverse the formula rules queried in step (4.1), add the input value numbers and operator symbols of the formula rules queried in step (3) to the queue and linked list created in step (4.1) in order of their priority, and judge the validity of the formula rule based on the symmetry of the multiple brackets of the formula rule.
[0056] (4.2.1) Set priorities for different operators. For example, multiplication and division have higher precedence than addition and subtraction.
[0057] (4.2.2) Traverse the formula rules retrieved in step (4.1): when traversing to the left bracket, add the left bracket to the queue; when traversing to the right bracket, remove the left bracket corresponding to the right bracket from the queue; when traversing to the input value number of the formula rule, directly add the input value number to the linked list; when traversing to the operator, query whether there is an operator with a priority greater than or equal to the operator in the current queue. If so, remove the operator in the queue and add it to the linked list in descending order of priority, and add the currently traversed operator to the queue; otherwise, add the operator to the queue; finally, add the remaining operators in the queue to the linked list in descending order of priority.
[0058] (4.2.3) Determine whether there is a left bracket in the queue finally obtained in step (4.2.2). If so, the formula rule is invalid; otherwise, the formula rule is valid.
[0059] For example, taking the formula rule [A6*B6*341.215-276.3*B6]*H / I as an example, we first set priorities for different operators. Then, we traverse the formula rule: when we traverse to a left bracket, we add it to the queue; when we traverse to a right bracket, we remove the left bracket corresponding to the right bracket from the queue; when we traverse to the input value number of the formula rule, we directly add the input value number to the linked list; when we traverse to an operator, we check whether there is an operator with a priority greater than or equal to the operator in the current queue. If so, we remove the operator in the queue and add it to the linked list in descending order of priority. At the same time, we add the currently traversed operator to the queue; otherwise, we add the operator to the queue; finally, we add the remaining operators in the queue to the linked list in descending order of priority. The resulting linked list contains: A6B6*341.215*276.3B6*-H*I / . Finally, check whether there is an open bracket in the current queue. If so, the formula rule is invalid; otherwise, the formula rule is valid. This method is compatible with various bracket types. If there are remaining brackets in the queue after the traversal is completed, the formula rule is invalid.
[0060] (4.3) Create a queue for calculation, traverse the formula rules in the linked list obtained at the end of step (4.2), and substitute the JSON format value corresponding to the input value number into the corresponding formula rule for calculation to obtain the measurement result.
[0061] The format of the input value number is letters + numbers, such as A1, B1, and C1. The format of the value in JSON format corresponding to the input value number is "input value number:numeric value", such as A1:100; B1:200; C1:300.
[0062] In this embodiment, traversing the formula rules in the linked list finally obtained in step (4.2) specifically includes: when traversing to the input value number of the formula rule, directly adding the input value number to the queue; when traversing to the operator symbol, taking out the first two input value numbers at the head of the queue, and performing calculations based on the input parameter assignment according to the principle of proximity to the operator symbol, and then pushing the calculation results back into the queue. It should be noted that when taking out the first two input value numbers at the head of the queue, it should be understood that the queue used for calculation follows the first-in, last-out principle.
[0063] For example, if the formula rule in the linked list finally obtained in step (4.2) is A1B1+C1D1 / +, according to the corresponding JSON format data input: {A1:1, B1:2, C1:3, D1:4}, the calculation is performed using the queue, specifically: the formula rule A1B1+C1D1 / + is traversed: first traverse to A1 and add it to the queue; when traversing to B1, add B1 to the queue; when traversing to "+", take out the first two input value numbers in the queue, i.e. A1 and B1, and calculate, A1+B1= 1+2=3, the calculation result 3 is pushed back into the queue; when traversing to C1, C1 is added to the queue; when traversing to D1, D1 is added to the queue; when traversing to " / ", the first two input value numbers at the head of the queue, namely D1 and C1, are taken out for calculation, and the calculation is performed according to the principle of proximity to the operation symbol, namely C1 / D1=3 / 4, and the calculation result is pushed into the queue; when traversing to "+", the first two input value numbers at the head of the queue, namely 3 and 3 / 4, are taken out for calculation, namely 3+3 / 4, and the result is the measurement result.
[0064] The present invention is based on flexible database formula configuration, and can customize the formulas that need to be imported, the field list of the corresponding input format text, the imported field name, etc. in a diversified manner; the present invention also has good compatibility with the engineering development framework, and is convenient and efficient in reading formula configuration and parsing calculation formulas, has strong practicality, is simple to operate, and is easy to promote.
[0065] The formula engine calculation method based on database configuration of the present invention is described in detail below according to the embodiments, and the purpose and effect of the present invention will become more obvious.
[0066] In this embodiment, taking the business scenario of calculating the relevant data of a bank's environmental benefits as an example, the data in JSON format is imported into the database based on a YAML (yet another markup language) configuration file. Specifically, the following steps are included:
[0067] (1) According to the specified rules, a database configuration table is constructed, that is, a formula index table and a formula rule table of the database configuration table are constructed.
[0068] Configure the fields in the formula index table: index number (INDEX_ID), index name (INDEX_NAME), parent index number (PARENT_INDEX_ID), formula index level (LEVEL), such as Figure 2 shown.
[0069] Configure the fields in the formula rule table: index number (INDEX_ID), rule name (RULE_CLASS), formula code identifier (VALUE_CODE), formula type (VALUE_TYPE), formula rule (VALUE_RULE), formula description (DESC), formula calculation unit (UNIT), such as Figure 3 shown.
[0070] (2) Read the index column of the formula index table and construct a one-to-many nonlinear tree data structure based on the index number and its corresponding upper index number.
[0071] Read the formula index table of the database configuration table and splice the corresponding tree structure. The specific process is as follows:
[0072] (2.1) Read the first field list of the formula index table: index number (INDEX_ID).
[0073] (2.2) Read the second field list of the formula index table: index name (INDEX_NAME).
[0074] (2.3) Read the third field list of the formula index table: parent index number (PARENT_INDEX_ID).
[0075] (2.4) Indexes are in a cascading relationship. For example, index 2.1.1 is a sub-index of 2.1. Therefore, a tree data structure is constructed for index query: the root node at the top level is selected, that is, a node without an upper index number is selected as the root node. Recursive calls are made to find all child nodes of the root node, generate a constructed node, and add the constructed node to the root node.
[0076] The nonlinear tree data structure after construction is as follows Figure 4 shown.
[0077] (3) The tree data structure constructed in step (2) is indexed to obtain an index number, and then the input value number of the corresponding formula rule is queried through the index number. The number format is defined as: letter + number, such as: A1; the input value of the interface is then concatenated with multiple "input value number: value" and the index number into the following JSON format as the API input for querying the formula result, such as Figure 6 As shown, the formula calculation interface shows an input example diagram.
[0078] (4) Query the corresponding formula rule in the formula rule table according to the index number and input value number passed in step (3), judge the validity of the formula rule according to the symmetry of the formula's multiple brackets, and use the queue and linked list to traverse and parse the formula rule. Finally, substitute the JSON format value corresponding to the input value number into the corresponding one or more formula rules for calculation to obtain the measurement result. The detailed process is as follows:
[0079] (4.1) Based on the index number passed in step (3), such as 1.7.6, the corresponding formula rule in the formula rule table is searched (if there are multiple rules, they are separated by the "&" symbol). For example, if the formula rule found is [A6*B6*341.215-276.3*B6]*H / I, where A6 represents a certain input value number, a bidirectional queue and a linked list are created to store the parsed formula rule.
[0080] (4.2) First, set priorities for different operators. Multiplication and division have equal priorities, addition and subtraction have equal priorities, and multiplication and division have higher priorities than addition and subtraction. Then traverse the formula rule: when traversing to the left bracket, add the left bracket to the queue; when traversing to A6, directly add the input value number A6 to the linked list; when traversing to "*", there is no operator with a priority greater than or equal to "*" in the queue at this time, so add "*" to the queue; when traversing to B6, directly add the input value number B6 to the linked list; when traversing to "*" again, there is a "*" with the same priority as the "*" in the queue at this time, so remove the operator "*" from the queue and add it to the linked list, and add the currently traversed "*" to the queue at the same time; when traversing to 341.215, add 341 to the queue. .215 is directly added to the linked list. At this time, the queue contains: [*, and the linked list contains: A6B6*341.215; when traversing to "-", there is an operator "*" with a priority greater than "-" in the current queue, so the operator "*" in the queue is removed and added to the linked list, and the currently traversed "-" is added to the queue. At this time, the queue contains: [-, and the linked list contains: A6B6*341.215*; when traversing to 276.3, 276.3 is directly added to the linked list; when traversing to "*", there is no operator with a priority greater than or equal to "*" in the current queue, so the operator "*" is added. Add to the queue, now the queue has: [-*, now the linked list has: A6B6*341.215*276.3; when traversing to B6, add the input value number B6 directly to the linked list; when traversing to the right bracket, remove the left bracket corresponding to the right bracket from the queue; when traversing to "*" again, there is an operator with the same priority as "*" in the current queue, so remove the operator "-*" in the queue and add it to the linked list in descending order of priority, and add the currently traversed "*" to the queue. Now the queue has: *, now the linked list has: A6B6*341.215*276.3B6*- ; When traversing to H, the input value number H is directly added to the linked list; when traversing to " / ", there is an operator "*" with the same priority as " / " in the queue, so the "*" in the queue is removed and added to the queue, and the currently traversed " / " is added to the queue; when traversing to I, the input value number I is directly added to the linked list. At this time, the queue contains: / , and the linked list contains: A6B6*341.215*276.3B6*-H*I; finally, the operator " / " in the queue is added to the linked list, and finally we can get: an empty queue and a linked list with the content A6B6*341.215*276.3B6*-H*I / .Finally, the current queue is judged to determine whether there is a left bracket in it. At this time, there is no left bracket, so the formula rule is valid; it should be understood that if there is still a left bracket in the queue, the formula rule is invalid and subsequent calculations cannot be performed.
[0081] (4.3) Establish a queue for calculation, traverse the formula rules in the linked list obtained at the end of step (4.2), substitute the JSON format value corresponding to the input value number obtained in step (3) into the corresponding formula rule calculation, and you can get the measurement result.
[0082] Taking the formula rule A6B6*341.215*276.3B6*-H*I / after parsing in step (4.2) above as an example, traverse the parsed formula list. If it is an operator, take the first two formula numbers in the queue, assign values based on the input parameters, perform the operation, and push the result back into the stack. If it is a formula number, add it directly to the queue. It should be noted that this queue follows the principle of first-in, last-out.
[0083] Specifically, first put the corresponding values of A6 and B6 into the queue. When traversing to "*", remove the values of A6 and B6 from the queue and calculate the result of A6*B6, and put the calculated result back into the queue; continue traversing and add 341.215 to the queue. Then, when traversing to "*", remove the two values at the head of the queue: A6*B6 and 341.215, calculate the result of A6*B6*341.215 and add the result to the queue; continue traversing and add 276.3 and B6 to the head of the queue. When traversing to "*", add 2 76.3, B6 takes the result of calculating 276.3*B6 and adds it to the head of the queue. When the traversal reaches "-", the result of calculating A6*B6*3341.215 - 276.3*B6 is calculated according to the principle of the nearest operator and added to the queue. Similarly, the value of [A6*B6*3341.215 - 276.3*B6]*H is calculated and added to the queue. Finally, when the traversal reaches " / ", [A6*B6*3341.215 - 276.3*B6]*H / I is calculated.
[0084] Finally, the output results are displayed on the front-end page, such as Figure 7 As shown, the method of the present invention is flexible, universal, convenient, highly compatible and practical.
[0085] The above examples are illustrative and should not be construed as limiting the present invention. The scope of patent protection of the present invention includes, but is not limited to, the above specific example implementation methods. Any modification, replacement, and variation of the database table configuration format and the JSON format during the calculation process that conforms to the claims of the present invention and is carried out by any person skilled in the art within the scope of the present invention according to different business scenarios and example data shall fall within the scope of patent protection of the present invention.
[0086] According to the formula index number, formula index name, and superior index number, a formula index table is constructed. According to the formula index number, formula input / output name, value type (formula input / formula output) and formula expression, a formula rule table is constructed. First, the index numbers of all index tables are read out. According to their connection with the superior index number, a cascade relationship between indexes is established through recursive operation to generate a tree format data structure. According to the formula index number finally selected by the user, the corresponding formula rule is read and returned to the page. Finally, the front end passes the formula input name, the input value of the corresponding user in the calculation interface, and the formula index number in a JSON format data structure, and the corresponding rule is substituted into the formula rule engine for re-analysis and calculation. Compared with the existing technology, the method of the present invention is based on the MySQL database table configuration, can calculate complex formulas, and can verify the correctness of the input formula. It is simple to operate and is applicable to scenarios where various types of formulas are calculated. Moreover, the method is based on the configuration of flexible index numbers, can randomly customize one or more formula rules and formula input and output field names that need to be calculated, etc., has fast calculation, strong practicality, simple operation, and is easy to promote.
[0087] Corresponding to the aforementioned embodiment of the formula engine calculation method based on database configuration, the present invention also provides an embodiment of a formula engine calculation device based on database configuration.
[0088] See also Figure 8 An embodiment of the present invention provides a formula engine calculation device based on database configuration, including one or more processors for implementing the formula engine calculation method based on database configuration in the above embodiment.
[0089] The embodiment of the formula engine calculation device based on database configuration of the present invention can be applied to any device with data processing capabilities, and the device with data processing capabilities can be a device or apparatus such as a computer. The device embodiment can be implemented through software, or through hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of any device with data processing capabilities in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory for execution. From the hardware level, if Figure 8As shown, this is a hardware structure diagram of any device with data processing capability where the formula engine calculation device based on database configuration of the present invention is located, except Figure 8 In addition to the processor, memory, network interface, and non-volatile memory shown, any device with data processing capabilities in which the apparatus in the embodiment is located may also include other hardware, generally based on the actual functions of the device with data processing capabilities, which will not be described in detail.
[0090] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0091] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and 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 network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present invention. A person of ordinary skill in the art can understand and implement the present invention without inventive work.
[0092] An embodiment of the present invention further provides a computer-readable storage medium having a program stored thereon. When the program is executed by a processor, the formula engine calculation method based on database configuration in the above embodiment is implemented.
[0093] The computer-readable storage medium may be an internal storage unit of any device with data processing capabilities described in any of the aforementioned embodiments, such as a hard disk or memory. The computer-readable storage medium may also be any device with data processing capabilities, such as a plug-in hard disk, a smart media card (SMC), an SD card, a flash card, etc. equipped on the device. Furthermore, the computer-readable storage medium may also include both an internal storage unit of any device with data processing capabilities and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by any device with data processing capabilities, and may also be used to temporarily store data that has been output or is to be output.
[0094] The above embodiments are intended only to illustrate the design concepts and features of the present invention. Their purpose is to enable those skilled in the art to understand the contents of the present invention and implement them accordingly. The scope of protection of the present invention is not limited to the above embodiments. Therefore, any equivalent changes or modifications made based on the principles and design concepts disclosed in the present invention are within the scope of protection of the present invention.
Claims
1. A formula engine calculation method based on database configuration, characterized in that: The following steps are involved: (1) Constructing a database configuration table, the database configuration table including a formula index table and a formula rule table; the formula index table including an index number, an index name, and a parent index number field name; the formula rule table including an index number, a rule name, a formula code identifier, a formula type, a formula rule, and a formula description field name; an index column in the formula index table corresponding to a plurality of formula rules in the formula rule table, the index column being an index number column; (2) reading the index column of the formula index table, and constructing a one-to-many nonlinear tree data structure based on the index number of the index column and its corresponding upper index number; (3) performing indexing according to the tree data structure obtained in step (2) to obtain an index number, and querying the input value number of the corresponding formula rule according to the index number; (4) According to the index number and input value number passed in step (3), the corresponding formula rule in the formula rule table is searched, the validity of the formula rule is judged according to the symmetry of the multiple brackets of the formula, the formula rule is traversed using the queue and the linked list, and the value corresponding to the input value number is calculated to obtain the measurement result.
2. The formula engine calculation method based on database configuration according to claim 1, characterized in that: The format of the index number is XYZ; the format of the input value number is letter+number.
3. The formula engine calculation method based on database configuration according to claim 1, characterized in that: If the current index number has no upper-level index number, the upper-level index number corresponding to the current index number is configured as 0 or NULL.
4. The formula engine calculation method based on database configuration according to claim 1, characterized in that: The formula types include formula input and formula output.
5. The formula engine calculation method based on database configuration according to claim 1, characterized in that: The step (2) is specifically as follows: reading the index column of the formula index table, determining the corresponding upper-level index number according to the index number of the index column, selecting the index number without an upper-level index number as the root node, traversing the formula index table, and searching for all index numbers corresponding to the root node as child nodes until all index numbers are traversed, so as to construct a one-to-many nonlinear tree data structure.
6. The formula engine calculation method based on database configuration according to claim 1, characterized in that: The step (4) includes the following sub-steps: (4.1) Query the corresponding formula rule in the formula rule table according to the index number passed in step (3), and create a bidirectional queue and a linked list for storing the parsed formula rules; (4.2) Establishing priorities for different operator symbols, traversing the formula rules retrieved in step (4.1), adding the input value numbers and operator symbols of the formula rules retrieved in step (3) to the queue and linked list created in step (4.1) in order of their priorities, and judging the validity of the formula rules based on the symmetry of the multiple brackets of the formula rules; (4.3) Create a queue for calculation, traverse the formula rules in the linked list obtained at the end of step (4.2), and substitute the JSON format value corresponding to the input value number into the corresponding formula rule for calculation to obtain the measurement result.
7. The formula engine calculation method based on database configuration according to claim 6, characterized in that: The step (4.2) includes the following sub-steps: (4.2.1) Establish priorities for different operators; (4.2.2) Traverse the formula rules found in step (4.1): when a left bracket is found, add the left bracket to the queue; When traversing to a right bracket, the left bracket corresponding to the right bracket is removed from the queue; when traversing to the input value number of the formula rule, the input value number is directly added to the linked list; when traversing to an operator, check whether there is an operator with a priority greater than or equal to the operator in the current queue. If so, remove the operator in the queue and add it to the linked list in descending order of priority, and add the currently traversed operator to the queue; otherwise, add the operator to the queue; finally, add the remaining operators in the queue to the linked list in descending order of priority; (4.2.3) Determine whether there is a left bracket in the queue finally obtained in step (4.2.2). If so, the formula rule is invalid; Otherwise, the formula rule is valid.
8. The formula engine calculation method based on database configuration according to claim 6, characterized in that: The step (4.3) of traversing the formula rules in the linked list finally obtained in the step (4.2) specifically includes: when traversing to the input value number of the formula rule, directly adding the input value number to the queue; when traversing to the operator symbol, taking out the first two input value numbers at the head of the queue, and calculating according to the input parameter assignment based on the principle of proximity to the operator symbol, and then pushing the calculation result back into the queue.
9. A formula engine calculation device based on database configuration, characterized in that: It includes one or more processors, used to implement the formula engine calculation method based on database configuration according to any one of claims 1-8.
10. A computer-readable storage medium, characterized in that A program is stored thereon, which, when executed by a processor, is used to implement the formula engine calculation method based on database configuration as described in any one of claims 1-8.
Citation Information
Patent Citations
Lightweight rule engine processing method and device
CN113312392A
Data query method and device based on tree structure, electronic equipment and storage medium
CN115269605A