Skip to content

Commit efd2653

Browse files
committed
2022.05.19:
* fixed: bash: inpage/accum-downloads.sh, boards/accum-stats.sh: incorrect save into `by_year` json file relative `downloads` counter * changed: bash: inpage/accum-downloads.sh, boards/accum-stats.sh: removed previous days increment/decrement counters, removed `STATS_PREV_DAY_*` return variables * refactor: bash: inpage/accum-downloads.sh, boards/accum-stats.sh: minor code refactor
1 parent 1d0c979 commit efd2653

File tree

4 files changed

+36
-45
lines changed

4 files changed

+36
-45
lines changed

bash/board/accum-stats.sh

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tkl_push_trap 'gh_flush_print_buffers; gh_prepend_changelog_file' EXIT
4343

4444
gh_print_notice_and_write_to_changelog_text_ln "current date/time: $current_date_time_utc" "$current_date_time_utc:"
4545

46-
current_date_utc=${current_date_time_utc/%T*}
46+
current_date_utc="${current_date_time_utc/%T*}"
4747

4848
# exit with non 0 code if nothing is changed
4949
IFS=$'\n' read -r -d '' last_replies last_views <<< "$(jq -c -r ".replies,.views" $stats_json)"
@@ -102,50 +102,42 @@ stats_prev_exec_replies_inc=0
102102
stats_prev_exec_views_inc=0
103103

104104
if [[ -n "$replies" ]]; then
105-
(( last_replies < replies )) && (( stats_prev_exec_replies_inc=replies-last_replies ))
105+
(( last_replies < replies )) && (( stats_prev_exec_replies_inc = replies - last_replies ))
106106
fi
107107
if [[ -n "$views" ]]; then
108-
(( last_views < views )) && (( stats_prev_exec_views_inc=views-last_views ))
108+
(( last_views < views )) && (( stats_prev_exec_views_inc = views - last_views ))
109109
fi
110110

111111
gh_print_notice_and_write_to_changelog_text_bullet_ln "query file size: $(stat -c%s "$TEMP_DIR/response.txt")"
112112

113-
gh_print_notice_and_write_to_changelog_text_bullet_ln "json prev / next / diff: re vi: $last_replies $last_views / ${replies:-"-"} ${views:-"-"} / +$stats_prev_exec_replies_inc +$stats_prev_exec_views_inc"
113+
gh_print_notice_and_write_to_changelog_text_bullet_ln "accum prev / next / diff: re vi: $last_replies $last_views / ${replies:-"-"} ${views:-"-"} / +$stats_prev_exec_replies_inc +$stats_prev_exec_views_inc"
114114

115115
# with check on integer value
116116
[[ -z "$replies" || -n "${replies//[0-9]/}" ]] && replies=$last_replies
117117
[[ -z "$views" || -n "${views//[0-9]/}" ]] && views=$last_views
118118

119-
# stats between last change in previous/next day (independent to the pipeline scheduler times)
120-
stats_prev_day_replies_inc=0
121-
stats_prev_day_views_inc=0
122-
119+
# stats between last date and previous date (independent to the pipeline scheduler times)
123120
replies_saved=0
124121
views_saved=0
125-
replies_prev_day_inc_saved=0
126-
views_prev_day_inc_saved=0
127122

128-
timestamp_date_utc=${current_date_time_utc/%T*}
129-
timestamp_year_utc=${timestamp_date_utc/%-*}
123+
timestamp_date_utc="${current_date_time_utc/%T*}"
124+
timestamp_year_utc="${timestamp_date_utc/%-*}"
130125
timestamp_year_dir="$stats_by_year_dir/$timestamp_year_utc"
131126
year_date_json="$timestamp_year_dir/$timestamp_date_utc.json"
132127

