Skip to content

Commit

Permalink
feat: add recipe_performance
Browse files Browse the repository at this point in the history
  • Loading branch information
zieka committed Oct 26, 2023
1 parent 27fcd06 commit b13106c
Show file tree
Hide file tree
Showing 4 changed files with 14,323 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions moderne_visualizations_misc/recipe_performance.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"sort_by = 'edit'\n",
"top_n = 10"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from code_data_science import data_table as dt\n",
"\n",
"df = dt.read_csv(\"../samples/recipe_performance.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import plotly.express as px\n",
"\n",
"# Group by recipe and sum up the times\n",
"grouped = df.groupby('recipe').agg({\n",
" 'scanTotalTime': 'sum',\n",
" 'editTotalTime': 'sum'\n",
"}).reset_index()\n",
"\n",
"byTotalTime = f'{sort_by}TotalTime'\n",
"\n",
"# Sort by the top N\n",
"grouped = grouped.sort_values(by=byTotalTime, ascending=False).head(top_n)\n",
"\n",
"# Sort again to have the longest at the top\n",
"grouped = grouped.sort_values(by=byTotalTime, ascending=True)\n",
"\n",
"# adjust topN if it exceeds the unique recipes\n",
"top_n = min(top_n, len(grouped))\n",
"top_n\n",
"\n",
"# Calculate the height of the plot\n",
"height_per_recipe = 25\n",
"total_height = top_n * height_per_recipe + 150\n",
"\n",
"\n",
"fig = px.bar(grouped,\n",
" x=byTotalTime,\n",
" y='recipe',\n",
" title=f'Total {sort_by} time for top {top_n} recipes',\n",
" labels={byTotalTime: f'Total {sort_by} time', 'recipe': 'Recipe'},\n",
" color=byTotalTime,\n",
" color_continuous_scale='Bluered',\n",
" orientation='h',\n",
" height=total_height\n",
" )\n",
"\n",
"fig.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
21 changes: 21 additions & 0 deletions moderne_visualizations_misc/specs/recipe_performance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
type: specs.moderne.io/v1beta/visualization
name: io.moderne.RecipePerformance
displayName: Recipe performance
description: Display the top N recipes by edit time or scan time.
recipe: org.openrewrite.*
dataTable: org.openrewrite.table.RecipeRunStats
options:
- sort_by:
displayName: Sort the recipes by
description: >
Sort the recipes by time spent scanning or time spent editing. (default: scan)
valid:
- scan
- edit
required: false
- top_n:
displayName: Top N recipes
description: >
The number of recipes to plot. (default: 10)
required: false
Loading

0 comments on commit b13106c

Please sign in to comment.