Skip to content

Commit afe34c2

Browse files
committed
2022.05.17:
* fixed: bash/github/accum-stats.sh: count/uniques minimum update fix * new: bash/github/accum-stats.sh: added `STATS_CHANGED_DATES` return variable to indicate the list of changed dates at the current date * changed: bash/github/accum-stats.sh: `STATS_CURRENT_DATE_*` return variables replaced by `STATS_LAST_CHANGED_DATE_*` return variable because last changed date and current date are different dates and the last changed date taken into account at the current date * changed: bash/github/accum-stats.sh: commit message is changed to indicate accumulation for the last changed date only instead of accumulation for all changed dates because the commit message will be placed for all files including `by_year/YYYY/YYYY-MM-DD.json` files * refactor: bash/github: minor refactor
1 parent 67604e5 commit afe34c2

File tree

7 files changed

+79
-81
lines changed

7 files changed

+79
-81
lines changed

bash/board/accum-stats.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fi
190190
191191
# CAUTION:
192192
# We must explicitly state the statistic calculation time in the script, because
193-
# the time taken from a script and the time set to commit changes ARE DIFFERENT
193+
# the time taken from the input and the time set to commit changes ARE DIFFERENT
194194
# and may be shifted to the next day.
195195
#
196196
gh_set_env_var STATS_DATE_UTC "$current_date_utc"

bash/cache/accum-content.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fi
432432
433433
# CAUTION:
434434
# We must explicitly state the content accumulation time in the script, because
435-
# the time taken from a script and the time set to commit changes ARE DIFFERENT
435+
# the time taken from the input and the time set to commit changes ARE DIFFERENT
436436
# and may be shifted to the next day.
437437
#
438438
gh_set_env_var STATS_DATE_UTC "$current_date_utc"

bash/github/accum-rate-limits.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fi
214214

215215
# CAUTION:
216216
# We must explicitly state the statistic calculation time in the script, because
217-
# the time taken from a script and the time set to commit changes ARE DIFFERENT
217+
# the time taken from the input and the time set to commit changes ARE DIFFERENT
218218
# and may be shifted to the next day.
219219
#
220220
gh_set_env_var STATS_DATE_UTC "$current_date_utc"

bash/github/accum-stats.sh

