I am writing a program in Python3, and one of the functions that I need is to calculate the value by reference to two datetime values, as described below.
Imagine a day divided into 8 three-hour pieces, always starting at 0000 UTC. Each of these pieces will have a value of x, which will vary from piece to piece, but will not change inside the fragment itself.
I need to pass the initial datetime object and the final datetime object to the function, and return the value for the function, which is the product of x and the number of minutes in this fragment between the starting datetime object and the datetime end object.
So, for example, if the start time is 0100 UTC, and the end time was 0200 UTC, and the x value for 0000 UTC is 0300 UTC chunk was 20, then this is easy, the value is 60 * 20 = 1200.
If the start time was 0100 UTC and the end time was 0400 UTC, and the x value for 0000 UTC - 0300 UTC chunk was 20, and the x value for 0300 UTC - 0600 UTC chunk was 30, then the sum is be (20 * 120) + ( 60 * 30) = 4200
Start and end times can span several pieces, or even several days.
What I propose to do is set the "day_list" of the dictionaries, where each dictionary {"startchunk_time": # (for example, 0000 UTC), "endchunk_time": # (for example, 0300 UTC), "x": value}. Then the pseudo code will be:
def find_value(start_time, end_time):
test_time = start_time
while test_time < end_time:
for item in day_list:
if test_time > itemstartchunk_time and test_time < endchunk_time:
This means that the whole day_list is repeated each time, even if the corresponding value is found, and the next one, as a rule, will be in one fragment.
: (i) for , ; (ii) ?