From bbed131e045624345a6044ab663304e3f1e89d5c Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 13:23:53 -0300 Subject: [PATCH 01/13] environment: remove charts related dependencies --- component_environment.ipynb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/component_environment.ipynb b/component_environment.ipynb index d34cc9c..d1d2086 100644 --- a/component_environment.ipynb +++ b/component_environment.ipynb @@ -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" @@ -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", @@ -147,4 +143,4 @@ "outputs": [] } ] -} +} \ No newline at end of file From 3260a5bf60a38df9e93e431b02d935812232da54 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 13:33:33 -0300 Subject: [PATCH 02/13] charts: add component notebook with all chart functions --- component_charts.ipynb | 319 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 319 insertions(+) create mode 100644 component_charts.ipynb diff --git a/component_charts.ipynb b/component_charts.ipynb new file mode 100644 index 0000000..1d21c0e --- /dev/null +++ b/component_charts.ipynb @@ -0,0 +1,319 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyPcAYVVDyOnEVxw6WKYfB8l" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "## Charts Setup\n", + "*You must run the cells in this section each time you connect to a new runtime. For example, when you return to the notebook after an idle timeout, when the runtime crashes, or when you restart or factory reset the runtime.*" + ], + "metadata": { + "id": "IhnbdjqU1e6p" + } + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "elpUvMf61Ym6" + }, + "outputs": [], + "source": [ + "! pip install --upgrade altair >> pip.log" + ] + }, + { + "cell_type": "markdown", + "source": [ + "Import chart packages and define chart functions:" + ], + "metadata": { + "id": "P1aenztz1zK3" + } + }, + { + "cell_type": "code", + "source": [ + "import altair as alt\n", + "\n", + "def plot_release_count(release_counts):\n", + " # check if input contains the right columns\n", + " if not set(\n", + " [\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]\n", + " ).issubset(release_counts.columns):\n", + " raise ValueError(\n", + " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", + " )\n", + " chart = (\n", + " alt.Chart(release_counts)\n", + " .mark_bar()\n", + " .encode(\n", + " x=alt.X(\n", + " \"release_count\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"release count\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"ocid_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"ocid count\", format=\"~s\", tickCount=5),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " title=\"release type\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"release_count\", title=\"release count\"),\n", + " alt.Tooltip(\"ocid_count\", title=\"ocid count\", format=\"~s\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + " return chart\n", + "\n", + "def plot_objects_per_stage(objects_per_stage):\n", + " # check if input contains the right columns\n", + " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_stage)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"stage\",\n", + " type=\"ordinal\",\n", + " scale=alt.Scale(\n", + " domain=[\n", + " \"planning\",\n", + " \"tender\",\n", + " \"awards\",\n", + " \"contracts\",\n", + " \"implementation\",\n", + " ]\n", + " ),\n", + " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"object_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"stage\", title=\"stage\"),\n", + " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_releases_by_month(release_dates):\n", + " # check if input contains the right columns\n", + " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(\n", + " release_dates.columns\n", + " ):\n", + " raise ValueError(\n", + " \"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\"\n", + " )\n", + " # check if number of rows is more than 5000\n", + " if release_dates.shape[0] > 5000:\n", + " alt.data_transformers.disable_max_rows()\n", + "\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(release_dates)\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\n", + " \"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")\n", + " ),\n", + " y=alt.Y(\n", + " \"release_count\",\n", + " type=\"quantitative\",\n", + " aggregate=\"sum\",\n", + " axis=alt.Axis(title=\"number of releases\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " legend=alt.Legend(title=\"release type\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"date\", timeUnit=\"yearmonth\", title=\"date\"),\n", + " alt.Tooltip(\n", + " \"release_count\", aggregate=\"sum\", title=\"number of releases\"\n", + " ),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "def plot_objects_per_year(objects_per_year):\n", + " # check if input contains the right columns\n", + " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_year)\n", + " .transform_fold([\"tenders\", \"awards\"])\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\n", + " \"year\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " ),\n", + " y=alt.Y(\n", + " \"value\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"key\",\n", + " type=\"nominal\",\n", + " title=\"object type\",\n", + " scale=alt.Scale(\n", + " domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]\n", + " ),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", + " alt.Tooltip(\"value\", title=\"number of objects\", type=\"quantitative\"),\n", + " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "def plot_top_buyers(buyers):\n", + " # check if input contains the right columns\n", + " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(buyers)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"total_tenders\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of tenders\", format=\"~s\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " \"name\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"buyer\", labelAngle=0),\n", + " sort=alt.SortField(\"total_tenders\", order=\"descending\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"name\", title=\"buyer\", type=\"nominal\"),\n", + " alt.Tooltip(\n", + " \"total_tenders\", title=\"number of tenders\", type=\"quantitative\"\n", + " ),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart" + ], + "metadata": { + "id": "Bip37aP917XY" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file From 30d782942df748214681060f8fa44a783dba8b00 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 13:45:13 -0300 Subject: [PATCH 03/13] feat: use base chart component when needed --- component_charts.ipynb | 132 ++++--- component_check_quality.ipynb | 9 +- component_environment.ipynb | 2 +- component_scope_kingfisher.ipynb | 15 +- component_scope_usability.ipynb | 45 +-- manage.py | 6 + template_data_quality_feedback.ipynb | 320 +++++++++++++++-- template_meta_analysis.ipynb | 6 +- template_publisher_analysis.ipynb | 314 ++++++++++++++++- template_structure_and_format_feedback.ipynb | 314 ++++++++++++++++- template_usability_checks.ipynb | 344 ++++++++++++++++--- template_usability_checks_fieldlist.ipynb | 299 +++++++++++++++- template_usability_checks_registry.ipynb | 299 +++++++++++++++- 13 files changed, 1846 insertions(+), 259 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 1d21c0e..41e16bf 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -50,11 +50,10 @@ "source": [ "import altair as alt\n", "\n", + "\n", "def plot_release_count(release_counts):\n", " # check if input contains the right columns\n", - " if not set(\n", - " [\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]\n", - " ).issubset(release_counts.columns):\n", + " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", " raise ValueError(\n", " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", " )\n", @@ -103,66 +102,63 @@ "\n", " return chart\n", "\n", + "\n", "def plot_objects_per_stage(objects_per_stage):\n", - " # check if input contains the right columns\n", - " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", - " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", - " # draw chart\n", - " chart = (\n", - " alt.Chart(objects_per_stage)\n", - " .mark_bar(fill=\"#d6e100\")\n", - " .encode(\n", - " x=alt.X(\n", - " \"stage\",\n", - " type=\"ordinal\",\n", - " scale=alt.Scale(\n", - " domain=[\n", - " \"planning\",\n", - " \"tender\",\n", - " \"awards\",\n", - " \"contracts\",\n", - " \"implementation\",\n", - " ]\n", - " ),\n", - " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", - " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", - " ),\n", - " y=alt.Y(\n", - " \"object_count\",\n", - " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", - " ),\n", - " tooltip=[\n", - " alt.Tooltip(\"stage\", title=\"stage\"),\n", - " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", - " ],\n", - " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", - " .configure_view(strokeWidth=0)\n", - " )\n", - " return chart\n", + " # check if input contains the right columns\n", + " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_stage)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"stage\",\n", + " type=\"ordinal\",\n", + " scale=alt.Scale(\n", + " domain=[\n", + " \"planning\",\n", + " \"tender\",\n", + " \"awards\",\n", + " \"contracts\",\n", + " \"implementation\",\n", + " ]\n", + " ),\n", + " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"object_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"stage\", title=\"stage\"),\n", + " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", "\n", "\n", "def plot_releases_by_month(release_dates):\n", " # check if input contains the right columns\n", - " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(\n", - " release_dates.columns\n", - " ):\n", - " raise ValueError(\n", - " \"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\"\n", - " )\n", + " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", " # check if number of rows is more than 5000\n", " if release_dates.shape[0] > 5000:\n", " alt.data_transformers.disable_max_rows()\n", @@ -172,9 +168,7 @@ " alt.Chart(release_dates)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", - " x=alt.X(\n", - " \"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")\n", - " ),\n", + " x=alt.X(\"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")),\n", " y=alt.Y(\n", " \"release_count\",\n", " type=\"quantitative\",\n", @@ -190,9 +184,7 @@ " ),\n", " tooltip=[\n", " alt.Tooltip(\"date\", timeUnit=\"yearmonth\", title=\"date\"),\n", - " alt.Tooltip(\n", - " \"release_count\", aggregate=\"sum\", title=\"number of releases\"\n", - " ),\n", + " alt.Tooltip(\"release_count\", aggregate=\"sum\", title=\"number of releases\"),\n", " alt.Tooltip(\"release_type\", title=\"release type\"),\n", " ],\n", " )\n", @@ -213,6 +205,7 @@ " )\n", " return chart\n", "\n", + "\n", "def plot_objects_per_year(objects_per_year):\n", " # check if input contains the right columns\n", " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", @@ -238,9 +231,7 @@ " \"key\",\n", " type=\"nominal\",\n", " title=\"object type\",\n", - " scale=alt.Scale(\n", - " domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]\n", - " ),\n", + " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", @@ -265,6 +256,7 @@ " )\n", " return chart\n", "\n", + "\n", "def plot_top_buyers(buyers):\n", " # check if input contains the right columns\n", " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", @@ -287,9 +279,7 @@ " ),\n", " tooltip=[\n", " alt.Tooltip(\"name\", title=\"buyer\", type=\"nominal\"),\n", - " alt.Tooltip(\n", - " \"total_tenders\", title=\"number of tenders\", type=\"quantitative\"\n", - " ),\n", + " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", " ],\n", " )\n", " .properties(\n", @@ -316,4 +306,4 @@ "outputs": [] } ] -} \ No newline at end of file +} diff --git a/component_check_quality.ipynb b/component_check_quality.ipynb index e4e2918..e0a4e9a 100644 --- a/component_check_quality.ipynb +++ b/component_check_quality.ipynb @@ -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": [] diff --git a/component_environment.ipynb b/component_environment.ipynb index d1d2086..ba69ccb 100644 --- a/component_environment.ipynb +++ b/component_environment.ipynb @@ -143,4 +143,4 @@ "outputs": [] } ] -} \ No newline at end of file +} diff --git a/component_scope_kingfisher.ipynb b/component_scope_kingfisher.ipynb index b265ebe..9c46232 100644 --- a/component_scope_kingfisher.ipynb +++ b/component_scope_kingfisher.ipynb @@ -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": [] @@ -374,11 +367,7 @@ "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", - "\n", - "format_thousands(ax.yaxis)\n", - "sns.despine()" + "plot_releases_by_month(release_dates)" ], "execution_count": null, "outputs": [] diff --git a/component_scope_usability.ipynb b/component_scope_usability.ipynb index 2255df2..2be757d 100644 --- a/component_scope_usability.ipynb +++ b/component_scope_usability.ipynb @@ -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" @@ -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" @@ -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" diff --git a/manage.py b/manage.py index 3155c49..8cb56eb 100755 --- a/manage.py +++ b/manage.py @@ -17,12 +17,14 @@ ], "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", @@ -30,6 +32,7 @@ ], "template_data_quality_feedback": [ "component_environment", + "component_charts", "component_setup_kingfisher", "component_errors_kingfisher", "component_scope_kingfisher", @@ -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", ], diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index c6122d0..a608c2d 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -29,7 +29,7 @@ "outputs": [], "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" ] }, { @@ -51,12 +51,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", @@ -134,6 +130,296 @@ "# set_light_mode()" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "IhnbdjqU1e6p" + }, + "source": [ + "## Charts Setup\n", + "*You must run the cells in this section each time you connect to a new runtime. For example, when you return to the notebook after an idle timeout, when the runtime crashes, or when you restart or factory reset the runtime.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "elpUvMf61Ym6" + }, + "outputs": [], + "source": [ + "! pip install --upgrade altair >> pip.log" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "P1aenztz1zK3" + }, + "source": [ + "Import chart packages and define chart functions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Bip37aP917XY" + }, + "outputs": [], + "source": [ + "import altair as alt\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " # check if input contains the right columns\n", + " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " raise ValueError(\n", + " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", + " )\n", + " chart = (\n", + " alt.Chart(release_counts)\n", + " .mark_bar()\n", + " .encode(\n", + " x=alt.X(\n", + " \"release_count\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"release count\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"ocid_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"ocid count\", format=\"~s\", tickCount=5),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " title=\"release type\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"release_count\", title=\"release count\"),\n", + " alt.Tooltip(\"ocid_count\", title=\"ocid count\", format=\"~s\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_stage(objects_per_stage):\n", + " # check if input contains the right columns\n", + " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_stage)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"stage\",\n", + " type=\"ordinal\",\n", + " scale=alt.Scale(\n", + " domain=[\n", + " \"planning\",\n", + " \"tender\",\n", + " \"awards\",\n", + " \"contracts\",\n", + " \"implementation\",\n", + " ]\n", + " ),\n", + " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"object_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"stage\", title=\"stage\"),\n", + " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_releases_by_month(release_dates):\n", + " # check if input contains the right columns\n", + " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " # check if number of rows is more than 5000\n", + " if release_dates.shape[0] > 5000:\n", + " alt.data_transformers.disable_max_rows()\n", + "\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(release_dates)\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")),\n", + " y=alt.Y(\n", + " \"release_count\",\n", + " type=\"quantitative\",\n", + " aggregate=\"sum\",\n", + " axis=alt.Axis(title=\"number of releases\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " legend=alt.Legend(title=\"release type\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"date\", timeUnit=\"yearmonth\", title=\"date\"),\n", + " alt.Tooltip(\"release_count\", aggregate=\"sum\", title=\"number of releases\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_year(objects_per_year):\n", + " # check if input contains the right columns\n", + " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_year)\n", + " .transform_fold([\"tenders\", \"awards\"])\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\n", + " \"year\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " ),\n", + " y=alt.Y(\n", + " \"value\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"key\",\n", + " type=\"nominal\",\n", + " title=\"object type\",\n", + " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", + " alt.Tooltip(\"value\", title=\"number of objects\", type=\"quantitative\"),\n", + " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_top_buyers(buyers):\n", + " # check if input contains the right columns\n", + " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(buyers)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"total_tenders\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of tenders\", format=\"~s\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " \"name\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"buyer\", labelAngle=0),\n", + " sort=alt.SortField(\"total_tenders\", order=\"descending\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"name\", title=\"buyer\", type=\"nominal\"),\n", + " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart" + ] + }, { "cell_type": "markdown", "metadata": { @@ -612,14 +898,7 @@ }, "outputs": [], "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)" ] }, { @@ -764,11 +1043,7 @@ "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", - "\n", - "format_thousands(ax.yaxis)\n", - "sns.despine()" + "plot_releases_by_month(release_dates)" ] }, { @@ -2068,14 +2343,7 @@ }, "outputs": [], "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)" ] }, { diff --git a/template_meta_analysis.ipynb b/template_meta_analysis.ipynb index a2b176b..e9bc6d0 100644 --- a/template_meta_analysis.ipynb +++ b/template_meta_analysis.ipynb @@ -29,7 +29,7 @@ "outputs": [], "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" ] }, { @@ -51,12 +51,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", diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index 252a0a7..a1f8057 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -29,7 +29,7 @@ "outputs": [], "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" ] }, { @@ -51,12 +51,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", @@ -134,6 +130,296 @@ "# set_light_mode()" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "IhnbdjqU1e6p" + }, + "source": [ + "## Charts Setup\n", + "*You must run the cells in this section each time you connect to a new runtime. For example, when you return to the notebook after an idle timeout, when the runtime crashes, or when you restart or factory reset the runtime.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "elpUvMf61Ym6" + }, + "outputs": [], + "source": [ + "! pip install --upgrade altair >> pip.log" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "P1aenztz1zK3" + }, + "source": [ + "Import chart packages and define chart functions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Bip37aP917XY" + }, + "outputs": [], + "source": [ + "import altair as alt\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " # check if input contains the right columns\n", + " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " raise ValueError(\n", + " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", + " )\n", + " chart = (\n", + " alt.Chart(release_counts)\n", + " .mark_bar()\n", + " .encode(\n", + " x=alt.X(\n", + " \"release_count\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"release count\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"ocid_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"ocid count\", format=\"~s\", tickCount=5),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " title=\"release type\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"release_count\", title=\"release count\"),\n", + " alt.Tooltip(\"ocid_count\", title=\"ocid count\", format=\"~s\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_stage(objects_per_stage):\n", + " # check if input contains the right columns\n", + " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_stage)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"stage\",\n", + " type=\"ordinal\",\n", + " scale=alt.Scale(\n", + " domain=[\n", + " \"planning\",\n", + " \"tender\",\n", + " \"awards\",\n", + " \"contracts\",\n", + " \"implementation\",\n", + " ]\n", + " ),\n", + " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"object_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"stage\", title=\"stage\"),\n", + " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_releases_by_month(release_dates):\n", + " # check if input contains the right columns\n", + " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " # check if number of rows is more than 5000\n", + " if release_dates.shape[0] > 5000:\n", + " alt.data_transformers.disable_max_rows()\n", + "\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(release_dates)\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")),\n", + " y=alt.Y(\n", + " \"release_count\",\n", + " type=\"quantitative\",\n", + " aggregate=\"sum\",\n", + " axis=alt.Axis(title=\"number of releases\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " legend=alt.Legend(title=\"release type\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"date\", timeUnit=\"yearmonth\", title=\"date\"),\n", + " alt.Tooltip(\"release_count\", aggregate=\"sum\", title=\"number of releases\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_year(objects_per_year):\n", + " # check if input contains the right columns\n", + " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_year)\n", + " .transform_fold([\"tenders\", \"awards\"])\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\n", + " \"year\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " ),\n", + " y=alt.Y(\n", + " \"value\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"key\",\n", + " type=\"nominal\",\n", + " title=\"object type\",\n", + " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", + " alt.Tooltip(\"value\", title=\"number of objects\", type=\"quantitative\"),\n", + " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_top_buyers(buyers):\n", + " # check if input contains the right columns\n", + " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(buyers)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"total_tenders\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of tenders\", format=\"~s\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " \"name\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"buyer\", labelAngle=0),\n", + " sort=alt.SortField(\"total_tenders\", order=\"descending\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"name\", title=\"buyer\", type=\"nominal\"),\n", + " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart" + ] + }, { "cell_type": "markdown", "metadata": { @@ -612,14 +898,7 @@ }, "outputs": [], "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)" ] }, { @@ -764,11 +1043,7 @@ "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", - "\n", - "format_thousands(ax.yaxis)\n", - "sns.despine()" + "plot_releases_by_month(release_dates)" ] }, { @@ -838,6 +1113,9 @@ "kernelspec": { "display_name": "Python 3", "name": "python3" + }, + "language_info": { + "name": "python" } }, "nbformat": 4, diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index 5fc7b86..651cc97 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -29,7 +29,7 @@ "outputs": [], "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" ] }, { @@ -51,12 +51,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", @@ -134,6 +130,296 @@ "# set_light_mode()" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "IhnbdjqU1e6p" + }, + "source": [ + "## Charts Setup\n", + "*You must run the cells in this section each time you connect to a new runtime. For example, when you return to the notebook after an idle timeout, when the runtime crashes, or when you restart or factory reset the runtime.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "elpUvMf61Ym6" + }, + "outputs": [], + "source": [ + "! pip install --upgrade altair >> pip.log" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "P1aenztz1zK3" + }, + "source": [ + "Import chart packages and define chart functions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Bip37aP917XY" + }, + "outputs": [], + "source": [ + "import altair as alt\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " # check if input contains the right columns\n", + " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " raise ValueError(\n", + " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", + " )\n", + " chart = (\n", + " alt.Chart(release_counts)\n", + " .mark_bar()\n", + " .encode(\n", + " x=alt.X(\n", + " \"release_count\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"release count\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"ocid_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"ocid count\", format=\"~s\", tickCount=5),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " title=\"release type\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"release_count\", title=\"release count\"),\n", + " alt.Tooltip(\"ocid_count\", title=\"ocid count\", format=\"~s\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_stage(objects_per_stage):\n", + " # check if input contains the right columns\n", + " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_stage)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"stage\",\n", + " type=\"ordinal\",\n", + " scale=alt.Scale(\n", + " domain=[\n", + " \"planning\",\n", + " \"tender\",\n", + " \"awards\",\n", + " \"contracts\",\n", + " \"implementation\",\n", + " ]\n", + " ),\n", + " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"object_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"stage\", title=\"stage\"),\n", + " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_releases_by_month(release_dates):\n", + " # check if input contains the right columns\n", + " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " # check if number of rows is more than 5000\n", + " if release_dates.shape[0] > 5000:\n", + " alt.data_transformers.disable_max_rows()\n", + "\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(release_dates)\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")),\n", + " y=alt.Y(\n", + " \"release_count\",\n", + " type=\"quantitative\",\n", + " aggregate=\"sum\",\n", + " axis=alt.Axis(title=\"number of releases\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " legend=alt.Legend(title=\"release type\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"date\", timeUnit=\"yearmonth\", title=\"date\"),\n", + " alt.Tooltip(\"release_count\", aggregate=\"sum\", title=\"number of releases\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_year(objects_per_year):\n", + " # check if input contains the right columns\n", + " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_year)\n", + " .transform_fold([\"tenders\", \"awards\"])\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\n", + " \"year\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " ),\n", + " y=alt.Y(\n", + " \"value\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"key\",\n", + " type=\"nominal\",\n", + " title=\"object type\",\n", + " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", + " alt.Tooltip(\"value\", title=\"number of objects\", type=\"quantitative\"),\n", + " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_top_buyers(buyers):\n", + " # check if input contains the right columns\n", + " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(buyers)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"total_tenders\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of tenders\", format=\"~s\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " \"name\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"buyer\", labelAngle=0),\n", + " sort=alt.SortField(\"total_tenders\", order=\"descending\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"name\", title=\"buyer\", type=\"nominal\"),\n", + " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart" + ] + }, { "cell_type": "markdown", "metadata": { @@ -612,14 +898,7 @@ }, "outputs": [], "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)" ] }, { @@ -764,11 +1043,7 @@ "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", - "\n", - "format_thousands(ax.yaxis)\n", - "sns.despine()" + "plot_releases_by_month(release_dates)" ] }, { @@ -1119,6 +1394,9 @@ "kernelspec": { "display_name": "Python 3", "name": "python3" + }, + "language_info": { + "name": "python" } }, "nbformat": 4, diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index 29a2dae..a0ccf08 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -29,7 +29,7 @@ "outputs": [], "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" ] }, { @@ -51,12 +51,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", @@ -134,6 +130,296 @@ "# set_light_mode()" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "IhnbdjqU1e6p" + }, + "source": [ + "## Charts Setup\n", + "*You must run the cells in this section each time you connect to a new runtime. For example, when you return to the notebook after an idle timeout, when the runtime crashes, or when you restart or factory reset the runtime.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "elpUvMf61Ym6" + }, + "outputs": [], + "source": [ + "! pip install --upgrade altair >> pip.log" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "P1aenztz1zK3" + }, + "source": [ + "Import chart packages and define chart functions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Bip37aP917XY" + }, + "outputs": [], + "source": [ + "import altair as alt\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " # check if input contains the right columns\n", + " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " raise ValueError(\n", + " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", + " )\n", + " chart = (\n", + " alt.Chart(release_counts)\n", + " .mark_bar()\n", + " .encode(\n", + " x=alt.X(\n", + " \"release_count\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"release count\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"ocid_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"ocid count\", format=\"~s\", tickCount=5),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " title=\"release type\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"release_count\", title=\"release count\"),\n", + " alt.Tooltip(\"ocid_count\", title=\"ocid count\", format=\"~s\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_stage(objects_per_stage):\n", + " # check if input contains the right columns\n", + " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_stage)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"stage\",\n", + " type=\"ordinal\",\n", + " scale=alt.Scale(\n", + " domain=[\n", + " \"planning\",\n", + " \"tender\",\n", + " \"awards\",\n", + " \"contracts\",\n", + " \"implementation\",\n", + " ]\n", + " ),\n", + " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"object_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"stage\", title=\"stage\"),\n", + " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_releases_by_month(release_dates):\n", + " # check if input contains the right columns\n", + " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " # check if number of rows is more than 5000\n", + " if release_dates.shape[0] > 5000:\n", + " alt.data_transformers.disable_max_rows()\n", + "\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(release_dates)\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")),\n", + " y=alt.Y(\n", + " \"release_count\",\n", + " type=\"quantitative\",\n", + " aggregate=\"sum\",\n", + " axis=alt.Axis(title=\"number of releases\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " legend=alt.Legend(title=\"release type\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"date\", timeUnit=\"yearmonth\", title=\"date\"),\n", + " alt.Tooltip(\"release_count\", aggregate=\"sum\", title=\"number of releases\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_year(objects_per_year):\n", + " # check if input contains the right columns\n", + " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_year)\n", + " .transform_fold([\"tenders\", \"awards\"])\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\n", + " \"year\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " ),\n", + " y=alt.Y(\n", + " \"value\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"key\",\n", + " type=\"nominal\",\n", + " title=\"object type\",\n", + " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", + " alt.Tooltip(\"value\", title=\"number of objects\", type=\"quantitative\"),\n", + " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_top_buyers(buyers):\n", + " # check if input contains the right columns\n", + " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(buyers)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"total_tenders\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of tenders\", format=\"~s\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " \"name\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"buyer\", labelAngle=0),\n", + " sort=alt.SortField(\"total_tenders\", order=\"descending\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"name\", title=\"buyer\", type=\"nominal\"),\n", + " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart" + ] + }, { "cell_type": "markdown", "metadata": { @@ -476,18 +762,7 @@ }, "outputs": [], "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)" ] }, { @@ -563,22 +838,7 @@ }, "outputs": [], "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)" ] }, { @@ -692,20 +952,7 @@ }, "outputs": [], "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))" ] }, { @@ -1564,6 +1811,9 @@ "kernelspec": { "display_name": "Python 3", "name": "python3" + }, + "language_info": { + "name": "python" } }, "nbformat": 4, diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index ecc0ee0..0a29f5f 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -29,7 +29,7 @@ "outputs": [], "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" ] }, { @@ -51,12 +51,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", @@ -134,6 +130,296 @@ "# set_light_mode()" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "IhnbdjqU1e6p" + }, + "source": [ + "## Charts Setup\n", + "*You must run the cells in this section each time you connect to a new runtime. For example, when you return to the notebook after an idle timeout, when the runtime crashes, or when you restart or factory reset the runtime.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "elpUvMf61Ym6" + }, + "outputs": [], + "source": [ + "! pip install --upgrade altair >> pip.log" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "P1aenztz1zK3" + }, + "source": [ + "Import chart packages and define chart functions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Bip37aP917XY" + }, + "outputs": [], + "source": [ + "import altair as alt\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " # check if input contains the right columns\n", + " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " raise ValueError(\n", + " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", + " )\n", + " chart = (\n", + " alt.Chart(release_counts)\n", + " .mark_bar()\n", + " .encode(\n", + " x=alt.X(\n", + " \"release_count\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"release count\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"ocid_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"ocid count\", format=\"~s\", tickCount=5),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " title=\"release type\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"release_count\", title=\"release count\"),\n", + " alt.Tooltip(\"ocid_count\", title=\"ocid count\", format=\"~s\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_stage(objects_per_stage):\n", + " # check if input contains the right columns\n", + " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_stage)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"stage\",\n", + " type=\"ordinal\",\n", + " scale=alt.Scale(\n", + " domain=[\n", + " \"planning\",\n", + " \"tender\",\n", + " \"awards\",\n", + " \"contracts\",\n", + " \"implementation\",\n", + " ]\n", + " ),\n", + " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"object_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"stage\", title=\"stage\"),\n", + " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_releases_by_month(release_dates):\n", + " # check if input contains the right columns\n", + " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " # check if number of rows is more than 5000\n", + " if release_dates.shape[0] > 5000:\n", + " alt.data_transformers.disable_max_rows()\n", + "\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(release_dates)\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")),\n", + " y=alt.Y(\n", + " \"release_count\",\n", + " type=\"quantitative\",\n", + " aggregate=\"sum\",\n", + " axis=alt.Axis(title=\"number of releases\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " legend=alt.Legend(title=\"release type\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"date\", timeUnit=\"yearmonth\", title=\"date\"),\n", + " alt.Tooltip(\"release_count\", aggregate=\"sum\", title=\"number of releases\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_year(objects_per_year):\n", + " # check if input contains the right columns\n", + " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_year)\n", + " .transform_fold([\"tenders\", \"awards\"])\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\n", + " \"year\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " ),\n", + " y=alt.Y(\n", + " \"value\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"key\",\n", + " type=\"nominal\",\n", + " title=\"object type\",\n", + " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", + " alt.Tooltip(\"value\", title=\"number of objects\", type=\"quantitative\"),\n", + " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_top_buyers(buyers):\n", + " # check if input contains the right columns\n", + " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(buyers)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"total_tenders\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of tenders\", format=\"~s\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " \"name\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"buyer\", labelAngle=0),\n", + " sort=alt.SortField(\"total_tenders\", order=\"descending\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"name\", title=\"buyer\", type=\"nominal\"),\n", + " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart" + ] + }, { "cell_type": "markdown", "metadata": { @@ -1062,6 +1348,9 @@ "kernelspec": { "display_name": "Python 3", "name": "python3" + }, + "language_info": { + "name": "python" } }, "nbformat": 4, diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index 346d61e..4ace403 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -29,7 +29,7 @@ "outputs": [], "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" ] }, { @@ -51,12 +51,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", @@ -134,6 +130,296 @@ "# set_light_mode()" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "IhnbdjqU1e6p" + }, + "source": [ + "## Charts Setup\n", + "*You must run the cells in this section each time you connect to a new runtime. For example, when you return to the notebook after an idle timeout, when the runtime crashes, or when you restart or factory reset the runtime.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "elpUvMf61Ym6" + }, + "outputs": [], + "source": [ + "! pip install --upgrade altair >> pip.log" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "P1aenztz1zK3" + }, + "source": [ + "Import chart packages and define chart functions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Bip37aP917XY" + }, + "outputs": [], + "source": [ + "import altair as alt\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " # check if input contains the right columns\n", + " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " raise ValueError(\n", + " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", + " )\n", + " chart = (\n", + " alt.Chart(release_counts)\n", + " .mark_bar()\n", + " .encode(\n", + " x=alt.X(\n", + " \"release_count\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"release count\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"ocid_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"ocid count\", format=\"~s\", tickCount=5),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " title=\"release type\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"release_count\", title=\"release count\"),\n", + " alt.Tooltip(\"ocid_count\", title=\"ocid count\", format=\"~s\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_stage(objects_per_stage):\n", + " # check if input contains the right columns\n", + " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_stage)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"stage\",\n", + " type=\"ordinal\",\n", + " scale=alt.Scale(\n", + " domain=[\n", + " \"planning\",\n", + " \"tender\",\n", + " \"awards\",\n", + " \"contracts\",\n", + " \"implementation\",\n", + " ]\n", + " ),\n", + " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", + " ),\n", + " y=alt.Y(\n", + " \"object_count\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"stage\", title=\"stage\"),\n", + " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_releases_by_month(release_dates):\n", + " # check if input contains the right columns\n", + " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " # check if number of rows is more than 5000\n", + " if release_dates.shape[0] > 5000:\n", + " alt.data_transformers.disable_max_rows()\n", + "\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(release_dates)\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\"date\", timeUnit=\"yearmonth\", axis=alt.Axis(title=\"year and month\")),\n", + " y=alt.Y(\n", + " \"release_count\",\n", + " type=\"quantitative\",\n", + " aggregate=\"sum\",\n", + " axis=alt.Axis(title=\"number of releases\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"release_type\",\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#D6E100\", \"#FB6045\", \"#23B2A7\", \"#6C75E1\"]),\n", + " legend=alt.Legend(title=\"release type\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"date\", timeUnit=\"yearmonth\", title=\"date\"),\n", + " alt.Tooltip(\"release_count\", aggregate=\"sum\", title=\"number of releases\"),\n", + " alt.Tooltip(\"release_type\", title=\"release type\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_objects_per_year(objects_per_year):\n", + " # check if input contains the right columns\n", + " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(objects_per_year)\n", + " .transform_fold([\"tenders\", \"awards\"])\n", + " .mark_line(strokeWidth=3)\n", + " .encode(\n", + " x=alt.X(\n", + " \"year\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " ),\n", + " y=alt.Y(\n", + " \"value\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " scale=alt.Scale(zero=False),\n", + " ),\n", + " color=alt.Color(\n", + " \"key\",\n", + " type=\"nominal\",\n", + " title=\"object type\",\n", + " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", + " alt.Tooltip(\"value\", title=\"number of objects\", type=\"quantitative\"),\n", + " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart\n", + "\n", + "\n", + "def plot_top_buyers(buyers):\n", + " # check if input contains the right columns\n", + " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", + " # draw chart\n", + " chart = (\n", + " alt.Chart(buyers)\n", + " .mark_bar(fill=\"#d6e100\")\n", + " .encode(\n", + " x=alt.X(\n", + " \"total_tenders\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=\"number of tenders\", format=\"~s\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " \"name\",\n", + " type=\"ordinal\",\n", + " axis=alt.Axis(title=\"buyer\", labelAngle=0),\n", + " sort=alt.SortField(\"total_tenders\", order=\"descending\"),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(\"name\", title=\"buyer\", type=\"nominal\"),\n", + " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", + " ],\n", + " )\n", + " .properties(\n", + " width=600,\n", + " height=350,\n", + " padding=50,\n", + " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + " )\n", + " .configure_axis(\n", + " titleFontSize=14,\n", + " labelFontSize=14,\n", + " labelPadding=5,\n", + " ticks=False,\n", + " domain=False,\n", + " )\n", + " .configure_view(strokeWidth=0)\n", + " )\n", + " return chart" + ] + }, { "cell_type": "markdown", "metadata": { @@ -1197,6 +1483,9 @@ "kernelspec": { "display_name": "Python 3", "name": "python3" + }, + "language_info": { + "name": "python" } }, "nbformat": 4, From 1d2f8c31362346c3db3c87a55d0c9b6c00cbe339 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 13:50:44 -0300 Subject: [PATCH 04/13] docs: add charts setup component to the README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8274bd4..6ddc236 100644 --- a/README.md +++ b/README.md @@ -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. From f0774234f38b27772494f4691c9ade78b13a8947 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 14:13:09 -0300 Subject: [PATCH 05/13] fix: fix altair installation and releases by date function call --- component_charts.ipynb | 10 ++++++++-- component_scope_kingfisher.ipynb | 2 +- template_data_quality_feedback.ipynb | 12 +++++++++--- template_publisher_analysis.ipynb | 12 +++++++++--- template_structure_and_format_feedback.ipynb | 12 +++++++++--- template_usability_checks.ipynb | 10 ++++++++-- template_usability_checks_fieldlist.ipynb | 10 ++++++++-- template_usability_checks_registry.ipynb | 10 ++++++++-- 8 files changed, 60 insertions(+), 18 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 41e16bf..72d8adb 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -33,13 +33,19 @@ }, "outputs": [], "source": [ - "! pip install --upgrade altair >> pip.log" + "! pip install altair pyarrow==11.0.0 >> pip.log" ] }, { "cell_type": "markdown", "source": [ - "Import chart packages and define chart functions:" + "Import chart packages and define chart functions. The currently available chart functions are:\n", + "\n", + "* Release count\n", + "* Objects per stage\n", + "* Releases by month\n", + "* Objects per year\n", + "* Top buyers" ], "metadata": { "id": "P1aenztz1zK3" diff --git a/component_scope_kingfisher.ipynb b/component_scope_kingfisher.ipynb index 9c46232..6b6851a 100644 --- a/component_scope_kingfisher.ipynb +++ b/component_scope_kingfisher.ipynb @@ -365,7 +365,7 @@ "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", + "release_dates = release_dates.groupby([\"collection_id\", \"release_type\"]).resample(\"M\").sum().reset_index()\n", "\n", "plot_releases_by_month(release_dates)" ], diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index a608c2d..b7a21c3 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -148,7 +148,7 @@ }, "outputs": [], "source": [ - "! pip install --upgrade altair >> pip.log" + "! pip install altair pyarrow==11.0.0 >> pip.log" ] }, { @@ -157,7 +157,13 @@ "id": "P1aenztz1zK3" }, "source": [ - "Import chart packages and define chart functions:" + "Import chart packages and define chart functions. The currently available chart functions are:\n", + "\n", + "* Release count\n", + "* Objects per stage\n", + "* Releases by month\n", + "* Objects per year\n", + "* Top buyers" ] }, { @@ -1041,7 +1047,7 @@ "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", + "release_dates = release_dates.groupby([\"collection_id\", \"release_type\"]).resample(\"M\").sum().reset_index()\n", "\n", "plot_releases_by_month(release_dates)" ] diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index a1f8057..d9d640c 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -148,7 +148,7 @@ }, "outputs": [], "source": [ - "! pip install --upgrade altair >> pip.log" + "! pip install altair pyarrow==11.0.0 >> pip.log" ] }, { @@ -157,7 +157,13 @@ "id": "P1aenztz1zK3" }, "source": [ - "Import chart packages and define chart functions:" + "Import chart packages and define chart functions. The currently available chart functions are:\n", + "\n", + "* Release count\n", + "* Objects per stage\n", + "* Releases by month\n", + "* Objects per year\n", + "* Top buyers" ] }, { @@ -1041,7 +1047,7 @@ "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", + "release_dates = release_dates.groupby([\"collection_id\", \"release_type\"]).resample(\"M\").sum().reset_index()\n", "\n", "plot_releases_by_month(release_dates)" ] diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index 651cc97..5bb4024 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -148,7 +148,7 @@ }, "outputs": [], "source": [ - "! pip install --upgrade altair >> pip.log" + "! pip install altair pyarrow==11.0.0 >> pip.log" ] }, { @@ -157,7 +157,13 @@ "id": "P1aenztz1zK3" }, "source": [ - "Import chart packages and define chart functions:" + "Import chart packages and define chart functions. The currently available chart functions are:\n", + "\n", + "* Release count\n", + "* Objects per stage\n", + "* Releases by month\n", + "* Objects per year\n", + "* Top buyers" ] }, { @@ -1041,7 +1047,7 @@ "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", + "release_dates = release_dates.groupby([\"collection_id\", \"release_type\"]).resample(\"M\").sum().reset_index()\n", "\n", "plot_releases_by_month(release_dates)" ] diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index a0ccf08..76ba737 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -148,7 +148,7 @@ }, "outputs": [], "source": [ - "! pip install --upgrade altair >> pip.log" + "! pip install altair pyarrow==11.0.0 >> pip.log" ] }, { @@ -157,7 +157,13 @@ "id": "P1aenztz1zK3" }, "source": [ - "Import chart packages and define chart functions:" + "Import chart packages and define chart functions. The currently available chart functions are:\n", + "\n", + "* Release count\n", + "* Objects per stage\n", + "* Releases by month\n", + "* Objects per year\n", + "* Top buyers" ] }, { diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index 0a29f5f..fc07207 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -148,7 +148,7 @@ }, "outputs": [], "source": [ - "! pip install --upgrade altair >> pip.log" + "! pip install altair pyarrow==11.0.0 >> pip.log" ] }, { @@ -157,7 +157,13 @@ "id": "P1aenztz1zK3" }, "source": [ - "Import chart packages and define chart functions:" + "Import chart packages and define chart functions. The currently available chart functions are:\n", + "\n", + "* Release count\n", + "* Objects per stage\n", + "* Releases by month\n", + "* Objects per year\n", + "* Top buyers" ] }, { diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index 4ace403..58b759a 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -148,7 +148,7 @@ }, "outputs": [], "source": [ - "! pip install --upgrade altair >> pip.log" + "! pip install altair pyarrow==11.0.0 >> pip.log" ] }, { @@ -157,7 +157,13 @@ "id": "P1aenztz1zK3" }, "source": [ - "Import chart packages and define chart functions:" + "Import chart packages and define chart functions. The currently available chart functions are:\n", + "\n", + "* Release count\n", + "* Objects per stage\n", + "* Releases by month\n", + "* Objects per year\n", + "* Top buyers" ] }, { From c26a3f204ee7e4cf5694167c7f3aa4476bf41cab Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 14:17:53 -0300 Subject: [PATCH 06/13] fix: update pyptoject as per deprecation warnings --- pyproject.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 529a505..3315248 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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 From 059989bbbeee3ac244f9110bd5bbe0a19d496acd Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 14:22:59 -0300 Subject: [PATCH 07/13] lint --- component_charts.ipynb | 28 ++++++++------------ template_data_quality_feedback.ipynb | 28 ++++++++------------ template_publisher_analysis.ipynb | 28 ++++++++------------ template_structure_and_format_feedback.ipynb | 28 ++++++++------------ template_usability_checks.ipynb | 28 ++++++++------------ template_usability_checks_fieldlist.ipynb | 28 ++++++++------------ template_usability_checks_registry.ipynb | 28 ++++++++------------ 7 files changed, 77 insertions(+), 119 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 72d8adb..26faec9 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -59,11 +59,11 @@ "\n", "def plot_release_count(release_counts):\n", " # check if input contains the right columns\n", - " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", " raise ValueError(\n", " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", " )\n", - " chart = (\n", + " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", " .encode(\n", @@ -106,15 +106,13 @@ " .configure_view(strokeWidth=0)\n", " )\n", "\n", - " return chart\n", - "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", " # check if input contains the right columns\n", - " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -158,19 +156,18 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_releases_by_month(release_dates):\n", " # check if input contains the right columns\n", - " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", " # check if number of rows is more than 5000\n", " if release_dates.shape[0] > 5000:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(release_dates)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", @@ -209,15 +206,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", " # check if input contains the right columns\n", - " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_year)\n", " .transform_fold([\"tenders\", \"awards\"])\n", " .mark_line(strokeWidth=3)\n", @@ -260,15 +256,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_top_buyers(buyers):\n", " # check if input contains the right columns\n", - " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -302,8 +297,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n", - " return chart" + " )\n" ], "metadata": { "id": "Bip37aP917XY" diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index b7a21c3..850881b 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -179,11 +179,11 @@ "\n", "def plot_release_count(release_counts):\n", " # check if input contains the right columns\n", - " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", " raise ValueError(\n", " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", " )\n", - " chart = (\n", + " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", " .encode(\n", @@ -226,15 +226,13 @@ " .configure_view(strokeWidth=0)\n", " )\n", "\n", - " return chart\n", - "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", " # check if input contains the right columns\n", - " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -278,19 +276,18 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_releases_by_month(release_dates):\n", " # check if input contains the right columns\n", - " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", " # check if number of rows is more than 5000\n", " if release_dates.shape[0] > 5000:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(release_dates)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", @@ -329,15 +326,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", " # check if input contains the right columns\n", - " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_year)\n", " .transform_fold([\"tenders\", \"awards\"])\n", " .mark_line(strokeWidth=3)\n", @@ -380,15 +376,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_top_buyers(buyers):\n", " # check if input contains the right columns\n", - " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -422,8 +417,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n", - " return chart" + " )\n" ] }, { diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index d9d640c..6316e3d 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -179,11 +179,11 @@ "\n", "def plot_release_count(release_counts):\n", " # check if input contains the right columns\n", - " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", " raise ValueError(\n", " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", " )\n", - " chart = (\n", + " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", " .encode(\n", @@ -226,15 +226,13 @@ " .configure_view(strokeWidth=0)\n", " )\n", "\n", - " return chart\n", - "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", " # check if input contains the right columns\n", - " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -278,19 +276,18 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_releases_by_month(release_dates):\n", " # check if input contains the right columns\n", - " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", " # check if number of rows is more than 5000\n", " if release_dates.shape[0] > 5000:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(release_dates)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", @@ -329,15 +326,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", " # check if input contains the right columns\n", - " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_year)\n", " .transform_fold([\"tenders\", \"awards\"])\n", " .mark_line(strokeWidth=3)\n", @@ -380,15 +376,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_top_buyers(buyers):\n", " # check if input contains the right columns\n", - " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -422,8 +417,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n", - " return chart" + " )\n" ] }, { diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index 5bb4024..bcd9b17 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -179,11 +179,11 @@ "\n", "def plot_release_count(release_counts):\n", " # check if input contains the right columns\n", - " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", " raise ValueError(\n", " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", " )\n", - " chart = (\n", + " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", " .encode(\n", @@ -226,15 +226,13 @@ " .configure_view(strokeWidth=0)\n", " )\n", "\n", - " return chart\n", - "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", " # check if input contains the right columns\n", - " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -278,19 +276,18 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_releases_by_month(release_dates):\n", " # check if input contains the right columns\n", - " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", " # check if number of rows is more than 5000\n", " if release_dates.shape[0] > 5000:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(release_dates)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", @@ -329,15 +326,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", " # check if input contains the right columns\n", - " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_year)\n", " .transform_fold([\"tenders\", \"awards\"])\n", " .mark_line(strokeWidth=3)\n", @@ -380,15 +376,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_top_buyers(buyers):\n", " # check if input contains the right columns\n", - " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -422,8 +417,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n", - " return chart" + " )\n" ] }, { diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index 76ba737..8738de2 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -179,11 +179,11 @@ "\n", "def plot_release_count(release_counts):\n", " # check if input contains the right columns\n", - " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", " raise ValueError(\n", " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", " )\n", - " chart = (\n", + " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", " .encode(\n", @@ -226,15 +226,13 @@ " .configure_view(strokeWidth=0)\n", " )\n", "\n", - " return chart\n", - "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", " # check if input contains the right columns\n", - " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -278,19 +276,18 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_releases_by_month(release_dates):\n", " # check if input contains the right columns\n", - " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", " # check if number of rows is more than 5000\n", " if release_dates.shape[0] > 5000:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(release_dates)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", @@ -329,15 +326,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", " # check if input contains the right columns\n", - " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_year)\n", " .transform_fold([\"tenders\", \"awards\"])\n", " .mark_line(strokeWidth=3)\n", @@ -380,15 +376,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_top_buyers(buyers):\n", " # check if input contains the right columns\n", - " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -422,8 +417,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n", - " return chart" + " )\n" ] }, { diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index fc07207..06c174e 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -179,11 +179,11 @@ "\n", "def plot_release_count(release_counts):\n", " # check if input contains the right columns\n", - " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", " raise ValueError(\n", " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", " )\n", - " chart = (\n", + " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", " .encode(\n", @@ -226,15 +226,13 @@ " .configure_view(strokeWidth=0)\n", " )\n", "\n", - " return chart\n", - "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", " # check if input contains the right columns\n", - " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -278,19 +276,18 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_releases_by_month(release_dates):\n", " # check if input contains the right columns\n", - " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", " # check if number of rows is more than 5000\n", " if release_dates.shape[0] > 5000:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(release_dates)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", @@ -329,15 +326,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", " # check if input contains the right columns\n", - " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_year)\n", " .transform_fold([\"tenders\", \"awards\"])\n", " .mark_line(strokeWidth=3)\n", @@ -380,15 +376,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_top_buyers(buyers):\n", " # check if input contains the right columns\n", - " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -422,8 +417,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n", - " return chart" + " )\n" ] }, { diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index 58b759a..993956c 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -179,11 +179,11 @@ "\n", "def plot_release_count(release_counts):\n", " # check if input contains the right columns\n", - " if not set([\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"]).issubset(release_counts.columns):\n", + " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", " raise ValueError(\n", " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", " )\n", - " chart = (\n", + " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", " .encode(\n", @@ -226,15 +226,13 @@ " .configure_view(strokeWidth=0)\n", " )\n", "\n", - " return chart\n", - "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", " # check if input contains the right columns\n", - " if not set([\"stage\", \"object_count\"]).issubset(objects_per_stage.columns):\n", + " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -278,19 +276,18 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_releases_by_month(release_dates):\n", " # check if input contains the right columns\n", - " if not set([\"date\", \"collection_id\", \"release_type\", \"release_count\"]).issubset(release_dates.columns):\n", + " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", " # check if number of rows is more than 5000\n", " if release_dates.shape[0] > 5000:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(release_dates)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", @@ -329,15 +326,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", " # check if input contains the right columns\n", - " if not set([\"year\", \"tenders\", \"awards\"]).issubset(objects_per_year.columns):\n", + " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(objects_per_year)\n", " .transform_fold([\"tenders\", \"awards\"])\n", " .mark_line(strokeWidth=3)\n", @@ -380,15 +376,14 @@ " )\n", " .configure_view(strokeWidth=0)\n", " )\n", - " return chart\n", "\n", "\n", "def plot_top_buyers(buyers):\n", " # check if input contains the right columns\n", - " if not set([\"name\", \"total_tenders\"]).issubset(buyers.columns):\n", + " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", " # draw chart\n", - " chart = (\n", + " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", " .encode(\n", @@ -422,8 +417,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n", - " return chart" + " )\n" ] }, { From eaa6cde5d19465abf38ec8586b23ef4cd57b9942 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 14:32:16 -0300 Subject: [PATCH 08/13] tidy up component_charts --- component_charts.ipynb | 58 ++++++++------------ template_data_quality_feedback.ipynb | 58 ++++++++------------ template_publisher_analysis.ipynb | 58 ++++++++------------ template_structure_and_format_feedback.ipynb | 58 ++++++++------------ template_usability_checks.ipynb | 58 ++++++++------------ template_usability_checks_fieldlist.ipynb | 58 ++++++++------------ template_usability_checks_registry.ipynb | 58 ++++++++------------ 7 files changed, 154 insertions(+), 252 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 26faec9..656fa1c 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -57,12 +57,14 @@ "import altair as alt\n", "\n", "\n", - "def plot_release_count(release_counts):\n", + "def check_columns(columns, data):\n", " # check if input contains the right columns\n", - " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", - " raise ValueError(\n", - " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", - " )\n", + " if not columns.issubset(data.columns):\n", + " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " check_columns({\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}, release_counts)\n", " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", @@ -108,10 +110,8 @@ "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", - " # check if input contains the right columns\n", - " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", - " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", - " # draw chart\n", + " check_columns({\"stage\", \"object_count\"}, objects_per_stage)\n", + " stages = [\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"]\n", " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -119,22 +119,14 @@ " x=alt.X(\n", " \"stage\",\n", " type=\"ordinal\",\n", - " scale=alt.Scale(\n", - " domain=[\n", - " \"planning\",\n", - " \"tender\",\n", - " \"awards\",\n", - " \"contracts\",\n", - " \"implementation\",\n", - " ]\n", - " ),\n", - " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " scale=alt.Scale(domain=stages),\n", + " sort=stages,\n", " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", " ),\n", " y=alt.Y(\n", " \"object_count\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=len(stages)),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"stage\", title=\"stage\"),\n", @@ -159,11 +151,10 @@ "\n", "\n", "def plot_releases_by_month(release_dates):\n", - " # check if input contains the right columns\n", - " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", - " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " check_columns({\"date\", \"collection_id\", \"release_type\", \"release_count\"}, release_dates)\n", + " max_rows = 5000\n", " # check if number of rows is more than 5000\n", - " if release_dates.shape[0] > 5000:\n", + " if release_dates.shape[0] > max_rows:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", @@ -209,19 +200,17 @@ "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", - " # check if input contains the right columns\n", - " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", - " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", - " # draw chart\n", + " check_columns({\"year\", \"tenders\", \"awards\"}, objects_per_year)\n", + " stages = [\"tenders\", \"awards\"]\n", " return (\n", " alt.Chart(objects_per_year)\n", - " .transform_fold([\"tenders\", \"awards\"])\n", + " .transform_fold(stages)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", " x=alt.X(\n", " \"year\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=objects_per_year.shape[0]),\n", " ),\n", " y=alt.Y(\n", " \"value\",\n", @@ -233,7 +222,7 @@ " \"key\",\n", " type=\"nominal\",\n", " title=\"object type\",\n", - " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " scale=alt.Scale(domain=stages, range=[\"#D6E100\", \"#FB6045\"]),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", @@ -259,10 +248,7 @@ "\n", "\n", "def plot_top_buyers(buyers):\n", - " # check if input contains the right columns\n", - " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", - " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", - " # draw chart\n", + " check_columns({\"name\", \"total_tenders\"}, buyers)\n", " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -297,7 +283,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n" + " )" ], "metadata": { "id": "Bip37aP917XY" diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index 850881b..1c373ff 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -177,12 +177,14 @@ "import altair as alt\n", "\n", "\n", - "def plot_release_count(release_counts):\n", + "def check_columns(columns, data):\n", " # check if input contains the right columns\n", - " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", - " raise ValueError(\n", - " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", - " )\n", + " if not columns.issubset(data.columns):\n", + " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " check_columns({\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}, release_counts)\n", " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", @@ -228,10 +230,8 @@ "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", - " # check if input contains the right columns\n", - " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", - " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", - " # draw chart\n", + " check_columns({\"stage\", \"object_count\"}, objects_per_stage)\n", + " stages = [\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"]\n", " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -239,22 +239,14 @@ " x=alt.X(\n", " \"stage\",\n", " type=\"ordinal\",\n", - " scale=alt.Scale(\n", - " domain=[\n", - " \"planning\",\n", - " \"tender\",\n", - " \"awards\",\n", - " \"contracts\",\n", - " \"implementation\",\n", - " ]\n", - " ),\n", - " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " scale=alt.Scale(domain=stages),\n", + " sort=stages,\n", " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", " ),\n", " y=alt.Y(\n", " \"object_count\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=len(stages)),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"stage\", title=\"stage\"),\n", @@ -279,11 +271,10 @@ "\n", "\n", "def plot_releases_by_month(release_dates):\n", - " # check if input contains the right columns\n", - " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", - " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " check_columns({\"date\", \"collection_id\", \"release_type\", \"release_count\"}, release_dates)\n", + " max_rows = 5000\n", " # check if number of rows is more than 5000\n", - " if release_dates.shape[0] > 5000:\n", + " if release_dates.shape[0] > max_rows:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", @@ -329,19 +320,17 @@ "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", - " # check if input contains the right columns\n", - " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", - " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", - " # draw chart\n", + " check_columns({\"year\", \"tenders\", \"awards\"}, objects_per_year)\n", + " stages = [\"tenders\", \"awards\"]\n", " return (\n", " alt.Chart(objects_per_year)\n", - " .transform_fold([\"tenders\", \"awards\"])\n", + " .transform_fold(stages)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", " x=alt.X(\n", " \"year\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=objects_per_year.shape[0]),\n", " ),\n", " y=alt.Y(\n", " \"value\",\n", @@ -353,7 +342,7 @@ " \"key\",\n", " type=\"nominal\",\n", " title=\"object type\",\n", - " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " scale=alt.Scale(domain=stages, range=[\"#D6E100\", \"#FB6045\"]),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", @@ -379,10 +368,7 @@ "\n", "\n", "def plot_top_buyers(buyers):\n", - " # check if input contains the right columns\n", - " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", - " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", - " # draw chart\n", + " check_columns({\"name\", \"total_tenders\"}, buyers)\n", " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -417,7 +403,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n" + " )" ] }, { diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index 6316e3d..e92233d 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -177,12 +177,14 @@ "import altair as alt\n", "\n", "\n", - "def plot_release_count(release_counts):\n", + "def check_columns(columns, data):\n", " # check if input contains the right columns\n", - " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", - " raise ValueError(\n", - " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", - " )\n", + " if not columns.issubset(data.columns):\n", + " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " check_columns({\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}, release_counts)\n", " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", @@ -228,10 +230,8 @@ "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", - " # check if input contains the right columns\n", - " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", - " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", - " # draw chart\n", + " check_columns({\"stage\", \"object_count\"}, objects_per_stage)\n", + " stages = [\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"]\n", " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -239,22 +239,14 @@ " x=alt.X(\n", " \"stage\",\n", " type=\"ordinal\",\n", - " scale=alt.Scale(\n", - " domain=[\n", - " \"planning\",\n", - " \"tender\",\n", - " \"awards\",\n", - " \"contracts\",\n", - " \"implementation\",\n", - " ]\n", - " ),\n", - " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " scale=alt.Scale(domain=stages),\n", + " sort=stages,\n", " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", " ),\n", " y=alt.Y(\n", " \"object_count\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=len(stages)),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"stage\", title=\"stage\"),\n", @@ -279,11 +271,10 @@ "\n", "\n", "def plot_releases_by_month(release_dates):\n", - " # check if input contains the right columns\n", - " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", - " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " check_columns({\"date\", \"collection_id\", \"release_type\", \"release_count\"}, release_dates)\n", + " max_rows = 5000\n", " # check if number of rows is more than 5000\n", - " if release_dates.shape[0] > 5000:\n", + " if release_dates.shape[0] > max_rows:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", @@ -329,19 +320,17 @@ "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", - " # check if input contains the right columns\n", - " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", - " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", - " # draw chart\n", + " check_columns({\"year\", \"tenders\", \"awards\"}, objects_per_year)\n", + " stages = [\"tenders\", \"awards\"]\n", " return (\n", " alt.Chart(objects_per_year)\n", - " .transform_fold([\"tenders\", \"awards\"])\n", + " .transform_fold(stages)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", " x=alt.X(\n", " \"year\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=objects_per_year.shape[0]),\n", " ),\n", " y=alt.Y(\n", " \"value\",\n", @@ -353,7 +342,7 @@ " \"key\",\n", " type=\"nominal\",\n", " title=\"object type\",\n", - " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " scale=alt.Scale(domain=stages, range=[\"#D6E100\", \"#FB6045\"]),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", @@ -379,10 +368,7 @@ "\n", "\n", "def plot_top_buyers(buyers):\n", - " # check if input contains the right columns\n", - " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", - " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", - " # draw chart\n", + " check_columns({\"name\", \"total_tenders\"}, buyers)\n", " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -417,7 +403,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n" + " )" ] }, { diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index bcd9b17..c65be0a 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -177,12 +177,14 @@ "import altair as alt\n", "\n", "\n", - "def plot_release_count(release_counts):\n", + "def check_columns(columns, data):\n", " # check if input contains the right columns\n", - " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", - " raise ValueError(\n", - " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", - " )\n", + " if not columns.issubset(data.columns):\n", + " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " check_columns({\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}, release_counts)\n", " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", @@ -228,10 +230,8 @@ "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", - " # check if input contains the right columns\n", - " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", - " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", - " # draw chart\n", + " check_columns({\"stage\", \"object_count\"}, objects_per_stage)\n", + " stages = [\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"]\n", " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -239,22 +239,14 @@ " x=alt.X(\n", " \"stage\",\n", " type=\"ordinal\",\n", - " scale=alt.Scale(\n", - " domain=[\n", - " \"planning\",\n", - " \"tender\",\n", - " \"awards\",\n", - " \"contracts\",\n", - " \"implementation\",\n", - " ]\n", - " ),\n", - " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " scale=alt.Scale(domain=stages),\n", + " sort=stages,\n", " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", " ),\n", " y=alt.Y(\n", " \"object_count\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=len(stages)),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"stage\", title=\"stage\"),\n", @@ -279,11 +271,10 @@ "\n", "\n", "def plot_releases_by_month(release_dates):\n", - " # check if input contains the right columns\n", - " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", - " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " check_columns({\"date\", \"collection_id\", \"release_type\", \"release_count\"}, release_dates)\n", + " max_rows = 5000\n", " # check if number of rows is more than 5000\n", - " if release_dates.shape[0] > 5000:\n", + " if release_dates.shape[0] > max_rows:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", @@ -329,19 +320,17 @@ "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", - " # check if input contains the right columns\n", - " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", - " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", - " # draw chart\n", + " check_columns({\"year\", \"tenders\", \"awards\"}, objects_per_year)\n", + " stages = [\"tenders\", \"awards\"]\n", " return (\n", " alt.Chart(objects_per_year)\n", - " .transform_fold([\"tenders\", \"awards\"])\n", + " .transform_fold(stages)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", " x=alt.X(\n", " \"year\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=objects_per_year.shape[0]),\n", " ),\n", " y=alt.Y(\n", " \"value\",\n", @@ -353,7 +342,7 @@ " \"key\",\n", " type=\"nominal\",\n", " title=\"object type\",\n", - " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " scale=alt.Scale(domain=stages, range=[\"#D6E100\", \"#FB6045\"]),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", @@ -379,10 +368,7 @@ "\n", "\n", "def plot_top_buyers(buyers):\n", - " # check if input contains the right columns\n", - " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", - " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", - " # draw chart\n", + " check_columns({\"name\", \"total_tenders\"}, buyers)\n", " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -417,7 +403,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n" + " )" ] }, { diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index 8738de2..927d055 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -177,12 +177,14 @@ "import altair as alt\n", "\n", "\n", - "def plot_release_count(release_counts):\n", + "def check_columns(columns, data):\n", " # check if input contains the right columns\n", - " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", - " raise ValueError(\n", - " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", - " )\n", + " if not columns.issubset(data.columns):\n", + " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " check_columns({\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}, release_counts)\n", " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", @@ -228,10 +230,8 @@ "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", - " # check if input contains the right columns\n", - " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", - " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", - " # draw chart\n", + " check_columns({\"stage\", \"object_count\"}, objects_per_stage)\n", + " stages = [\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"]\n", " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -239,22 +239,14 @@ " x=alt.X(\n", " \"stage\",\n", " type=\"ordinal\",\n", - " scale=alt.Scale(\n", - " domain=[\n", - " \"planning\",\n", - " \"tender\",\n", - " \"awards\",\n", - " \"contracts\",\n", - " \"implementation\",\n", - " ]\n", - " ),\n", - " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " scale=alt.Scale(domain=stages),\n", + " sort=stages,\n", " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", " ),\n", " y=alt.Y(\n", " \"object_count\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=len(stages)),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"stage\", title=\"stage\"),\n", @@ -279,11 +271,10 @@ "\n", "\n", "def plot_releases_by_month(release_dates):\n", - " # check if input contains the right columns\n", - " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", - " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " check_columns({\"date\", \"collection_id\", \"release_type\", \"release_count\"}, release_dates)\n", + " max_rows = 5000\n", " # check if number of rows is more than 5000\n", - " if release_dates.shape[0] > 5000:\n", + " if release_dates.shape[0] > max_rows:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", @@ -329,19 +320,17 @@ "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", - " # check if input contains the right columns\n", - " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", - " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", - " # draw chart\n", + " check_columns({\"year\", \"tenders\", \"awards\"}, objects_per_year)\n", + " stages = [\"tenders\", \"awards\"]\n", " return (\n", " alt.Chart(objects_per_year)\n", - " .transform_fold([\"tenders\", \"awards\"])\n", + " .transform_fold(stages)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", " x=alt.X(\n", " \"year\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=objects_per_year.shape[0]),\n", " ),\n", " y=alt.Y(\n", " \"value\",\n", @@ -353,7 +342,7 @@ " \"key\",\n", " type=\"nominal\",\n", " title=\"object type\",\n", - " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " scale=alt.Scale(domain=stages, range=[\"#D6E100\", \"#FB6045\"]),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", @@ -379,10 +368,7 @@ "\n", "\n", "def plot_top_buyers(buyers):\n", - " # check if input contains the right columns\n", - " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", - " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", - " # draw chart\n", + " check_columns({\"name\", \"total_tenders\"}, buyers)\n", " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -417,7 +403,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n" + " )" ] }, { diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index 06c174e..94282ff 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -177,12 +177,14 @@ "import altair as alt\n", "\n", "\n", - "def plot_release_count(release_counts):\n", + "def check_columns(columns, data):\n", " # check if input contains the right columns\n", - " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", - " raise ValueError(\n", - " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", - " )\n", + " if not columns.issubset(data.columns):\n", + " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " check_columns({\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}, release_counts)\n", " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", @@ -228,10 +230,8 @@ "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", - " # check if input contains the right columns\n", - " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", - " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", - " # draw chart\n", + " check_columns({\"stage\", \"object_count\"}, objects_per_stage)\n", + " stages = [\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"]\n", " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -239,22 +239,14 @@ " x=alt.X(\n", " \"stage\",\n", " type=\"ordinal\",\n", - " scale=alt.Scale(\n", - " domain=[\n", - " \"planning\",\n", - " \"tender\",\n", - " \"awards\",\n", - " \"contracts\",\n", - " \"implementation\",\n", - " ]\n", - " ),\n", - " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " scale=alt.Scale(domain=stages),\n", + " sort=stages,\n", " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", " ),\n", " y=alt.Y(\n", " \"object_count\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=len(stages)),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"stage\", title=\"stage\"),\n", @@ -279,11 +271,10 @@ "\n", "\n", "def plot_releases_by_month(release_dates):\n", - " # check if input contains the right columns\n", - " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", - " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " check_columns({\"date\", \"collection_id\", \"release_type\", \"release_count\"}, release_dates)\n", + " max_rows = 5000\n", " # check if number of rows is more than 5000\n", - " if release_dates.shape[0] > 5000:\n", + " if release_dates.shape[0] > max_rows:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", @@ -329,19 +320,17 @@ "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", - " # check if input contains the right columns\n", - " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", - " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", - " # draw chart\n", + " check_columns({\"year\", \"tenders\", \"awards\"}, objects_per_year)\n", + " stages = [\"tenders\", \"awards\"]\n", " return (\n", " alt.Chart(objects_per_year)\n", - " .transform_fold([\"tenders\", \"awards\"])\n", + " .transform_fold(stages)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", " x=alt.X(\n", " \"year\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=objects_per_year.shape[0]),\n", " ),\n", " y=alt.Y(\n", " \"value\",\n", @@ -353,7 +342,7 @@ " \"key\",\n", " type=\"nominal\",\n", " title=\"object type\",\n", - " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " scale=alt.Scale(domain=stages, range=[\"#D6E100\", \"#FB6045\"]),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", @@ -379,10 +368,7 @@ "\n", "\n", "def plot_top_buyers(buyers):\n", - " # check if input contains the right columns\n", - " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", - " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", - " # draw chart\n", + " check_columns({\"name\", \"total_tenders\"}, buyers)\n", " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -417,7 +403,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n" + " )" ] }, { diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index 993956c..3678340 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -177,12 +177,14 @@ "import altair as alt\n", "\n", "\n", - "def plot_release_count(release_counts):\n", + "def check_columns(columns, data):\n", " # check if input contains the right columns\n", - " if not {\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}.issubset(release_counts.columns):\n", - " raise ValueError(\n", - " \"Input data must contain the following columns: collection_id, release_type, release_count, ocid_count\"\n", - " )\n", + " if not columns.issubset(data.columns):\n", + " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + "\n", + "\n", + "def plot_release_count(release_counts):\n", + " check_columns({\"collection_id\", \"release_type\", \"release_count\", \"ocid_count\"}, release_counts)\n", " return (\n", " alt.Chart(release_counts)\n", " .mark_bar()\n", @@ -228,10 +230,8 @@ "\n", "\n", "def plot_objects_per_stage(objects_per_stage):\n", - " # check if input contains the right columns\n", - " if not {\"stage\", \"object_count\"}.issubset(objects_per_stage.columns):\n", - " raise ValueError(\"Data must contain columns 'stage' and 'object_count'\")\n", - " # draw chart\n", + " check_columns({\"stage\", \"object_count\"}, objects_per_stage)\n", + " stages = [\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"]\n", " return (\n", " alt.Chart(objects_per_stage)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -239,22 +239,14 @@ " x=alt.X(\n", " \"stage\",\n", " type=\"ordinal\",\n", - " scale=alt.Scale(\n", - " domain=[\n", - " \"planning\",\n", - " \"tender\",\n", - " \"awards\",\n", - " \"contracts\",\n", - " \"implementation\",\n", - " ]\n", - " ),\n", - " sort=[\"planning\", \"tender\", \"awards\", \"contracts\", \"implementation\"],\n", + " scale=alt.Scale(domain=stages),\n", + " sort=stages,\n", " axis=alt.Axis(title=\"stage\", labelAngle=0),\n", " ),\n", " y=alt.Y(\n", " \"object_count\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=5),\n", + " axis=alt.Axis(title=\"number of objects\", format=\"~s\", tickCount=len(stages)),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"stage\", title=\"stage\"),\n", @@ -279,11 +271,10 @@ "\n", "\n", "def plot_releases_by_month(release_dates):\n", - " # check if input contains the right columns\n", - " if not {\"date\", \"collection_id\", \"release_type\", \"release_count\"}.issubset(release_dates.columns):\n", - " raise ValueError(\"Data must contain columns 'date', 'collection_id', 'release_type', 'release_count'\")\n", + " check_columns({\"date\", \"collection_id\", \"release_type\", \"release_count\"}, release_dates)\n", + " max_rows = 5000\n", " # check if number of rows is more than 5000\n", - " if release_dates.shape[0] > 5000:\n", + " if release_dates.shape[0] > max_rows:\n", " alt.data_transformers.disable_max_rows()\n", "\n", " # draw chart\n", @@ -329,19 +320,17 @@ "\n", "\n", "def plot_objects_per_year(objects_per_year):\n", - " # check if input contains the right columns\n", - " if not {\"year\", \"tenders\", \"awards\"}.issubset(objects_per_year.columns):\n", - " raise ValueError(\"Data must contain columns 'year', 'tenders' and 'awards'\")\n", - " # draw chart\n", + " check_columns({\"year\", \"tenders\", \"awards\"}, objects_per_year)\n", + " stages = [\"tenders\", \"awards\"]\n", " return (\n", " alt.Chart(objects_per_year)\n", - " .transform_fold([\"tenders\", \"awards\"])\n", + " .transform_fold(stages)\n", " .mark_line(strokeWidth=3)\n", " .encode(\n", " x=alt.X(\n", " \"year\",\n", " type=\"quantitative\",\n", - " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=dates.shape[0]),\n", + " axis=alt.Axis(title=\"year\", format=\".0f\", tickCount=objects_per_year.shape[0]),\n", " ),\n", " y=alt.Y(\n", " \"value\",\n", @@ -353,7 +342,7 @@ " \"key\",\n", " type=\"nominal\",\n", " title=\"object type\",\n", - " scale=alt.Scale(domain=[\"tenders\", \"awards\"], range=[\"#D6E100\", \"#FB6045\"]),\n", + " scale=alt.Scale(domain=stages, range=[\"#D6E100\", \"#FB6045\"]),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"year\", title=\"year\", type=\"quantitative\"),\n", @@ -379,10 +368,7 @@ "\n", "\n", "def plot_top_buyers(buyers):\n", - " # check if input contains the right columns\n", - " if not {\"name\", \"total_tenders\"}.issubset(buyers.columns):\n", - " raise ValueError(\"Data must contain columns 'name' and 'total_tenders'\")\n", - " # draw chart\n", + " check_columns({\"name\", \"total_tenders\"}, buyers)\n", " return (\n", " alt.Chart(buyers)\n", " .mark_bar(fill=\"#d6e100\")\n", @@ -417,7 +403,7 @@ " domain=False,\n", " )\n", " .configure_view(strokeWidth=0)\n", - " )\n" + " )" ] }, { From ea4a0be303cb665f55f4aaf195b5bbdc09a4d578 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 14:36:46 -0300 Subject: [PATCH 09/13] lint: define custom exception class --- component_charts.ipynb | 5 ++++- template_data_quality_feedback.ipynb | 5 ++++- template_publisher_analysis.ipynb | 5 ++++- template_structure_and_format_feedback.ipynb | 5 ++++- template_usability_checks.ipynb | 5 ++++- template_usability_checks_fieldlist.ipynb | 5 ++++- template_usability_checks_registry.ipynb | 5 ++++- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 656fa1c..0b76031 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -56,11 +56,14 @@ "source": [ "import altair as alt\n", "\n", + "class MissingColumns(Exception):\n", + " def __init__(self, columns):\n", + " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + " raise MissingColumns(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index 1c373ff..886e968 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -176,11 +176,14 @@ "source": [ "import altair as alt\n", "\n", + "class MissingColumns(Exception):\n", + " def __init__(self, columns):\n", + " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + " raise MissingColumns(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index e92233d..3838d17 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -176,11 +176,14 @@ "source": [ "import altair as alt\n", "\n", + "class MissingColumns(Exception):\n", + " def __init__(self, columns):\n", + " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + " raise MissingColumns(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index c65be0a..20f42a9 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -176,11 +176,14 @@ "source": [ "import altair as alt\n", "\n", + "class MissingColumns(Exception):\n", + " def __init__(self, columns):\n", + " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + " raise MissingColumns(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index 927d055..a83342f 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -176,11 +176,14 @@ "source": [ "import altair as alt\n", "\n", + "class MissingColumns(Exception):\n", + " def __init__(self, columns):\n", + " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + " raise MissingColumns(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index 94282ff..38f1caf 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -176,11 +176,14 @@ "source": [ "import altair as alt\n", "\n", + "class MissingColumns(Exception):\n", + " def __init__(self, columns):\n", + " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + " raise MissingColumns(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index 3678340..817a5fb 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -176,11 +176,14 @@ "source": [ "import altair as alt\n", "\n", + "class MissingColumns(Exception):\n", + " def __init__(self, columns):\n", + " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise ValueError(f\"Input data must contain the columns {columns}\")\n", + " raise MissingColumns(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", From 85e373acbf4afb0b23cec6f916af790e9e9d0d37 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 14:42:18 -0300 Subject: [PATCH 10/13] lint --- component_charts.ipynb | 4 ++-- template_data_quality_feedback.ipynb | 4 ++-- template_publisher_analysis.ipynb | 4 ++-- template_structure_and_format_feedback.ipynb | 4 ++-- template_usability_checks.ipynb | 4 ++-- template_usability_checks_fieldlist.ipynb | 4 ++-- template_usability_checks_registry.ipynb | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 0b76031..8422176 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -56,14 +56,14 @@ "source": [ "import altair as alt\n", "\n", - "class MissingColumns(Exception):\n", + "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise MissingColumns(columns)\n", + " raise MissingColumnsError(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index 886e968..1791be9 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -176,14 +176,14 @@ "source": [ "import altair as alt\n", "\n", - "class MissingColumns(Exception):\n", + "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise MissingColumns(columns)\n", + " raise MissingColumnsError(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index 3838d17..10456f5 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -176,14 +176,14 @@ "source": [ "import altair as alt\n", "\n", - "class MissingColumns(Exception):\n", + "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise MissingColumns(columns)\n", + " raise MissingColumnsError(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index 20f42a9..42a1e43 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -176,14 +176,14 @@ "source": [ "import altair as alt\n", "\n", - "class MissingColumns(Exception):\n", + "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise MissingColumns(columns)\n", + " raise MissingColumnsError(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index a83342f..e691577 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -176,14 +176,14 @@ "source": [ "import altair as alt\n", "\n", - "class MissingColumns(Exception):\n", + "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise MissingColumns(columns)\n", + " raise MissingColumnsError(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index 38f1caf..90911c1 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -176,14 +176,14 @@ "source": [ "import altair as alt\n", "\n", - "class MissingColumns(Exception):\n", + "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise MissingColumns(columns)\n", + " raise MissingColumnsError(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index 817a5fb..dd81dd3 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -176,14 +176,14 @@ "source": [ "import altair as alt\n", "\n", - "class MissingColumns(Exception):\n", + "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", - " raise MissingColumns(columns)\n", + " raise MissingColumnsError(columns)\n", "\n", "\n", "def plot_release_count(release_counts):\n", From d5655b151229f7be2875fd90c0a7711d25a71d23 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 15:00:06 -0300 Subject: [PATCH 11/13] component_charts: remove code duplications --- component_charts.ipynb | 106 +++++------ template_data_quality_feedback.ipynb | 175 ++++++++++++------- template_publisher_analysis.ipynb | 175 ++++++++++++------- template_structure_and_format_feedback.ipynb | 175 ++++++++++++------- template_usability_checks.ipynb | 175 ++++++++++++------- template_usability_checks_fieldlist.ipynb | 175 ++++++++++++------- template_usability_checks_registry.ipynb | 175 ++++++++++++------- 7 files changed, 687 insertions(+), 469 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 8422176..3b35545 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -56,10 +56,27 @@ "source": [ "import altair as alt\n", "\n", + "\n", "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", + "\n", + "chart_properties = {\n", + " \"width\": 600,\n", + " \"height\": 350,\n", + " \"padding\": 50,\n", + " \"title\": alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + "}\n", + "chart_axis = {\n", + " \"titleFontSize\": 14,\n", + " \"labelFontSize\": 14,\n", + " \"labelPadding\": 5,\n", + " \"ticks\": False,\n", + " \"domain\": False,\n", + "}\n", + "\n", + "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", @@ -95,19 +112,8 @@ " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -136,19 +142,8 @@ " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -185,19 +180,8 @@ " alt.Tooltip(\"release_type\", title=\"release type\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -233,19 +217,8 @@ " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -272,27 +245,26 @@ " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )" ], "metadata": { "id": "Bip37aP917XY" }, - "execution_count": null, - "outputs": [] + "execution_count": 5, + "outputs": [ + { + "data": { + "text/html": "\n\n
\n", + "text/plain": "alt.Chart(...)" + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ] } ] } diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index 1791be9..f343fbf 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -168,18 +168,114 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "Bip37aP917XY" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import altair as alt\n", "\n", + "\n", "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", + "\n", + "chart_properties = {\n", + " \"width\": 600,\n", + " \"height\": 350,\n", + " \"padding\": 50,\n", + " \"title\": alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + "}\n", + "chart_axis = {\n", + " \"titleFontSize\": 14,\n", + " \"labelFontSize\": 14,\n", + " \"labelPadding\": 5,\n", + " \"ticks\": False,\n", + " \"domain\": False,\n", + "}\n", + "\n", + "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", @@ -215,19 +311,8 @@ " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -256,19 +341,8 @@ " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -305,19 +379,8 @@ " alt.Tooltip(\"release_type\", title=\"release type\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -353,19 +416,8 @@ " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -392,19 +444,8 @@ " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )" ] diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index 10456f5..377b04c 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -168,18 +168,114 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "Bip37aP917XY" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import altair as alt\n", "\n", + "\n", "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", + "\n", + "chart_properties = {\n", + " \"width\": 600,\n", + " \"height\": 350,\n", + " \"padding\": 50,\n", + " \"title\": alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + "}\n", + "chart_axis = {\n", + " \"titleFontSize\": 14,\n", + " \"labelFontSize\": 14,\n", + " \"labelPadding\": 5,\n", + " \"ticks\": False,\n", + " \"domain\": False,\n", + "}\n", + "\n", + "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", @@ -215,19 +311,8 @@ " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -256,19 +341,8 @@ " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -305,19 +379,8 @@ " alt.Tooltip(\"release_type\", title=\"release type\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -353,19 +416,8 @@ " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -392,19 +444,8 @@ " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )" ] diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index 42a1e43..436ebd9 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -168,18 +168,114 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "Bip37aP917XY" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import altair as alt\n", "\n", + "\n", "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", + "\n", + "chart_properties = {\n", + " \"width\": 600,\n", + " \"height\": 350,\n", + " \"padding\": 50,\n", + " \"title\": alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + "}\n", + "chart_axis = {\n", + " \"titleFontSize\": 14,\n", + " \"labelFontSize\": 14,\n", + " \"labelPadding\": 5,\n", + " \"ticks\": False,\n", + " \"domain\": False,\n", + "}\n", + "\n", + "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", @@ -215,19 +311,8 @@ " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -256,19 +341,8 @@ " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -305,19 +379,8 @@ " alt.Tooltip(\"release_type\", title=\"release type\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -353,19 +416,8 @@ " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -392,19 +444,8 @@ " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )" ] diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index e691577..32c06d4 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -168,18 +168,114 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "Bip37aP917XY" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import altair as alt\n", "\n", + "\n", "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", + "\n", + "chart_properties = {\n", + " \"width\": 600,\n", + " \"height\": 350,\n", + " \"padding\": 50,\n", + " \"title\": alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + "}\n", + "chart_axis = {\n", + " \"titleFontSize\": 14,\n", + " \"labelFontSize\": 14,\n", + " \"labelPadding\": 5,\n", + " \"ticks\": False,\n", + " \"domain\": False,\n", + "}\n", + "\n", + "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", @@ -215,19 +311,8 @@ " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -256,19 +341,8 @@ " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -305,19 +379,8 @@ " alt.Tooltip(\"release_type\", title=\"release type\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -353,19 +416,8 @@ " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -392,19 +444,8 @@ " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )" ] diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index 90911c1..6515233 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -168,18 +168,114 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "Bip37aP917XY" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import altair as alt\n", "\n", + "\n", "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", + "\n", + "chart_properties = {\n", + " \"width\": 600,\n", + " \"height\": 350,\n", + " \"padding\": 50,\n", + " \"title\": alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + "}\n", + "chart_axis = {\n", + " \"titleFontSize\": 14,\n", + " \"labelFontSize\": 14,\n", + " \"labelPadding\": 5,\n", + " \"ticks\": False,\n", + " \"domain\": False,\n", + "}\n", + "\n", + "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", @@ -215,19 +311,8 @@ " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -256,19 +341,8 @@ " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -305,19 +379,8 @@ " alt.Tooltip(\"release_type\", title=\"release type\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -353,19 +416,8 @@ " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -392,19 +444,8 @@ " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )" ] diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index dd81dd3..4bee278 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -168,18 +168,114 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "Bip37aP917XY" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import altair as alt\n", "\n", + "\n", "class MissingColumnsError(Exception):\n", " def __init__(self, columns):\n", " super().__init__(f\"The source data is missing one or more of these columns: {columns}\")\n", "\n", + "\n", + "chart_properties = {\n", + " \"width\": 600,\n", + " \"height\": 350,\n", + " \"padding\": 50,\n", + " \"title\": alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", + "}\n", + "chart_axis = {\n", + " \"titleFontSize\": 14,\n", + " \"labelFontSize\": 14,\n", + " \"labelPadding\": 5,\n", + " \"ticks\": False,\n", + " \"domain\": False,\n", + "}\n", + "\n", + "\n", "def check_columns(columns, data):\n", " # check if input contains the right columns\n", " if not columns.issubset(data.columns):\n", @@ -215,19 +311,8 @@ " alt.Tooltip(\"collection_id\", title=\"collection id\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -256,19 +341,8 @@ " alt.Tooltip(\"object_count\", title=\"number of objects\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -305,19 +379,8 @@ " alt.Tooltip(\"release_type\", title=\"release type\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -353,19 +416,8 @@ " alt.Tooltip(\"key\", title=\"object type\", type=\"nominal\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )\n", "\n", @@ -392,19 +444,8 @@ " alt.Tooltip(\"total_tenders\", title=\"number of tenders\", type=\"quantitative\"),\n", " ],\n", " )\n", - " .properties(\n", - " width=600,\n", - " height=350,\n", - " padding=50,\n", - " title=alt.TitleParams(text=\"\", subtitle=[\"\"], fontSize=18),\n", - " )\n", - " .configure_axis(\n", - " titleFontSize=14,\n", - " labelFontSize=14,\n", - " labelPadding=5,\n", - " ticks=False,\n", - " domain=False,\n", - " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", " )" ] From 9f30b9b7e6cff0dd9d3437c041ff37106e64ae00 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 15:39:06 -0300 Subject: [PATCH 12/13] component_check_usability: move plot fuction to component_charts --- component_charts.ipynb | 61 ++++++++- component_check_usability.ipynb | 65 +--------- template_data_quality_feedback.ipynb | 61 ++++++++- template_publisher_analysis.ipynb | 61 ++++++++- template_structure_and_format_feedback.ipynb | 61 ++++++++- template_usability_checks.ipynb | 126 +++++++++---------- template_usability_checks_fieldlist.ipynb | 126 +++++++++---------- template_usability_checks_registry.ipynb | 126 +++++++++---------- 8 files changed, 424 insertions(+), 263 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 3b35545..5e326bc 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -45,7 +45,8 @@ "* Objects per stage\n", "* Releases by month\n", "* Objects per year\n", - "* Top buyers" + "* Top buyers\n", + "* Usability indicators" ], "metadata": { "id": "P1aenztz1zK3" @@ -248,6 +249,64 @@ " .properties(**chart_properties)\n", " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + "\n", + "def plot_usability_indicators(data, lang=\"English\"):\n", + " labels = {\n", + " \"English\": {\n", + " \"nrow\": \"row_number(indicator)\",\n", + " \"sort\": \"calculation\",\n", + " \"y_sort\": \"indicator\",\n", + " \"groupby\": \"Use case\",\n", + " \"title\": \"number of indicators\",\n", + " \"tooltip_missing\": \"Missing Fields\",\n", + " },\n", + " \"Spanish\": {\n", + " \"nrow\": \"row_number(Indicador)\",\n", + " \"sort\": \"¿Se puede calcular?\",\n", + " \"y_sort\": \"Indicador\",\n", + " \"groupby\": \"Caso de uso\",\n", + " \"title\": \"Número de indicadores\",\n", + " \"tooltip_missing\": \"Campos faltantes\",\n", + " },\n", + " }\n", + " return (\n", + " alt.Chart(data)\n", + " .transform_window(\n", + " nrow=labels[lang][\"nrow\"],\n", + " frame=[None, None],\n", + " sort=[{\"field\": labels[lang][\"sort\"]}],\n", + " groupby=[labels[lang][\"groupby\"]],\n", + " )\n", + " .mark_circle(size=250, opacity=1)\n", + " .encode(\n", + " x=alt.X(\n", + " \"nrow\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=[labels[lang][\"title\"], \"\"], orient=\"top\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " labels[lang][\"groupby\"],\n", + " type=\"nominal\",\n", + " sort=alt.Sort(field=labels[lang][\"y_sort\"], op=\"count\", order=\"descending\"),\n", + " ),\n", + " color=alt.Color(\n", + " labels[lang][\"sort\"],\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n", + " legend=alt.Legend(title=[labels[lang][\"sort\"]]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(labels[lang][\"y_sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"groupby\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"tooltip_missing\"], type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", + " .configure_view(strokeWidth=0)\n", " )" ], "metadata": { diff --git a/component_check_usability.ipynb b/component_check_usability.ipynb index 84d3162..33d1fa3 100644 --- a/component_check_usability.ipynb +++ b/component_check_usability.ipynb @@ -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" diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index f343fbf..70f6812 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -163,7 +163,8 @@ "* Objects per stage\n", "* Releases by month\n", "* Objects per year\n", - "* Top buyers" + "* Top buyers\n", + "* Usability indicators" ] }, { @@ -447,6 +448,64 @@ " .properties(**chart_properties)\n", " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + "\n", + "def plot_usability_indicators(data, lang=\"English\"):\n", + " labels = {\n", + " \"English\": {\n", + " \"nrow\": \"row_number(indicator)\",\n", + " \"sort\": \"calculation\",\n", + " \"y_sort\": \"indicator\",\n", + " \"groupby\": \"Use case\",\n", + " \"title\": \"number of indicators\",\n", + " \"tooltip_missing\": \"Missing Fields\",\n", + " },\n", + " \"Spanish\": {\n", + " \"nrow\": \"row_number(Indicador)\",\n", + " \"sort\": \"¿Se puede calcular?\",\n", + " \"y_sort\": \"Indicador\",\n", + " \"groupby\": \"Caso de uso\",\n", + " \"title\": \"Número de indicadores\",\n", + " \"tooltip_missing\": \"Campos faltantes\",\n", + " },\n", + " }\n", + " return (\n", + " alt.Chart(data)\n", + " .transform_window(\n", + " nrow=labels[lang][\"nrow\"],\n", + " frame=[None, None],\n", + " sort=[{\"field\": labels[lang][\"sort\"]}],\n", + " groupby=[labels[lang][\"groupby\"]],\n", + " )\n", + " .mark_circle(size=250, opacity=1)\n", + " .encode(\n", + " x=alt.X(\n", + " \"nrow\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=[labels[lang][\"title\"], \"\"], orient=\"top\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " labels[lang][\"groupby\"],\n", + " type=\"nominal\",\n", + " sort=alt.Sort(field=labels[lang][\"y_sort\"], op=\"count\", order=\"descending\"),\n", + " ),\n", + " color=alt.Color(\n", + " labels[lang][\"sort\"],\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n", + " legend=alt.Legend(title=[labels[lang][\"sort\"]]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(labels[lang][\"y_sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"groupby\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"tooltip_missing\"], type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", + " .configure_view(strokeWidth=0)\n", " )" ] }, diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index 377b04c..058b83e 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -163,7 +163,8 @@ "* Objects per stage\n", "* Releases by month\n", "* Objects per year\n", - "* Top buyers" + "* Top buyers\n", + "* Usability indicators" ] }, { @@ -447,6 +448,64 @@ " .properties(**chart_properties)\n", " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + "\n", + "def plot_usability_indicators(data, lang=\"English\"):\n", + " labels = {\n", + " \"English\": {\n", + " \"nrow\": \"row_number(indicator)\",\n", + " \"sort\": \"calculation\",\n", + " \"y_sort\": \"indicator\",\n", + " \"groupby\": \"Use case\",\n", + " \"title\": \"number of indicators\",\n", + " \"tooltip_missing\": \"Missing Fields\",\n", + " },\n", + " \"Spanish\": {\n", + " \"nrow\": \"row_number(Indicador)\",\n", + " \"sort\": \"¿Se puede calcular?\",\n", + " \"y_sort\": \"Indicador\",\n", + " \"groupby\": \"Caso de uso\",\n", + " \"title\": \"Número de indicadores\",\n", + " \"tooltip_missing\": \"Campos faltantes\",\n", + " },\n", + " }\n", + " return (\n", + " alt.Chart(data)\n", + " .transform_window(\n", + " nrow=labels[lang][\"nrow\"],\n", + " frame=[None, None],\n", + " sort=[{\"field\": labels[lang][\"sort\"]}],\n", + " groupby=[labels[lang][\"groupby\"]],\n", + " )\n", + " .mark_circle(size=250, opacity=1)\n", + " .encode(\n", + " x=alt.X(\n", + " \"nrow\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=[labels[lang][\"title\"], \"\"], orient=\"top\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " labels[lang][\"groupby\"],\n", + " type=\"nominal\",\n", + " sort=alt.Sort(field=labels[lang][\"y_sort\"], op=\"count\", order=\"descending\"),\n", + " ),\n", + " color=alt.Color(\n", + " labels[lang][\"sort\"],\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n", + " legend=alt.Legend(title=[labels[lang][\"sort\"]]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(labels[lang][\"y_sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"groupby\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"tooltip_missing\"], type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", + " .configure_view(strokeWidth=0)\n", " )" ] }, diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index 436ebd9..f1ff1c7 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -163,7 +163,8 @@ "* Objects per stage\n", "* Releases by month\n", "* Objects per year\n", - "* Top buyers" + "* Top buyers\n", + "* Usability indicators" ] }, { @@ -447,6 +448,64 @@ " .properties(**chart_properties)\n", " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + "\n", + "def plot_usability_indicators(data, lang=\"English\"):\n", + " labels = {\n", + " \"English\": {\n", + " \"nrow\": \"row_number(indicator)\",\n", + " \"sort\": \"calculation\",\n", + " \"y_sort\": \"indicator\",\n", + " \"groupby\": \"Use case\",\n", + " \"title\": \"number of indicators\",\n", + " \"tooltip_missing\": \"Missing Fields\",\n", + " },\n", + " \"Spanish\": {\n", + " \"nrow\": \"row_number(Indicador)\",\n", + " \"sort\": \"¿Se puede calcular?\",\n", + " \"y_sort\": \"Indicador\",\n", + " \"groupby\": \"Caso de uso\",\n", + " \"title\": \"Número de indicadores\",\n", + " \"tooltip_missing\": \"Campos faltantes\",\n", + " },\n", + " }\n", + " return (\n", + " alt.Chart(data)\n", + " .transform_window(\n", + " nrow=labels[lang][\"nrow\"],\n", + " frame=[None, None],\n", + " sort=[{\"field\": labels[lang][\"sort\"]}],\n", + " groupby=[labels[lang][\"groupby\"]],\n", + " )\n", + " .mark_circle(size=250, opacity=1)\n", + " .encode(\n", + " x=alt.X(\n", + " \"nrow\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=[labels[lang][\"title\"], \"\"], orient=\"top\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " labels[lang][\"groupby\"],\n", + " type=\"nominal\",\n", + " sort=alt.Sort(field=labels[lang][\"y_sort\"], op=\"count\", order=\"descending\"),\n", + " ),\n", + " color=alt.Color(\n", + " labels[lang][\"sort\"],\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n", + " legend=alt.Legend(title=[labels[lang][\"sort\"]]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(labels[lang][\"y_sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"groupby\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"tooltip_missing\"], type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", + " .configure_view(strokeWidth=0)\n", " )" ] }, diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index 32c06d4..a29d3ed 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -163,7 +163,8 @@ "* Objects per stage\n", "* Releases by month\n", "* Objects per year\n", - "* Top buyers" + "* Top buyers\n", + "* Usability indicators" ] }, { @@ -447,6 +448,64 @@ " .properties(**chart_properties)\n", " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + "\n", + "def plot_usability_indicators(data, lang=\"English\"):\n", + " labels = {\n", + " \"English\": {\n", + " \"nrow\": \"row_number(indicator)\",\n", + " \"sort\": \"calculation\",\n", + " \"y_sort\": \"indicator\",\n", + " \"groupby\": \"Use case\",\n", + " \"title\": \"number of indicators\",\n", + " \"tooltip_missing\": \"Missing Fields\",\n", + " },\n", + " \"Spanish\": {\n", + " \"nrow\": \"row_number(Indicador)\",\n", + " \"sort\": \"¿Se puede calcular?\",\n", + " \"y_sort\": \"Indicador\",\n", + " \"groupby\": \"Caso de uso\",\n", + " \"title\": \"Número de indicadores\",\n", + " \"tooltip_missing\": \"Campos faltantes\",\n", + " },\n", + " }\n", + " return (\n", + " alt.Chart(data)\n", + " .transform_window(\n", + " nrow=labels[lang][\"nrow\"],\n", + " frame=[None, None],\n", + " sort=[{\"field\": labels[lang][\"sort\"]}],\n", + " groupby=[labels[lang][\"groupby\"]],\n", + " )\n", + " .mark_circle(size=250, opacity=1)\n", + " .encode(\n", + " x=alt.X(\n", + " \"nrow\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=[labels[lang][\"title\"], \"\"], orient=\"top\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " labels[lang][\"groupby\"],\n", + " type=\"nominal\",\n", + " sort=alt.Sort(field=labels[lang][\"y_sort\"], op=\"count\", order=\"descending\"),\n", + " ),\n", + " color=alt.Color(\n", + " labels[lang][\"sort\"],\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n", + " legend=alt.Legend(title=[labels[lang][\"sort\"]]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(labels[lang][\"y_sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"groupby\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"tooltip_missing\"], type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", + " .configure_view(strokeWidth=0)\n", " )" ] }, @@ -1766,70 +1825,7 @@ }, "outputs": [], "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)" ] } ], diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index 6515233..722764b 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -163,7 +163,8 @@ "* Objects per stage\n", "* Releases by month\n", "* Objects per year\n", - "* Top buyers" + "* Top buyers\n", + "* Usability indicators" ] }, { @@ -447,6 +448,64 @@ " .properties(**chart_properties)\n", " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + "\n", + "def plot_usability_indicators(data, lang=\"English\"):\n", + " labels = {\n", + " \"English\": {\n", + " \"nrow\": \"row_number(indicator)\",\n", + " \"sort\": \"calculation\",\n", + " \"y_sort\": \"indicator\",\n", + " \"groupby\": \"Use case\",\n", + " \"title\": \"number of indicators\",\n", + " \"tooltip_missing\": \"Missing Fields\",\n", + " },\n", + " \"Spanish\": {\n", + " \"nrow\": \"row_number(Indicador)\",\n", + " \"sort\": \"¿Se puede calcular?\",\n", + " \"y_sort\": \"Indicador\",\n", + " \"groupby\": \"Caso de uso\",\n", + " \"title\": \"Número de indicadores\",\n", + " \"tooltip_missing\": \"Campos faltantes\",\n", + " },\n", + " }\n", + " return (\n", + " alt.Chart(data)\n", + " .transform_window(\n", + " nrow=labels[lang][\"nrow\"],\n", + " frame=[None, None],\n", + " sort=[{\"field\": labels[lang][\"sort\"]}],\n", + " groupby=[labels[lang][\"groupby\"]],\n", + " )\n", + " .mark_circle(size=250, opacity=1)\n", + " .encode(\n", + " x=alt.X(\n", + " \"nrow\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=[labels[lang][\"title\"], \"\"], orient=\"top\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " labels[lang][\"groupby\"],\n", + " type=\"nominal\",\n", + " sort=alt.Sort(field=labels[lang][\"y_sort\"], op=\"count\", order=\"descending\"),\n", + " ),\n", + " color=alt.Color(\n", + " labels[lang][\"sort\"],\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n", + " legend=alt.Legend(title=[labels[lang][\"sort\"]]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(labels[lang][\"y_sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"groupby\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"tooltip_missing\"], type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", + " .configure_view(strokeWidth=0)\n", " )" ] }, @@ -1303,70 +1362,7 @@ }, "outputs": [], "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)" ] } ], diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index 4bee278..cb1bdd3 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -163,7 +163,8 @@ "* Objects per stage\n", "* Releases by month\n", "* Objects per year\n", - "* Top buyers" + "* Top buyers\n", + "* Usability indicators" ] }, { @@ -447,6 +448,64 @@ " .properties(**chart_properties)\n", " .configure_axis(**chart_axis)\n", " .configure_view(strokeWidth=0)\n", + " )\n", + "\n", + "\n", + "def plot_usability_indicators(data, lang=\"English\"):\n", + " labels = {\n", + " \"English\": {\n", + " \"nrow\": \"row_number(indicator)\",\n", + " \"sort\": \"calculation\",\n", + " \"y_sort\": \"indicator\",\n", + " \"groupby\": \"Use case\",\n", + " \"title\": \"number of indicators\",\n", + " \"tooltip_missing\": \"Missing Fields\",\n", + " },\n", + " \"Spanish\": {\n", + " \"nrow\": \"row_number(Indicador)\",\n", + " \"sort\": \"¿Se puede calcular?\",\n", + " \"y_sort\": \"Indicador\",\n", + " \"groupby\": \"Caso de uso\",\n", + " \"title\": \"Número de indicadores\",\n", + " \"tooltip_missing\": \"Campos faltantes\",\n", + " },\n", + " }\n", + " return (\n", + " alt.Chart(data)\n", + " .transform_window(\n", + " nrow=labels[lang][\"nrow\"],\n", + " frame=[None, None],\n", + " sort=[{\"field\": labels[lang][\"sort\"]}],\n", + " groupby=[labels[lang][\"groupby\"]],\n", + " )\n", + " .mark_circle(size=250, opacity=1)\n", + " .encode(\n", + " x=alt.X(\n", + " \"nrow\",\n", + " type=\"quantitative\",\n", + " axis=alt.Axis(title=[labels[lang][\"title\"], \"\"], orient=\"top\", tickCount=5),\n", + " ),\n", + " y=alt.Y(\n", + " labels[lang][\"groupby\"],\n", + " type=\"nominal\",\n", + " sort=alt.Sort(field=labels[lang][\"y_sort\"], op=\"count\", order=\"descending\"),\n", + " ),\n", + " color=alt.Color(\n", + " labels[lang][\"sort\"],\n", + " type=\"nominal\",\n", + " scale=alt.Scale(range=[\"#fb6045\", \"#d6e100\"]),\n", + " legend=alt.Legend(title=[labels[lang][\"sort\"]]),\n", + " ),\n", + " tooltip=[\n", + " alt.Tooltip(labels[lang][\"y_sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"groupby\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"sort\"], type=\"nominal\"),\n", + " alt.Tooltip(labels[lang][\"tooltip_missing\"], type=\"nominal\"),\n", + " ],\n", + " )\n", + " .properties(**chart_properties)\n", + " .configure_axis(**chart_axis)\n", + " .configure_view(strokeWidth=0)\n", " )" ] }, @@ -1438,70 +1497,7 @@ }, "outputs": [], "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)" ] } ], From 96e4c5051a58387adf03154374b8242e9e830245 Mon Sep 17 00:00:00 2001 From: Yohanna Lisnichuk Date: Sat, 10 Feb 2024 15:55:55 -0300 Subject: [PATCH 13/13] component_charts: fix Spanish indicators chart --- component_charts.ipynb | 2 +- template_data_quality_feedback.ipynb | 2 +- template_publisher_analysis.ipynb | 2 +- template_structure_and_format_feedback.ipynb | 2 +- template_usability_checks.ipynb | 2 +- template_usability_checks_fieldlist.ipynb | 2 +- template_usability_checks_registry.ipynb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/component_charts.ipynb b/component_charts.ipynb index 5e326bc..d87477a 100644 --- a/component_charts.ipynb +++ b/component_charts.ipynb @@ -266,7 +266,7 @@ " \"nrow\": \"row_number(Indicador)\",\n", " \"sort\": \"¿Se puede calcular?\",\n", " \"y_sort\": \"Indicador\",\n", - " \"groupby\": \"Caso de uso\",\n", + " \"groupby\": \"Caso de Uso\",\n", " \"title\": \"Número de indicadores\",\n", " \"tooltip_missing\": \"Campos faltantes\",\n", " },\n", diff --git a/template_data_quality_feedback.ipynb b/template_data_quality_feedback.ipynb index 70f6812..4f348c5 100644 --- a/template_data_quality_feedback.ipynb +++ b/template_data_quality_feedback.ipynb @@ -465,7 +465,7 @@ " \"nrow\": \"row_number(Indicador)\",\n", " \"sort\": \"¿Se puede calcular?\",\n", " \"y_sort\": \"Indicador\",\n", - " \"groupby\": \"Caso de uso\",\n", + " \"groupby\": \"Caso de Uso\",\n", " \"title\": \"Número de indicadores\",\n", " \"tooltip_missing\": \"Campos faltantes\",\n", " },\n", diff --git a/template_publisher_analysis.ipynb b/template_publisher_analysis.ipynb index 058b83e..cbdb5c3 100644 --- a/template_publisher_analysis.ipynb +++ b/template_publisher_analysis.ipynb @@ -465,7 +465,7 @@ " \"nrow\": \"row_number(Indicador)\",\n", " \"sort\": \"¿Se puede calcular?\",\n", " \"y_sort\": \"Indicador\",\n", - " \"groupby\": \"Caso de uso\",\n", + " \"groupby\": \"Caso de Uso\",\n", " \"title\": \"Número de indicadores\",\n", " \"tooltip_missing\": \"Campos faltantes\",\n", " },\n", diff --git a/template_structure_and_format_feedback.ipynb b/template_structure_and_format_feedback.ipynb index f1ff1c7..97b15d5 100644 --- a/template_structure_and_format_feedback.ipynb +++ b/template_structure_and_format_feedback.ipynb @@ -465,7 +465,7 @@ " \"nrow\": \"row_number(Indicador)\",\n", " \"sort\": \"¿Se puede calcular?\",\n", " \"y_sort\": \"Indicador\",\n", - " \"groupby\": \"Caso de uso\",\n", + " \"groupby\": \"Caso de Uso\",\n", " \"title\": \"Número de indicadores\",\n", " \"tooltip_missing\": \"Campos faltantes\",\n", " },\n", diff --git a/template_usability_checks.ipynb b/template_usability_checks.ipynb index a29d3ed..c2e4191 100644 --- a/template_usability_checks.ipynb +++ b/template_usability_checks.ipynb @@ -465,7 +465,7 @@ " \"nrow\": \"row_number(Indicador)\",\n", " \"sort\": \"¿Se puede calcular?\",\n", " \"y_sort\": \"Indicador\",\n", - " \"groupby\": \"Caso de uso\",\n", + " \"groupby\": \"Caso de Uso\",\n", " \"title\": \"Número de indicadores\",\n", " \"tooltip_missing\": \"Campos faltantes\",\n", " },\n", diff --git a/template_usability_checks_fieldlist.ipynb b/template_usability_checks_fieldlist.ipynb index 722764b..e887dc9 100644 --- a/template_usability_checks_fieldlist.ipynb +++ b/template_usability_checks_fieldlist.ipynb @@ -465,7 +465,7 @@ " \"nrow\": \"row_number(Indicador)\",\n", " \"sort\": \"¿Se puede calcular?\",\n", " \"y_sort\": \"Indicador\",\n", - " \"groupby\": \"Caso de uso\",\n", + " \"groupby\": \"Caso de Uso\",\n", " \"title\": \"Número de indicadores\",\n", " \"tooltip_missing\": \"Campos faltantes\",\n", " },\n", diff --git a/template_usability_checks_registry.ipynb b/template_usability_checks_registry.ipynb index cb1bdd3..d16570e 100644 --- a/template_usability_checks_registry.ipynb +++ b/template_usability_checks_registry.ipynb @@ -465,7 +465,7 @@ " \"nrow\": \"row_number(Indicador)\",\n", " \"sort\": \"¿Se puede calcular?\",\n", " \"y_sort\": \"Indicador\",\n", - " \"groupby\": \"Caso de uso\",\n", + " \"groupby\": \"Caso de Uso\",\n", " \"title\": \"Número de indicadores\",\n", " \"tooltip_missing\": \"Campos faltantes\",\n", " },\n",