Skip to content

Commit

Permalink
feat: Add unit measurement to language composition notebooks (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmccarp authored Nov 10, 2023
1 parent c2895bc commit f8ee8ac
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions moderne_visualizations_misc/language_composition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
"This report shows the different languages that are used in the projects."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"unit: str = \"files\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -26,6 +39,7 @@
"import code_data_science.palette as palette\n",
"\n",
"df = dt.read_csv(\"../samples/language_composition.csv\")\n",
"df[\"files\"] = 1\n",
"\n",
"# Exit early if there are no rows and render a plot with a message\n",
"if len(df) == 0:\n",
Expand Down Expand Up @@ -65,16 +79,19 @@
" df[(df[\"hasParseFailures\"] == True) & (df[\"fileType\"] == \"java\")]\n",
" )\n",
"\n",
" # sum of lines of text in java files affected by parse failures\n",
" # determine measurement field based on `unit`\n",
" measurement_field = \"files\" if unit == \"files\" else \"linesOfText\"\n",
"\n",
" # sum of unit in java files affected by parse failures\n",
" total_lines_of_java_affected_by_parse_failures = df[\n",
" (df[\"hasParseFailures\"] == True) & (df[\"fileType\"] == \"java\")\n",
" ][\"linesOfText\"].sum()\n",
" ][measurement_field].sum()\n",
"\n",
" # Set the color palette\n",
" colors = palette.qualitative()\n",
"\n",
" fig = px.treemap(\n",
" df_file_grouped, path=path, values=\"linesOfText\", color_discrete_sequence=colors\n",
" df_file_grouped, path=path, values=measurement_field, color_discrete_sequence=colors\n",
" )\n",
"\n",
" fig.update_layout(\n",
Expand Down Expand Up @@ -136,7 +153,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
23 changes: 20 additions & 3 deletions moderne_visualizations_misc/language_composition_by_repo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
"This report shows the different languages that are used in each repository."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"unit: str = \"files\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -25,6 +38,7 @@
"import code_data_science.palette as palette\n",
"\n",
"df = dt.read_csv(\"../samples/language_composition.csv\")\n",
"df[\"files\"] = 1\n",
"\n",
"# Exit early if there are no rows and render a plot with a message\n",
"if len(df) == 0:\n",
Expand Down Expand Up @@ -72,16 +86,19 @@
" df[(df[\"hasParseFailures\"] == True) & (df[\"fileType\"] == \"java\")]\n",
" )\n",
"\n",
" # determine measurement field based on `unit`\n",
" measurement_field = \"files\" if unit == \"files\" else \"linesOfText\"\n",
"\n",
" # sum of lines of text in java files affected by parse failures\n",
" total_lines_of_java_affected_by_parse_failures = df[\n",
" (df[\"hasParseFailures\"] == True) & (df[\"fileType\"] == \"java\")\n",
" ][\"linesOfText\"].sum()\n",
" ][measurement_field].sum()\n",
"\n",
" # Set the color palette\n",
" colors = palette.qualitative()\n",
"\n",
" fig = px.treemap(\n",
" df_file_grouped, path=path, values=\"linesOfText\", color_discrete_sequence=colors\n",
" df_file_grouped, path=path, values=measurement_field, color_discrete_sequence=colors\n",
" )\n",
"\n",
" fig.update_layout(\n",
Expand Down Expand Up @@ -143,7 +160,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
16 changes: 16 additions & 0 deletions moderne_visualizations_misc/specs/language_composition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@ displayName: Language composition
description: This report shows the different languages that are used in the projects.
recipe: org.openrewrite.LanguageComposition
dataTable: org.openrewrite.table.LanguageCompositionPerFile
options:
- unit:
displayName: Unit
description: >
Which unit to use when measuring language compositions. Options include `lines` and `files`.
`lines` will measure language composition by lines of code. `files` will count the number of files with each language.
Because Moderne cannot parse all languages, you may want to know which files are not being parsed. Measuring by `lines` will
only show you successfully-parsed files, as unparseable files cannot have their lines of code counted.
Defaults to `lines`.
valid:
- lines
- files
required: false
16 changes: 16 additions & 0 deletions moderne_visualizations_misc/specs/language_composition_by_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@ displayName: Language composition by repository
description: This report shows the different languages that are used in each repository.
recipe: org.openrewrite.LanguageComposition
dataTable: org.openrewrite.table.LanguageCompositionPerFile
options:
- unit:
displayName: Unit
description: >
Which unit to use when measuring language compositions. Options include `lines` and `files`.
`lines` will measure language composition by lines of code. `files` will count the number of files with each language.
Because Moderne cannot parse all languages, you may want to know which files are not being parsed. Measuring by `lines` will
only show you successfully-parsed files, as unparseable files cannot have their lines of code counted.
Defaults to `lines`.
valid:
- lines
- files
required: false

0 comments on commit f8ee8ac

Please sign in to comment.