133128
if [[ -f "$year_date_json" ]]; then
134-
IFS=$'\n' read -r -d '' replies_saved views_saved replies_prev_day_inc_saved views_prev_day_inc_saved <<< \
135-
"$(jq -c -r ".replies,.views,.replies_prev_day_inc,.views_prev_day_inc" $year_date_json)"
129+
IFS=$'\n' read -r -d '' replies_saved views_saved <<< \
130+
"$(jq -c -r ".replies,.views" $year_date_json)"
136131
137132
# CAUTION:
138133
# Prevent of invalid values spread if upstream user didn't properly commit completely correct json file or didn't commit at all.
139134
#
140135
jq_fix_null \
141-
replies_saved:0 views_saved:0 \
142-
replies_prev_day_inc_saved:0 views_prev_day_inc_saved:0
136+
replies_saved:0 views_saved:0
143137
fi
144138
145-
(( stats_prev_day_replies_inc+=replies_prev_day_inc_saved+stats_prev_exec_replies_inc ))
146-
(( stats_prev_day_views_inc+=views_prev_day_inc_saved+stats_prev_exec_views_inc ))
147-
148-
gh_print_notice_and_write_to_changelog_text_bullet_ln "prev day diff: re vi: +$stats_prev_day_replies_inc +$stats_prev_day_views_inc"
139+
(( replies_saved += stats_prev_exec_replies_inc ))
140+
(( views_saved += stats_prev_exec_views_inc ))
149141
150142
if (( replies != last_replies || views != last_views )); then
151143
echo "\
@@ -161,9 +153,7 @@ if (( replies != last_replies || views != last_views )); then
161153
{
162154
\"timestamp\" : \"$current_date_time_utc\",
163155
\"replies\" : $replies_saved,
164-
\"replies_prev_day_inc\" : $stats_prev_day_replies_inc,
165-
\"views\" : $views_saved,
166-
\"views_prev_day_inc\" : $stats_prev_day_views_inc
156+
\"views\" : $views_saved
167157
}" > "$year_date_json"
168158
fi
169159
@@ -199,9 +189,6 @@ gh_set_env_var STATS_DATE_TIME_UTC "$current_date_time_utc"
199189
gh_set_env_var STATS_PREV_EXEC_REPLIES_INC "$stats_prev_exec_replies_inc"
200190
gh_set_env_var STATS_PREV_EXEC_VIEWS_INC "$stats_prev_exec_views_inc"
201191
202-
gh_set_env_var STATS_PREV_DAY_REPLIES_INC "$stats_prev_day_replies_inc"
203-
gh_set_env_var STATS_PREV_DAY_VIEWS_INC "$stats_prev_day_views_inc"
204-
205192
gh_set_env_var COMMIT_MESSAGE_DATE_TIME_PREFIX "$commit_message_date_time_prefix"
206193
207194
gh_set_env_var COMMIT_MESSAGE_PREFIX "re vi: +$stats_prev_exec_replies_inc +$stats_prev_exec_views_inc / $replies_saved $views_saved"

bash/inpage/accum-downloads.sh

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tkl_push_trap 'gh_flush_print_buffers; gh_prepend_changelog_file' EXIT
3838

3939
gh_print_notice_and_write_to_changelog_text_ln "current date/time: $current_date_time_utc" "$current_date_time_utc:"
4040

41-
current_date_utc=${current_date_time_utc/%T*}
41+
current_date_utc="${current_date_time_utc/%T*}"
4242

4343
# exit with non 0 code if nothing is changed
4444
IFS=$'\n' read -r -d '' last_downloads <<< "$(jq -c -r ".downloads" $stats_json)"
@@ -90,42 +90,40 @@ downloads="$(sed -rn "$downloads_sed_regexp" "$TEMP_DIR/response.txt")"
9090
stats_prev_exec_downloads_inc=0
9191

9292
if [[ -n "$downloads" ]]; then
93-
(( last_downloads < downloads )) && (( stats_prev_exec_downloads_inc=downloads-last_downloads ))
93+
(( last_downloads < downloads )) && (( stats_prev_exec_downloads_inc = downloads - last_downloads ))
9494
fi
9595

9696
gh_print_notice_and_write_to_changelog_text_bullet_ln "query file size: $(stat -c%s "$TEMP_DIR/response.txt")"
9797

98-
gh_print_notice_and_write_to_changelog_text_bullet_ln "json prev / next / diff: dl: $last_downloads / ${downloads:-"-"} / +$stats_prev_exec_downloads_inc"
98+
gh_print_notice_and_write_to_changelog_text_bullet_ln "accum prev / next / diff: dl: $last_downloads / ${downloads:-"-"} / +$stats_prev_exec_downloads_inc"
9999

100100
# with check on integer value
101101
[[ -z "$downloads" || -n "${downloads//[0-9]/}" ]] && downloads=0
102102

103-
# stats between last change in previous/next day (independent to the pipeline scheduler times)
104-
stats_prev_day_downloads_inc=0
103+
# stats between last date and previous date (independent to the pipeline scheduler times)
104+
stats_last_changed_date_downloads_inc=0
105105

106106
downloads_saved=0
107-
downloads_prev_day_inc_saved=0
108107

