Multi-rate charging method, readable storage medium and electric energy meter
By using a rate change point array and a binary search algorithm in the electricity meter, the problem of excessive memory usage in traditional multi-rate electricity meters is solved, achieving memory optimization and performance improvement, reducing hardware costs and improving billing efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- QINGDAO TOPSCOMM COMM
- Filing Date
- 2026-03-04
- Publication Date
- 2026-05-01
AI Technical Summary
Traditional multi-rate electricity meters consume a lot of memory for rate data, which increases hardware costs and limits the scalability of system functions.
Rate data is stored using an array of rate change points. By mapping time codes and rate index values, time processing is simplified to integer operations. Combined with a binary search algorithm, the rate index value is located, reducing memory usage and improving processing efficiency.
It reduces memory usage, saves hardware costs, improves processing efficiency and billing accuracy, and optimizes the performance of resource-constrained embedded systems.
Smart Images

Figure CN121963353A_ABST
Abstract
Description
A multi-rate billing method, a readable storage medium, and an energy meter Technical Field
[0001] This invention relates to the field of embedded software technology for electricity meters, and more specifically, to a multi-rate billing method, a readable storage medium, and an electricity meter. Background Technology
[0002] With the rapid development of smart grids, multi-rate functionality has become a standard requirement for electricity meters. By applying different electricity prices (such as peak, off-peak, and valley rates) at different times, it effectively promotes the balance of power load. As the core device for electricity metering, smart meters are usually based on resource-constrained embedded systems (such as single-phase or three-phase meters), and their software needs to implement complex time-of-use billing functions under limited memory conditions.
[0003] In traditional multi-rate electricity meter implementations, rate data is typically stored in its entirety. Existing technologies use fixed arrays or structures to store multiple rate tables, each containing fields such as rate ID, start time, end time, and rate value. However, traditional multi-rate solutions suffer from high memory consumption when storing and processing rate data, which not only increases hardware costs but also limits the system's scalability.
[0004] In summary, the high memory consumption of rate data in traditional multi-rate electricity meters is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a multi-rate billing method, a readable storage medium, and an energy meter, which can solve the problem of excessive memory usage for rate data in traditional multi-rate energy meters.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] A multi-rate billing method includes:
[0008] The system stores rate data, which includes multiple rate change points. These rate change points are arranged in chronological order to form a rate change point array. Each rate change point includes a time code and a rate index value corresponding to the time code. The time code is an integer.
[0009] Obtain the current time of the clock, and calculate a time value based on the current time, wherein the time value represents the total number of minutes in a day; the time value is an integer.
[0010] Locate the largest time code in the rate change point array that is not greater than the current time value, and obtain the corresponding rate index value;
[0011] Obtain the current rate index value and output the rate value, thereby enabling electricity billing based on the rate value.
[0012] Alternatively, a time value can be calculated based on the current time as follows: Time value = number of hours of the current clock × 60 + number of minutes of the current clock.
[0013] Optionally, the method includes: setting a rate index table, the rate index table being used to record the mapping relationship between the rate index value and the rate value; the rate index value being mapped to a rate value; after locating the largest time code not greater than the current time value from the rate change point array, obtaining the rate index value corresponding to the time code, and determining the rate value based on the rate index value.
[0014] Optionally, the rate index value is a positive integer.
[0015] Optionally, methods for locating the time code that is the largest integer value not greater than the current time include:
[0016] Take two time codes as the left and right endpoint values, and calculate the average of the two time codes; compare the calculated average with the time value.
[0017] If the average is less than the time value, then increase the left endpoint value and compare again.
[0018] If the average is greater than the time value, then lower the right endpoint value and compare again.
[0019] Until the largest integer value not greater than the current time is located, the time code is determined.
[0020] Optionally, in the method of taking two time codes as the left endpoint value and the right endpoint value, the time code with the smallest value is preferred as the left endpoint value; and / or, the time code with the largest value is preferred as the right endpoint value.
[0021] Optionally, a boundary check is performed before locating the largest integer value that is not greater than the current time. The boundary check method includes: determining whether the current time code is greater than or equal to the largest time code or less than the smallest time code in the rate change point array; if so, it is considered to be in a cross-day period, and the rate index value corresponding to the last change point is directly returned; if not, the largest integer value that is not greater than the current time is located.
[0022] A readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the multi-rate billing method as described above.
[0023] Optionally, the readable storage medium stores:
[0024] The rate change table is used to record time codes and the corresponding rate index values;
[0025] A rate index table is used to record rate index values and the rate values corresponding to the rate index values;
[0026] The rate index value is used to obtain the rate value corresponding to the time code.
[0027] An electricity meter includes a memory, a processor, and a clock module, characterized in that the memory stores instructions, which, when executed by the processor, implement the multi-rate billing method as described above.
[0028] By using the multi-rate billing method provided by this invention, the method begins in step S101: storing an array of rate change points. This array only stores the time of rate change and the corresponding rate value, rather than the full time period data. By compressing the storage structure, data redundancy is significantly reduced, resulting in lower memory usage and thus saving hardware costs.
[0029] Next, in step S102, the current time is obtained and the time value is calculated, simplifying time processing into integer operations. In this step, the time is converted into integer minutes, simplifying the time comparison operation, reducing computational complexity, and improving processing efficiency.
[0030] Then, in step S103, the system accesses the stored array of rate change points and uses a location algorithm to find the last change point that is no greater than the current time. This efficient search method improves the accuracy and speed of rate switching and avoids traversing all rate tables.
[0031] Finally, in step S104, the rate value is output for billing.
[0032] Using the above method, memory optimization and performance improvement were achieved in resource-constrained embedded systems, solving the problem of excessive memory consumption of rate data in traditional multi-rate energy meters. Attached Figure Description
[0033] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0034] Figure 1 is a flowchart of an embodiment of a multi-rate billing method provided by the present invention;
[0035] Figure 2 is a flowchart of another embodiment of a multi-rate billing method provided by the present invention. Detailed Implementation
[0036] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0037] The core of this invention is to provide a multi-rate billing method, a readable storage medium, and an energy meter, aiming to reduce memory usage in embedded systems and improve billing efficiency by optimizing data storage and lookup algorithms.
[0038] Please refer to Figures 1 and 2. A multi-rate billing method includes: storing rate data, which includes multiple rate change points; arranging the multiple rate change points in chronological order to form a rate change point array, each rate change point including a time code and a rate index value corresponding to the time code; the time code being an integer; obtaining the current time of a clock, calculating a time value based on the current time, the time value representing the total number of minutes in a day; the time value being an integer; locating the largest time code in the rate change point array that is not greater than the current time value, and obtaining the corresponding rate index value; obtaining the current rate index value and outputting the rate value, thereby billing electricity based on the rate value.
[0039] Specifically, referring to Figure 1, the method begins with step S101: storing an array of rate change points. This array only stores the time of rate change and the corresponding rate value, rather than the full time period data. By compressing the storage structure, data redundancy is significantly reduced, resulting in lower memory usage and thus saving hardware costs.
[0040] Next, in step S102, the current time is obtained and the time value is calculated, simplifying time processing into integer operations. In this step, the time is converted into integer minutes, simplifying the time comparison operation, reducing computational complexity, and improving processing efficiency.
[0041] Then, in step S103, the system accesses the stored array of rate change points and uses a location algorithm to find the last change point that is no greater than the current time. This efficient search method improves the accuracy and speed of rate switching and avoids traversing all rate tables.
[0042] Finally, in step S104, the rate value is output for billing.
[0043] Using the above method, memory optimization and performance improvement were achieved in resource-constrained embedded systems, solving the problem of excessive memory consumption of rate data in traditional multi-rate energy meters.
[0044] In some embodiments, a method for calculating a time value based on the current time is: Time value = (Current hour of the clock) × 60 + (Current minute of the clock). This simplifies the time period into simple minutes using simple arithmetic operations, thereby reducing algorithm complexity, improving code maintainability, and reducing the instruction cycle of the embedded system.
[0045] In some embodiments, referring to Table 1, the method includes: setting a rate index table, the rate index table being used to record the mapping relationship between the rate index value and the rate value; the rate index value being mapped to a rate value; after locating the largest time code not greater than the current time value from the rate change point array, obtaining the rate index value corresponding to the time code, and determining the rate value based on the rate index value.
[0046] Table 1: Rate Index Table
[0047] Because the same rate value can be used for different time periods, duplicate rate values are stored in memory, and these rate values are often quite complex. The above setup stores rate indices in the change point array instead of the direct rate values. After locating a change point, the system first retrieves the index and then queries the mapping table to obtain the rate value, further reducing storage space.
[0048] In some embodiments, the rate index value is a positive integer. See Table 2; for example, a rate index value of 0-7 represents 8 different rates, reducing array size and improving storage efficiency.
[0049] Table 2: Time Encoding Table
[0050] In some embodiments, a method for locating the largest integer value not greater than the current time includes: taking two time codes as left endpoint values and right endpoint values, and calculating the average of the two time codes; comparing the calculated average with the time value; if the average is less than the time value; increasing the left endpoint value and comparing again; if the average is greater than the time value; decreasing the right endpoint value and comparing again; until the largest integer value not greater than the current time is located.
[0051] Specifically, the binary search is detailed in step S201: initializing the left and right endpoints, calculating the intermediate point, comparing time codes and adjusting the endpoints, and repeating until the target is located. When there are many time codes, efficiency can be significantly improved and time reduced. Through dynamic adjustment, the search accuracy is ensured, missed detections are avoided, and billing accuracy is improved.
[0052] In some embodiments, the method of taking two time codes as the left endpoint value and the right endpoint value preferentially selects the smallest time code as the left endpoint value; and / or preferentially selects the largest time code as the right endpoint value.
[0053] By adopting the above settings, we can ensure that the search range covers the entire day, optimize the search starting point, reduce unnecessary comparisons, and improve algorithm efficiency.
[0054] In some embodiments, a boundary check is performed before locating the largest integer value that is not greater than the current time. The boundary check method includes: determining whether the current time code is greater than or equal to the largest time code in the rate change point array or less than the smallest time code; if so, it is considered to be in a cross-day period, and the rate index value corresponding to the last change point is directly returned; if not, the largest integer value that is not greater than the current time is located.
[0055] Referring to the flowchart in Figure 2, boundary checks are performed before the search. The current time is checked to see if it is less than the minimum change point or greater than the maximum change point; if so, the end index is used directly. For example, as shown in Table 2, when the time is between 23:20 and 00:30, the rate value is returned directly, thereby improving system robustness and avoiding out-of-bounds search errors.
[0056] This embodiment provides a readable storage medium storing a computer program. When executed by a processor, the computer program implements the multi-rate billing method described above. Storing the computer program on a readable storage medium allows the aforementioned low-memory-occupancy multi-rate billing method to be solidified and easily deployed to various types of electricity meters, improving the versatility and portability of the solution.
[0057] Preferably, the readable storage medium stores: a rate change table for recording time codes and corresponding rate index values; and a rate index table for recording rate index values and corresponding rate values; wherein the rate index values are used to retrieve the rate value corresponding to the time code. Storing the rate change table and rate index table separately in the storage medium achieves clear separation of data structures, facilitating independent updates and maintenance while maintaining storage efficiency.
[0058] The electricity meter in this embodiment includes a memory, a processor, and a clock module. The memory stores instructions, and when the processor executes the instructions, it implements the multi-rate billing method described above. This provides an electricity meter product with low memory usage and multi-rate billing functionality. By integrating a memory, processor, and clock module, it achieves efficient and accurate time-of-use billing, reduces hardware costs, and enhances market competitiveness.
[0059] A preferred embodiment of the multi-rate billing method is described below:
[0060] Get the current time and encode it into minutes: Read the system time, get the number of hours and minutes, calculate and save the time code (total minutes). The calculation formula is: Time code = number of hours * 60 + number of minutes.
[0061] Binary search in the rate change point array: Using binary search instead of traditional traversal search significantly improves data retrieval efficiency; the larger the data scale, the greater the efficiency improvement. When the number of time periods is greater than or equal to 10, the search efficiency increases by more than 1.5 times. Before performing the binary search, a boundary check is first performed. When the time is greater than or equal to 1400 (23:20) or less than 30 (00:30), the search loop is not entered, and the time period is considered to be from 23:20 to 00:30 the next day. The rate index corresponding to the time change point 1400 is used.
[0062] Find the last rate change point that is not greater than the current time: This is achieved by continuously comparing time change points using a binary search method. The initial indices of the left and right endpoints correspond to the first and last rate change points in the rate change point array, respectively. The middle index is obtained by dividing the sum of the left and right endpoint indices by 2 and rounding up. This right shift method replaces division, allowing for faster calculation. Compare the time change point corresponding to the middle index with the current time. If they are equal, this time change point is the last rate change point not greater than the current time. If they are not equal, compare the time change point relative to the current time. If the time change point is less than the current time, set the left endpoint index to the middle index plus 1; if the time change point is only greater than the current time, set the right endpoint index to the middle index minus 1; if the time change point of the middle index is not only greater than the current time but also has a previous time change point less than or equal to the current time, then the time change point corresponding to the middle index minus 1 is the last rate change point not greater than the current time. Continuously adjust the left and right endpoint indices and the middle index until the correct time change point is found.
[0063] To obtain the rate index value of the rate change point: determine the time period based on the time code, and obtain the rate index corresponding to the time period through the rate change point array.
[0064] Query the rate value mapping table: Find the rate value corresponding to the obtained rate index in the rate index value and rate value mapping table.
[0065] Returns the current rate value: Returns the rate value obtained from the rate mapping table.
[0066] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. Any combination of all embodiments provided by this invention is within the scope of protection of this invention and will not be elaborated upon here.
[0067] The multi-rate billing method, readable storage medium, and energy meter provided by this invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this invention. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this invention. It should be noted that those skilled in the art can make various improvements and modifications to this invention without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this invention.
Claims
1. A multi-rate billing method, characterized in that, include: The system stores rate data, which includes multiple rate change points. These rate change points are arranged in chronological order to form a rate change point array. Each rate change point includes a time code and a rate index value corresponding to the time code. The time code is an integer. The system obtains the current time of a clock and calculates a time value based on the current time. The time value represents the total number of minutes in a day. The time value is an integer. The system locates the largest time code in the rate change point array that is not greater than the current time value and obtains the corresponding rate index value. The system obtains the current rate index value and outputs the rate value, thereby using the rate value for electricity billing.
2. The multi-rate billing method according to claim 1, characterized in that, The method to calculate a time value based on the current time is: Time value = current hour of the clock × 60 + current minute of the clock.
3. The multi-rate billing method according to claim 1, characterized in that, The method includes: setting a rate index table, which is used to record the mapping relationship between rate index values and rate values; each rate index value is mapped to a rate value; after locating the largest time code not greater than the current time value from the rate change point array, obtaining the rate index value corresponding to the time code, and determining the rate value based on the rate index value.
4. The multi-rate billing method according to claim 3, characterized in that, The rate index value is a positive integer.
5. The multi-rate billing method according to claim 1, characterized in that, The method for locating the largest integer value not greater than the current time includes: taking two time codes as the left endpoint value and the right endpoint value, and calculating the average of the two time codes; comparing the calculated average with the time value; if the average is less than the time value, increasing the left endpoint value and comparing again; if the average is greater than the time value, decreasing the right endpoint value and comparing again; until the largest integer value not greater than the current time is located.
6. The multi-rate billing method according to claim 5, characterized in that, The method of taking two time codes as the left endpoint value and the right endpoint value prioritizes selecting the time code with the smallest time code as the left endpoint value; and / or prioritizes selecting the time code with the largest time code as the right endpoint value.
7. The multi-rate billing method according to claim 5, characterized in that, Before locating the largest integer value that is not greater than the current time, a boundary check is performed. The boundary check method includes: determining whether the current time code is greater than or equal to the largest time code in the rate change point array or less than the smallest time code; if so, it is considered to be in a cross-day period, and the rate index value corresponding to the last change point is directly returned; if not, the largest integer value that is not greater than the current time is located.
8. A readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the multi-rate billing method as described in any one of claims 1 to 7.
9. The readable storage medium according to claim 8, characterized in that, The readable storage medium stores: a rate change table for recording time codes and rate index values corresponding to the time codes; and a rate index table for recording rate index values and rate values corresponding to the rate index values; wherein the rate index values are used to obtain the rate values corresponding to the time codes.
10. An electricity meter, comprising a memory, a processor, and a clock module, characterized in that, The memory stores instructions that, when executed by the processor, implement the multi-rate billing method as described in any one of claims 1 to 7.