def calculate_rfmscore(value, q_dict, one_is_worst=True):
	"""
	:param value: a value to be rendered into RFM score
	:param q_dict: quantile calculation by using bucket like[0.25,0.50,0.75] , a dictionary of keys are the percentages and values are calculated percentiles
	:param one_is_worst: When True, the smallest value will have lowest RFM score, vise versa.
	:return: calculated RFM score, 1 is the worst and len(buckets)+1 is the best (ASC), 1 is the best and len(buckets)+1 is worst (DESC)
	"""
	max_score = len(q_dict) + 1  # Max score 5 needs 4 break points(percentiles)
	sorted_bucket = sorted(list(q_dict.keys()))  # Sort the percentage by ascending, first percentage wil be the smallest
	for idx, percentage in enumerate(sorted_bucket):
		if value <= q_dict[percentage]:
			return idx + 1 if one_is_worst else max_score - idx  # Bigger than or equal to the current percentile
	return max_score if one_is_worst else 1