content
stringlengths 7
1.05M
|
---|
"""
https://leetcode.com/problems/number-of-islands/
"""
class Solution:
""" Wrapper for LeetCode Solution """
def numIslands(self, grid: [[str]]) -> int:
"""
Determines the number of islands in a matrix, before destroying them
"""
# No islands or land
if not grid or not grid[0]:
return 0
islands_found = 0
for row_index, row in enumerate(grid):
for col_index, _col in enumerate(row):
# if the current position is an island
if grid[row_index][col_index] == "1":
# Mark island as found
islands_found += 1
# Destory entire island
self._destroy_island(grid, row_index, col_index)
return islands_found
def _destroy_island(self, grid: [[str]], row_index: int, col_index: int):
""" Destroys the entire island """
out_of_bounds_longitude = col_index < 0 or col_index >= len(grid[0])
out_of_bounds_latitude = row_index < 0 or row_index >= len(grid)
if out_of_bounds_longitude or out_of_bounds_latitude:
return
current_position = grid[row_index][col_index]
if current_position == "0":
return
# Destroy island underneath the current position
grid[row_index][col_index] = "0"
# Destroy contigious island landmass to the north, south, east and west
self._destroy_island(grid, row_index-1, col_index)
self._destroy_island(grid, row_index+1, col_index)
self._destroy_island(grid, row_index, col_index-1)
self._destroy_island(grid, row_index, col_index+1)
def main():
""" The entry point of the python script """
world_1 = [
["1","1","1","1","0"],
["1","1","0","1","0"],
["1","1","0","0","0"],
["0","0","0","0","1"]
]
sln = Solution()
number_of_islands_world_1 = sln.numIslands(world_1)
print(f"Number of islands destroyed in world_1: {number_of_islands_world_1}")
if __name__ == "__main__":
main()
|
# author Mahmud Ahsan
# --------------------
# msmath module under mspack package
# --------------------
def sum(x, y):
return x + y
def subtract(x, y):
return x - y
def multiplication(x, y):
return x * y
def division(x, y):
return x / y
|
rows=input()
rows=int(rows)
k=0
matrixList=[]; evenMatrix=[]
while rows!=0:
matrix=input()
matrix=matrix.split(", "); matrix=[int(e) for e in matrix]
e=0; elements=len(matrix)
matrixList.append([])
while e < elements:
matrixList[k].append(matrix[0])
del matrix[0]
e += 1
rows-=1; k+=1
for k in matrixList:
evenMatrix.append([])
for j in k:
if j%2==0:
evenMatrix[len(evenMatrix)-1].append(j)
print(evenMatrix)
|
def profitable_gamble(prob, prize, pay):
if prob * prize > pay:
return True
return False
print(profitable_gamble(4,8,12))
|
#addition.py
def add(a,b):
return a+b
a=int(input("Enter the a value"))
b= int(input("Enter the b value"))
c=add(a,b)
print(c)
|
"""
VARIAVEIS COMPOSTAS (LISTAS PARTE 2)
dados = [nome, idade]
pessoas.append(dados[:]) -> o [:] é usado para fazer uma copia da lista "dados"
print(pessoas[0][0]) -> Neste Caso pessoas terá dentro dela a lista "dados", e pegará assim então o item 0 da lista
"dados, que é "nome".
"""
|
class DissectError(Exception):
"""
Error when
- initially parsing / constructing a message (Checksum error, message to small, ...) or
- trying to access data / certain attributes (No payload, payload too small, payload does make no sense)
May also occur when encountering edge cases not yet handled by the dissector
"""
pass
|
class Block:
def __init__(self):
self.statements = []
def add_statement(self, statement):
self.statements.append(statement)
|
# TODO: Just change this to CSS
colors = {
"text" : "#aaaaaa",
"background" : "#222221",
"plot_background" : "#222221",
"plot_gridlines" : "#777776",
"page_background" : "#222221"
}
|
clang_env = {
"ASAN_SYMBOLIZER_PATH": "/usr/local/bin/llvm-symbolizer",
"CC": "/usr/local/bin/clang",
"GCOV": "/dev/null",
"LD_LIBRARY_PATH": "/usr/local/lib",
"MSAN_SYMBOLIZER_PATH": "/usr/local/bin/llvm-symbolizer",
"TSAN_SYMBOLIZER_PATH": "/usr/local/bin/llvm-symbolizer",
"UBSAN_SYMBOLIZER_PATH": "/usr/local/bin/llvm-symbolizer",
}
|
# Task 03. Special Numbers
num = int(input())
digits = [x for x in range(1,num+1)]
is_special = False
for digit in digits:
digit_iter = [int(x) for x in str(digit)]
if sum(digit_iter) == 5 or sum(digit_iter) == 7 or sum(digit_iter) == 11:
is_special = True
else:
is_special = False
print(f'{digit} -> {is_special}')
|
__version__ = '0.11.2'
# import importlib
# import logging
# from pathlib import Path
# importlib.reload(logging)
# logpath = Path.home() / 'p4reduction.log'
# logging.basicConfig(filename=str(logpath), filemode='w',
# format='%(asctime)s %(levelname)s: %(message)s',
# datefmt='%Y-%m-%d %H:%M:%S')
|
def binario(n):
num = []
while(n>1):
if(n==2 or n==3):
resto = n % 2
n //= 2
num.append(resto)
num.append(n)
else:
resto = n % 2
n //= 2
num.append(resto)
return num
n = int(input('digite um numero: '))
num = []
bin = 0
if(n > 1):
num = binario(n)
i = len(num)-1
while(i>-1):
bin+= num[i]*10**i
i-=1
else:
bin = n
print('numero: {} em binario = {}'.format(n,bin))
|
# Aula 20 - 05-12-2019
# Surgiu a necessidade de envio massivo de e-mails dos clientes cadastrados
# no arquivo cadastro1.txt
# >>>> Fazer tudo com metodos <<<<<
# 1 - Para isso o programa necessita que separe os clientes maiores de 20 anos
# em um arquivo separado chamado menores_de_idade.txt
# 2 - Separar os clientes femininos e salvar em um arquivo chamado feminini.txt
# 3 - Fazer um terminal de consulta onde se digita o código cliente e
# imprima na tela o (f-string) o codigo, nome, idade, sexo, email, telefone.
# Se digitar um número que não exista, deverá aparecer uma mensagem dizendo
# "código não encontrado!" Se digitar 'S' (sair) o programa deve finalizar.
def ler_cadastro():
lista = []
arquivo = open('TrabalhosPython\Aula20 05-12\exercicios\cadastro1.txt','r')
for linha in arquivo:
linha.strip()
lista_linha = linha.split(';')
dicionario = {'codigo':lista_linha[0],'nome':lista_linha[1],'idade':lista_linha[2],'sexo':lista_linha[3],'email':lista_linha[4],'telefone':lista_linha[5]}
lista.append(dicionario)
return lista
lista = ler_cadastro()
for i in lista:
print(i)
|
#
#
# Package libApp in directory source
#
#
print("Loaded libApp")
#
# This file can be left empty, but its presence informs the import mechanism
#
|
EXPECTED_DAILY_WEBSITE_GENERATE_SAMPLES_QUERIES_SIZE = """delimiter //
DROP PROCEDURE IF EXISTS get_daily_samples_size_websites;
CREATE PROCEDURE get_daily_samples_size_websites (
IN id INT,
OUT entry0 FLOAT,
OUT entry1 FLOAT,
OUT entry2 FLOAT,
OUT entry3 FLOAT,
OUT entry4 FLOAT,
OUT entry5 FLOAT,
OUT entry6 FLOAT,
OUT entry7 FLOAT,
OUT entry8 FLOAT,
OUT entry9 FLOAT,
OUT entry10 FLOAT,
OUT entry11 FLOAT,
OUT entry12 FLOAT,
OUT entry13 FLOAT,
OUT entry14 FLOAT,
OUT entry15 FLOAT,
OUT entry16 FLOAT,
OUT entry17 FLOAT,
OUT entry18 FLOAT,
OUT entry19 FLOAT,
OUT entry20 FLOAT,
OUT entry21 FLOAT,
OUT entry22 FLOAT,
OUT entry23 FLOAT,
OUT start_hour FLOAT
)
BEGIN
select HOUR(now()) INTO start_hour;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 24 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 23 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry0 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 24 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 23 HOUR) AND Websiteid = id limit 1);
else SET entry0 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 23 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 22 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry1 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 23 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 22 HOUR) AND Websiteid = id limit 1);
else SET entry1 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 22 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 21 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry2 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 22 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 21 HOUR) AND Websiteid = id limit 1);
else SET entry2 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 21 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 20 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry3 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 21 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 20 HOUR) AND Websiteid = id limit 1);
else SET entry3 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 20 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 19 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry4 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 20 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 19 HOUR) AND Websiteid = id limit 1);
else SET entry4 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 19 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 18 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry5 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 19 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 18 HOUR) AND Websiteid = id limit 1);
else SET entry5 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 18 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 17 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry6 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 18 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 17 HOUR) AND Websiteid = id limit 1);
else SET entry6 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 17 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 16 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry7 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 17 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 16 HOUR) AND Websiteid = id limit 1);
else SET entry7 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 16 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 15 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry8 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 16 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 15 HOUR) AND Websiteid = id limit 1);
else SET entry8 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 15 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 14 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry9 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 15 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 14 HOUR) AND Websiteid = id limit 1);
else SET entry9 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 14 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 13 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry10 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 14 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 13 HOUR) AND Websiteid = id limit 1);
else SET entry10 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 13 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry11 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 13 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Websiteid = id limit 1);
else SET entry11 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 12 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 11 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry12 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 12 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 11 HOUR) AND Websiteid = id limit 1);
else SET entry12 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 11 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 10 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry13 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 11 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 10 HOUR) AND Websiteid = id limit 1);
else SET entry13 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 10 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 9 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry14 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 10 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 9 HOUR) AND Websiteid = id limit 1);
else SET entry14 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 9 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 8 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry15 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 9 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 8 HOUR) AND Websiteid = id limit 1);
else SET entry15 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 8 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 7 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry16 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 8 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 7 HOUR) AND Websiteid = id limit 1);
else SET entry16 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 7 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 6 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry17 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 7 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 6 HOUR) AND Websiteid = id limit 1);
else SET entry17 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 6 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 5 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry18 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 6 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 5 HOUR) AND Websiteid = id limit 1);
else SET entry18 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 5 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 4 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry19 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 5 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 4 HOUR) AND Websiteid = id limit 1);
else SET entry19 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 4 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 3 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry20 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 4 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 3 HOUR) AND Websiteid = id limit 1);
else SET entry20 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 3 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 2 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry21 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 3 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 2 HOUR) AND Websiteid = id limit 1);
else SET entry21 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 2 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 1 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry22 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 2 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 1 HOUR) AND Websiteid = id limit 1);
else SET entry22 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 1 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 0 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry23 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 1 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 0 HOUR) AND Websiteid = id limit 1);
else SET entry23 := 0;
end if;
END//
delimiter ;
"""
EXPECTED_WEEKLY_WEBSITE_GENERATE_SAMPLES_QUERIES_SIZE = """delimiter //
DROP PROCEDURE IF EXISTS get_weekly_samples_size_websites;
CREATE PROCEDURE get_weekly_samples_size_websites (
IN id INT,
OUT entry0 FLOAT,
OUT entry1 FLOAT,
OUT entry2 FLOAT,
OUT entry3 FLOAT,
OUT entry4 FLOAT,
OUT entry5 FLOAT,
OUT entry6 FLOAT,
OUT entry7 FLOAT,
OUT entry8 FLOAT,
OUT entry9 FLOAT,
OUT entry10 FLOAT,
OUT entry11 FLOAT,
OUT entry12 FLOAT,
OUT entry13 FLOAT,
OUT entry14 FLOAT,
OUT entry15 FLOAT,
OUT entry16 FLOAT,
OUT entry17 FLOAT,
OUT entry18 FLOAT,
OUT entry19 FLOAT,
OUT entry20 FLOAT,
OUT entry21 FLOAT,
OUT entry22 FLOAT,
OUT entry23 FLOAT,
OUT entry24 FLOAT,
OUT entry25 FLOAT,
OUT entry26 FLOAT,
OUT entry27 FLOAT,
OUT start_hour FLOAT
)
BEGIN
select HOUR(now()) INTO start_hour;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 168 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 162 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry0 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 168 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 162 HOUR) AND Websiteid = id limit 1);
else SET entry0 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 162 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 156 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry1 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 162 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 156 HOUR) AND Websiteid = id limit 1);
else SET entry1 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 156 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 150 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry2 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 156 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 150 HOUR) AND Websiteid = id limit 1);
else SET entry2 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 150 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 144 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry3 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 150 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 144 HOUR) AND Websiteid = id limit 1);
else SET entry3 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 144 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 138 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry4 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 144 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 138 HOUR) AND Websiteid = id limit 1);
else SET entry4 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 138 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 132 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry5 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 138 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 132 HOUR) AND Websiteid = id limit 1);
else SET entry5 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 132 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 126 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry6 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 132 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 126 HOUR) AND Websiteid = id limit 1);
else SET entry6 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 126 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 120 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry7 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 126 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 120 HOUR) AND Websiteid = id limit 1);
else SET entry7 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 120 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 114 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry8 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 120 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 114 HOUR) AND Websiteid = id limit 1);
else SET entry8 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 114 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 108 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry9 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 114 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 108 HOUR) AND Websiteid = id limit 1);
else SET entry9 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 108 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 102 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry10 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 108 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 102 HOUR) AND Websiteid = id limit 1);
else SET entry10 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 102 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 96 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry11 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 102 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 96 HOUR) AND Websiteid = id limit 1);
else SET entry11 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 96 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 90 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry12 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 96 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 90 HOUR) AND Websiteid = id limit 1);
else SET entry12 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 90 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 84 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry13 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 90 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 84 HOUR) AND Websiteid = id limit 1);
else SET entry13 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 84 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 78 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry14 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 84 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 78 HOUR) AND Websiteid = id limit 1);
else SET entry14 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 78 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 72 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry15 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 78 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 72 HOUR) AND Websiteid = id limit 1);
else SET entry15 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 72 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 66 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry16 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 72 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 66 HOUR) AND Websiteid = id limit 1);
else SET entry16 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 66 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 60 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry17 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 66 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 60 HOUR) AND Websiteid = id limit 1);
else SET entry17 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 60 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 54 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry18 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 60 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 54 HOUR) AND Websiteid = id limit 1);
else SET entry18 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 54 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 48 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry19 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 54 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 48 HOUR) AND Websiteid = id limit 1);
else SET entry19 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 48 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 42 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry20 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 48 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 42 HOUR) AND Websiteid = id limit 1);
else SET entry20 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 42 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 36 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry21 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 42 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 36 HOUR) AND Websiteid = id limit 1);
else SET entry21 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 36 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 30 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry22 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 36 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 30 HOUR) AND Websiteid = id limit 1);
else SET entry22 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 30 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 24 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry23 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 30 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 24 HOUR) AND Websiteid = id limit 1);
else SET entry23 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 24 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 18 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry24 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 24 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 18 HOUR) AND Websiteid = id limit 1);
else SET entry24 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 18 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry25 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 18 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Websiteid = id limit 1);
else SET entry25 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 12 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 6 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry26 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 12 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 6 HOUR) AND Websiteid = id limit 1);
else SET entry26 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 6 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 0 HOUR) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry27 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 6 HOUR) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 0 HOUR) AND Websiteid = id limit 1);
else SET entry27 := 0;
end if;
END//
delimiter ;
"""
EXPECTED_MONTHLY_WEBSITE_GENERATE_SAMPLES_QUERIES_SIZE = """delimiter //
DROP PROCEDURE IF EXISTS get_monthly_samples_size_websites;
CREATE PROCEDURE get_monthly_samples_size_websites (
IN id INT,
OUT entry0 FLOAT,
OUT entry1 FLOAT,
OUT entry2 FLOAT,
OUT entry3 FLOAT,
OUT entry4 FLOAT,
OUT entry5 FLOAT,
OUT entry6 FLOAT,
OUT entry7 FLOAT,
OUT entry8 FLOAT,
OUT entry9 FLOAT,
OUT entry10 FLOAT,
OUT entry11 FLOAT,
OUT entry12 FLOAT,
OUT entry13 FLOAT,
OUT entry14 FLOAT,
OUT entry15 FLOAT,
OUT entry16 FLOAT,
OUT entry17 FLOAT,
OUT entry18 FLOAT,
OUT entry19 FLOAT,
OUT entry20 FLOAT,
OUT entry21 FLOAT,
OUT entry22 FLOAT,
OUT entry23 FLOAT,
OUT entry24 FLOAT,
OUT entry25 FLOAT,
OUT entry26 FLOAT,
OUT entry27 FLOAT,
OUT entry28 FLOAT,
OUT entry29 FLOAT,
OUT entry30 FLOAT,
OUT start_hour FLOAT
)
BEGIN
select DAY(now()) INTO start_hour;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 31 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 30 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry0 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 31 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 30 DAY) AND Websiteid = id limit 1);
else SET entry0 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 29 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry1 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 29 DAY) AND Websiteid = id limit 1);
else SET entry1 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 29 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 28 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry2 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 29 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 28 DAY) AND Websiteid = id limit 1);
else SET entry2 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 28 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 27 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry3 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 28 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 27 DAY) AND Websiteid = id limit 1);
else SET entry3 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 27 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 26 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry4 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 27 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 26 DAY) AND Websiteid = id limit 1);
else SET entry4 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 26 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 25 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry5 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 26 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 25 DAY) AND Websiteid = id limit 1);
else SET entry5 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 25 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 24 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry6 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 25 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 24 DAY) AND Websiteid = id limit 1);
else SET entry6 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 24 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 23 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry7 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 24 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 23 DAY) AND Websiteid = id limit 1);
else SET entry7 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 23 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 22 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry8 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 23 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 22 DAY) AND Websiteid = id limit 1);
else SET entry8 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 22 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 21 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry9 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 22 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 21 DAY) AND Websiteid = id limit 1);
else SET entry9 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 21 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 20 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry10 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 21 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 20 DAY) AND Websiteid = id limit 1);
else SET entry10 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 20 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 19 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry11 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 20 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 19 DAY) AND Websiteid = id limit 1);
else SET entry11 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 19 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 18 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry12 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 19 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 18 DAY) AND Websiteid = id limit 1);
else SET entry12 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 18 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 17 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry13 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 18 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 17 DAY) AND Websiteid = id limit 1);
else SET entry13 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 17 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 16 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry14 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 17 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 16 DAY) AND Websiteid = id limit 1);
else SET entry14 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 16 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 15 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry15 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 16 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 15 DAY) AND Websiteid = id limit 1);
else SET entry15 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 15 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 14 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry16 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 15 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 14 DAY) AND Websiteid = id limit 1);
else SET entry16 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 14 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 13 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry17 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 14 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 13 DAY) AND Websiteid = id limit 1);
else SET entry17 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 13 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 12 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry18 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 13 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 12 DAY) AND Websiteid = id limit 1);
else SET entry18 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 12 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 11 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry19 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 12 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 11 DAY) AND Websiteid = id limit 1);
else SET entry19 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 11 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 10 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry20 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 11 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 10 DAY) AND Websiteid = id limit 1);
else SET entry20 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 10 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 9 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry21 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 10 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 9 DAY) AND Websiteid = id limit 1);
else SET entry21 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 9 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 8 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry22 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 9 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 8 DAY) AND Websiteid = id limit 1);
else SET entry22 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 8 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 7 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry23 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 8 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 7 DAY) AND Websiteid = id limit 1);
else SET entry23 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 7 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 6 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry24 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 7 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 6 DAY) AND Websiteid = id limit 1);
else SET entry24 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 6 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 5 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry25 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 6 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 5 DAY) AND Websiteid = id limit 1);
else SET entry25 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 5 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 4 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry26 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 5 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 4 DAY) AND Websiteid = id limit 1);
else SET entry26 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 4 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 3 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry27 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 4 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 3 DAY) AND Websiteid = id limit 1);
else SET entry27 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 3 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 2 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry28 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 3 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 2 DAY) AND Websiteid = id limit 1);
else SET entry28 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 2 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 1 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry29 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 2 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 1 DAY) AND Websiteid = id limit 1);
else SET entry29 := 0;
end if;
if EXISTS(SELECT SUM(bodySize) from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 1 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 0 DAY) AND Websiteid = id limit 1))
then SELECT SUM(bodySize) INTO entry30 from REQUESTS where Metricid = (SELECT Metricid FROM WEBSITES_METRICS WHERE TIMESTAMP >= DATE_SUB(NOW(), INTERVAL 1 DAY) AND TIMESTAMP <= DATE_SUB(NOW(), INTERVAL 0 DAY) AND Websiteid = id limit 1);
else SET entry30 := 0;
end if;
END//
delimiter ;
"""
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2015, Corwin Brown <[email protected]>
# Copyright: (c) 2017, Dag Wieers (@dagwieers) <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: win_uri
version_added: '2.1'
short_description: Interacts with webservices
description:
- Interacts with FTP, HTTP and HTTPS web services.
- Supports Digest, Basic and WSSE HTTP authentication mechanisms.
- For non-Windows targets, use the M(uri) module instead.
options:
url:
description:
- Supports FTP, HTTP or HTTPS URLs in the form of (ftp|http|https)://host.domain:port/path.
type: str
required: yes
method:
description:
- The HTTP Method of the request or response.
type: str
default: GET
content_type:
description:
- Sets the "Content-Type" header.
type: str
body:
description:
- The body of the HTTP request/response to the web service.
type: raw
dest:
description:
- Output the response body to a file.
type: path
version_added: '2.3'
creates:
description:
- A filename, when it already exists, this step will be skipped.
type: path
version_added: '2.4'
removes:
description:
- A filename, when it does not exist, this step will be skipped.
type: path
version_added: '2.4'
return_content:
description:
- Whether or not to return the body of the response as a "content" key in
the dictionary result. If the reported Content-type is
"application/json", then the JSON is additionally loaded into a key
called C(json) in the dictionary results.
type: bool
default: no
version_added: '2.4'
status_code:
description:
- A valid, numeric, HTTP status code that signifies success of the request.
- Can also be comma separated list of status codes.
type: list
default: [ 200 ]
version_added: '2.4'
url_username:
description:
- The username to use for authentication.
- Was originally called I(user) but was changed to I(url_username) in
Ansible 2.9.
version_added: "2.4"
url_password:
description:
- The password for I(url_username).
- Was originally called I(password) but was changed to I(url_password) in
Ansible 2.9.
version_added: "2.4"
follow_redirects:
version_added: "2.4"
maximum_redirection:
version_added: "2.4"
client_cert:
version_added: "2.4"
client_cert_password:
version_added: "2.5"
use_proxy:
version_added: "2.9"
proxy_url:
version_added: "2.9"
proxy_username:
version_added: "2.9"
proxy_password:
version_added: "2.9"
extends_documentation_fragment:
- url_windows
seealso:
- module: uri
- module: win_get_url
author:
- Corwin Brown (@blakfeld)
- Dag Wieers (@dagwieers)
'''
EXAMPLES = r'''
- name: Perform a GET and Store Output
win_uri:
url: http://example.com/endpoint
register: http_output
# Set a HOST header to hit an internal webserver:
- name: Hit a Specific Host on the Server
win_uri:
url: http://example.com/
method: GET
headers:
host: www.somesite.com
- name: Perform a HEAD on an Endpoint
win_uri:
url: http://www.example.com/
method: HEAD
- name: POST a Body to an Endpoint
win_uri:
url: http://www.somesite.com/
method: POST
body: "{ 'some': 'json' }"
'''
RETURN = r'''
elapsed:
description: The number of seconds that elapsed while performing the download.
returned: always
type: float
sample: 23.2
url:
description: The Target URL.
returned: always
type: str
sample: https://www.ansible.com
status_code:
description: The HTTP Status Code of the response.
returned: success
type: int
sample: 200
status_description:
description: A summary of the status.
returned: success
type: str
sample: OK
content:
description: The raw content of the HTTP response.
returned: success and return_content is True
type: str
sample: '{"foo": "bar"}'
content_length:
description: The byte size of the response.
returned: success
type: int
sample: 54447
json:
description: The json structure returned under content as a dictionary.
returned: success and Content-Type is "application/json" or "application/javascript" and return_content is True
type: dict
sample: {"this-is-dependent": "on the actual return content"}
'''
|
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Detroit'
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 't76+zh&*@(p*l3y50$f^el8q79o7gytx)64@uwt280hf=+)x1('
|
"""
Ordered fractions
Problem 71
https://projecteuler.net/problem=71
Consider the fraction n/d, where n and d are positive
integers. If n<d and HCF(n,d)=1, it is called a reduced proper fraction.
If we list the set of reduced proper fractions for d ≤ 8
in ascending order of size, we get:
1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7,
1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
It can be seen that 2/5 is the fraction immediately to the left of 3/7.
By listing the set of reduced proper fractions for d ≤ 1,000,000
in ascending order of size, find the numerator of the fraction
immediately to the left of 3/7.
"""
def solution(numerator: int = 3, denominator: int = 7, limit: int = 1000000) -> int:
"""
Returns the closest numerator of the fraction immediately to the
left of given fraction (numerator/denominator) from a list of reduced
proper fractions.
>>> solution()
428570
>>> solution(3, 7, 8)
2
>>> solution(6, 7, 60)
47
"""
max_numerator = 0
max_denominator = 1
for current_denominator in range(1, limit + 1):
current_numerator = current_denominator * numerator // denominator
if current_denominator % denominator == 0:
current_numerator -= 1
if current_numerator * max_denominator > current_denominator * max_numerator:
max_numerator = current_numerator
max_denominator = current_denominator
return max_numerator
if __name__ == "__main__":
print(solution(numerator=3, denominator=7, limit=1000000))
|
VERSION = "3.6.dev1"
SERIES = '.'.join(VERSION.split('.')[:2])
|
cookie = {
'ipb_member_id': '',
'ipb_pass_hash': '',
'igneous': '',
}
|
reta1 = int(input("Valor da 1° reta: "))
reta2 = int(input("Valor da 2° reta: "))
reta3 = int(input("Valor da 3° reta: "))
if reta1+reta2 > reta3 and reta1+reta3 > reta2 and reta2+reta3 > reta1:
print("Formam um triangulo")
else:
print("Não formam um triangulo")
|
def asal_mi(sayi):
if(sayi==1):
return False
elif(sayi==2):
return True
else:
for i in range(2,sayi):
if(sayi%i ==0) :
return False
return True
while True:
sayi = input("sayi : ")
if(sayi =="q"):
break
else:
sayi = int(sayi)
if(asal_mi(sayi)):
print(sayi,"asal bir sayidir")
else:
print(sayi,"asal bir sayi değildir.")
|
"""
TASK: Find the edit distance between two given strings.
The edit distance between two strings refers to the minimum number of character insertions,
deletions, and substitutions required to change one string to the other
"""
def edit_distance(str1: str, str2: str) -> int:
print("->edit_distance: str1={}, str2={}".format(str1, str2))
difference = 0
if len(str1) > len(str2):
difference = len(str1) - len(str2)
str1 = str1[:difference]
print("updated str1="+str1)
if len(str2) > len(str1):
difference = len(str2) - len(str1)
str2 = str2[:difference]
print("updated str2=" + str2)
len1 = len(str1)
len2 = len(str2)
print("len1="+str(len1))
print("len2=" + str(len2))
max_len = max(len1, len2)
print("max_len="+str(max_len))
for i in range(max_len):
if str1[i] != str2[i]:
difference += 1
return difference
def test_edit_distance_1():
print("->test_edit_distance_1: start")
result = edit_distance("kitten", "sitting")
expected = 3 # substitute the "k" for "s", substitute the "e" for "i", and append a "g"
print("result={}, expected={}".format(result, expected))
assert result == expected
print("->test_edit_distance_1: end\n")
def test():
test_edit_distance_1()
print("======================")
print("ALL TEST CASES FINISHED")
test()
|
class UserTarget:
@staticmethod
def get_response():
return "Response by UserTarget"
|
guys = list()
dado = list()
tormai = tormen = 0
for c in range(0,3):
dado.append(str(input('Nome: ')))
dado.append(int(input('Idade: ')))
guys.append(dado[:])
dado.clear()
print(guys)
for p in guys:
if p[1] >=21:
print(f'{p[0]} é maior de idade.')
tormai += 1
else:
print(f'{p[0]} é menor de idade.')
tormen += 1
print(f'Temos {tormai} pessoas maiores de idade nessa lista e'
f' {tormen} menores de idade.')
|
class ATM:
def __init__(self, balance, bank_name):
self.balance = balance
self.bank_name = bank_name
self.withdrawals_list = []
def calcul(self,request):
self.withdrawals_list.append(request)
self.balance -= request
notes =[100,50,10,5]
for note in notes :
while request >= note :
request-=note
print("give ", str(note))
if request < 5:
print("give " + str(request))
request = 0
return self.balance
def withdraw(self, request):
print("the name of bank is :",self.bank_name)
print("the balance is",self.balance)
if request > self.balance:
print("Can't give you all this money !!")
elif request < 0:
print("More than zero plz!")
else:
self.calcul(request)
def show_withdrawals(self):
for withdrawal in self.withdrawals_list:
print(withdrawal)
balance1=500
balance2=1000
atm1=ATM(balance1,"smart_bank")
atm2=ATM(balance2,"baraka_bank")
atm1.withdraw(700)
atm1.withdraw(300)
print("the rest of balance for smart bank are",atm1.balance)
atm2.withdraw(500)
print("the rest of balance for baraka bank are",atm2.balance)
atm2.withdraw(257)
print("the rest of balance for baraka bank are",atm2.balance)
atm2.show_withdrawals()
|
# Минимум 4 чисел
def min4(a, b, c, d):
return min(min(a, b), min(c, d))
if __name__ == '__main__':
a, b, c, d = int(input()), int(input()), int(input()), int(input())
print(min4(a, b, c, d))
|
# ESTATISTICAS EM PRODUTOS
# Crie um programa que leia o nome e o preço de vários produtos. O programa deverá perguntar se o usuário vai continuar ou não. No final, mostre:
# A) qual é o total gasto na compra.
# B) quantos produtos custam mais de R$1000.
# C) qual é o nome do produto mais barato.
st = sm = maior = menor = nome = cont = 0
barato = ''
while True:
nome = str(input('DIGITE O NOME DO PRODUTO: ')).strip()
preco = float(input('DIGITE O PREÇO DO PRODUTO: R$'))
cont += 1
if cont == 1:
maior = preco
menor = preco
else:
if preco < menor:
menor = preco
barato = nome
st += preco
if preco >= 1000:
sm += 1
usuario = ' '
while usuario not in 'SN':
usuario = str(input('QUER CONTINUAR? [S/N] ')).strip().upper()[0]
if usuario in 'N':
break
print('=-' * 20)
print(f'O total da compra foi R${st:.2f}')
print(f'Temos {sm:.2f} produtos custando mais de R$1000')
print(f'O produto mais barato custa R${menor:.2f} e é o {barato}')
|
#
# @lc app=leetcode id=53 lang=python3
#
# [53] Maximum Subarray
#
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
if all([x < 0 for x in nums]):
return max(nums)
running_sum = 0
ans = 0
for x in nums:
running_sum += x
if running_sum < 0:
running_sum = 0
continue
if ans < running_sum:
ans = running_sum
return ans
|
#include inc/node.py
class Example(Node):
def __init__(self, selector):
self.dom_bind_to_node_by_selector(selector)
print(self._node)
self.dom_set_classes(['blue'])
# some raw js...
# RawJS("""/* foo */""")
|
# flake8: NOQA: E501
# This proves that the given key (which is an account) exists on the trie rooted at this state
# root. It was obtained by querying geth via the LES protocol
state_root = b'Gu\xd8\x85\xf5/\x83:e\xf5\x9e0\x0b\xce\x86J\xcc\xe4.0\xc8#\xdaW\xb3\xbd\xd0).\x91\x17\xe8'
key = b'\x9b\xbf\xc3\x08Z\xd0\xd47\x84\xe6\xe4S4ndG|\xac\xa3\x0f^7\xd5nv\x14\x9e\x98\x84\xe7\xc2\x97'
proof = ([b'\x01\xb2\xcf/\xa7&\xef{\xec9c%\xed\xeb\x9b)\xe9n\xb5\xd5\x0e\x8c\xa9A\xc1:-{<2$)', b'\xa2\xbab\xe5J\x88\xa1\x8b\x90y\xa5yW\xd7G\x13\x16\xec\xb3\xb6\x87S9okV\xa3\rlC\xbfU', b'\xd6\x06\x92\x9e\x0b\xd310|\xbeV\x9d\xb4r\xdf0\xa5Q\xfb\xec\xb9I\x8c\x96r\x81\xeb\xefX7_l', b'\xa8\x88\xed@\x04\x7f\xa6\xbe&\x89&\x89T\t+\xac\xb8w\x8a\xebn\x16\x0c\xe1n\xb4?\xad\x14\xfdF\xff', b'\xc9\t\xd0\xaa\xb0:P\xdc\xea\xedX%\x04\x9a\xbe\x1f\x16\x0cf\xbc\x04P#@\xfd\xd60\xad\xecK\x8b\x08', b'x\xff\xb2\x9ajO\xbc\x1bjR\x80$I\xe6\x95\xf6Tow\x82\xf9\x01\xa8V\xa9\xaa4\xa6`\x88\xf9\x10', b'I\x1cQc\x8a\xeda\xf8\xd1D\x01GT)\xc9\x02O\xef\x8d\xcc\\\xf9\xe6}\x8a~\xcc\x98~\xd5\xd6\xb6', b"U'\xa2\xa0 \xe4\xb1\xb6\xc3\xcd4C_\x9c]\xb3P\xa8w\xef\x8c\xde\xc2\x02^v\xcd\x12\xed%\x89\xa5", b'(\xa6x\xfa\xbe\xc3\x9a\xae\xaa\xe9\xbcv#u\\\xdfo\x14\x9a3\xbc\x89c\xc1\xfe\xdf[{|\x02P\x03', b'\xcf5\x07\x8f3\xa9\x1f\x19Q\xbb\x11\x8a\xb0\x97\xbe\x93\xb2\xd5~\xe2\xe06\x07\xc37\x08vg\x80 BD', b'U\x8e/\x95&\n\xc5\xf1\xd4\xc3\xb9\xa84Rd\xaa\x80\xfe8\xf1\xcf G\xcc\xe3\x99\x01\x07\xceH\x9a`', b'W\x1f\xb5\x1c\xec\xf7\x0b\x86\x15\r\xf9\xf9\x94\xcd|\xe6B\x9f\xa8l\x8d]D\xf7\xba\xee:\xc0\\\x11\xb8\x08', b'\xf5i\xee)\xc4\xd24\xfc\x8f\xba\xc0vS\x1dU>\xccz\xd18\n\xa2+\n\xcf\xe2i*\xee\x18\xe8\xc1', b'\x9dmSX\x1e\xee\xf7`\x1d\x0cO\xfcF\xe4\xbd\x0cE2\x10H6\xf0\x93|\xd5z\xe7=\xebbJ\xd6', b'u\x08\x92\x08\xa5Nl\x938\x03\xa3\xe2O\xe8\xfe\xb1\xc4\x87\x8c\xb8q\x9eb\x89b\x96\x98\xd7\xf22\xb9\xa2', b'\xa6V\xb5?\xcc\xd2\xc8*ME\xe7\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\xa5', b'#p\x15\x8bU\x04\x88/K|4a\xfc\x0e.Zm^{\x15uk\x8d\xe4_\xfe\xee\xae\xb99\xd1\x8e', b'C \x9f\xb3y\xf3d.\x8b\t\x1cF\x9eL\x08\x07y\x08\xb9\xe1\xffM\x87\xfd\xd6\xfd\xdb\x8f\x94\x9e\x88\xc2', b'\x17X\x1f/\x8b\x82\xf5\xe4\x02\x84}\xbe\x9bz` \x94\'"_\x9c\xff\x06\t>\x8a\xd7oK\xf9\xf5w', b'6Q\x8db\xd8\\\x84_Rin\x18\x1f\x17\x89\x7f@\xd6\xbb%>\xafa\'\x80A\xa7\xd8}d\x07"', b'\xccgm\xf7\x05\xc8\xe4G\xf4\xb3\x18\xc7\\.\x0b\xa25]\xdc\x80w\xda\xc9;\xde\x9b\x03\xa0LS\xce\x8c', b''], [b'\xe4\xd3\x15\xe0\xaa\x0f\xf9\xd0\xa6\xc2\xc8B_\xaf"0\x8c\xea;\x91\xe4E\x04\xec\x901yZ\xd6>\xadc', b'wM\xce\x16JS:\xe96\x98\x12|\xa0\xc9~G\xbb\xc7u8\xc8\x93\x9b\x05\x92yh\xaa\xda\x94NK', b'\x89\xc7\xa2\xbd\xe1\xda\x06$|\xde\x03\xd9RS\x90\x84\xe7\x05\x0cc\xdfy\xb0\xfb@\x065\xdb8\xa9\xef\x1f', b'@\x11>\xe8\xb8\x19\xb7\xc7@\x92m$\x93 \x08\xc5\x15\xbd\x97\xb0;\xf5\x05q;\xb5\xc69\xd3E\xc4\x0e', b'\xd5_ol\x05o\x8e\xf0V\xd2\xa0n\xe7CxR\xc9\x92HTQhkc\x10K\xad\xfdU\xe9\x97\x8f', b'v\x7f\xc5KB\xdaYS\xa1\xbf \xda\xe2\x99\x84\xef,\x92\xdd\xc9\xb8\x9eo\xfcv(\x95\xff\x94t\xbc5', b"\xcbQ\x962!$\x1f\xdc\xdb\xfe\xef'\xc8\xc8O\xec\xa2\xae\xd3P\x88\xbf\xbd!\xea\x0e\xb0\x89\xe9\xdd\xf3w", b'H\xb8\x1b\xc3&\x86|!o\x003/\xc7K\xc9+,K\xe1y\xf2\x86\xa9*H\x05W\xcd\xf8\x8b\xb5\n', b'\x06\xc5\xa1\x83\xe4\xb4\xdc\xbf\xc0\x8c4Q\x93\x14W\xaf\xbb\xe9f\x82\xa2\x8d\xa3m\xda\xed\xc0W\x88UA\xd9', b'\x9czV\x7f$\xa8\xb9\xf3\xc1W0\x19\xac\xc5\xaap\x03?*\xe6\xd6\xee<\x0b\xafr\xf6ji\xd9\x87\xed', b'\xc7\x1d\xca\x95\xab~\xd3|\xa6\x9f\xba\x9e\xd5KxI\x95Y\xadx\xb8\xda\xa7!\xba\x93\xbbB,\x97n\xe4', b'\xd7"\x13\xca=\xa9|e\x11\x8f%\xb2^\x1b\xa6\xff\x93Z\x8b(\xca\xab\x12\xed\x8b3\x0f\xe0\xa7U\xa9\xe1', b'\xc2\xb4\x98\xb7\x08\x18#i7\x81\x85\xfd\xc3\xc6k\x12\x86\x99\xa55\x0c8\xd3\xbc\x9d\xc8\xe0\xd3\xcd=\xc6x', b'\xad\xf0\xea&\xf4\x8f=5\xe1\xb5b\xc1}\xba\xa1\n \xa4\xb7J2\x1f\xd7\xc9\x1d\xa4\xc2\xaf\xb7O\xb2\x12', b'\xd5~\x94\x99~Vy,4\xedMJ\x1a\xda3\xe7\x90\x91\xd4\xafw\xba\xbf\x89`\x0e\x99s\x93E\xdf%', b'\x82\xd2O\x16\xca{\x15\x87\xef-\x8a\xea\xb9\xcd\xfc\x82\x84\x99\xdco\xc1\x1eg\xf3-\x07\xf8\xa3\xed\xffx\x85', b''], [b"\xc5\xa5\xd38zu\xfc\xe9\xe2j\x97\xf0\x81T$\xee5\x94AC\xb1\x85\x0c\xef\x10\xcb`Z\xfcT'\xcb", b'ZU\xe4?lj\x05\xf8\xbc\xa7\xf1\xe4\xdb\x08M\x06\xad\xbf\xb3s\xfa\xcaS\xb9{U\xd2n\x981+|', b'l\x0cL\xfb\\(g\xb47\xc2<\xcb\x14\xf3\xa9l\x01#\xdb"|\xdc\xfd\xa0#\xa2\x89\xcfx\x97\xb4\x8e', b'\x0b\xe7$\x1d\xa2\x1c\\\xa5)t\xd6\x82\xec\xed\x02]\xdd\xefz\xa3C`\x1b\xda\x81\t\xb3\x14\xdf5\xbb\xcb', b'\xe7%b2\xd4\xc6\x98\x90\xd8:B\xa4\x9e\n\xc6\xa1\x01\xac\x94\xbdr\xca\xdd\x8a\xa8\xe8\xc6F\xed\x04\xe9\x14', b'\xa7\xac\xc0S\xcbo\x98\xebJ)\xb1\x8b{\xda,\x98\xf2M\xca,\xcd\xc4%\x94\xe4\xdc<\xf5o}\x90\x1d', b'[\xd9}F\xe2\n\x84\xbc\xa0\x81\x0f\xb9\x0b]\x0c\x10%\x9d\r\x00RZgbV*2b\xd1z\xb5\xd3', b'\xac\xcag\xdb\xc3y\x91\x82\xddu\xad\x85%g\x82\xa0\r\xf4\x99^=\x14h\xee\xac\x81/o\xe6\xe4\xec\x0c', b'8\xeb\xed\x80}2\xd9.\x0e\xeb\x92\xa7\xae\xeb\x8d\x9b>8<\x9d\xc4\x05\xf2W;F\xce!\t\x15\xb2\xe3', b'*\xed\xbfJ\x80\x9f7\xd1\xcd\xeft\x89.e\x02M\r\x85D-\x9bL\x8d\xac*3h\xf3\x9f\xde\xe0F', b'd\xf9\xdf\xfb\xfa`\x97:\x11\xc4\x89u_\xe9&\xd0LX;r\x12\x86\\,}\x7f:\xbc\xf9\x9a\xd2\xe9', b'\x94\x80\xd4\xb8\xe4\xa6\xd4\x9cS\xcc\xc7*xo]2y~\xd6\x18a\xfb\xafP\x19\x87\xe7:\xb1r\x96\xdc', b'\x1c\xdar\xc1\x18\x1f\x0b\xf3\xe2\xf0\xf1<\x05\x88\xa4\x01J,\xc2\xa1\xbd`L\x8b\x95\xa6\xbdze4&\xc1', b'>0\x01SdF=\x8c\xa7\x1d4\x1elOt\xcd;,|\xf0l\xe9O\x83\xf3\xc0rm\xb6\x82\xaa\x08', b'\xd0\xef\x12\xc5<\\\x00\x82$\x98\x8d\xb6\xa7l\xd6w\xa3\x00<D\x15\xf7\xd6\xc9\xd0\xfb\xd3\x9f\xed,\x9e\xf7', b'\xa6->\xb1\x80jz\xc3\x8a,5\xb8\xf8\xbf\xb4^\x880\x824A\xfa\xbf\x0e\x1f\x9b /\x02\xadhx', b''], [b"\xc1\x17\xa1{\x135'>\xce\x8a\xe8;\x84V\x8c\xfer\xdaZS\xc7v\xd7\x18\xfb\xe3\xbf\xff\x92\x87@D", b'\x06\xb9c\xad\x8d2\xc0WU\xaf"w\xe5>\x1a\xfd\x02\xf1\xdd\x91$h/\x02)\xc6\xd3\xbc\x17\xc42\xe8', b'\xc4\xa2\xb3*k\xa8\xc8\x124\x86\xa0\x9b\xad\xfa\xb9$5?\xc6\x0c]\x98Kb\xd13\xdb:\x85\xed\xe1[', b'%\xa4>aM\x08\xbet\x1b\xc8\xb5\xf2c.9o!\x03G\x99_\n\xef\x93OA^\xabC\x91\xce\x97', b'\xc9T\xc1\xf6\xc8\xbe\xd8h\x86\xfey\x82Evg\xe1zP\x9ct\x98(\x01\xf5\xfc\xf8\xbe\xf6\x1d\xc0\x15\x8e', b'\xd3\xf1\xe6T\xd7"\xba\xdeipC\xe5\xe1\x04\x0e?o\x84\xcb\x1aE\x18\xd0\xa36\x0eC\xc7D>\x12 ', b'\xe0\x06\x0c\xaf\xec\xe3op*j\xcd\x84\xef\x9b\x82a{,\x1c\x98\xba-\x10\xf9\x7f+\xb6\x8a/q,\xeb', b"\x8a'\xeb\x1a\xe8i\x91S\xf3;\xa8[f-\xb02\x01?\xac\xe4Ds\xd8E\xa0\x87\x8a\xec]\x9b?\x9e", b'\xcf\x0cM\xbd\x92\xbbaS\x9d\xd0:\x7f\xfe\xd5\x08\xac\xe4\xb5\x81ga\xc2>\\\x89\x95\x08\xd6C\xf9\xe6\xb7', b'\x9bh\xd3\xb0x\xf0\xfa5\xa6vV\x96_\x16\x9dx\x95B2\xa9\xcem\xc8\xb9\xaf\xb9\xff\n\xae\xc7\x14\x13', b'H\x03\x82\xd6\xbd\x00Z\r\xa03YQ\xa4\xfa\xcdl\xea8g{L\x16\x18\xca\xdb\xb75~\xff\x1b]&', b'A?l1\xbf\x04\xc3Qs\x9b\x08c\xc3|\xf5D6\xa2\x82\xf8\xd3\xf4@\xab\xa0oDx\xc4\xffY*', b'\x0c\xd7U\x880\xa0\xd3\xad\xdd\xda\xdb\x01\xac\x99ya:\xeb\xab8K%\xaf\xc4\xf1G\xd3*\xb7\xae\x01*', b'\xb8s\xab\x0e\xf4\x90\xdb\xce\x0b)l\xb3\x7f\xf1p\xc6&\x0eh\xfb\xc8\xd7\x88`\xcd\xdc\x97-l\xb6L\x82', b'x\xf2\x15\x85\xe9\x01\xd8\xdc\xc5\xbc\xb7\xda\xcd$\xf0\xae\xc9\x01\xcdHZ\xb8)\x97\x11\xff\xcc7\xa5\x98\xb4\xb6', b'\xf3\xb6\xdd\xe9\xb1\x93\x08A\xda\xa39\xfe$\x8dO\n$ Mn"-\'\xa5$F5\xae\xcd>\xa2\x0c', b''], [b'\x82\x8b\x9d\x85\x0b/\x83\xacmb\x07\x89h\xa5\x86R\x8e\xf4\xd9_\x00\t\xeb\xb3>\\@\x11\xecOp\x7f', b'', b'', b'"\xee\xd9\x89<\xc3_\xca\xe9\xed\xc2v\r,\x9e\x10\x1c\x07\xe8E\xbd\x10\x9a\x16_:hk\xb9Om\xf2', b'', b'', b'\x11]i\xb3t6\xabKF\xc0\xa9\x81z&\xdf\x02\xcaRQ\x82\x92\xac\xf1\xf9~\x94\x94tM9\xbe\x1a', b'\xd0dY\xbc\xbe\xe5\xa8\x93\xc8e\xbd\x15\xf8\xb6b\x9a+\xbeh\xeb\x9d\x85\x1f(\xee\xd5\xb2 \xf2\xea\xa1\xf2', b'', b'`\xa8\xcd0:I\xdd\xd7\xa1\xc9W\r\x00\xa6\x1b\x0cM\xbb8\xb0Z\x8b\xe2\x87\x16\x0f\x99U\xf7\xdf\xc4U', b'', b'\xbcR\x17x\x12Y\xf1r\xb9c\xf5\x17#\xcd\xdb\xd5\x1c0\xd2\xda~\x99a\x96\xd5k\xef\x94\x0f\xd0$\xcb', b'!\x16\xaee\xb5H7X\xd5\tA\xb5{\x98\x8f\x12\x0bX\x85K\x184\x04\xcf\x80\x17\xf81V\xbc\xed\x9c', b'\x00\x08C^\xb5\xcfb\xb3\x13\xf0\x95S\x8eyQ\xe8\xdf\x9bI\xfe\xa2\x9c\x91@_\x16\x9d\x82w,u\x86', b'6&\x99Z\xae\xe6r\xab\xec\xb3X\x87\\\x02\x99>\xfa\xebP:\xd5\xd2t\xe2p\xc7\xe2\xe0\x0e\x95\xf9D', b'\xcf\x7f\x99\x9a\x1c\x18\xa6\x9av\xe6\xa2\xd5\xb3E\x8aJ\x18\xa7\x8c\xc0\x07\xda\xe9\x0bi\r\t\x0f\x9b\x06\xf8S', b''], [b'\x07\x83C\xd1X\xdf\xddJ\xd4\xf2\x7f3+\n\x95\xb2\x89\xd2"\x9d\xc5S\xfb\xfc\x9ed\x8d\xd2\xd2\xe5\x99B', b'', b'', b'', b'', b'-m2\x00\xef\x95\xcd\xfe\xf8\x9e\x0b\xbf\xae\xd8\xb4\xd2\xa1*\xfde\xaa\xb1\x8a\xdd\x1d\x07\x03\xc7,<\xe8\xe7', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b''], [b'8Z\xd0\xd47\x84\xe6\xe4S4ndG|\xac\xa3\x0f^7\xd5nv\x14\x9e\x98\x84\xe7\xc2\x97', b'\xf8D\x01\x80\xa0U\xbd\x1daQ\x97{bg,!\xc2uK\xbe\xeb;\x82x\xb2\xe0\xc3\x8e\xdc\xd9I\x84n\xe3b\x8b\xf1\xa0\x1e\x0b*\xd9p\xb3e\xa2\x17\xc4\x0b\xcf5\x82\xcb\xb4\xfc\xc1d-z]\xd7\xa8*\xe1\xe2x\xe0\x10\x12>'])
|
#!/usr/bin/python
#
# This file is part of PyRQA.
# Copyright 2015 Tobias Rawald, Mike Sips.
"""
Custom exceptions.
"""
class UnsupportedNeighbourhoodException(Exception):
""" Neighbourhood chosen is not supported. """
def __init__(self, message):
super(UnsupportedNeighbourhoodException, self).__init__(message)
class NoOpenCLPlatformDetectedException(Exception):
""" No OpenCL platform could be detected. """
def __init__(self, message):
super(NoOpenCLPlatformDetectedException, self).__init__(message)
class NoOpenCLDeviceDetectedException(Exception):
""" No OpenCL device could be detected. """
def __init__(self, message):
super(NoOpenCLDeviceDetectedException, self).__init__(message)
class OpenCLPlatformIndexOutOfBoundsException(Exception):
""" OpenCL Platform index is out of bounds. """
def __init__(self, message):
super(OpenCLPlatformIndexOutOfBoundsException, self).__init__(message)
class OpenCLDeviceIndexOutOfBoundsException(Exception):
""" OpenCL Device index is out of bounds. """
def __init__(self, message):
super(OpenCLDeviceIndexOutOfBoundsException, self).__init__(message)
class NoOpenCLKernelsFoundException(Exception):
""" No OpenCL kernels have been found. """
def __init__(self, message):
super(NoOpenCLKernelsFoundException, self).__init__(message)
|
# Minizip library
unz = StaticLibrary( 'unz', sources = ['ioapi.c', 'mztools.c', 'unzip.c', 'zip.c'] )
# minizip
minizip = Executable( 'minizip', libs = [ unz, 'z' ], sources = ['minizip.c'] )
# miniunz
miniunz = Executable( 'miniunz', libs = [ unz, 'z' ], sources = ['miniunz.c'] )
# Platform specific settings
if platform == 'MacOS':
project.define( 'unix' )
elif platform == 'iOS':
project.define( 'unix' )
elif platform == 'Windows':
unz.files( 'iowin32.c' )
|
"""
The tests in this module are based on those from Python
https://github.com/python/cpython/tree/master/Lib/test/test_json
Licensed under the Python Software Foundation License Version 2.
Copyright © 2001-2020 Python Software Foundation. All rights reserved.
Copyright © 2000 BeOpen.com . All rights reserved.
Copyright © 1995-2000 Corporation for National Research Initiatives . All rights reserved.
Copyright © 1991-1995 Stichting Mathematisch Centrum . All rights reserved.
Converted from Unittest to PyTest using `unittest2pytest` 0.5.dev0 by Hartmut Goebel
https://github.com/pytest-dev/unittest2pytest
"""
|
_base_ = [
'./coco_resize.py'
]
data = dict(
train=dict(classes=('person',)),
val=dict(classes=('person',)),
test=dict(classes=('person',))
)
|
class DFS:
def __init__(self):
self.visited_node_counter = 0
def visitor(self):
self.visited_node_counter += 1
def visit(self, node):
node.accept_visitor(self.visitor)
for child in node.children: self.visit(child)
class Node:
def __init__(self):
self.children = []
def add_child(self, node):
self.children.append(node)
def accept_visitor(self, visitor):
visitor()
root = Node()
for i in xrange(0, firstLevelNodes):
root.add_child(Node())
for child in root.children:
for i in xrange(0, secondLevelNodes): child.add_child(Node())
dfs = DFS()
dfs.visit(root)
result = dfs.visited_node_counter
|
n=int(input())
l=[1 for i in range(n)]
for i in range(1,n):
for x in range(n):
if x==0:
continue
else:
l[x]=l[x]+l[x-1]
print(l[-1])
|
android = 70 # percents of people using nova poshta on android
ios = 30 # percents of people using nova poshta on ios
people_count = 5000000
ios_people = people_count/ 100 * ios
print (ios_people, " people using nova poshta on ios.")
|
# Desenvolva um algoritmo em Python que exiba os números pares entre 0 a 10
for num in range(11):
if num%2==0:
print(num)
|
class Profile:
'''
Example
my = Profile('Rob')
my.company = 'CPF'
my.hobby = ['Reading','Sleeping','Eating']
print(my.name)
my.show_email()
my.show_myart()
my.show_hobby()
'''
def __init__(self,name):
self.name = name
self.company = ''
self.hobby = []
self.art = '''
|\ _,,,---,,_
ZZZzz /,`.-'`' -. ;-;;,_
|,4- ) )-,_. ,\ ( `'-'
'---''(_/--' `-'\_)
CAT'''
self.art2 = '''
~~~~
~~
_||____
/\ /\ /\ /\\\\\\\\
//\\/\\/\\ __ /__\\\\\\\\ _,
//\\/\\/\\ __/ \_ |__|_|_|__| \__,
|| || || '-o---o-' | |/|\| /| /\ \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'''
def show_email(self):
if self.company != '':
print('{}@{}.com'.format(self.name.lower(),self.company))
else:
print('{}@gmail.com'.format(self.name.lower()))
def show_myart(self):
print(self.art)
def show_myart2(self):
print(self.art2)
def show_hobby(self):
if len(self.hobby) != 0:
print('------my hobby-------')
for i,h in enumerate(self.hobby,start = 1):
print(i,h)
print('---------------------')
else:
print('No hobby')
if __name__ == '__main__':
my = Profile('Rob')
my.company = 'CPF'
my.hobby = ['Reading','Sleeping','Eating']
print(my.name)
my.show_email()
my.show_myart()
my.show_myart2()
my.show_hobby()
#help(my)
|
def format_duration(seconds):
years = int(seconds/(365*24*60*60))
days = int((seconds-(years*365*24*60*60))/(24*60*60))
hours = int((seconds-(years*365*24*60*60)-(days*24*60*60)) / (60*60))
mins = int((seconds-(years*365*24*60*60)-(days*24*60*60) - hours*60*60)/60)
sec = (seconds -(years*365*24*60*60)-(days*24*60*60)- hours*60*60 - mins*60)
total = [years, days, hours, mins, sec]
x = ""
if years == 1:
x += "1 year, "
elif years > 1:
x += str(years) + " years, "
if days == 1:
x += "1 day, "
elif days >1:
x += str(days) + " days, "
if hours == 1:
x += "1 hour, "
elif hours >1:
x += str(hours) + " hours, "
if sec == 0 and mins > 0:
x = x[:-2]
x += " and "
if mins == 1:
x += "1 minute, "
elif mins >1:
x += str(mins) + " minutes, "
if sec == 1:
x = x[:-2]
x += " and 1 second"
elif sec > 1:
x = x[:-2]
x += " and " + str(sec) + " seconds"
if seconds == 0:
x = "now"
if x[0] == ",":
x = x[1:]
if x[0] == " ":
x = x[1:]
if x[-1] == " ":
x = x[:-1]
if x[-1] == ",":
x = x[:-1]
if x[0] == "a":
x = x[4:]
return x
print(format_duration(100000))
|
# "range(1,11)" just provides us a list of numbers 1-10 (the last number isn't included).
# The list in this case would look like this: [1,2,3,4,5,6,7,8,9,10].
# For loop
## This takes each number inside "range", and saves it as a variable "i". It does whatever is in the loop with that variable, then moves to the next number.
## In this case, the first time it goes through the loop, i is 1 (the first item in the list provided by range).
## Then it will print it, since that's the only thing inside the loop. When it's done with that, it will move to the next number: 2 and do the same thing.
## And so on and so on until it reaches 10. It will print 10 and exit the loop.
for i in range(1,11):
print(i)
# While loop
## While loops will go on forever until whatever condition you provide turns false.
## If the condition is false at the start, the loop is never entered.
do_loop = True
while do_loop:
user_input = input("Should I do the loop again? ")
if user_input == 'no':
do_loop = False
print("Ok, exiting loop")
|
"""
Exercícios proposto
"""
carrinho = []
carrinho.append(('Produto 1', 30))
carrinho.append(('Produto 2', 20))
carrinho.append(('Produto 3', 50))
total = sum([float(y) for x, y in carrinho])
# total = {x: y+y for x, y in carrinho}
print(total)
|
def merge_sort(sorted_l1, sorted_l2):
""" Merge sorting two sorted array """
result = []
i = 0
j = 0
while i < len(sorted_l1) and j < len(sorted_l2):
if sorted_l1[i] < sorted_l2[j]:
result.append(sorted_l1[i])
i += 1
else:
result.append(sorted_l2[j])
j += 1
while i < len(sorted_l1):
result.append(sorted_l1[i])
i += 1
while j < len(sorted_l2):
result.append(sorted_l2[j])
j += 1
return result
print(f'Merge Sort : {merge_sort([1,3,5], [2,4,6, 100, 1001])}')
# Big O notation O(n)
|
math_str = input("please input a number: ")
math = int(math_str)
math6 = 6
if math == math6:
print("Yes, it is 6!")
elif math < math6:
print("That's less than 6!")
else:
print("That's more than 6!")
|
a = arr = [[False for i in range(100)] for j in range(100)]
ans = 0
sl = 0
block= []
def findLargestRectangle(blockNumber):
global sl
global block
block = blockNumber
for i in block: sl += i
for i in range(1,9):
find(i, 1)
return ans
def find(r,n):
global ans
global a
# calc result
if (((n - 1) * 4) % r == 0):
l = (n - 1) * 4 // r
check = True
for i in range(l):
for j in range(r):
if (not a[i][j]):
check = False
break
if (not check): break
if (check and ans < (n-1)*4):
ans = (n-1)*4
# condition end
if (n > sl): return
#fill - backtracking
for i in range(80):
for j in range(r):
if (not a[i][j]):
if (block[0] > 0):
if (not a[i + 1][j] and not a[i + 2][j] and not a[i + 3][j]):
a[i][j] = True
a[i + 1][j] = True
a[i + 2][j] = True
a[i + 3][j] = True
block[0]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 2][j] = False
a[i + 3][j] = False
block[0]+=1
if (j + 3 < r and not a[i][j + 1] and not a[i][j + 2] and not a[i][j + 3]):
a[i][j] = True
a[i][j + 1] = True
a[i][j + 2] = True
a[i][j + 3] = True
block[0]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i][j + 2] = False
a[i][j + 3] = False
block[0]+=1
if (block[1] > 0):
if (j + 1 < r and not a[i][j + 1] and not a[i + 1][j] and not a[i + 1][j + 1]):
a[i][j] = True
a[i][j + 1] = True
a[i + 1][j] = True
a[i + 1][j + 1] = True
block[1]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i + 1][j] = False
a[i + 1][j + 1] = False
block[1]+=1
if (block[2] > 0):
if (j + 2 < r and not a[i][j + 1] and not a[i][j + 2] and not a[i + 1][j + 2]):
a[i][j] = True
a[i][j + 1] = True
a[i][j + 2] = True
a[i + 1][j + 2] = True
block[2]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i][j + 2] = False
a[i + 1][j + 2] = False
block[2]+=1
if (j + 1 < r and not a[i][j + 1] and not a[i + 1][j] and not a[i + 2][j]):
a[i][j] = True
a[i][j + 1] = True
a[i + 1][j] = True
a[i + 2][j] = True
block[2]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i + 1][j] = False
a[i + 2][j] = False
block[2]+=1
if (j + 2 < r and not a[i + 1][j] and not a[i + 1][j + 1] and not a[i + 1][j + 2]):
a[i][j] = True
a[i + 1][j] = True
a[i + 1][j + 1] = True
a[i + 1][j + 2] = True
block[2]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 1][j + 1] = False
a[i + 1][j + 2] = False
block[2]+=1
if (j > 0):
if (not a[i + 1][j] and not a[i + 2][j] and not a[i + 2][j - 1]):
a[i][j] = True
a[i + 1][j] = True
a[i + 2][j] = True
a[i + 2][j - 1] = True
block[2]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 2][j] = False
a[i + 2][j - 1] = False
block[2]+=1
if (block[3] > 0):
if (j + 2 < r and not a[i][j + 1] and not a[i + 1][j + 1] and not a[i + 1][j + 2]):
a[i][j] = True
a[i][j + 1] = True
a[i + 1][j + 1] = True
a[i + 1][j + 2] = True
block[3]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i + 1][j + 1] = False
a[i + 1][j + 2] = False
block[3]+=1
if (j > 0):
if (not a[i + 1][j] and not a[i + 1][j - 1] and not a[i + 2][j - 1]):
a[i][j] = True
a[i + 1][j] = True
a[i + 1][j - 1] = True
a[i + 2][j - 1] = True
block[3]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 1][j - 1] = False
a[i + 2][j - 1] = False
block[3]+=1
if (block[4] > 0):
if (j + 1 < r and j > 0):
if(not a[i][j + 1] and not a[i + 1][j] and not a[i + 1][j - 1]):
a[i][j] = True
a[i][j + 1] = True
a[i + 1][j] = True
a[i + 1][j - 1] = True
block[4]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i + 1][j] = False
a[i + 1][j - 1] = False
block[4]+=1
if (j + 1 < r):
if (not a[i + 1][j] and not a[i + 1][j + 1] and not a[i + 2][j + 1]):
a[i][j] = True
a[i + 1][j] = True
a[i + 1][j + 1] = True
a[i + 2][j + 1] = True
block[4]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 1][j + 1] = False
a[i + 2][j + 1] = False
block[4]+=1
if (block[5] > 0):
if (j + 2 < r and not a[i][j + 1] and not a[i][j + 2] and not a[i + 1][j]):
a[i][j] = True
a[i][j + 1] = True
a[i][j + 2] = True
a[i + 1][j] = True
block[5]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i][j + 2] = False
a[i + 1][j] = False
block[5]+=1
if (j + 1 < r and not a[i][j + 1] and not a[i + 1][j + 1] and not a[i + 2][j + 1]):
a[i][j] = True
a[i][j + 1] = True
a[i + 1][j + 1] = True
a[i + 2][j + 1] = True
block[5]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i + 1][j + 1] = False
a[i + 2][j + 1] = False
block[5]+=1
if (j > 1):
if(not a[i + 1][j] and not a[i + 1][j - 1] and not a[i + 1][j - 2]):
a[i][j] = True
a[i + 1][j] = True
a[i + 1][j - 1] = True
a[i + 1][j - 2] = True
block[5]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 1][j - 1] = False
a[i + 1][j - 2] = False
block[5]+=1
if (j + 1 < r):
if (not a[i + 1][j] and not a[i + 2][j] and not a[i + 2][j + 1]):
a[i][j] = True
a[i + 1][j] = True
a[i + 2][j] = True
a[i + 2][j + 1] = True
block[5]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 2][j] = False
a[i + 2][j + 1] = False
block[5]+=1
if (block[6] > 0):
if (j + 2 < r and not a[i][j + 1] and not a[i][j + 2] and not a[i + 1][j + 1]):
a[i][j] = True
a[i][j + 1] = True
a[i][j + 2] = True
a[i + 1][j + 1] = True
block[6]-=1
find(r, n + 1)
a[i][j] = False
a[i][j + 1] = False
a[i][j + 2] = False
a[i + 1][j + 1] = False
block[6]+=1
if (j + 1 < r and not a[i + 1][j] and not a[i + 1][j + 1] and not a[i + 2][j]):
a[i][j] = True
a[i + 1][j] = True
a[i + 1][j + 1] = True
a[i + 2][j] = True
block[6]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 1][j + 1] = False
a[i + 2][j] = False
block[6]+=1
if (j > 0):
if (not a[i + 1][j] and not a[i + 1][j - 1] and not a[i + 2][j]):
a[i][j] = True
a[i + 1][j] = True
a[i + 1][j - 1] = True
a[i + 2][j] = True
block[6]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 1][j - 1] = False
a[i + 2][j] = False
block[6]+=1
if (j + 1 < r and j > 0):
if(not a[i + 1][j] and not a[i + 1][j + 1] and not a[i + 1][j - 1]):
a[i][j] = True
a[i + 1][j] = True
a[i + 1][j - 1] = True
a[i + 1][j + 1] = True
block[6]-=1
find(r, n + 1)
a[i][j] = False
a[i + 1][j] = False
a[i + 1][j - 1] = False
a[i + 1][j + 1] = False
block[6]+=1
return
print(findLargestRectangle([0,0,1,1,0,1,0]))
|
"""
В условиях предыдущей задачи определите количество школьников, ставших победителями в каждом классе. Победителями
объявляются все, кто набрал наибольшее число баллов по данному классу. Гарантируется, что в каждом классе был хотя бы
один участник.
Формат вывода
Выведите три числа: количество победителей олимпиады по 9 классу, по 10 классу, по 11 классу.
"""
fin = open('input.txt', encoding='utf8')
maxes = [0, 0, 0]
count = [0, 0, 0]
for line in fin:
surname, name, clas, grade = line.split(' ')
if clas == '9':
if int(grade) > maxes[0]:
maxes[0] = int(grade)
count[0] = 1
elif int(grade) == maxes[0]:
count[0] += 1
elif clas == '10':
if int(grade) > maxes[1]:
maxes[1] = int(grade)
count[1] = 1
elif int(grade) == maxes[1]:
count[1] += 1
elif clas == '11':
if int(grade) > maxes[2]:
maxes[2] = int(grade)
count[2] = 1
elif int(grade) == maxes[2]:
count[2] += 1
print(*count)
|
# -*- coding: utf-8 -*-
# @Time : 2019-12-20 17:31
# @Author : songzhenxi
# @Email : [email protected]
# @File : LeetCode_77_1034.py
# @Software: PyCharm
# 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。
#
# 示例:
#
# 输入: n = 4, k = 2
# 输出:
# [
# [2,4],
# [3,4],
# [2,3],
# [1,2],
# [1,3],
# [1,4],
# ]
# Related Topics 回溯算法
# leetcode submit region begin(Prohibit modification and deletion)
class Solution(object):
def combine(self, n, k):
"""
题目:77.组合(https://leetcode-cn.com/problems/combinations/)
学号:1034(五期一班三组)
标签:递归 回溯
:type n: int
:type k: int
:rtype: List[List[int]]
"""
return self.helper([], [], 1, n, k)
def helper(self, combs, comb, a, n, k):
if k == 0:
combs.append(list(comb))
return combs
for i in xrange(a, n + 1):
comb.append(i)
self.helper(combs, comb, i + 1, n, k - 1)
comb.pop()
return combs
# leetcode submit region end(Prohibit modification and deletion)
|
# Adicione na classe MyLinkedList, um método que retorne a quantidade de elementos na lista.
class Node:
def __init__(self, data, next=None):
self.data = data
self.next = next
class MyLinkedList:
def __init__(self):
self.head = None
self.length = 0
def add(self, value):
if(self.head):
current = self.head
while(current.next):
current = current.next
current.next = Node(value)
else:
self.head = Node(value)
self.length += 1
def count(self):
return self.length
myList = MyLinkedList()
myList.add(2)
myList.add(3)
print(myList.count())
myList.add(4)
myList.add(3)
print(myList.count())
myList.add(7)
print(myList.count())
|
def rook_cells_under_attack(p, width=8, height=8):
cells = []
for i in range(height):
cells.append((p[0], i))
for i in range(width):
cells.append((i, p[1]))
return cells
# TODO: add width and height parameters
def bishop_cells_under_attack(p, width=8, height=8):
cells = []
for k in range(max(width, height)):
if p[0] + k <= width and p[1] + k <= height:
cells.append((p[0] + k, p[1] + k))
if p[0] + k <= width and p[1] - k >= 0:
cells.append((p[0] + k, p[1] - k))
if p[0] - k >= 0 and p[1] - k >= 0:
cells.append((p[0] - k, p[1] - k))
if p[0] - k >= 0 and p[1] + k <= height:
cells.append((p[0] - k, p[1] + k))
return cells
def queen_cells_under_attack(p, width=8, height=8):
return rook_cells_under_attack(p, width, height) + bishop_cells_under_attack(p, width, height)
|
nome = str(input("Digite seu nome completo: ")).strip()
nome = nome.lower()
#verifica = nome.find('silva') > 0
print("Seu nome tem Silva? ")
#print("{}".format(verifica))
print("{}".format("silva" in nome))
|
# Solution
# O(n*l) time / O(c) space
# n - number of words
# l - length of the longest word
# c - number of unique characters across all words
def minimumCharactersForWords(words):
maximumCharacterFrequencies = {}
for word in words:
characterFrequencies = countCharacterFrequencies(word)
updateMaximumFrequencies(characterFrequencies, maximumCharacterFrequencies)
return makeArrayFromCharacterFrequencies(maximumCharacterFrequencies)
def countCharacterFrequencies(string):
characterFrequencies = {}
for character in string:
if character not in characterFrequencies:
characterFrequencies[character] = 0
characterFrequencies[character] += 1
return characterFrequencies
def updateMaximumFrequencies(frequencies, maximumFrequencies):
for character in frequencies:
frequency = frequencies[character]
if character in maximumFrequencies:
maximumFrequencies[character] = max(frequency, maximumFrequencies[character])
else:
maximumFrequencies[character] = frequency
def makeArrayFromCharacterFrequencies(characterFrequencies):
characters = []
for character in characterFrequencies:
frequency = characterFrequencies[character]
for _ in range(frequency):
characters.append(character)
return characters
|
a = map(int, input().split())
b = map(int, input().split())
c = map(int, input().split())
d = map(int, input().split())
e = map(int, input().split())
_a, _b, _c, _d, _e = sum(a), sum(b), sum(c), sum(d), sum(e)
m = max(_a, _b, _c, _d, _e)
if m == _a:
print(1, _a)
elif m == _b:
print(2, _b)
elif m == _c:
print(3, _c)
elif m == _d:
print(4, _d)
elif m == _e:
print(5, _e)
|
L=[23,45,88,23,56,78,96]
Temp=L[0]
L[0]=L[-1]
L[-1]=Temp
print(L)
|
# Time: O(n)
# Space: O(1)
class Solution(object):
# @param {integer} s
# @param {integer[]} nums
# @return {integer}
def minSubArrayLen(self, s, nums):
start = 0
sum = 0
min_size = float("inf")
for i in xrange(len(nums)):
sum += nums[i]
while sum >= s:
min_size = min(min_size, i - start + 1)
sum -= nums[start]
start += 1
return min_size if min_size != float("inf") else 0
# Time: O(nlogn)
# Space: O(n)
# Binary search solution.
class Solution2(object):
# @param {integer} s
# @param {integer[]} nums
# @return {integer}
def minSubArrayLen(self, s, nums):
min_size = float("inf")
sum_from_start = [n for n in nums]
for i in xrange(len(sum_from_start) - 1):
sum_from_start[i + 1] += sum_from_start[i]
for i in xrange(len(sum_from_start)):
end = self.binarySearch(lambda x, y: x <= y, sum_from_start, \
i, len(sum_from_start), \
sum_from_start[i] - nums[i] + s)
if end < len(sum_from_start):
min_size = min(min_size, end - i + 1)
return min_size if min_size != float("inf") else 0
def binarySearch(self, compare, A, start, end, target):
while start < end:
mid = start + (end - start) / 2
if compare(target, A[mid]):
end = mid
else:
start = mid + 1
return start
|
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test.db',
'TEST_NAME': 'test1.db',
}
}
ROOT_URLCONF='testapp.urls'
SITE_ID = 1
SECRET_KEY = "not very secret in tests"
ALLOWED_HOSTS = (
'testserver',
'*'
)
INSTALLED_APPS = (
"rest_framework",
"testapp"
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
)
|
#Write a Python program that reads your height in cms and converts your height to feet and inches.
heightCM = float(input('Enter the height in CM: '))
totalInch = heightCM * 0.393701
heightInch = (totalInch % 12)
heightFeet = (totalInch - heightInch)*0.0833333
print('The height is : ',heightFeet,' feet AND 163',heightInch,' inch')
|
"""Given a string, determine if a permutation of the string could form a palindrome.
For example,
"code" -> False, "aab" -> True, "carerac" -> True."""
class Solution:
def canPermutePalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
check = set()
for c in s:
if c in check:
check.remove(c)
else:
check.add(c)
return len(check) <= 1
|
#!/usr/bin/env python3.7
rules = {}
with open('input.txt') as fd:
for line in fd:
words = line[:-1].split()
this_bag = words[0]+ " " + words[1]
rules[this_bag] = []
b = line[:-1].split('contain')
bags = b[1].split(',')
for bag in bags:
words = bag.split()
count = 0
try:
count = int(words[0])
except:
break
new_bag = [count,words[1]+" "+words[2]]
rules[this_bag].append(new_bag)
def contains(rules, find):
res = []
for f in find:
for rule in rules:
for bag in rules[rule]:
if f in bag:
res.append(rule)
return res
search_for = ['shiny gold']
final = {}
while True:
res = contains(rules,search_for)
if res == []:
break
for bag in res:
final[bag] = 1
search_for = res
print(final.keys())
print(len(final))
|
ordered_params = ['vmax', 'km', 'k_synt_s', 'k_deg_s', 'k_deg_p']
n_vars = 2
def model(y, t, yout, p):
#---------------------------------------------------------#
#Parameters#
#---------------------------------------------------------#
vmax = p[0]
km = p[1]
k_synt_s = p[2]
k_deg_s = p[3]
k_deg_p = p[4]
#---------------------------------------------------------#
#Variables#
#---------------------------------------------------------#
_s = y[0]
_p = y[1]
#---------------------------------------------------------#
#Differential Equations#
#---------------------------------------------------------#
yout[0] = ((-_s * vmax + (_s + km) * (-_s * k_deg_s + k_synt_s)) / (_s + km))
yout[1] = ((-_p * k_deg_p * (_s + km) + _s * vmax) / (_s + km))
|
"""
Purpose: Stakoverflow question finding first and last coordinates for values in matrix
Date created: 2019-12-28
URI: https://stackoverflow.com/questions/59511521/how-to-get-start-and-end-of-subsection-of-2d-array-where-a-condition-holds/59511652#59511652
Contributor(s):
Mark M.
"""
a = [[0, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]]
results_list= list()
while True:
for i, v in enumerate(a):
if 1 in v:
results_list.append([i, v.index(1)])
first_pair = results_list[0]
last_pair = results_list[-1]
break
results_list[0]
results_list[-1]
|
def max_num_in_list( list ):
max = list[ 0 ]
for a in list:
if a > max:
max = a
return max
ls=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
ls.append(b)
print("Max number in the list is:",max_num_in_list(ls))
|
def ports():
portas_top10 = [21,22,23,25,53,80,110,139,443,445]
portas_top20 = [21,22,23,25,53,80,110,135,139,143,443,445,993,995,1723,2222,3306,3389,5900,8080,8291]
portas_top30 = [21,22,23,25,80,110,135,139,143,443,445,993,995,1723,2222,3306,3389,5900,5060,5666,6001,8000,8008,8080,8291,8443,8888,10000,32768,49152,49154]
print("Selecione uma das listas de portas disponíveis:")
print("1 - Lista top 10")
print("2 - Lista top 20")
print("3 - Lista top 30")
escolha = input("\n>>>")
lista = []
if (escolha == "1"):
lista = portas_top10
return lista
elif (escolha == "2"):
lista = portas_top20
return lista
else:
lista = portas_top30
return lista
|
iter_num = 0
def fib(num):
global iter_num
iter_num += 1
print("Iteration number {0}. num = {1}".format(iter_num, num))
# Base class for fibonnaci series
if num==0 or num==1:
return 1
# Recursive call
else:
return fib(num-1)+fib(num-2)
if __name__ == '__main__':
num = int(input("Enter a number: "))
ans = fib(num)
print("Fibonnaci sum of the number is ", ans)
|
class Solution:
@staticmethod
def _encode(word):
enc = []
idx = 0
repeat = 0
prev = None
while idx < len(word):
if word[idx] == prev:
idx += 1
repeat += 1
else:
if prev:
enc.append((prev, repeat))
prev = word[idx]
repeat = 1
idx += 1
if prev:
enc.append((prev, repeat))
return enc
@staticmethod
def _is_expressive(enc_s, enc_w):
if len(enc_s) != len(enc_w):
return False
else:
for i in range(len(enc_s)):
ch_s = enc_s[i]
ch_w = enc_w[i]
if ch_s[0] == ch_w[0] and \
(ch_s[1] == ch_w[1] or (ch_s[1] >= ch_w[1] and ch_s[1] >= 3)):
continue
else:
return False
return True
def expressiveWords(self, S: str, words: list) -> int:
"""
helllooo
hello, hellllo
"""
enc_s = self._encode(S)
cnt = 0
print(enc_s)
for w in words:
enc_w = self._encode(w)
print(enc_w)
cnt += self._is_expressive(enc_s, enc_w)
return cnt
|
def getNext(instr):
count=0
curch=instr[0]
outstr=[]
for ch in instr:
if ch != curch:
outstr.append(str(count)+curch)
curch=ch
count=1
else:
count+=1
outstr.append(str(count)+curch)
return ''.join(outstr)
a=['1']
for i in range(31):
a.append(getNext(a[i]))
print(len(a[30]))
|
# coding=utf-8
__author__ = 'Gareth Coles'
class BaseAlgorithm(object):
def hash(self, value, salt):
pass
def check(self, hash, value, salt):
return hash == self.hash(value, salt)
def gen_salt(self):
pass
|
description = ''
pages = ['header',
'my_account']
def setup(data):
pass
def test(data):
navigate('http://store.demoqa.com/')
click(header.my_account)
verify_is_not_selected(my_account.remember_me)
capture('Remember me is not selected')
def teardown(data):
pass
|
# -*- coding: utf-8 -*-
# 配置参数
class Config:
def __init__(self):
self.BATCH_SIZE = 64
self.TEST_BATCH_SIZE = 1000
self.EPOCHS = 3
self.LEARNING_RATE = 0.001
self.SGD_MOMENTUM = 0.5
self.SEED = 1
self.LOG_INTERVAL = 10
|
# Vamos a convertir un numero entero en una lista de sus digitos
numero = int(input('Dime tu numero\n'))
digitos =[]
while numero !=0:
digitos.insert(0,numero%10)
numero //= 10
print('Los digitos de su numero son',digitos)
|
def main():
input = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
output = findMaxConsecutiveOnes(input)
print(output)
def findMaxConsecutiveOnes(nums):
globalMax = 0
count = 0
if (len(nums) == 0):
return 0
for n in nums:
if n == 1:
count = count +n
if(count > globalMax):
globalMax = count
elif n==0:
count = 0
return globalMax
if __name__ == '__main__':
main()
|
n=int(input().strip())
b=input().strip()
step=0
for i in range(0,n-2):
if(b[i]+b[i+1]+b[i+2]=='010'):
step+=1
print(step)
|
# -*- coding: utf-8 -*-
"""
View and Model base classes used to control access permissions for CRUD requests.
"""
__version__ = '0.1'
|
"""Dummy technologies
"""
def insert_dummy_technologies(technologies, tech_p_by, all_specified_tech_enduse_by):
"""Define dummy technologies
Where no specific technologies are assigned for an enduse
and a fueltype, dummy technologies are generated. This is
necessary because the model needs a technology for every
fueltype in an enduse. Technologies are however defined
with no efficiency changes, so that the energy demand
for an enduse per fueltype can be treated not related
to technologies (e.g. definieng definin overall
eficiency change)
Parameters
----------
tech_p_by : dict
Fuel assignement of technologies in base year
all_specified_tech_enduse_by : dict
Technologies per enduse
Returns
-------
tech_p_by : dict
all_specified_tech_enduse_by : dict
dummy_techs : dict
TODO
"""
for end_use in tech_p_by:
for fuel_type in tech_p_by[end_use]:
# TODO write explicit in assumptions: Test if any fueltype is specified with a technology.
# If yes, do not insert dummy technologies
# because in the fuel definition all technologies of all endueses need to be defined
crit_tech_defined_in_enduse = False
all_defined_tech_in_fueltype = tech_p_by[end_use].values()
for definition in all_defined_tech_in_fueltype:
if definition == {}:
pass
else:
crit_tech_defined_in_enduse = True
continue
# If an enduse has no defined technologies across all fueltypes
if crit_tech_defined_in_enduse is False:
if tech_p_by[end_use][fuel_type] == {}:
all_specified_tech_enduse_by[end_use].append("dummy_tech")
# Assign total fuel demand to dummy technology
tech_p_by[end_use][fuel_type] = {"dummy_tech": 1.0}
# Insert dummy tech
technologies['dummy_tech'] = {}
return tech_p_by, all_specified_tech_enduse_by, technologies
def get_enduses_with_dummy_tech(enduse_tech_p_by):
"""Find all enduses with defined dummy technologies
Parameters
----------
enduse_tech_p_by : dict
Fuel share definition of technologies
Return
------
dummy_enduses : list
List with all endueses with dummy technologies
"""
dummy_enduses = set([])
for enduse in enduse_tech_p_by:
for fueltype in enduse_tech_p_by[enduse]:
for tech in enduse_tech_p_by[enduse][fueltype]:
if tech == 'dummy_tech':
dummy_enduses.add(enduse)
continue
return list(dummy_enduses)
|
SHOWNAMES = [
"ap1/product-id",
"ap1/adc0",
"ap1/adc1",
"ap1/adc2",
"ap1/din0",
"ap1/din1",
"ap1/din2",
"ap1/din3",
"ap1/led1",
"ap1/led2",
"ap1/device-id",
"ap1/vendor-id",
"ap1/dout0",
"ap1/dout1",
"ap1/dout2",
"ap1/dout3",
"ap1/reset",
"ap1/dout-enable",
"ap1/hw-version",
"capability/adc",
"capability/din",
"capability/gps",
"capability/dout",
"capability/lora",
"capability/wifi",
"capability/bluetooth",
"device-id",
"eth-reset",
"gpiob/product-id",
"gpiob/adc0",
"gpiob/adc1",
"gpiob/adc2",
"gpiob/din0",
"gpiob/din1",
"gpiob/din2",
"gpiob/din3",
"gpiob/led1",
"gpiob/led2",
"gpiob/device-id",
"gpiob/vendor-id",
"gpiob/dout0",
"gpiob/dout1",
"gpiob/dout2",
"gpiob/dout3",
"gpiob/reset",
"gpiob/dout-enable",
"gpiob/hw-version",
"has-radio",
"hw-version",
"imei",
"led-a",
"led-b",
"led-c",
"led-cd",
"led-d",
"led-sig1",
"led-sig2",
"led-sig3",
"led-status",
"mac-eth",
"product-id",
"reset",
"reset-monitor",
"reset-monitor-intervals",
"uuid",
"vendor-id",
]
|
def merge(left, right, sorted_lst):
i, j, k = 0, 0, 0
while i < len(left) and j < len(right):
if left[i] <= right[j]:
sorted_lst[k] = left[i]
i += 1
else:
sorted_lst[k] = right[j]
j += 1
k += 1
while i < len(left):
sorted_lst[k] = left[i]
i += 1
k += 1
while j < len(right):
sorted_lst[k] = right[j]
j += 1
k += 1
return sorted_lst
def mergesort(arr: list):
if len(arr) > 1:
mid = len(arr) // 2
left, right = mergesort(arr[:mid]), mergesort(arr[mid:])
return merge(left, right, arr)
return arr
def min_pair_arr(arr):
arr = mergesort(arr)
min_pair = abs(arr[1] - arr[0]), arr[1], arr[0]
for i in range(1, len(arr)):
dist = abs(arr[i] - arr[i - 1])
if dist < min_pair[0]:
min_pair = dist, arr[i - 1], arr[i]
return min_pair[1:]
if __name__ == "__main__":
arr = [6,2, 1,9, 3, 0, 5, 23 , 73, 123, 4]
print(mergesort(arr))
print(min_pair_arr(arr))
|
# vestlus:admin:actions
def make_read(model, request, queryset):
queryset.update(read=True)
make_read.short_description = "Mark as read"
def make_unread(model, request, queryset):
queryset.update(read=False)
make_unread.short_description = "Mark as unread"
def make_private(model, request, queryset):
queryset.update(is_private=True)
make_private.short_description = "Make private"
def make_public(model, request, queryset):
queryset.update(is_private=False)
make_public.short_description = "Make public"
|
def find(key, dictionary):
"""
Generator to extract items from complex nested data structures
source: https://stackoverflow.com/questions/9807634/find-all-occurrences-of-a-key-in-nested-python-dictionaries-and-lists
:param key: Key to look for
:param dictionary: Object with nested dicts and lists
:return: generator with all values matching the desired key
"""
for k, v in dictionary.items():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
elif isinstance(v, list):
for d in v:
if isinstance(d, dict) or isinstance(d, list):
for result in find(key, d):
yield result
|
class FeedMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
if self.is_atom_feed(environ['PATH_INFO']):
def _start_response(status, headers, exc_info=None):
return start_response(status, self.set_charset(headers), exc_info)
else:
_start_response = start_response
return self.app(environ, _start_response)
@staticmethod
def set_charset(headers, charset='utf-8'):
for header in headers:
attr, value = header
if attr.lower() == 'content-type':
if '; ' not in value:
value += '; charset={}'.format(charset)
yield (attr, value)
@staticmethod
def is_atom_feed(path_info):
return path_info.startswith('/feeds/') and path_info.endswith('.atom')
|
var = 0
print("Hello!")
while var < 10:
print(10 - var, end="\n")
var += 2
|
email = input("Introduce email: ")
if email.count("@") == 1 and email.count("@", 1, len(email) - 1) == 1:
print("La dirección de correo es correcta.")
else:
print("La dirección de correo es incorrecta.")
|
def main():
# input
ABCs = [*map(int, input().split())]
# compute
# output
print(2 * sum([ABCs[i-1]*ABCs[i] for i in range(3)]))
if __name__ == '__main__':
main()
|
# global关键字声明的变量必须在全局作用域上,不能嵌套作用域上,
# 当要修改嵌套作用域(enclosing作用域,外层非全局作用域)中的变量怎么办呢,这时就需要nonlocal关键字了
def outer():
count = 10
def inner():
# nonlocal count
# global count
count = 100
print(count)
inner()
print(count)
outer()
# 当内部作用域想修改外部作用域的变量时,就要用到global和nonlocal关键字了,
# 当修改的变量是在全局作用域(global作用域)上的,就要使用global先声明一下
|
async def async_value(value):
"""
Gives an object which can be used in .thenReturn for methods that are coroutines
:param value: what should be returned after coroutine is awaited
:return: coroutine that can be awaited
"""
return value
# noinspection PyPep8Naming
class async_iter:
"""
Object that can be used in async for. Specify it in .thenReturn as needed.
"""
def __init__(self, *items: any) -> None:
self.not_done = list(items)
self.done = list()
async def __aiter__(self):
return self
async def __anext__(self):
if self.not_done:
self.done.append(self.not_done.pop())
if not self.done:
assert not self.not_done
raise StopAsyncIteration()
return self.done.pop()
|
def get_larger(x, y):
if x > y:
return x
else:
return y
larger_value = get_larger(23, 32)
print(larger_value)
def add_numbers(x, y):
total = x + y
return total
print("This won't be printed")
print(add_numbers(4, 5))
#Comment and doc string
# few variables below
x = 10
y = 5
# make sum of the above two variables
# and store the result in z
z = x + y
print(z) # print the result
# print (x // y)
# another comment
def greet(word):
"""
Print a word with an
exclamation mark following it.
"""
print(word + "!")
def greet(word):
"""
Print a word with an
exclamation mark following it.
"""
print(word + "!")
# What the fucntion does?
print(greet.__doc__)
# Make sense, now lets use it
greet("Hello World")
def square_root(n):
"""Calculate the square root of a number.
Args:
n: the number to get the square root of.
Returns:
the square root of n.
Raises:
TypeError: if n is not a number.
ValueError: if n is negative.
"""
pass
|
class Worker:
""" An abstraction of a worker. """
def __init__(self, worker_id: str):
""" Create a worker instance.
Args:
worker_id: the id that uniquely identifies the user.
"""
self._worker_id = worker_id
def worker_id(self) -> str:
""" Get the id of this worker.
Returns:
worker_id (str) : the id of this worker.
"""
return self._worker_id
|
"""
imutils/ml/aug/image/__init__.py
"""
|
"""AyudaEnPython: https://www.facebook.com/groups/ayudapython
Crea un programa, que calcule el equivalente humano de la edad de un
perro. Si los dos primeros años de vida de un perro equivalen diez años
humanos, y los siguientes años de vida de un perro equivalen cada uno a
cuatro años humanos.
"""
def calcular(edad: int) -> int:
if edad <= 2:
return 10 * edad
else:
return 20 + 4 * (edad - 2)
def main():
edad = int(input("Ingrese la edad del perro: "))
print("La edad del perro es:", calcular(edad))
if __name__ == "__main__":
main()
|
#Q.1 Convert tuples to list.
tup=(5,4,2,'a',16,'ram') #this is a tuples.
l=[] #this is empty list.
lenght=len(tup)
for i in (tup):
l.append(i)
print("list converted form tuples is :",l)
|
#A particularly hard problem to solve
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
#Suppose we have two arrays that are sorted
#l1 = [1,2,3]
#l2 = [4,5,6]
#L1 + L2 = [1,2,3,4,5,6]
#The median 3.5.
#Notice that the index where 3,4 are located is basically the maximum of the left split. And the right split of the union of the 2 arryas
#Well this implies a good algorithm too use
#We basically split the indexes of both arrays 2 parts each. First assume that 3 and 4 is where we can split off
#Then the left partitions [1,2,4] and right partition is [3,5,6]
#Then basically the the left partitions can be broken again on the median [1,2] and [2,4]
#The right partition is again brokn on the median [3,5] and [5,6]
#Notice that 2 and 5 were the medians on their respected parition we use discard them but then maximum(1,3) is used. And then minimum [4,6] is used.
#So averaging out (3,4) is 3.5
#The same idea applies when we add 2 sets and get odd numbers
#Get the lenghts of the two arrays
x = len(nums1)
y = len(nums2)
#Since we always want the median of the smaller array. We will want to swap them. If they are equal then this doesnt matter
#Since python is extremely anal about calling methods on itself in a clas. We have to say self
if y < x:
return self.findMedianSortedArrays(nums2,nums1)
start = 0
end = x
#If start becomes greater than the end then we cant partitition arrays in ascending order
while(start <= end):
#Create a partition based on the (start + (min(x,y))/2)
pivotx = int((start + end)/2)
pivoty = int((x + y + 1)/2) - pivotx
#These cases occur if find that a partition is the length of the entire array
#Particularly the mininums edge case occurs if the pivot winds up taking up the arrya
#The maximum edge cases occurs if the pivot gets completely reduced to zero
maxLeftX = -(sys.maxsize-1 ) if pivotx == 0 else nums1[pivotx-1]
minRightX = sys.maxsize if pivotx == x else nums1[pivotx]
maxLeftY = -(sys.maxsize-1) if pivoty == 0 else nums2[pivoty-1]
minRightY = sys.maxsize if pivoty == y else nums2[pivoty]
#We care about these specific integers to get the conclusion we so desired.
#Which is the maximum of the Left partitions of each array and the minimum of each partition in the Right partition of each arryas
#It is up the reader to understand why we can get the medium through these four numbers
if(maxLeftX <= minRightY and maxLeftY <= minRightX):
#We found the correct partition
#return their specific cases
#In the case of even. The median the average of the maximum(maxLeftx,maxLefty) and min(minRightX,minRightY)
if (x+y) % 2 == 0:
maximum = max(maxLeftX,maxLeftY)
minimum = min(minRightX,minRightY)
return float((maximum + minimum)/2 )
#Otherwise its the maximum between the maximum of the left partition of X and Y
else:
return float(max(maxLeftX,maxLeftY))
#We gone too far in the array. We need to move the pivot back
elif maxLeftX > minRightY:
end = pivotx -1
else:
#We gone too far back in the array. We need to the move the pivote forward
start = pivotx + 1
|
epsilon = 0.001
def sqr_root(low,high,n,const_value):
mid = (low+high)/2.0
mid_2 = mid
for _i in range(n-1):
mid_2*=mid
dif = mid_2 - const_value
if abs(dif) <= epsilon:
return mid
elif mid_2 > const_value:
return sqr_root(low,mid,n,const_value)
elif mid_2 < const_value:
return sqr_root(mid,high,n,const_value)
def find_nth_root(value, n):
low = 0
high = value
return sqr_root(low,high,n,value)
def main():
print(find_nth_root(12345,3))
if __name__ == "__main__":
main()
|
#! /usr/bin/python3
# seesway.py -- This script counts from -10 to 10 and then back from 10 to -10
# Author -- Prince Oppong Boamah<[email protected]>
# Date -- 27th August 2015
for i in range(-10, 11): print(i)
for i in range(9, -1, -1): print(i)
for i in range(-10, 0): print(i)
|
#WAP to input marks of 5 subject and find average and assign grade
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
total=(sub1+sub2+sub3+sub4+sub4)
avg=total/5
if(avg>=90):
print("Grade: O")
elif(avg>=80 and avg<=89):
print("Grade: E")
elif(avg>=70 and avg<=79):
print("Grade: A")
elif(avg<70):
print("Grade: B")
|
"""Kata url: https://www.codewars.com/kata/5803c0c6ab6c20a06f000026."""
def swap_vowel_case(st: str) -> str:
return ''.join(
x.swapcase() if x.lower() in 'aeoui' else x for x in st
)
|
class Solution:
def thirdMax(self, nums: List[int]) -> int:
maxs = [-float('inf'),-float('inf'),-float('inf')]
m = 0
for i in range(len(nums)):
if nums[i] not in maxs:
if m < 3 :
maxs[m] = nums[i]
m += 1
if m == 3:
maxs = sorted(maxs)
else:
if nums[i] > maxs[0]:
j = len(maxs) - 1
while j >= 0:
if nums[i] > maxs[j]:
for k in range(j):
maxs[k] = maxs[k+1]
maxs[j] = nums[i]
break
j -= 1
if m > 2:
return maxs[0]
else:
if maxs[0] > maxs[1]:
return maxs[0]
else:
return maxs[1]
|
VERSION = '0.2'
TYPE = 'type'
LIBRML = 'libRML'
ITEM = 'item'
ID = 'id'
ACTIONS = 'actions'
RESTRICTIONS = 'restrictions'
PERMISSION = 'permission'
TENANT = 'tenant'
MENTION = 'mention'
SHARE = 'sharealike'
USAGEGUIDE = 'usageguide'
TEMPLATE = 'template'
#XML
XRESTRICTION = 'restriction'
XACTION = 'action'
XPART = 'part'
XGROUP = 'group'
XSUBNET = 'subnet'
XMACHINE = 'machine'
# Fieldnames
SUBNET = 'subnet'
GROUPS = 'groups'
PARTS = 'parts'
MINAGE = 'minage'
INSIDE = 'inside'
OUTSIDE = 'outside'
MACHINES = 'machines'
FROMDATE = 'fromdate'
TODATE = 'todate'
DURATION = 'duration'
COUNT = 'count'
SESSIONS = 'sessions'
WATERMARK = 'watermarkvalue'
COMMERCIAL = 'commercialuse'
NONCOMMERCIAL = 'noncommercialuse'
MAXRES = 'maxresolution'
MAXBIT = 'maxbitrate'
|
def factorial(n):
if(n == 0):
return 1
else:
return n*factorial(n-1)
if __name__ == "__main__":
number = int(input("Enter number:"))
print(f'Factorial of {number} is {factorial(number)}')
|
# TRATANDO VÁRIOS VALORES v1.0
# Crie um programa que leia vários números inteiros pelo teclado. O programa só vai parar quando o usuário digitar o valor 999, que é a condição de parada. No final, mostre quantos números foram digitados e qual foi a soma entre eles (desconsiderando o flag).
cont = 0
s = 0
valor = int(input('Digite um numero'))
while valor != 999:
s += valor
valor = int(input('Digite um numero'))
cont += 1
print(f'{cont} - {s}')
|
A = True
B = False
C = A and B
D = A or B
if C == True:
print("A and B is True.")
else:
print("A and B is False.")
if D == True:
print("A or B is True.")
else:
print("A or B is False.")
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.