Skip to content

Instantly share code, notes, and snippets.

View RaMSFT's full-sized avatar

RaMS Nelluri RaMSFT

View GitHub Profile
@RaMSFT
RaMSFT / w01-c01-positive-negative.py
Created January 22, 2022 17:29
From a given list of Integers, calculate the percentage (up to 4 decimals) of elements that are positive, negative and zeros
def positive_negative(input_list):
# Write your code here
zeros = input_list.count(0)
total = len(input_list)
if zeros == 0:
input_list.append(0)
input_list.sort()
neg_list = input_list[:input_list.index(0)]
import time
table_list = ['customers','orders','adress','payments','shipment','sellers','products','tax','fraud','revenue']
def create_table_loop(table_name):
spark.sql(f"create table loop_db.{table_name}(id int, name string)")
loop_start_time = time.time()
for table in table_list:
import time
from multiprocessing.pool import ThreadPool
table_list = ['customers','orders','adress','payments','shipment','sellers','products','tax','fraud','revenue']
print(table_list)
def create_table_fanout(table_name):
spark.sql(f"create table fanout_db.{table_name}(id int, name string)")
import time
from multiprocessing.pool import ThreadPool
table_list = ['customers','orders','adress','payments','shipment','sellers','products','tax','fraud','revenue']
print(table_list)
def create_table_loop(table_name):
spark.sql(f"create table loop_db.{table_name}(id int, name string)")
from multiprocessing.pool import ThreadPool
import time
## Change the database name of your choice
databse_name = 'your_database_name'
#create a list of all tables to generate metrics
table_list = spark.sql(f"show tables in {databse_name}").select('database','tablename').collect()
print(table_list)
#if you would like to know how tage works, un commete these
# list(range(5)) #0, 1, 2, 3, 4
# list(range(2, 8)) #2, 3, 4, 5, 6, 7
# list(range(2, 8, 2)) #2, 4, 6
firstdf = spark.range(100)
firstdf.count()
firstdf.show()
def string_int(text):
"""_summary_
Args:
text (string): a number enclosed in " or ' quotes as string
Returns:
integer: cast the string to number and return
"""
def calculate_power(x, n):
"""calculate the power
Args:
x (integer): integr value
n (integer): integer value
Returns:
_type_: power of x to the n
"""
def calculate_points(wins, draws, losses):
"""calculate points for a football match based on wins, losses, and draws
Args:
wins (integer): number of wins
draws (integer): number of draws
losses (integer): number of losses
Returns:
_type_: _description_
def is_same_num(num1, num2):
"""Check if given two numbers are equal
Args:
num1 (numeric): input numebr one
num2 (numeric): input number two
Returns:
Boolean: Rteurn True when both numbers are same, else False
"""