Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,62 @@
func[] StandardRank d[] .
for i to len d[]
if i = 1 or d[i] <> d[i - 1] : k = i
r[] &= k
.
return r[]
.
func[] ModifiedRank d[] .
for i to len d[]
k = i
j = i + 1
while j <= len d[] and d[i] = d[j]
k = j
j += 1
.
r[] &= k
.
return r[]
.
func[] DenseRank d[] .
for i to len d[]
if i = 1 or d[i] <> d[i - 1] : k += 1
r[] &= k
.
return r[]
.
func[] OrdinalRank d[] .
for i to len d[] : r[] &= i
return r[]
.
func[] FractionalRank d[] .
i = 1
while i <= len d[]
f = i
j = i + 1
while j <= len d[] and d[i] = d[j]
f += j
j += 1
.
f /= (j - i)
while i < j
r[] &= f
i += 1
.
.
return r[]
.
data[] = [ 44 42 42 41 41 41 39 ]
names$[] = [ "Solomon" "Jason" "Errol" "Garry" "Bernard" "Barry" "Stephen" ]
#
proc show name$ r[] .
print name$ & " Ranking"
for i to len names$[]
print " " & r[i] & " - " & data[i] & " " & names$[i]
.
print ""
.
show "Standard" StandardRank data[]
show "Modified" ModifiedRank data[]
show "Dense" DenseRank data[]
show "Ordinal" OrdinalRank data[]
show "Fractional" FractionalRank data[]

View file

@ -0,0 +1,142 @@
function Get-Ranking
{
[CmdletBinding(DefaultParameterSetName="Standard")]
[OutputType([PSCustomObject])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]
$InputObject,
[Parameter(Mandatory=$false,
ParameterSetName="Standard")]
[switch]
$Standard,
[Parameter(Mandatory=$false,
ParameterSetName="Modified")]
[switch]
$Modified,
[Parameter(Mandatory=$false,
ParameterSetName="Dense")]
[switch]
$Dense,
[Parameter(Mandatory=$false,
ParameterSetName="Ordinal")]
[switch]
$Ordinal,
[Parameter(Mandatory=$false,
ParameterSetName="Fractional")]
[switch]
$Fractional
)
Begin
{
function Get-OrdinalRank ([PSCustomObject[]]$Values)
{
for ($i = 0; $i -lt $Values.Count; $i++)
{
$Values[$i].Rank = $i + 1
}
$Values
}
function Get-Rank ([PSCustomObject[]]$Scores)
{
foreach ($score in $Scores)
{
$score.Group | ForEach-Object {$_.Rank = $score.Rank}
}
$Scores.Group
}
function New-Competitor ([string]$Name, [int]$Score, [int]$Rank = 0)
{
[PSCustomObject]@{
Name = $Name
Score = $Score
Rank = $Rank
}
}
$competitors = @()
$scores = @()
}
Process
{
@($input) | ForEach-Object {$competitors += New-Competitor -Name $_.Split()[1] -Score $_.Split()[0]}
}
End
{
$scores = $competitors |
Sort-Object -Property Score -Descending |
Group-Object -Property Score |
Select-Object -Property @{Name="Score"; Expression={[int]$_.Name}}, @{Name="Rank"; Expression={0}}, Count, Group
switch ($PSCmdlet.ParameterSetName)
{
"Standard"
{
$rank = 1
for ($i = 0; $i -lt $scores.Count; $i++)
{
$scores[$i].Rank = $rank
$rank += $scores[$i].Count
}
Get-Rank $scores
}
"Modified"
{
$rank = 0
foreach ($score in $scores)
{
$rank = $score.Count + $rank
$score.Rank = $rank
}
Get-Rank $scores
}
"Dense"
{
for ($i = 0; $i -lt $scores.Count; $i++)
{
$scores[$i].Rank = $i + 1
}
Get-Rank $scores
}
"Ordinal"
{
Get-OrdinalRank $competitors
}
"Fractional"
{
Get-OrdinalRank $competitors | Group-Object -Property Score | ForEach-Object {
if ($_.Count -gt 1)
{
$rank = ($_.Group.Rank | Measure-Object -Average).Average
foreach ($competitor in $_.Group)
{
$competitor.Rank = $rank
}
}
}
$competitors
}
}
}
}

View file

@ -0,0 +1 @@
$scores = "44 Solomon","42 Jason","42 Errol","41 Garry","41 Bernard","41 Barry","39 Stephen"

View file

@ -0,0 +1 @@
$scores | Get-Ranking -Standard

View file

@ -0,0 +1 @@
$scores | Get-Ranking -Modified

View file

@ -0,0 +1 @@
$scores | Get-Ranking -Dense

View file

@ -0,0 +1 @@
$scores | Get-Ranking -Ordinal

View file

@ -0,0 +1 @@
$scores | Get-Ranking -Fractional