Using Python3,
How can I aggregate the output from each iteration to one single list? Because from the program I have right now, it gives me the result of every iteration and gives me something like this as individual results and not one large list:
None
None
...
None
130.0
None
...
1764
1765
None
To clarify, I have this program where it calculates the sum of bytes sent within each incrementation of every 1 second, but there are instances where I want to record the specific times when the sum of the bytes in the given second are above the threshold value.
The main part of code is below:
max_time = round(max_time,0) #rounding the number so that it should
have only integer value
chunk = 1 #defines length of constant interval which is 1sec
def event_occurence(time, threshold):
load,res=[],[]
for i,j in zip(data_timestamp,data_load):
if(i<chunk and i>=time-chunk): #limit calculation for
timestamps between restrictions, for example (3.14<4 and
3.14>=3)
load.append(j) #add bytes to list
if sum(load) >= threshold: #check to see if total bytes sent in
that second pass threshold
res.append(i) #the timestamp of the very first instance it passed
the threshold is added to res list
fin = np.ceil(res[0]) #round timestamp of first instance since its
orignally a decimal
return int(fin)
for k in range(chunk, max_time+chunk, chunk):
print(event_occurence(k,3500))
How can I make just one big list that also does not include "None"
ignore xl import
# I couldn't add an execution screenshot because I don't have the excel file used in the question but the code will run fine
max_time = round(max_time,0) #rounding the number so that it should have only integer value
chunk = 1 #defines length of constant interval which is 1sec
def event_occurence(time, threshold):
load,res=[],[]
for i,j in zip(data_timestamp,data_load):
if(i<chunk and i>=time-chunk): #limit calculation for
timestamps between restrictions, for example (3.14<4 and
3.14>=3)
load.append(j) #add bytes to list
if sum(load) >= threshold: #check to see if total bytes sent in
that second pass threshold
res.append(i) #the timestamp of the very first instance it passed
the threshold is added to res list
fin = np.ceil(res[0]) #round timestamp of first instance since its
orignally a decimal
return int(fin)
# Code is same upto this point
event_list = [] # starting an empty list
for k in range(chunk, max_time+chunk, chunk):
e = event_occurence(k,3500)
if e != None: # check that the returned value is not None
event_list.append(e) # appending the value to the list
print(event_list) # printing the list
Using Python3, How can I aggregate the output from each iteration to one single list? Because...