<commit_before>#!/usr/bin/python3

from math import exp, pow, factorial
from viewer import *

"""doc
	@method
	Prob_AccDataUnderTH:
		calculate the probability that i-th packet accumulate in T ms under threshold
	Prob_AccDataUnderTH:
		calculate the probability that i-th packet accumulate in T ms over threshold
	LengthAwkSlpCyl: calc awake-sleep-cycle, K (TTI)
	DataAcc: calc data accumulation, DataAcc (#packet)
"""
def Prob_AccDataUnderTH(lambd, threshold, simTime):
	if type(threshold) is float: threshold= int(threshold)
	p_accumulate = 0;
	while(threshold >= 0):
		# p_accumulate += exp(-1*lambd*time)*pow(lambd*time, threshold)/factorial(threshold);
		tmp_p = exp(-1*lambd*simTime);
		for i in range(1, threshold+1): tmp_p *= lambd*simTime/i;
		p_accumulate += tmp_p;
		threshold -= 1;
	# print("-	p_accumulate: %g" % p_accumulate)
	return p_accumulate;

def Prob_AccDataOverTH(lambd, threshold, simTime):
	return 1-Prob_AccDataUnderTH(lambd, threshold, simTime);

def LengthAwkSlpCyl(lambd, DATA_TH, PROB_TH= 0.8, view= None):
	# print("Calculating awake-sleep-cycle with DATA_TH(%d pkt), PROB_TH(%.2f)" % (DATA_TH, PROB_TH));
	K= 1;			# ms
	d_K= dict();	# {K: prob}
	while(1):
		p_acc= Prob_AccDataOverTH(lambd, DATA_TH, K);
		d_K[K]= p_acc;
		# print("Get	prob: %f in %d TTI" % (p_acc, K))

		if(p_acc > PROB_TH): break;
		else: K+=1;
	return d_K if view is True else K

def DataAcc(lambd, K, PROB_TH= 0.8, view= None):
	# print("Calculating number of packet accumulate in %d TTI with lambd %g (packet/ms)" %(K, lambd))
	pkt=0;			# number of packet
	d_K= dict();	# {pkt: prob}
	while(1):
		p_acc= Prob_AccDataUnderTH(lambd, pkt, K);
		d_K[pkt]= p_acc;
		# print("Get	prob: %f in %d TTI only accumulate %d packet" % (p_acc, K, pkt))

		if(p_acc > PROB_TH): break;
		else: pkt+= 1;
	return d_K if view is True else pkt;

def getDataTH(buf_size, pkt_size, percent=0.8):
	"""[summary] get DATA_TH

	[description] check the capability and return how many packet could buffer in queue

	Arguments:
		buf_size {int} -- [description] (bits)
		pkt_size {int} -- [description] (bits)

	Keyword Arguments:
		percent {number} -- [description] (default: {0.8})
	"""
	return (buf_size/pkt_size)*percent

if __name__ == "__main__":

	# For same UE, larger PROB_TH leads to larger K value
	# Fake UE info:
	#	bufSize= 8000 bits
	# 	lambd= (50 bit/ms) / pktSize (800 bits)
	#	DATA_TH= int(testUE.buf[testUE.status] * 0.8 / pktSize)= int(6400/800) = 8
	#	PROB_TH1= 0.8, PROB_TH2= 0.2
	lambd=50/800
	Data_TH=8
	P1=0.8
	P2=0.2

	K_star = LengthAwkSlpCyl(lambd, Data_TH, P1, True)
	K_caret = LengthAwkSlpCyl(lambd, Data_TH, P2, True)<commit_msg>bugfix: DATA_TH should based on capacity<commit_after>#!/usr/bin/python3

from math import exp, pow, factorial
from viewer import *

"""doc
	@method
	Prob_AccDataUnderTH:
		calculate the probability that i-th packet accumulate in T ms under threshold
	Prob_AccDataUnderTH:
		calculate the probability that i-th packet accumulate in T ms over threshold
	LengthAwkSlpCyl: calc awake-sleep-cycle, K (TTI)
	DataAcc: calc data accumulation, DataAcc (#packet)
"""
def Prob_AccDataUnderTH(lambd, threshold, simTime):
	if type(threshold) is float: threshold= int(threshold)
	p_accumulate = 0;
	while(threshold >= 0):
		# p_accumulate += exp(-1*lambd*time)*pow(lambd*time, threshold)/factorial(threshold);
		tmp_p = exp(-1*lambd*simTime);
		for i in range(1, threshold+1): tmp_p *= lambd*simTime/i;
		p_accumulate += tmp_p;
		threshold -= 1;
	# print("-	p_accumulate: %g" % p_accumulate)
	return p_accumulate;

def Prob_AccDataOverTH(lambd, threshold, simTime):
	return 1-Prob_AccDataUnderTH(lambd, threshold, simTime);

def LengthAwkSlpCyl(lambd, DATA_TH, PROB_TH= 0.8, view= None):
	# print("Calculating awake-sleep-cycle with DATA_TH(%d pkt), PROB_TH(%.2f)" % (DATA_TH, PROB_TH));
	K= 1;			# ms
	d_K= dict();	# {K: prob}
	while(1):
		p_acc= Prob_AccDataOverTH(lambd, DATA_TH, K);
		d_K[K]= p_acc;
		# print("Get	prob: %f in %d TTI" % (p_acc, K))

		if(p_acc > PROB_TH): break;
		else: K+=1;
	return d_K if view is True else K

def DataAcc(lambd, K, PROB_TH= 0.8, view= None):
	# print("Calculating number of packet accumulate in %d TTI with lambd %g (packet/ms)" %(K, lambd))
	pkt=0;			# number of packet
	d_K= dict();	# {pkt: prob}
	while(1):
		p_acc= Prob_AccDataUnderTH(lambd, pkt, K);
		d_K[pkt]= p_acc;
		# print("Get	prob: %f in %d TTI only accumulate %d packet" % (p_acc, K, pkt))

		if(p_acc > PROB_TH): break;
		else: pkt+= 1;
	return d_K if view is True else pkt;

def getDataTH(capacity, pkt_size, percent=0.8):
	return (capacity/pkt_size)*percent

if __name__ == "__main__":

	# For same UE, larger PROB_TH leads to larger K value
	# Fake UE info:
	#	bufSize= 8000 bits
	# 	lambd= (50 bit/ms) / pktSize (800 bits)
	#	DATA_TH= int(testUE.buf[testUE.status] * 0.8 / pktSize)= int(6400/800) = 8
	#	PROB_TH1= 0.8, PROB_TH2= 0.2
	lambd=50/800
	Data_TH=8
	P1=0.8
	P2=0.2

	K_star = LengthAwkSlpCyl(lambd, Data_TH, P1, True)
	K_caret = LengthAwkSlpCyl(lambd, Data_TH, P2, True)
{'fraction_non_alphanumeric': 0.13909399321492716, 'fraction_numerical': 0.02474555976850928, 'mean_word_length': 4.6, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '57996', 'n_tokens_mistral': 2216, 'n_tokens_neox': 2080, 'n_words': 558}