Skip to content

Commit

Permalink
Add simple script to convert wbs source to csv
Browse files Browse the repository at this point in the history
  • Loading branch information
darius-bluespec committed Sep 12, 2024
1 parent 8324b94 commit 7d8c3d5
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions wbs2csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# usage: wbs2csv < wbs.md > wbs.csv

normalize_time () {
if [[ $1 =~ ^([[:digit:]]+)([hdwm]) ]]; then
case ${BASH_REMATCH[2]} in
h) echo ${BASH_REMATCH[1]} ;;
d) echo $(( ${BASH_REMATCH[1]} * 8 )) ;;
w) echo $(( ${BASH_REMATCH[1]} * 5 * 8 )) ;;
m) echo $(( ${BASH_REMATCH[1]} * 5 * 30 )) ;;
esac
else
echo $1
fi
}

echo "\"element\",\"description\",\"dependencies\",\"owner\",\"optimistic\",\"expected\",\"pessimistic\",\"progress\""
while IFS= read line; do
element=""
description=""
dep=""
owner=""
optimistic=""
expected=""
pessimistic=""
progress=""

if [[ $line =~ ^([[:alnum:].-]+)[[:space:]]((:?[^=[]+[[:space:]]?)+)([[:space:]]|$) ]]; then
element="${BASH_REMATCH[1]}"
description="${BASH_REMATCH[2]}"
else
continue
fi
if [[ $line =~ [[:space:]][[]([0-9dwm]+),\ ([0-9dwm]+),\ ([0-9dwm]+)[]]([[:space:]]|$) ]]; then
optimistic="$(normalize_time ${BASH_REMATCH[1]})"
expected="$(normalize_time ${BASH_REMATCH[2]})"
pessimistic="$(normalize_time ${BASH_REMATCH[3]})"
fi
if [[ $line =~ dep=([[:alnum:].,-]+)([[:space:]]|$) ]]; then
dep="${BASH_REMATCH[1]}"
fi
if [[ $line =~ owner=([[:alnum:]]+)([[:space:]]|$) ]]; then
owner="${BASH_REMATCH[1]}"
fi
if [[ $line =~ progress=([[:digit:]]+)%([[:space:]]|$) ]]; then
progress="${BASH_REMATCH[1]}"
fi
echo "\"$element\",\"$description\",\"$dep\",\"$owner\",\"$optimistic\",\"$expected\",\"$pessimistic\",\"$progress\""
done

0 comments on commit 7d8c3d5

Please sign in to comment.