Skip to content

Commit

Permalink
Merge pull request #59 from open-contracting/ah-chart-components
Browse files Browse the repository at this point in the history
Ah chart components
  • Loading branch information
yolile authored Feb 10, 2024
2 parents de43c0d + 96e4c50 commit 747f4de
Show file tree
Hide file tree
Showing 16 changed files with 2,661 additions and 456 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ To ease maintenance, the notebooks are made up of reusable components. To see wh
Component name | Open in Colab | Tasks
-- | -- | --
[Environment](https://github.com/open-contracting/notebooks-ocds/blob/main/component_environment.ipynb) | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-contracting/notebooks-ocds/blob/main/component_environment.ipynb) | Install requirements, import packages, load extensions and configure the notebook.
[Charts setup](https://github.com/open-contracting/notebooks-ocds/blob/main/component_charts.ipynb) | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-contracting/notebooks-ocds/blob/main/component_charts.ipynb) | Install charts requirements, import charts packages and define plot functions.
[Kingfisher Process setup](https://github.com/open-contracting/notebooks-ocds/blob/main/component_setup_kingfisher.ipynb) | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-contracting/notebooks-ocds/blob/main/component_setup_kingfisher.ipynb) | Connect to the database. Choose the collection(s) and schema to work with.
[Field list setup](https://github.com/open-contracting/notebooks-ocds/blob/main/component_setup_fieldlist.ipynb) | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-contracting/notebooks-ocds/blob/main/component_setup_fieldlist.ipynb) | Load the field list.
[Data Registry setup](https://github.com/open-contracting/notebooks-ocds/blob/main/component_setup_registry.ipynb) | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-contracting/notebooks-ocds/blob/main/component_setup_registry.ipynb) | Install Cardinal, download the data, and calculate the field list.
Expand Down
329 changes: 329 additions & 0 deletions component_charts.ipynb

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions component_check_quality.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,7 @@
"id": "yeBOaDsO6uDS"
},
"source": [
"release_count_chart = sns.catplot(\n",
" x=\"release_count\", y=\"ocid_count\", kind=\"bar\", col=\"collection_id\", hue=\"release_type\", data=release_counts\n",
").set_xticklabels(rotation=90)\n",
"\n",
"for ax in release_count_chart.axes.flat:\n",
" format_thousands(ax.yaxis)\n",
"\n",
"plt.show(release_count_chart)"
"plot_release_count(release_counts)"
],
"execution_count": null,
"outputs": []
Expand Down
65 changes: 1 addition & 64 deletions component_check_usability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -788,70 +788,7 @@
{
"cell_type": "code",
"source": [
"if lang.value == \"English\":\n",
" alt.Chart(result_final).transform_window(\n",
" nrow=\"row_number(indicator)\", frame=[None, None], sort=[{\"field\": \"calculation\"}], groupby=[\"Use case\"]\n",
" ).mark_circle(size=250, opacity=1).encode(\n",
" x=alt.X(\n",
" \"nrow\", type=\"quantitative\", axis=alt.Axis(title=[\"number of indicators\", \"\"], orient=\"top\", tickCount=5)\n",
" ),\n",
" y=alt.Y(\"Use case\", type=\"nominal\", sort=alt.Sort(field=\"indicator\", op=\"count\", order=\"descending\")),\n",
" color=alt.Color(\n",
" \"calculation\",\n",
" type=\"nominal\",\n",
" scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n",
" legend=alt.Legend(title=[\"can we calculate it?\"]),\n",
" ),\n",
" tooltip=[\n",
" alt.Tooltip(\"indicator\", type=\"nominal\"),\n",
" alt.Tooltip(\"Use case\", type=\"nominal\"),\n",
" alt.Tooltip(\"calculation\", type=\"nominal\"),\n",
" alt.Tooltip(\"missing fields\", type=\"nominal\"),\n",
" ],\n",
" ).properties(\n",
" width=600, height=350, padding=50, title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18)\n",
" ).configure_axis(\n",
" titleFontSize=14, labelFontSize=14, labelPadding=5, ticks=False, domain=False\n",
" ).configure_legend(\n",
" labelFontSize=14, titleFontSize=14\n",
" ).configure_view(\n",
" strokeWidth=0\n",
" ).display()\n",
"\n",
"else:\n",
" alt.Chart(result_final).transform_window(\n",
" nrow=\"row_number(Indicador)\",\n",
" frame=[None, None],\n",
" sort=[{\"field\": \"¿Se puede calcular?\"}],\n",
" groupby=[\"Caso de Uso\"],\n",
" ).mark_circle(size=250, opacity=1).encode(\n",
" x=alt.X(\n",
" \"nrow\",\n",
" type=\"quantitative\",\n",
" axis=alt.Axis(title=[\"Cantidad de indicadores\", \"\"], orient=\"top\", tickCount=5),\n",
" ),\n",
" y=alt.Y(\"Caso de Uso\", type=\"nominal\", sort=alt.Sort(field=\"Indicador\", op=\"count\", order=\"descending\")),\n",
" color=alt.Color(\n",
" \"¿Se puede calcular?\",\n",
" type=\"nominal\",\n",
" scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n",
" legend=alt.Legend(title=[\"¿Se puede calcular?\"]),\n",
" ),\n",
" tooltip=[\n",
" alt.Tooltip(\"Indicador\", type=\"nominal\"),\n",
" alt.Tooltip(\"Caso de uso\", type=\"nominal\"),\n",
" alt.Tooltip(\"¿Se puede calcular?\", type=\"nominal\"),\n",
" alt.Tooltip(\"Campos faltantes\", type=\"nominal\"),\n",
" ],\n",
" ).properties(\n",
" width=600, height=350, padding=50, title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18)\n",
" ).configure_axis(\n",
" titleFontSize=14, labelFontSize=14, labelPadding=5, ticks=False, domain=False\n",
" ).configure_legend(\n",
" labelFontSize=14, titleFontSize=14\n",
" ).configure_view(\n",
" strokeWidth=0\n",
" ).display()"
"plot_usability_indicators(result_final, lang.value)"
],
"metadata": {
"id": "3tW-Q8-uJC89"
Expand Down
6 changes: 1 addition & 5 deletions component_environment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"cell_type": "code",
"source": [
"! pip install --upgrade pip > pip.log\n",
"! pip install --upgrade 'ocdskingfishercolab<0.4' altair ipywidgets matplotlib plotly psycopg2-binary seaborn >> pip.log"
"! pip install --upgrade 'ocdskingfishercolab<0.4' ipywidgets psycopg2-binary >> pip.log"
],
"metadata": {
"id": "X4nmyvOa_Ls7"
Expand All @@ -58,12 +58,8 @@
"source": [
"from collections import Counter\n",
"\n",
"import altair as alt\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import plotly.express as px\n",
"import seaborn as sns\n",
"from google.colab.data_table import DataTable\n",
"from google.colab.files import download\n",
"from ipywidgets import widgets\n",
Expand Down
17 changes: 3 additions & 14 deletions component_scope_kingfisher.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,7 @@
"id": "mKo6Q4HimvQZ"
},
"source": [
"objects_per_stage_chart = sns.catplot(x=\"stage\", y=\"object_count\", kind=\"bar\", data=objects_per_stage).set_xticklabels(\n",
" rotation=90\n",
")\n",
"\n",
"for ax in objects_per_stage_chart.axes.flat:\n",
" format_thousands(ax.yaxis)\n",
"\n",
"objects_per_stage"
"plot_objects_per_stage(objects_per_stage)"
],
"execution_count": null,
"outputs": []
Expand Down Expand Up @@ -372,13 +365,9 @@
"source": [
"# Resample by month\n",
"release_dates = release_dates.set_index(\"date\")\n",
"release_dates = release_dates.groupby([\"collection_id\", \"release_type\"]).resample(\"M\").sum()\n",
"\n",
"fig, ax = plt.subplots(figsize=[15, 5])\n",
"sns.lineplot(data=release_dates, x=\"date\", y=\"release_count\", hue=\"collection_id\", style=\"release_type\")\n",
"release_dates = release_dates.groupby([\"collection_id\", \"release_type\"]).resample(\"M\").sum().reset_index()\n",
"\n",
"format_thousands(ax.yaxis)\n",
"sns.despine()"
"plot_releases_by_month(release_dates)"
],
"execution_count": null,
"outputs": []
Expand Down
45 changes: 3 additions & 42 deletions component_scope_usability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,7 @@
{
"cell_type": "code",
"source": [
"fig = px.bar(\n",
" stages,\n",
" x=\"stage\",\n",
" y=\"object_count\",\n",
" title=\"Stages covered\",\n",
" template=\"plotly_white\",\n",
" text=\"object_count\",\n",
" labels={\"stage\": \"Stage\", \"object_count\": \"Number of releases\"},\n",
")\n",
"fig.update_traces(marker_color=\"#D6E100\")\n",
"fig.update_layout(width=400, height=350, bargap=0.5)\n",
"fig.show()"
"plot_objects_per_stage(stages)"
],
"metadata": {
"id": "zGNrN_occdW5"
Expand Down Expand Up @@ -242,22 +231,7 @@
{
"cell_type": "code",
"source": [
"final = pd.melt(dates, id_vars=[\"year\"], value_vars=[\"tenders\", \"awards\"])\n",
"fig = px.bar(\n",
" final,\n",
" x=\"year\",\n",
" y=\"value\",\n",
" color=\"variable\",\n",
" barmode=\"group\",\n",
" title=\"Tenders and awards by year\",\n",
" template=\"plotly_white\",\n",
" text=\"value\",\n",
" color_discrete_sequence=[\"#D6E100\", \"#6c75e1\"],\n",
" labels={\"value\": \"Tenders and awards\"},\n",
")\n",
"fig.update_layout(width=600, height=350, bargap=0.5)\n",
"\n",
"fig.show()"
"plot_objects_per_year(dates)"
],
"metadata": {
"id": "ZFUPPW51dF4m"
Expand Down Expand Up @@ -371,20 +345,7 @@
{
"cell_type": "code",
"source": [
"fig = px.bar(\n",
" buyers.head(10),\n",
" y=\"name\",\n",
" x=\"total_tenders\",\n",
" title=\"Top 10 buyers\",\n",
" template=\"plotly_white\",\n",
" text=\"total_tenders\",\n",
" labels={\"total_tenders\": \"Number of procedures\", \"name\": \"buyer\"},\n",
" color_discrete_sequence=[\"#D6E100\", \"#6c75e1\"],\n",
" orientation=\"h\",\n",
")\n",
"# fig.update_traces()\n",
"fig.update_layout(width=850, height=450, bargap=0.4, yaxis={\"categoryorder\": \"total ascending\"})\n",
"fig.show()"
"plot_top_buyers(buyers.head(10))"
],
"metadata": {
"id": "KmgHVCXaiCeG"
Expand Down
6 changes: 6 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@
],
"template_publisher_analysis": [
"component_environment",
"component_charts",
"component_setup_kingfisher",
"component_errors_kingfisher",
"component_scope_kingfisher",
],
"template_structure_and_format_feedback": [
"component_environment",
"component_charts",
"component_setup_kingfisher",
"component_errors_kingfisher",
"component_scope_kingfisher",
"component_check_structure",
],
"template_data_quality_feedback": [
"component_environment",
"component_charts",
"component_setup_kingfisher",
"component_errors_kingfisher",
"component_scope_kingfisher",
Expand All @@ -39,17 +42,20 @@
],
"template_usability_checks": [
"component_environment",
"component_charts",
"component_setup_kingfisher",
"component_scope_usability",
"component_check_usability",
],
"template_usability_checks_fieldlist": [
"component_environment",
"component_charts",
"component_setup_fieldlist",
"component_check_usability",
],
"template_usability_checks_registry": [
"component_environment",
"component_charts",
"component_setup_registry",
"component_check_usability",
],
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ line-length = 119

[tool.ruff]
line-length = 119
select = ["ALL"]
lint.select = ["ALL"]
target-version = "py310"
extend-include = ["*.ipynb"]
ignore = [
lint.ignore = [
"ANN", "COM", "CPY", "D", "EM",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191", "E501", "D206", "Q000", "Q001", "Q002", "Q003", "ISC001",
Expand All @@ -17,8 +17,8 @@ ignore = [
"ERA001", # commented-out code
]

[tool.ruff.flake8-builtins]
[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = ["copyright"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"template_*" = ["E402"] # import not at top
Loading

0 comments on commit 747f4de

Please sign in to comment.