Skip to content

Commit 8f8fcd1

Browse files
committed
Add script to generate CSV report reference doc
1 parent f15ad69 commit 8f8fcd1

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

COMMANDS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ Change into the [scripts](./scripts/) directory e.g. with `cd scripts` and then
118118
./documentation/generateScriptReference.sh
119119
```
120120
121+
### Generate CSV Cypher Query Report Reference
122+
123+
Change into the [results](./results/) directory e.g. with `cd results` and then execute the script [generateCsvReportReference.sh](./scripts/documentation/generateCsvReportReference.sh) with the following command:
124+
125+
👉**Note:** This script is automatically triggered at the end of [copyReportsIntoResults.sh](./scripts/copyReportsIntoResults.sh)
126+
which is included in the pipeline [code-structure-analysis.yml](.github/workflows/code-structure-analysis.yml) and doesn't need to be executed manually normally.
127+
128+
```script
129+
./../scripts/documentation/generateCsvReportReference.sh
130+
```
131+
121132
### Generate Jupyter Notebook Report Reference
122133

123134
Change into the [results](./results/) directory e.g. with `cd results` and then execute the script [generateJupyterReportsReference.sh](./scripts/documentation/generateJupyterReportsReference.sh) with the following command:

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ The [Code Structure Analysis Pipeline](./.github/workflows/code-structure-analys
8181

8282
[COMMANDS.md](./COMMANDS.md) contains further details on commands and how to do a manual setup.
8383

84+
## 📃 CSV Cypher Query Report Reference
85+
86+
[CSV_REPORTS.md](./results/CSV_REPORTS.md) lists all CSV Cypher query result reports inside the [results](./results) directory. It can be generated as described in [Generate Jupyter Notebook Report Reference](./COMMANDS.md#generate-csv-cypher-query-report-reference).
87+
8488
## 📈 Jupyter Notebook Report Reference
8589

8690
[JUPYTER_REPORTS.md](./results/JUPYTER_REPORTS.md) lists all Jupyter Notebook reports inside the [results](./results) directory. It can be generated as described in [Generate Jupyter Notebook Report Reference](./COMMANDS.md#generate-jupyter-notebook-report-reference).

scripts/copyReportsIntoResults.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ for report_source_folder in **/"${REPORTS_DIRECTORY}"; do
4040
cp -Rp "${report_source_folder}" "${reportTargetDirectory}"
4141
done
4242

43-
# Generate REPORTS.md containing a reference to all Jupyter Notebook Markdown reports in the "results" directory and its subdirectories.
44-
(cd "./../${RESULTS_DIRECTORY}" && exec "${SCRIPTS_DIR}/documentation/generateJupyterReportsReference.sh")
43+
# Generate JUPYTER_REPORTS.md containing a reference to all Jupyter Notebook Markdown reports in the "results" directory and its subdirectories.
44+
(cd "./../${RESULTS_DIRECTORY}" && exec "${SCRIPTS_DIR}/documentation/generateJupyterReportsReference.sh")
45+
46+
# Generate CSV_REPORTS.md containing a reference to all CSV cypher query reports in the "results" directory and its subdirectories.
47+
(cd "./../${RESULTS_DIRECTORY}" && exec "${SCRIPTS_DIR}/documentation/generateCsvReportReference.sh")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
# Generates "CSV_REPORTS.md" containing a reference to all CSV cypher query reports in this directory and its subdirectories.
4+
5+
# Note: This script was generated by Chat-GPT after some messages back and forth:
6+
# https://chat.openai.com/share/0bd3cde7-32d0-460d-830c-79b7d00a2492
7+
8+
# Output Markdown file name
9+
output_file="CSV_REPORTS.md"
10+
11+
# Function to count rows in a CSV file
12+
count_rows() {
13+
wc -l < "$1"
14+
}
15+
16+
# Function to extract the source query name from CSV header
17+
get_source_query() {
18+
header=$(head -n 1 "$1")
19+
source_query=$(echo "$header" | sed -n 's/.*Source Cypher File: \(.*\)"/\1/p')
20+
echo "$source_query"
21+
}
22+
23+
# Create the Markdown header
24+
{
25+
echo "# CSV Cypher Query Reports Reference"
26+
echo ""
27+
echo "This document serves as a reference for all CSV Cypher query reports in the current directory and its subdirectories. It provides a table listing each file, its corresponding analysis, the row count and the source query. This file was generated with the script [generateCsvReportsReference](./../scripts/documentation/generateCsvReportsReference.sh)."
28+
echo ""
29+
30+
# Create the Markdown table header
31+
echo "| CSV File | Analysis | Number of Rows | Source Query |"
32+
echo "| -------- | -------- | -------------- | ------------ |"
33+
} > "$output_file"
34+
35+
# Find and process CSV files
36+
find . -type f -name "*.csv" | while IFS= read -r csv_file; do
37+
num_rows=$(count_rows "$csv_file")
38+
source_query=$(get_source_query "$csv_file")
39+
40+
# Get the main directory name
41+
main_dir=$(dirname "$csv_file" | cut -d '/' -f 2)
42+
43+
# Get the base name of the file
44+
base_name=$(basename "$csv_file")
45+
46+
# Escape special characters for Markdown
47+
csv_link=$(echo "$csv_file" | sed 's/\[/\\[/g; s/\]/\\]/g')
48+
49+
# Create a link to the source query
50+
source_query_link="./../cypher/$source_query"
51+
52+
# Append a new row to the Markdown table
53+
echo "| [$base_name]($csv_link) | $main_dir | $num_rows | [$source_query]($source_query_link) |" >> "$output_file"
54+
done
55+
56+
echo "CSV table and header generated in $output_file"

0 commit comments

Comments
 (0)