Lines changed: 62 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,13 @@ stats_uniques_max=()
160160
161161
stats_changed_data_timestamps=()
162162
163-
last_date_count_dec=0
164-
last_date_count_inc=0
165-
last_date_uniques_dec=0
166-
last_date_uniques_inc=0
163+
stats_last_changed_date_count=0
164+
stats_last_changed_date_uniques=0
165+
166+
stats_last_changed_date_count_dec=0
167+
stats_last_changed_date_count_inc=0
168+
stats_last_changed_date_uniques_dec=0
169+
stats_last_changed_date_uniques_inc=0
167170
168171
for i in $(jq ".$stat_list_key|keys|.[]" $stats_json); do
169172
# CAUTION:
@@ -198,6 +201,9 @@ for i in $(jq ".$stat_list_key|keys|.[]" $stats_json); do
198201
199202
[[ ! -d "$timestamp_year_dir" ]] && mkdir -p "$timestamp_year_dir"
200203
204+
count_saved=0
205+
uniques_saved=0
206+
201207
count_min=$count
202208
count_max=$count
203209
uniques_min=$uniques
@@ -208,13 +214,10 @@ for i in $(jq ".$stat_list_key|keys|.[]" $stats_json); do
208214
uniques_inc=0
209215
uniques_dec=0
210216
211-
count_saved=0
212-
uniques_saved=0
213-
214-
count_min_saved=0
215-
count_max_saved=0
216-
uniques_min_saved=0
217-
uniques_max_saved=0
217+
count_min_saved=$count
218+
count_max_saved=$count
219+
uniques_min_saved=$uniques
220+
uniques_max_saved=$uniques
218221
219222
count_dec_saved=0
220223
count_inc_saved=0
@@ -238,6 +241,25 @@ for i in $(jq ".$stat_list_key|keys|.[]" $stats_json); do
238241
count_dec_saved:0 count_inc_saved:0 \
239242
uniques_dec_saved:0 uniques_inc_saved:0
240243
244+
# min cleanup
245+
(( ! count_min_saved )) && count_min_saved=$count
246+
(( ! uniques_min_saved )) && uniques_min_saved=$uniques
247+
248+
# sign cleanup
249+
(( count_inc_saved = count_inc_saved )) # remove plus sign
250+
if (( count_dec_saved < 0 )); then
251+
(( count_dec_saved = -count_dec_saved ))
252+
else
253+
(( count_dec_saved = count_dec_saved ))
254+
fi
255+
256+
(( uniques_inc_saved = uniques_inc_saved )) # remove plus sign
257+
if (( uniques_dec_saved < 0 )); then
258+
(( uniques_dec_saved = -uniques_dec_saved ))
259+
else
260+
(( uniques_dec_saved = uniques_dec_saved ))
261+
fi
262+
241263
(( count_max_saved > count_max )) && count_max=$count_max_saved
242264
(( count_min_saved < count_min )) && count_min=$count_min_saved
243265
(( uniques_max_saved > uniques_max )) && uniques_max=$uniques_max_saved
@@ -255,27 +277,30 @@ for i in $(jq ".$stat_list_key|keys|.[]" $stats_json); do
255277
(( count < count_saved )) && (( count_dec=count_saved-count ))
256278
(( uniques < uniques_saved )) && (( uniques_dec=uniques_saved-uniques ))
257279
258-
(( stats_prev_exec_count_inc+=count_inc ))
259-
(( stats_prev_exec_count_dec+=count_dec ))
280+
(( stats_prev_exec_count_inc += count_inc ))
281+
(( stats_prev_exec_count_dec += count_dec ))
260282
261-
(( stats_prev_exec_uniques_inc+=uniques_inc ))
262-
(( stats_prev_exec_uniques_dec+=uniques_dec ))
283+
(( stats_prev_exec_uniques_inc += uniques_inc ))
284+
(( stats_prev_exec_uniques_dec += uniques_dec ))
263285
264286
# accumulate saved increment/decrement in a day
265-
(( count_inc+=count_inc_saved ))
266-
(( count_dec+=count_dec_saved ))
267-
(( uniques_inc+=uniques_inc_saved ))
268-
(( uniques_dec+=uniques_dec_saved ))
287+
(( count_inc += count_inc_saved ))
288+
(( count_dec += count_dec_saved ))
289+
(( uniques_inc += uniques_inc_saved ))
290+
(( uniques_dec += uniques_dec_saved ))
269291
270292
if (( count_inc || uniques_inc || count_dec || uniques_dec || \
271293
count_min != count_min_saved || count_max != count_max_saved || \
272294
uniques_min != uniques_min_saved || uniques_max != uniques_max_saved )); then
273295
stats_changed_data_timestamps[${#stats_changed_data_timestamps[@]}]="$timestamp"
274296
275-
last_date_count_inc=$count_inc
276-
last_date_count_dec=$count_dec
277-
last_date_uniques_inc=$uniques_inc
278-
last_date_uniques_dec=$uniques_dec
297+
stats_last_changed_date_count=$count
298+
stats_last_changed_date_uniques=$uniques
299+
300+
stats_last_changed_date_count_inc=$count_inc
301+
stats_last_changed_date_count_dec=$count_dec
302+
stats_last_changed_date_uniques_inc=$uniques_inc
303+
stats_last_changed_date_uniques_dec=$uniques_dec
279304
280305
echo "\
281306
{
@@ -290,48 +315,6 @@ for i in $(jq ".$stat_list_key|keys|.[]" $stats_json); do
290315
fi
291316
done
292317
293-
# stats between last change in previous/next day (independent to the pipeline scheduler times)
294-
current_date_count=0
295-
current_date_uniques=0
296-
297-
count_saved=0
298-
uniques_saved=0
299-
300-
count_min_saved=0
301-
count_max_saved=0
302-
uniques_min_saved=0
303-
uniques_max_saved=0
304-
305-
stats_curr_date_count_inc=0
306-
stats_curr_date_count_dec=0
307-
stats_curr_date_uniques_inc=0
308-
stats_curr_date_uniques_dec=0
309-
310-
timestamp_date_utc="$current_date_utc"
311-
timestamp_year_utc="${current_date_utc/%-*}"
312-
timestamp_year_dir="$stats_by_year_dir/$timestamp_year_utc"
313-
year_date_json="$timestamp_year_dir/$timestamp_date_utc.json"
314-
315-
if [[ -f "$year_date_json" ]]; then
316-
IFS=$'\n' read -r -d '' count_saved uniques_saved count_min_saved count_max_saved uniques_min_saved uniques_max_saved \
317-
stats_curr_date_count_dec stats_curr_date_count_inc stats_curr_date_uniques_dec stats_curr_date_uniques_inc <<< \
318-
"$(jq -c -r ".count,.uniques,.count_minmax[0],.count_minmax[1],.uniques_minmax[0],.uniques_minmax[1],.count_decinc[0],.count_decinc[1],.uniques_decinc[0],.uniques_decinc[1]" \
319-
$year_date_json)"
320-
321-
# CAUTION:
322-
# Prevent of invalid values spread if upstream user didn't properly commit completely correct json file or didn't commit at all.
323-
#
324-
jq_fix_null \
325-
count_saved:0 uniques_saved:0 \
326-
count_min_saved:$count_saved count_max_saved:$count_saved \
327-
uniques_min_saved:$uniques_saved uniques_max_saved:$uniques_saved \
328-
stats_curr_date_count_dec:0 stats_curr_date_count_inc:0 \
329-
stats_curr_date_uniques_dec:0 stats_curr_date_uniques_inc:0
330-
331-
current_date_count=$count_saved
332-
current_date_uniques=$uniques_saved
333-
fi
334-
335318
# accumulate statistic
336319
count_outdated_next=$count_outdated_prev
337320
uniques_outdated_next=$uniques_outdated_prev
@@ -363,12 +346,12 @@ done
363346
364347
gh_print_notice_and_write_to_changelog_text_bullet_ln "next accum: outdated-all outdated-unq / all unq: $count_outdated_next $uniques_outdated_next / $count_next $uniques_next"
365348
366-
gh_print_notice_ln "prev exec diff: unq all: +$stats_prev_exec_uniques_inc +$stats_prev_exec_count_inc / -$stats_prev_exec_uniques_dec -$stats_prev_exec_count_dec"
349+
gh_print_notice_ln "prev exec diff: unq all: +$stats_prev_exec_uniques_inc +$stats_prev_exec_count_inc -$stats_prev_exec_uniques_dec -$stats_prev_exec_count_dec"
367350
368-
gh_print_notice_ln "last date diff: unq all: +$last_date_uniques_inc +$last_date_count_inc / -$last_date_uniques_dec -$last_date_count_dec"
351+
gh_print_notice_ln "last date diff / accum: unq all: +$stats_last_changed_date_uniques_inc +$stats_last_changed_date_count_inc -$stats_last_changed_date_uniques_dec -$stats_last_changed_date_count_dec / $stats_last_changed_date_uniques $stats_last_changed_date_count"
369352
370353
gh_write_notice_to_changelog_text_bullet_ln \
371-
"prev exec diff / last date diff: unq all: +$stats_prev_exec_uniques_inc +$stats_prev_exec_count_inc -$stats_prev_exec_uniques_dec -$stats_prev_exec_count_dec / +$last_date_uniques_inc +$last_date_count_inc -$last_date_uniques_dec -$last_date_count_dec"
354+
"prev exec diff / last date diff / accum: unq all: +$stats_prev_exec_uniques_inc +$stats_prev_exec_count_inc -$stats_prev_exec_uniques_dec -$stats_prev_exec_count_dec / +$stats_last_changed_date_uniques_inc +$stats_last_changed_date_count_inc -$stats_last_changed_date_uniques_dec -$stats_last_changed_date_count_dec / $stats_last_changed_date_uniques $stats_last_changed_date_count"
372355
373356
stats_changed_dates=()
374357
@@ -504,20 +487,22 @@ fi
504487
505488
# CAUTION:
506489
# We must explicitly state the statistic calculation time in the script, because
507-
# the time taken from a script and the time set to commit changes ARE DIFFERENT
490+
# the time taken from the input and the time set to commit changes ARE DIFFERENT
508491
# and may be shifted to the next day.
509492
#
510493
gh_set_env_var STATS_DATE_UTC "$current_date_utc"
511494
gh_set_env_var STATS_DATE_TIME_UTC "$current_date_time_utc"
512495
513-
# counters of current date
514-
gh_set_env_var STATS_CURRENT_DATE_COUNT "$current_date_count"
515-
gh_set_env_var STATS_CURRENT_DATE_UNIQUES "$current_date_uniques"
496+
# counters of last changed date
497+
gh_set_env_var STATS_LAST_CHANGED_DATE_COUNT "$stats_last_changed_date_count"
498+
gh_set_env_var STATS_LAST_CHANGED_DATE_UNIQUES "$stats_last_changed_date_uniques"
499+
500+
gh_set_env_var STATS_LAST_CHANGED_DATE_COUNT_INC "$stats_last_changed_date_count_inc"
501+
gh_set_env_var STATS_LAST_CHANGED_DATE_UNIQUES_INC "$stats_last_changed_date_uniques_inc"
502+
gh_set_env_var STATS_LAST_CHANGED_DATE_COUNT_DEC "$stats_last_changed_date_count_dec"
503+
gh_set_env_var STATS_LAST_CHANGED_DATE_UNIQUES_DEC "$stats_last_changed_date_uniques_dec"
516504
517-
gh_set_env_var STATS_CURRENT_DATE_COUNT_INC "$stats_curr_date_count_inc"
518-
gh_set_env_var STATS_CURRENT_DATE_UNIQUES_INC "$stats_curr_date_uniques_inc"
519-
gh_set_env_var STATS_CURRENT_DATE_COUNT_DEC "$stats_curr_date_count_dec"
520-
gh_set_env_var STATS_CURRENT_DATE_UNIQUES_DEC "$stats_curr_date_uniques_dec"
505+
gh_set_env_var STATS_CHANGED_DATES "${stats_changed_dates[*]}"
521506
522507
# counters of GitHub dated period (not greater than 14-days)
523508
gh_set_env_var STATS_DATED_COUNT "$count_next"
@@ -534,7 +519,7 @@ gh_set_env_var STATS_PREV_EXEC_UNIQUES_DEC "$stats_prev_exec_uniques_dec"
534519
535520
gh_set_env_var COMMIT_MESSAGE_DATE_TIME_PREFIX "$commit_message_date_time_prefix"
536521
537-
gh_set_env_var COMMIT_MESSAGE_PREFIX "unq all: +$stats_prev_exec_uniques_inc +$stats_prev_exec_count_inc -$stats_prev_exec_uniques_dec -$stats_prev_exec_count_dec / $current_date_uniques $current_date_count"
522+
gh_set_env_var COMMIT_MESSAGE_PREFIX "unq all: +$stats_last_changed_date_uniques_inc +$stats_last_changed_date_count_inc -$stats_last_changed_date_uniques_dec -$stats_last_changed_date_count_dec / $stats_last_changed_date_uniques $stats_last_changed_date_count"
538523
gh_set_env_var COMMIT_MESSAGE_SUFFIX "$commit_msg_entity"
539524
540525
tkl_set_return

bash/inpage/accum-downloads.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fi
167167
168168
# CAUTION:
169169
# We must explicitly state the statistic calculation time in the script, because
170-
# the time taken from a script and the time set to commit changes ARE DIFFERENT
170+
# the time taken from the input and the time set to commit changes ARE DIFFERENT
171171
# and may be shifted to the next day.
172172
#
173173
gh_set_env_var STATS_DATE_UTC "$current_date_utc"

changelog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2022.05.17:
2+
* fixed: bash/github/accum-stats.sh: count/uniques minimum update fix
3+
* new: bash/github/accum-stats.sh: added `STATS_CHANGED_DATES` return variable to indicate the list of changed dates at the current date
4+
* changed: bash/github/accum-stats.sh: `STATS_CURRENT_DATE_*` return variables replaced by `STATS_LAST_CHANGED_DATE_*` return variable because last changed date and current date are different dates and the last changed date taken into account at the current date
5+
* changed: bash/github/accum-stats.sh: commit message is changed to indicate accumulation for the last changed date only instead of accumulation for all changed dates because the commit message will be placed for all files including `by_year/YYYY/YYYY-MM-DD.json` files
6+
* refactor: bash/github: minor refactor
7+
18
2022.05.17:
29
* new: bash/github/accum-stats.sh: added `STATS_CURRENT_DATE_*_INC` and `STATS_CURRENT_DATE_*_DEC` return variables
310
* changed: bash/github/accum-stats.sh: removed previous days increment/decrement counters and replaced by increment/decrement counters in a last date, removed `STATS_PREV_DAY_*` return variables

userlog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
33
> :warning: to find all changes use [changelog.txt](https://github.com/andry81-devops/gh-workflow/blob/master/changelog.txt) file in a directory
44
5+
## 2022.05.17:
6+
* fixed: bash/github/accum-stats.sh: count/uniques minimum update fix
7+
* new: bash/github/accum-stats.sh: added `STATS_CHANGED_DATES` return variable to indicate the list of changed dates at the current date
8+
* changed: bash/github/accum-stats.sh: `STATS_CURRENT_DATE_*` return variables replaced by `STATS_LAST_CHANGED_DATE_*` return variable because last changed date and current date are different dates and the last changed date taken into account at the current date
9+
* changed: bash/github/accum-stats.sh: commit message is changed to indicate accumulation for the last changed date only instead of accumulation for all changed dates because the commit message will be placed for all files including `by_year/YYYY/YYYY-MM-DD.json` files
10+
511
## 2022.05.17:
612
* new: bash/github/accum-stats.sh: added `STATS_CURRENT_DATE_*_INC` and `STATS_CURRENT_DATE_*_DEC` return variables
713
* changed: bash/github/accum-stats.sh: removed previous days increment/decrement counters and replaced by increment/decrement counters in a last date, removed `STATS_PREV_DAY_*` return variables

0 commit comments

Comments
 (0)