diff --git a/Makefile b/Makefile index 3f1da33..5bc1885 100644 --- a/Makefile +++ b/Makefile @@ -11,5 +11,12 @@ lint: ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 . ruff --format=github --target-version=py37 . +.PHONY: update-examples +update-example: + pip3 install -r requirements.txt + python3 main.py -r "open-telemetry/opentelemetry-java-instrumentation" -l "java,groovy" -s "2022-11-15" -i 14 -o "./media/example_output.png" + python3 main.py -r "open-telemetry/opentelemetry-java-instrumentation" -l "groovy" -s "2022-11-15" -i 14 -o "./media/example_output2.png" + + .PHONY: all all: install test lint \ No newline at end of file diff --git a/main.py b/main.py index cff5324..6cf9c06 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,8 @@ from collections import defaultdict from datetime import datetime from typing import List +import seaborn as sns +import pandas as pd import matplotlib.pyplot as plt import argparse @@ -45,9 +47,7 @@ def get_repository_by_commit(self, repository, commit): def main(args): - languages = [ - "groovy" - ] + languages = args.languages.split(",") app = App( languages=languages, @@ -84,16 +84,53 @@ def main(args): except KeyError: language_counts[language] = [item[language]] - for lang, counts in language_counts.items(): - plt.plot(dates, counts, label=lang.capitalize()) + sns.set_style('whitegrid') + plt.figure(figsize=(10, 8)) - plt.xlabel('Date') - plt.ylabel('Count') - plt.title('Test Classes by Lang in Instrumentation Directory') + for lang, counts in language_counts.items(): + df = pd.DataFrame({'Date': dates, 'Count': counts}) + df['Date'] = pd.to_datetime(df['Date']) + sns.lineplot(x='Date', y='Count', label=lang.capitalize(), data=df, marker='o') + + # Find highest and lowest points + highest_point = df[df['Count'] == df['Count'].max()] + lowest_point = df[df['Count'] == df['Count'].min()] + + # Annotate the highest point + plt.annotate(highest_point["Count"].values[0], + xy=( + highest_point['Date'].values[0], highest_point['Count'].values[0]), + xytext=(highest_point['Date'].values[0], + highest_point['Count'].values[0] - 40), + xycoords='data', + textcoords='data', + size=15, va="bottom", ha="left", + arrowprops=dict(arrowstyle="simple", + connectionstyle="arc3,rad=-0.2")) + + # Annotate lowest point + plt.annotate(lowest_point["Count"].values[0], + xy=( + lowest_point['Date'].values[0], lowest_point['Count'].values[0]), + xytext=(lowest_point['Date'].values[0], + lowest_point['Count'].values[0] + 40), + xycoords='data', + textcoords='data', + size=15, va="top", ha="left", + arrowprops=dict(arrowstyle="simple", + connectionstyle="arc3,rad=-0.2")) + + plt.xlabel('Date', fontsize=14) + plt.ylabel('Count', fontsize=14) + plt.title('Test File Count by extension in Instrumentation Directory', fontsize=16) plt.xticks(rotation=45) + plt.legend() plt.tight_layout() - plt.show() + + if len(args.output) > 0: + plt.savefig(args.output) + plt.draw() if __name__ == '__main__': @@ -107,5 +144,12 @@ def main(args): required=True) parser.add_argument("-i", "--interval", help="Interval (in days) between data points", required=True) + parser.add_argument("-l", "--languages", + help="Languages (comma separated list, no spaces)." + "ex: groovy,java", + required=True) + parser.add_argument("-o", "--output", + help="File name to output graph to (leave blank and no file is generated)." + "ex: file-count.png") arguments = parser.parse_args() main(arguments) diff --git a/media/example_output.png b/media/example_output.png index dc74fed..25d818e 100644 Binary files a/media/example_output.png and b/media/example_output.png differ diff --git a/media/example_output2.png b/media/example_output2.png new file mode 100644 index 0000000..954ee51 Binary files /dev/null and b/media/example_output2.png differ diff --git a/readme.md b/readme.md index 5d4582d..bf9ec42 100644 --- a/readme.md +++ b/readme.md @@ -33,24 +33,33 @@ make lint ### Arguments -| Argument | Command | Description | Example | -|------------|----------------|----------------------------------------------------------------------------|------------------------------------------------------------| -| Repository | -r, --repo | Repository name. | --repo "open-telemetry/opentelemetry-java-instrumentation" | -| Start Date | -s, --start | Starting Date in format %Y-%m-%d (will calculate from this date until now) | --start "2022-11-15" | -| Interval | -i, --interval | Interval (in days) between data points | --interval 14 | - +| Argument | Command | Description | Example | +|------------|-----------------|----------------------------------------------------------------------------|------------------------------------------------------------| +| Repository | -r, --repo | Repository name. | --repo "open-telemetry/opentelemetry-java-instrumentation" | +| Start Date | -s, --start | Starting Date in format %Y-%m-%d (will calculate from this date until now) | --start "2022-11-15" | +| Interval | -i, --interval | Interval (in days) between data points | --interval 14 | +| Languages | -l, --languages | Languages to count (in comma separated list) | --languages "java,groovy" | +| Output | -o, --output | (Optional) Location where file should be saved | --output "./media/example.png" | ### Example Usage: In the `open-telemetry/opentelemetry-java-instrumentation` repository, track the conversion of tests from groovy to java in the `instrumentation` directory starting from 2022-11-15 with a data point every 2 weeks. -`python main.py -r "open-telemetry/opentelemetry-java-instrumentation" -s "2022-11-15" -i 14` +`python main.py -r "open-telemetry/opentelemetry-java-instrumentation" -l "groovy,java" -s "2022-11-15" -i 14` Output: ![Example](./media/example_output.png) +Now just groovy + +`python main.py -r "open-telemetry/opentelemetry-java-instrumentation" -l "groovy" -s "2022-11-15" -i 14` + +Output: + +![Example](./media/example_output2.png) + ## Benchmark Visualization @@ -58,11 +67,11 @@ This is very specific to the open-telemetry/opentelemetry-java-instrumentation r ### Arguments -| Argument | Command | Description | Example | -|------------|----------------|----------------------------------------------------------------------------|------------------------------------------------------------| -| Repository | -r, --repo | Repository name. | --repo "open-telemetry/opentelemetry-java-instrumentation" | -| Start Date | -s, --start | Starting Date in format %Y-%m-%d (will calculate from this date until now) | --start "2022-11-15" | -| Interval | -i, --interval | Interval (in days) between data points | --interval 14 | +| Argument | Command | Description | Example | +|------------|-----------------|----------------------------------------------------------------------------|------------------------------------------------------------| +| Repository | -r, --repo | Repository name. | --repo "open-telemetry/opentelemetry-java-instrumentation" | +| Start Date | -s, --start | Starting Date in format %Y-%m-%d (will calculate from this date until now) | --start "2022-11-15" | +| Interval | -i, --interval | Interval (in days) between data points | --interval 14 | ### Example Usage: diff --git a/requirements.txt b/requirements.txt index fcd9ea7..60c2ba1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,6 @@ matplotlib argparse pytest pytest-cov -ruff \ No newline at end of file +ruff +seaborn +pandas \ No newline at end of file