Skip to content

Commit 027a17e

Browse files
authored
Merge pull request #18 from attogram/trending-report-updates
Fix trending report and null values
2 parents e1031d6 + 0c7e1c0 commit 027a17e

3 files changed

Lines changed: 49 additions & 9 deletions

File tree

docs/dashboard-reporters.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ The `trending` reporter shows the change in each metric over a period of time, b
4343
- If `[days]` is not provided, it will analyze all reports in your `reports/` directory to show the all-time change.
4444
- If `[days]` is provided, it will show the change over the last `N` days.
4545

46+
**Example Output:**
47+
48+
```
49+
Change Last Value First Value Metrics
50+
------ ---------- ----------- -------
51+
-1 0 1 github open_issues repo.attogram.agents
52+
-15 0 15 github closed_prs repo.attogram.ote
53+
-1 0 1 github open_prs repo.attogram.agents
54+
-13 0 13 github closed_prs repo.attogram.justrefs
55+
+6 10 4 github stars repo.attogram.llm-council
56+
```
57+
4658
### `top-stars`
4759

4860
The `top-stars` reporter finds the most recent report file and lists the top repositories by their star count.

modules/github.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ fi
3636

3737
# --- Data Fetching and Formatting -------------------------------------------
3838

39+
# Helper function to safely get a value from jq
40+
get_json_value() {
41+
local json=$1
42+
local key=$2
43+
local value
44+
value=$(echo "$json" | jq -r "$key")
45+
if [ "$value" == "null" ] || [ -z "$value" ]; then
46+
echo "0"
47+
else
48+
echo "$value"
49+
fi
50+
}
51+
3952
fetch_repo_data() {
4053
local repo_name=$1
4154
local api_url="https://api.github.com/repos/${GITHUB_USER}/${repo_name}"
@@ -67,15 +80,20 @@ fetch_repo_data() {
6780
local open_prs
6881
local closed_prs
6982

70-
stars=$(echo "$api_response" | jq -r '.stargazers_count')
71-
forks=$(echo "$api_response" | jq -r '.forks_count')
72-
issues=$(echo "$api_response" | jq -r '.open_issues_count')
73-
watchers=$(echo "$api_response" | jq -r '.subscribers_count')
83+
stars=$(get_json_value "$api_response" '.stargazers_count')
84+
forks=$(get_json_value "$api_response" '.forks_count')
85+
issues=$(get_json_value "$api_response" '.open_issues_count')
86+
watchers=$(get_json_value "$api_response" '.subscribers_count')
7487

7588
# Fetch PR counts using the search API to be more efficient
7689
local search_api_url="https://api.github.com/search/issues?q=is:pr+repo:${GITHUB_USER}/${repo_name}"
77-
open_prs=$(curl -s "${curl_headers[@]}" "${search_api_url}+is:open" | jq -r '.total_count')
78-
closed_prs=$(curl -s "${curl_headers[@]}" "${search_api_url}+is:closed" | jq -r '.total_count')
90+
local open_prs_response
91+
local closed_prs_response
92+
open_prs_response=$(curl -s "${curl_headers[@]}" "${search_api_url}+is:open")
93+
closed_prs_response=$(curl -s "${curl_headers[@]}" "${search_api_url}+is:closed")
94+
95+
open_prs=$(get_json_value "$open_prs_response" '.total_count')
96+
closed_prs=$(get_json_value "$closed_prs_response" '.total_count')
7997

8098
local now
8199
now=$(date -u +%Y-%m-%dT%H:%M:%SZ)

reporters/trending.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,30 @@ awk '
6969
BEGIN {
7070
FS="\t";
7171
OFS="\t";
72-
print "Metric\tFirst Value\tLast Value\tChange";
73-
print "------\t-----------\t----------\t------";
72+
print "Change\tLast Value\tFirst Value\tMetrics";
73+
print "------\t----------\t-----------\t-------";
7474
}
7575
FNR == 1 { next; } # Skip header row of each file
7676
{
7777
metric = $2 OFS $3 OFS $4; # module, channel, namespace
7878
value = $5;
79+
if (value == "null") {
80+
value = 0;
81+
}
7982
if (!(metric in first_value)) {
8083
first_value[metric] = value;
8184
}
8285
last_value[metric] = value;
8386
}
8487
END {
8588
for (metric in last_value) {
89+
# Safeguard for nulls in old reports
90+
if (first_value[metric] == "null") {
91+
first_value[metric] = 0;
92+
}
93+
if (last_value[metric] == "null") {
94+
last_value[metric] = 0;
95+
}
8696
change = last_value[metric] - first_value[metric];
8797
if (change != 0) {
8898
# Add a plus sign for positive changes
@@ -91,7 +101,7 @@ END {
91101
} else {
92102
change_str = change;
93103
}
94-
print metric, first_value[metric], last_value[metric], change_str;
104+
print change_str, last_value[metric], first_value[metric], metric;
95105
}
96106
}
97107
}' "${TARGET_FILES[@]}"

0 commit comments

Comments
 (0)