Quick Report to show Tenting eligibility

I am attempting to better know who is allowed to tent together per policy. I put the following two scripts together which uses the exported Roster_Report.csv from my.scouting.org. One is PowerShell and the other is Python. Hopefully they will be useful for others.

Python Version (tested against 3.9)


import csv

def find_close_ages(filename):
    with open(filename, mode='r') as file:
        for _ in range(10):  # Skip the first 10 lines
            next(file)
        csv_reader = csv.DictReader(file)
        people = [
            {
                'FullName': f"{row['First_Name']} {row['Last_Name']}",
                'Age': int(row['Age'])
            } for row in csv_reader if int(row['Age']) < 18
        ]

    close_age_pairs = []
    greater_age_pairs = []
    
    for i in range(len(people)):
        for j in range(i+1, len(people)):
            age_diff = abs(people[i]['Age'] - people[j]['Age'])
            if age_diff <= 2:
                close_age_pairs.append(
                    (
                        f"{people[i]['FullName']} ({people[i]['Age']})", 
                        f"{people[j]['FullName']} ({people[j]['Age']})"
                    )
                )
            else:
                greater_age_pairs.append(
                    (
                        f"{people[i]['FullName']} ({people[i]['Age']})", 
                        f"{people[j]['FullName']} ({people[j]['Age']})"
                    )
                )

    print('Eligible Tenters (within 2 years of age):')
    for pair in close_age_pairs:
        print(f"  {pair[0]} and {pair[1]}")

    print('\nUneligible Tenters (greater than 2 years of age):')
    for pair in greater_age_pairs:
        print(f"  {pair[0]} and {pair[1]}")

# Usage
find_close_ages('Roster_Report.csv')

and PowerShell (tested with 5.1)

function Find-CloseAges {
    param (
        [string]$filename
    )

    # Read the file and skip the first 10 lines
    $people = Get-Content $filename | Select-Object -Skip 10 | ConvertFrom-Csv | Where-Object { [int]$_.Age -lt 18 }

    $closeAgePairs = @()
    $greaterAgePairs = @()

    $closeAgePairs += @("scout1, scout2")
    $greaterAgePairs += @("scout1, scout2")

    for ($i = 0; $i -lt $people.Count; $i++) {
        for ($j = $i + 1; $j -lt $people.Count; $j++) {
            $ageDiff = [math]::Abs([int]$people[$i].Age - [int]$people[$j].Age)
            if ($ageDiff -le 2) {
                $closeAgePairs += @("{0} {1} ({2}), {3} {4} ({5})" -f $people[$i].First_Name, $people[$i].Last_Name, $people[$i].Age, $people[$j].First_Name, $people[$j].Last_Name, $people[$j].Age)
            } else {
                $greaterAgePairs += @("{0} {1} ({2}), {3} {4} ({5})" -f $people[$i].First_Name, $people[$i].Last_Name, $people[$i].Age, $people[$j].First_Name, $people[$j].Last_Name, $people[$j].Age)
            }
        }
    }

    Write-Output "Eligible Tenters (within 2 years of age):"
    $closeAgePairs | ConvertFrom-Csv

    Write-Output "`nIneligible Tenters (greater than 2 years of age):"
    $greaterAgePairs | ConvertFrom-Csv

}

# Usage
Find-CloseAges -filename 'Roster_Report.csv'

Or just ask the Scouts who want to tent together “how old are you?”

1 Like

Very true, but it is a good idea to trust but verify.

Scout’s age is displayed on the Scoutbook Plus roster and you can optionally sort by age.

1 Like