'''
Array {data} contains arrays of elements of database query times [speed,isSuccess] 
isSuccess values are defined as follows:
1 = true,
-1 = false,
0 = no data

Calculate the average speed of succesful queries
'''

def solution(data):
    corr_times = []
    for time, corr in trainingData:
        if(corr == 1):
            corr_times.append(time)
    if(len(corr_times) == 0): return 0
    
    avg_time = sum(corr_times)/len(corr_times)
    return avg_time


'''
Test Cases
'''
print(solution([[3, 1],
                [6, 1],
                [4, 1],
                [5, 1]]
              )
     ) #output 4.5


print(solution([[4,1], 
                 [4,-1], 
                 [0,0], 
                 [6,1]]
              )
     ) #output 5.0


print(solution([[4,-1], 
                 [0,0], 
                 [5,-1]]
              )
     ) #output 0

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: