Best Python code snippet using fMBT_python
rr4OO.py
Source:rr4OO.py  
1def waitingTime(nProcess, wTimeL):2    accu = 03    for i in wTimeL:4        accu += i5    6    avgWT = accu / nProcess7    return avgWT8def turnAroungTime(nProcess, wTimeL, processList):9    accu = 010    for i in range(len(wTimeL)):11        accu += wTimeL[i] + processList[i].peak12    13    avgTAT = accu / nProcess14    return avgTAT15def responseTime(nProcess, reTimeL):16    accu = 017    for i in reTimeL:18        accu += i19    avgRT = accu / nProcess20    return avgRT21def organizer(nProcess, processList):22    finished = False23    time = 024    quantum = 225    accu = 026    index = 027    wTimeL = [0] * nProcess28    resTimeL = [0] * nProcess29    ready = []30    # lista auxiliar guarda quais processos tiveram31    # os tempos de resposta já calculados32    aux = []33    while finished != True:34        skip = False35        # Inicialmente, se o tamanho de ready for 0,36        # preenche com o que tiver pronto37        if (len(ready) == 0):38            for i in processList:39                if (time >= i.arrival) and (i not in ready):40                    ready.append(i)41        # Aqui começa o merengue42        if (ready[0].rPeak >= quantum):43            index = processList.index(ready[0])44            # Caso o processo não esteja em aux, ele entra e45            # em seguida é guardado o tempo de resposta dele.46            if (processList[index] not in aux):47                aux.append(processList[index])48                resTimeL[index] = time - processList[index].arrival49                      50            # Se o pico restante for exatamente igual ao51            # quantum, então sabemos que este processo vai52            # terminar. Sendo assim, aproveitamos pra53            # calcular o tempo de espera dele.54            if (processList[index].rPeak == quantum):55                processList[index].rPeak -= quantum56                time += quantum57                wTimeL[index] = time - processList[index].peak - \58                    processList[index].arrival59                skip = True60            if (skip != True):61                processList[index].rPeak -= quantum62                time += quantum63            # Checa se existem outros processos, neste novo64            # tempo, disponÃveis para entrar na fila de prontos.65            for j in processList:66                if (time >= j.arrival) and (j not in ready) and (j.rPeak > 0):67                    ready.append(j)68            69            # Exclui o processo da lista de prontos e,70            # caso o tempo de pico dele não tenha chegado a 0,71            # reintroduz o mesmo processo ao final da fila.72            ready.pop(0)73            if (processList[index].rPeak > 0):74                ready.append(processList[index])75        76        elif (0 < ready[0].rPeak < quantum):77            index = processList.index(ready[0])78            if (processList[index] not in aux):79                aux.append(processList[index])80                resTimeL[index] = time - processList[index].arrival81            time += ready[0].rPeak82            processList[index].rPeak -= ready[0].rPeak83            wTimeL[index] = time - processList[index].peak - \84                processList[index].arrival85            86            # Checa se existem outros processos, neste novo87            # tempo, disponÃveis para entrar na fila de prontos.88            for j in processList:89                if (time >= j.arrival) and (j not in ready) and (j.rPeak > 0):90                    ready.append(j)91            92            # Exclui o processo da lista de prontos.93            ready.pop(0)94        if len(ready) == 0:95            finished = True96            97    return resTimeL, wTimeL98def run(processList):99    nProcess = len(processList)100    101    reTimeL, wTimeL = organizer(nProcess, processList)102    avgWT = waitingTime(nProcess, wTimeL)103    avgTAT = turnAroungTime(nProcess, wTimeL, processList)104    avgRT = responseTime(nProcess, reTimeL)...sjfOO.py
Source:sjfOO.py  
1def waitingTime(nProcess, processList):2    accu = 03    for i in range(nProcess):4        if i == 0:5            processList[i].wTime = i + processList[i].arrival6            accu += processList[i].wTime7        else:8            processList[i].wTime = processList[i - 1].peak + processList[i - 1].wTime - \9                (processList[i].arrival - processList[i - 1].arrival)10            accu += processList[i].wTime11    avgWT = accu / nProcess12    return avgWT13def turnAroungTime(nProcess, processList):14    accu = 015    for i in range(nProcess):16        processList[i].taTime = processList[i].wTime + processList[i].peak17        accu += processList[i].taTime18    avgTAT = accu / nProcess19    return avgTAT20def responseTime(nProcess, processList):21    accuPeak = [0] * nProcess22    accu = 023    for i in range(nProcess):24        if i == 0:25            processList[i].rTime = 026            accuPeak[i] = processList[i].peak27            accu += processList[i].rTime28        else:29            processList[i].rTime = accuPeak[i - 1] - processList[i].arrival30            accuPeak[i] = accuPeak[i - 1] + processList[i].peak31            accu += processList[i].rTime32    33    avgRT = accu / nProcess34    return avgRT35def organizer(nProcess, processList):36    finished = False37    time = 038    order = [processList[x] for x in range(len(processList))]39    trueOrder = []40    order = sorted(order, key = lambda process: process.peak)41    while finished != True:42        for i in order:43            if (time >= i.arrival) and (i not in trueOrder):44                trueOrder.append(i)45                time += i.peak46                break47        if len(trueOrder) == nProcess:48            finished = True49        50    return trueOrder51def run(processList):52    nProcess = len(processList)53    newOrdList = organizer(nProcess, processList)54    avgWT = waitingTime(nProcess, newOrdList)55    avgTAT = turnAroungTime(nProcess, newOrdList)56    avgRT = responseTime(nProcess, newOrdList)...fcfsOO.py
Source:fcfsOO.py  
1def waitingTime(nProcess, processList):2    accu = 03    # Calcula os tempos de espera de cada processo. No caso dele4    # ser o primeiro, recebe o tempo de chegada (no caso do primeiro5    # tempo ser diferente de 0).6    for i in range(nProcess):7        if i == 0:8            processList[i].wTime = i + processList[i].arrival9            accu += processList[i].wTime10        else:11            processList[i].wTime = processList[i - 1].peak + processList[i - 1].wTime - \12                (processList[i].arrival - processList[i - 1].arrival)13            accu += processList[i].wTime14    avgWT = accu / len(processList)15    return avgWT16def turnAroundTime(nProcess, processList):17    accu = 018    for i in range(nProcess):19        processList[i].taTime = processList[i].wTime + processList[i].peak20        accu += processList[i].taTime21    avgTAT = accu / len(processList)22    return avgTAT23def responseTime(nProcess, processList):24    accuPeak = [0] * nProcess25    accu = 026    for i in range(nProcess):27        if i == 0:28            processList[i].rTime = 029            accuPeak[i] = processList[i].peak30            accu += processList[i].rTime31        else:32            processList[i].rTime = accuPeak[i - 1] - processList[i].arrival33            accuPeak[i] = accuPeak[i - 1] + processList[i].peak34            accu += processList[i].rTime35    36    avgRT = accu / len(processList)37    return avgRT38def run(processList):39    nProcess = len(processList)40    avgWT = waitingTime(nProcess, processList)41    avgTAT = turnAroundTime(nProcess, processList)42    avgRT = responseTime(nProcess, processList)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
