Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions docs/dashboard-reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
30 changes: 18 additions & 12 deletions reporters/timespan.sh → reporters/trending.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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[@]}"