Last active
February 18, 2025 09:25
-
-
Save blzzua/c197b8b6755d4b1ce183bb03ff80cb90 to your computer and use it in GitHub Desktop.
pareto principle coeffiecient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pareto_coef(data, is_already_sorted = False): | |
"""https://en.wikipedia.org/wiki/Pareto_principle""" | |
if not is_already_sorted: | |
data.sort(reverse=True) | |
data_len = len(data) | |
data_sum = sum(data) | |
acum = 0 | |
for i, value in enumerate(data,1): | |
acum += value | |
i_pct = 100*i/data_len | |
acum_val_pct = 100*acum/data_sum | |
if i_pct > 100-acum_val_pct: | |
break | |
return i_pct |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF exists #data | |
go | |
select count(1) as cnt into #data from SOMETABLE | |
group by SOME, GROUP, OF, FIELDS | |
order by 1 desc | |
declare @total_cnt bigint | |
declare @total_rownumber bigint | |
select @total_cnt = sum(cnt), @t_rn = count(cnt) from #data | |
select top 1 rn_percent as beer_law_coef from ( | |
select | |
100*ROW_NUMBER ( ) over ( order by cnt desc) / (@total_rownumber*1.0) as rn_percent, | |
100*(1-sum(cnt) over ( order by cnt desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)/(@total_cnt*1.0)) as value_percent | |
from #data ) t | |
where rn_percent >= value_percent | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment