From 4b3c7a6fa17f3e1b76e6f388b432c5483ae222ef Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 11 Jan 2024 12:03:37 +0000 Subject: [PATCH] Add cicsdev-summary.sh script Create script to generate summaries of the cicsdev stats Signed-off-by: James Taylor --- README.md | 13 ++++++++- scripts/cicsdev-summary.sh | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 scripts/cicsdev-summary.sh diff --git a/README.md b/README.md index 04855a70c4..30d4889676 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,18 @@ -# repo-stats +# CICSdev stats Download statistics for repos in the CICSDev org +## Summary + +The [github-repo-stats GitHub Action](https://github.com/marketplace/actions/github-repo-stats) collects stats and generates [reports for each repository in the cicsdev organisation](https://github.com/cicsdev/repo-stats/tree/github-repo-stats/cicsdev) individually. + +The `cicsdev-summary.sh` script can be used to create summary files for *clones*, *forks*, *stargazers*, and *views*. To run the script: + +1. copy `cicsdev-summary.sh` to a suitable directory on your path, e.g. `~/bin` +2. clone the `repo-stats` repository +3. check out the `github-repo-stats` branch +4. run `cicsdev-summary.sh` from the root of the `repo-stats` repository + ## TODO Get the list of repos automatically instead of hard coding it in the workflow diff --git a/scripts/cicsdev-summary.sh b/scripts/cicsdev-summary.sh new file mode 100755 index 0000000000..025b6bb8a8 --- /dev/null +++ b/scripts/cicsdev-summary.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +statsdir=./cicsdev +outdir=./summary +tempdir="$outdir/temp" + +if ! command -v qsv >/dev/null 2>&1 +then + echo >&2 "This script requires qsv." + exit 1 +fi + +if [ ! -d "$statsdir" ]; then + echo >&2 "Cannot find cicsdev directory: $statsdir" + exit 1 +fi + +mkdir -p "$tempdir" + +for csvfile in forks stargazers; do + echo "Combining $csvfile.csv files..." + echo "repo,total" > "$tempdir/$csvfile.csv" + find "$statsdir" -name "$csvfile.csv" -type f -exec sh -c 'repo=$(echo "$1" | cut -d "/" -f3); printf "$repo,"; tail -n 1 $1 | cut -d , -f 2' _ {} \; >> "$tempdir/$csvfile.csv" + qsv sort -s repo "$tempdir/$csvfile.csv" > "$outdir/$csvfile.csv" + qsv sort -NR -s total "$tempdir/$csvfile.csv" | head -n 11 > "$outdir/${csvfile}_top10.csv" +done + +for col in clones views; do + echo "Combining $col data..." + mkdir -p "$tempdir/$col" + + find "$statsdir" -name "views_clones_aggregate.csv" -type f -exec sh -c 'repo=$(echo "$1" | cut -d "/" -f3); qsv select time_iso8601,$2_total "$1" | qsv rename date,$repo - > "$3/$repo.csv"' _ {} "$col" "$tempdir/$col" \; + + rm -f "$tempdir/$col.csv" + + for filename in "$tempdir/$col/"*.csv + do + if [ ! -f "$filename" ]; then + echo "Skipping $filename" + continue + elif [ ! -f "$tempdir/$col.csv" ]; then + echo "Copying $filename" + + cp "$filename" "$tempdir/$col.csv" + else + echo "Joining $filename" + + qsv joinp --null-value "0" --full date "$tempdir/$col.csv" date "$filename" > "$tempdir/joined_$col.csv" + mv "$tempdir/joined_$col.csv" "$tempdir/$col.csv" + fi + done + + qsv sort -s date "$tempdir/$col.csv" > "$outdir/$col.csv" + qsv stats "$tempdir/$col.csv" | qsv select field,sum | qsv sort -NR -s sum | qsv rename repo,$col | head -n 11 > "$outdir/${col}_top10.csv" +done