Skip to content

List or generate aggregate data using ctbk aggregate #11

List or generate aggregate data using ctbk aggregate

List or generate aggregate data using ctbk aggregate #11

Workflow file for this run

name: List or generate aggregate data using `ctbk aggregate`
on:
workflow_dispatch:
inputs:
# Combined a few sets of flags into single `choice` inputs, to avoid "you may only define up to 10 `inputs` for a `workflow_dispatch` event": https://github.com/neighbor-ryan/ctbk.dev/actions/runs/5954742040
time:
description: "Group by time-period granularity"
type: choice
options:
- Year
- Month
- Day
- Hour
weekday:
description: "Group by \"weekday\""
type: boolean
region:
description: "Group by \"region\""
type: boolean
gender:
description: "Group by \"gender\""
type: boolean
user_type:
description: "Group by \"user_type\""
type: boolean
rideable_type:
description: "Group by \"rideable_type\""
type: boolean
stations:
description: "Group by station start or end"
type: choice
options:
- "Start station"
- "End station"
- "Both"
aggregate_by:
description: "Aggregate by \"count\", \"duration\", or both"
type: choice
options:
- "Ride count"
- "Duration"
- "Both"
date_range:
description: "Date range (e.g. \"2022-\", \"202302-202304\"). Default \"-\" is \"all\" (same as \"201306-\")."
type: string
default: "-"
subcommand:
description: "Subcommand"
type: choice
options:
- "List S3 URLs"
- "Create S3 URLs"
jobs:
dispatch:
name: List or generate aggregate data using `ctbk aggregate`
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.11
cache: 'pip'
- run: pip install -e .
- env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
run: |
# Build "-g" ("Group keys") arg
time=${{ inputs.time }}
if [ $time == Year ]; then
g=y
elif [ $time == Month ]; then
g=ym
elif [ $time == Day ]; then
g=ymd
elif [ $time == Hour ]; then
g=ymdh
fi
g=$g${{ inputs.weekday && 'w' || '' }}
g=$g${{ inputs.region && 'r' || '' }}
g=$g${{ inputs.gender && 'g' || '' }}
g=$g${{ inputs.user_type && 't' || '' }}
g=$g${{ inputs.rideable_type && 'b' || '' }}
stations=${{ inputs.stations }}
if [ "$stations" == "Start station" ]; then
s=s
elif [ "$stations" == "End station" ]; then
s=e
elif [ "$stations" == "Both" ]; then
s=se
fi
g=$g$s
# Build "-a" ("Aggregation keys") arg
agg_by="${{ inputs.aggregate_by }}"
if [ "$agg_by" == "Ride count" ]; then
a=c
elif [ "$agg_by" == "Duration" ]; then
a=d
elif [ "$agg_by" == "Both" ]; then
a=cd
fi
# Subcommand arg
if [ "${{ inputs.subcommand }}" == "List S3 URLs" ]; then
subcmd=urls
else
subcmd=create
fi
# Run (list URLs, or generate them)
ctbk --s3 aggregated -d${{ inputs.date_range }} -g$g -a$a $subcmd