Skip to content

Commit

Permalink
Add cicsdev-summary.sh script
Browse files Browse the repository at this point in the history
Create script to generate summaries of the cicsdev stats

Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti committed Jan 11, 2024
1 parent 5da5600 commit 4b3c7a6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
55 changes: 55 additions & 0 deletions scripts/cicsdev-summary.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4b3c7a6

Please sign in to comment.