109-
timestamp_date_utc=${current_date_time_utc/%T*}
110-
timestamp_year_utc=${timestamp_date_utc/%-*}
108+
timestamp_date_utc="${current_date_time_utc/%T*}"
109+
timestamp_year_utc="${timestamp_date_utc/%-*}"
111110
timestamp_year_dir="$stats_by_year_dir/$timestamp_year_utc"
112111
year_date_json="$timestamp_year_dir/$timestamp_date_utc.json"
113112

114113
if [[ -f "$year_date_json" ]]; then
115-
IFS=$'\n' read -r -d '' downloads_saved downloads_prev_day_inc_saved <<< \
116-
"$(jq -c -r ".downloads,.downloads_prev_day_inc" $year_date_json)"
114+
IFS=$'\n' read -r -d '' downloads_saved <<< \
115+
"$(jq -c -r ".downloads" $year_date_json)"
117116
118117
# CAUTION:
119118
# Prevent of invalid values spread if upstream user didn't properly commit completely correct json file or didn't commit at all.
120119
#
121120
jq_fix_null \
122-
downloads_saved:0 \
123-
downloads_prev_day_inc_saved:0
121+
downloads_saved:0
124122
fi
125123
126-
(( stats_prev_day_downloads_inc+=downloads_prev_day_inc_saved+stats_prev_exec_downloads_inc ))
124+
(( downloads_saved += stats_prev_exec_downloads_inc ))
127125
128-
gh_print_notice_and_write_to_changelog_text_bullet_ln "prev day diff: dl: +$stats_prev_day_downloads_inc"
126+
gh_print_notice_and_write_to_changelog_text_bullet_ln "prev exec diff: dl: +$stats_prev_exec_downloads_inc"
129127
130128
if (( downloads != last_downloads )); then
131129
echo "\
@@ -139,8 +137,7 @@ if (( downloads != last_downloads )); then
139137
echo "\
140138
{
141139
\"timestamp\" : \"$current_date_time_utc\",
142-
\"downloads\" : $downloads_saved,
143-
\"downloads_prev_day_inc\" : $stats_prev_day_downloads_inc
140+
\"downloads\" : $downloads_saved
144141
}" > "$year_date_json"
145142
fi
146143
@@ -175,11 +172,9 @@ gh_set_env_var STATS_DATE_TIME_UTC "$current_date_time_utc"
175172
176173
gh_set_env_var STATS_PREV_EXEC_DOWNLOADS_INC "$stats_prev_exec_downloads_inc"
177174
178-
gh_set_env_var STATS_PREV_DAY_DOWNLOADS_INC "$stats_prev_day_downloads_inc"
179-
180175
gh_set_env_var COMMIT_MESSAGE_DATE_TIME_PREFIX "$commit_message_date_time_prefix"
181176
182-
gh_set_env_var COMMIT_MESSAGE_PREFIX "dl: +$stats_prev_exec_downloads_inc +$stats_prev_day_downloads_inc / $downloads_saved"
177+
gh_set_env_var COMMIT_MESSAGE_PREFIX "dl: +$stats_prev_exec_downloads_inc / $downloads_saved"
183178
gh_set_env_var COMMIT_MESSAGE_SUFFIX "$commit_msg_entity"
184179
185180
tkl_set_return

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2022.05.19:
2+
* fixed: bash: inpage/accum-downloads.sh, boards/accum-stats.sh: incorrect save into `by_year` json file relative `downloads` counter
3+
* changed: bash: inpage/accum-downloads.sh, boards/accum-stats.sh: removed previous days increment/decrement counters, removed `STATS_PREV_DAY_*` return variables
4+
* refactor: bash: inpage/accum-downloads.sh, boards/accum-stats.sh: minor code refactor
5+
16
2022.05.18:
27
* fixed: bash/github/accum-stats.sh: `by_year` file rewrite on empty changes
38
* changed: bash/github/accum-stats.sh: made `uniques` counter goes first in all messages

userlog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
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.19:
6+
* fixed: bash: inpage/accum-downloads.sh, boards/accum-stats.sh: incorrect save into `by_year` json file relative `downloads` counter
7+
* changed: bash: inpage/accum-downloads.sh, boards/accum-stats.sh: removed previous days increment/decrement counters, removed `STATS_PREV_DAY_*` return variables
8+
59
## 2022.05.18:
610
* fixed: bash/github/accum-stats.sh: `by_year` file rewrite on empty changes
711
* changed: bash/github/accum-stats.sh: made `uniques` counter goes first in all messages

0 commit comments

Comments
 (0)