-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcomment-commenter-report.sh
executable file
·97 lines (72 loc) · 2.43 KB
/
comment-commenter-report.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
set -e
org_to_process="$1"
# Has the org parameter been given?
if [ -z "$org_to_process" ];
then
echo "Processing the Jenkins org (no alternate org specified)"
org_to_process="jenkins"
fi
if [[ "$org_to_process" == "jenkins" ]];
then
org_data_dir="data"
org_data_consolidation_dir="./consolidated_data"
else
org_data_dir="alt_orgs/${org_to_process}/data"
org_data_consolidation_dir="alt_orgs/${org_to_process}/consolidated_data"
fi
# create the data directory if it doesn't exist
[ -d "$org_data_dir" ] || mkdir -p "$org_data_dir"
[ -d "$org_data_consolidation_dir" ] || mkdir -p "$org_data_consolidation_dir"
# Constants
oldest_year=2020
oldest_month=01
# initialize data
today_year=$(date '+%Y')
today_month=$(date '+%m')
current_year_month="${today_month} ${today_year}"
# Make sure that we are using GNU Date on MacOS
if [[ "$OSTYPE" == "darwin"* ]]; then
gnu_date="gdate"
else
gnu_date="date"
fi
output_dir="$org_data_consolidation_dir"
[ -d $output_dir ] || mkdir $output_dir
report_filename="${output_dir}/summary_comment_counts.csv"
echo "month,comments,commenter" > $report_filename
i=0
while :
do
to_process_year=$(${gnu_date} -d "${oldest_year}/${oldest_month}/1 + ${i} month" "+%Y")
to_process_month=$(${gnu_date} -d "${oldest_year}/${oldest_month}/1 + ${i} month" "+%m")
full_to_process_date="${to_process_month} ${to_process_year}"
if [[ "$current_year_month" == "$full_to_process_date" ]]; then
echo "done..."
break
fi
csv_filename="$org_data_dir/comments-${to_process_year}-${to_process_month}.csv"
if [ -f "$csv_filename" ]
then
temp_nbr=$(tail -n +2 "$csv_filename" | wc -l)
number_submissions=$(echo "$temp_nbr" | xargs)
else
number_submissions="0"
fi
submitter_csv_filename="$org_data_dir/comments_per_commenter-${to_process_year}-${to_process_month}.csv"
if [ -f "$submitter_csv_filename" ]
then
temp_nbr=$(tail -n +2 "$submitter_csv_filename" | wc -l)
number_submitters=$(echo "$temp_nbr" | xargs)
else
number_submitters="0"
fi
echo "\"${to_process_month}-${to_process_year}\",${number_submissions},${number_submitters}"
echo "\"${to_process_month}-${to_process_year}\",${number_submissions},${number_submitters}" >> $report_filename
# For Debug
# if [[ "$i" == '4' ]]; then
# echo "STOP !!!!"
# break
# fi
i=$((i+1))
done