This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
sourceStats.sh
executable file
·134 lines (88 loc) · 2.81 KB
/
sourceStats.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
source config/config.sh
# Chargement des métadonnées des sources
curl -sL https://raw.githubusercontent.com/etalab/decp-rama/master/sources/metadata.json > source-metadata.json
sources=`jq -r '.[] | .code' source-metadata.json`
if [[ -f nbMarches_* ]]
then
rm nbMarches_*
fi
if [[ ! -d logs/all ]]
then
mkdir -p logs/all
fi
# Initialise JSON
echo "[]" > sourceStats.json
# Make CSV header line
head="date"
for source in $sources
do
head="$head,$source,${source}_new"
done
echo $head > sourceStats.csv
# Download logs from circle
# Jobs before 51 are rubbish
i=51
# Get last job number
lastLog=`curl -sL "https://circleci.com/api/v1.1/project/github/etalab/decp-rama/tree/master?circle-token=$circleApiKey&limit=1&filter=completed" | jq -r '.[0].build_num'`
echo "last log = $lastLog"
while [[ ! $i -gt $lastLog ]]
do
log=logs/all/$i.log
# Get job metadata
if [[ ! -s logs/all/$i.json ]]
then
curl -sL https://circleci.com/api/v1.1/project/github/etalab/decp-rama/$i -u "$circleApiKey:" > logs/all/$i.json
fi
date=`jq -r '.start_time | split("T") | .[0]' logs/all/$i.json`
url=102
grepNb=`grep "début du traitement pour source" $log | wc -l`
while [ $url -lt 105 -a $grepNb -le 1 ]
do
echo "Downloading logs ($i $url)..."
curl -sL "https://circleci.com/api/v1.1/project/github/etalab/decp-rama/$i/output/$url/0?file=true" > $log
grepNb=`grep "début du traitement pour source" $log | wc -l`
((url++))
done
if [[ $grepNb -gt 1 ]]
then
cp $log logs/$date.log
fi
((i++))
done
# Processing logs to extract stats
for log in `ls logs/*.log`
do
echo ""
echo "Processing $log..."
dateObject="{\"sources\":["
date=`basename -s .log $log`
csvLine="$date"
for source in $sources
do
nbMarches=`grep "$source contient" $log | sed -r 's/^.*contient ([0-9]+) marchés/\1/' | tr -d "\r\n "`
csvLine="$csvLine,$nbMarches"
if [[ -f nbMarches_$source ]]
then
prevNbMarches=`cat nbMarches_$source | tr -d "\r\n "`
nbNewMarches=$((nbMarches - prevNbMarches))
else
nbNewMarches=0
fi
echo $nbMarches > nbMarches_$source
dateObject="$dateObject
{\"source\":\"$source\",\"marches\":$nbMarches,\"nouveauxMarches\":$nbNewMarches},"
csvLine="$csvLine,$nbNewMarches"
done
# Close the date object
dateObject="${dateObject::-1}],\"date\":\"$date\"}"
echo $dateObject > dateObject.json
echo $csvLine >> sourceStats.csv
jq --slurpfile object dateObject.json '. += $object' sourceStats.json > sourceStatsTemp
mv sourceStatsTemp sourceStats.json
done
jq '.' sourceStats.json | head
head sourceStats.csv
#rm job.json dateObject.json
rm nbMarches*
# Close JSON