diff --git a/README.md b/README.md index 21e7306..bbf433a 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,12 @@ To run only a specific module: ./dashboard.sh --format html hackernews ``` +To run a specific reporter: + +- **`top-stars`**: Shows the top 10 repositories by stars. +- **`trending`**: Shows the change in metrics over a given timespan. Only shows metrics that have changed. + - Usage: `./dashboard.sh -r trending [days]` + ## Configuration All configuration is done in the `config/config.sh` file. diff --git a/dashboard.sh b/dashboard.sh index 10a9e1e..99796dc 100755 --- a/dashboard.sh +++ b/dashboard.sh @@ -260,7 +260,7 @@ else if ($5 == "null") { printf "{\"date\":\"%s\",\"module\":\"%s\",\"channels\":\"%s\",\"namespace\":\"%s\",\"value\":null}", $1, $2, $3, $4 - } else if ($5 ~ /^[0-9]+$/) { + } else if ($5 != "" && $5 == $5+0) { printf "{\"date\":\"%s\",\"module\":\"%s\",\"channels\":\"%s\",\"namespace\":\"%s\",\"value\":%s}", $1, $2, $3, $4, $5 } else { printf "{\"date\":\"%s\",\"module\":\"%s\",\"channels\":\"%s\",\"namespace\":\"%s\",\"value\":\"%s\"}", $1, $2, $3, $4, $5 diff --git a/docs/dashboard-reporters.md b/docs/dashboard-reporters.md index 9b62830..7bd06f2 100644 --- a/docs/dashboard-reporters.md +++ b/docs/dashboard-reporters.md @@ -26,14 +26,14 @@ Some reporters accept their own arguments, which you can pass after the reporter Here is a list of the currently available reporters. -### `timespan` +### `trending` -The `timespan` reporter shows the change in each metric over a period of time. It reads all the `.tsv` report files from the `reports/` directory and calculates the difference between the first and last recorded values for each metric. +The `trending` reporter shows the change in each metric over a period of time, but it only includes metrics that have actually changed. It reads all the `.tsv` report files from the `reports/` directory and calculates the difference between the first and last recorded values for each metric, filtering out any that have a change of zero. **Usage:** ```bash -./dashboard.sh -r timespan [days] +./dashboard.sh -r trending [days] ``` - **`[days]`** (optional): The number of days of history to analyze. @@ -43,8 +43,6 @@ The `timespan` reporter shows the change in each metric over a period of time. I - If `[days]` is not provided, it will analyze all reports in your `reports/` directory to show the all-time change. - If `[days]` is provided, it will show the change over the last `N` days. -**Note on `[days]` filtering:** This feature is currently not working as expected due to limitations in the `date` command of the execution environment. The script is unable to parse dates from the report filenames reliably. At present, the `timespan` reporter will always show the all-time history regardless of this argument. - ### `top-stars` The `top-stars` reporter finds the most recent report file and lists the top repositories by their star count. diff --git a/reporters/timespan.sh b/reporters/trending.sh similarity index 69% rename from reporters/timespan.sh rename to reporters/trending.sh index 29a2113..d58dd7c 100755 --- a/reporters/timespan.sh +++ b/reporters/trending.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash -# reporters/timespan.sh +# reporters/trending.sh # -# Shows the change in metrics over a given timespan. -# Usage: ./dashboard.sh -r timespan [days] +# Shows the trending metrics over a given timespan. +# Only shows metrics that have changed. +# Usage: ./dashboard.sh -r trending [days] # # If [days] is provided, it shows the change over the last N days. # If not, it shows the change over all available history. @@ -36,9 +37,12 @@ if [ -n "$DAYS_AGO" ]; then CUTOFF_DATE=$(date -d "$DAYS_AGO days ago" +%s) for file in "${ALL_FILES[@]}"; do FILENAME=$(basename "$file" .tsv) - # The filename is a timestamp. It can be in various formats. - # We normalize it to a format that `date -d` can handle. - FILENAME_FOR_DATE=$(echo "$FILENAME" | sed 's/_/T/') + # The filename is a timestamp in the format YYYY-MM-DDTHH-MM-SSZ. + # We normalize it to 'YYYY-MM-DD HH:MM:SS' so that `date -d` can parse it. + DATE_PART=$(echo "$FILENAME" | cut -d'T' -f1) + TIME_PART=$(echo "$FILENAME" | cut -d'T' -f2 | sed 's/Z$//') + TIME_PART_COLONS=$(echo "$TIME_PART" | tr '-' ':') + FILENAME_FOR_DATE="$DATE_PART $TIME_PART_COLONS" FILE_DATE=$(date -d "$FILENAME_FOR_DATE" +%s 2>/dev/null) if [ -z "$FILE_DATE" ]; then @@ -80,12 +84,14 @@ FNR == 1 { next; } # Skip header row of each file END { for (metric in last_value) { change = last_value[metric] - first_value[metric]; - # Add a plus sign for positive changes - if (change > 0) { - change_str = "+" change; - } else { - change_str = change; + if (change != 0) { + # Add a plus sign for positive changes + if (change > 0) { + change_str = "+" change; + } else { + change_str = change; + } + print metric, first_value[metric], last_value[metric], change_str; } - print metric, first_value[metric], last_value[metric], change_str; } }' "${TARGET_FILES[@]}"