{ "cells": [ { "cell_type": "markdown", "id": "8364c581", "metadata": {}, "source": [ "# Lets-Plot in 2021" ] }, { "cell_type": "markdown", "id": "18b0b501", "metadata": {}, "source": [ "## Preparation" ] }, { "cell_type": "code", "execution_count": 1, "id": "15092fb8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *\n", "from lets_plot.mapping import as_discrete\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "bfe2a766", "metadata": {}, "outputs": [], "source": [ "WINTER_PALETTE = {\n", " 'cold': ['#ffffff', '#97b7d8', '#4177a1', '#172540'],\n", " 'warm': ['#fdd0a2', '#fdae6b', '#f16913', '#d94801'],\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "id": "7a7093c2", "metadata": {}, "outputs": [], "source": [ "def winter_theme(tiles=False):\n", " winter_line_light = element_line(color=WINTER_PALETTE['cold'][1])\n", " winter_line_dark = element_line(color=WINTER_PALETTE['cold'][3])\n", " winter_text = element_text(color=WINTER_PALETTE['cold'][3])\n", " return theme_none() + theme(\n", " axis_line_x=(winter_line_dark if not tiles else 'blank'),\n", " axis_line_y='blank',\n", " axis_ticks=winter_line_light,\n", " axis_text=winter_text,\n", " axis_title=winter_text,\n", " line=winter_line_light,\n", " rect=element_rect(color=WINTER_PALETTE['cold'][1], fill=WINTER_PALETTE['cold'][0]),\n", " panel_background=(None if not tiles else 'blank'),\n", " text=winter_text,\n", " panel_grid=(winter_line_light if not tiles else 'blank'),\n", " panel_grid_minor='blank',\n", " axis_tooltip=element_rect(color=WINTER_PALETTE['cold'][0], fill=WINTER_PALETTE['cold'][3])\n", " )" ] }, { "cell_type": "code", "execution_count": 4, "id": "0d0290e0", "metadata": {}, "outputs": [], "source": [ "def style_getter(d):\n", " def style(keys=None):\n", " if not keys:\n", " return d\n", " if type(keys) is list:\n", " return {k: v for k, v in d.items() if k in keys}\n", " else:\n", " return d[keys] if keys in d.keys() else d\n", " return style\n", "\n", "def geom_style(keys=None, is_point=False):\n", " style = {\n", " 'color': WINTER_PALETTE['warm'][2],\n", " 'fill': WINTER_PALETTE['warm'][1],\n", " 'outlier_color': WINTER_PALETTE['warm'][2],\n", " 'outlier_fill': WINTER_PALETTE['warm'][1],\n", " 'shape': 21,\n", " 'size': 3 if is_point else 1,\n", " 'outlier_shape': 21,\n", " 'outlier_size': 3,\n", " }\n", " return style_getter(style)(keys)\n", "\n", "def scale_continuous_style(keys=None):\n", " return style_getter({\n", " 'low': WINTER_PALETTE['warm'][0],\n", " 'high': WINTER_PALETTE['warm'][3],\n", " })(keys)" ] }, { "cell_type": "code", "execution_count": 5, "id": "1356f913", "metadata": {}, "outputs": [], "source": [ "def plot_size(size_type=None):\n", " if size_type == 'big':\n", " return ggsize(720, 540)\n", " return ggsize(600, 450)" ] }, { "cell_type": "code", "execution_count": 6, "id": "6d67d35e", "metadata": {}, "outputs": [], "source": [ "def get_data(path_to_csv):\n", " from datetime import datetime\n", "\n", " EXTENSIONS_TOP_SIZE = 3\n", "\n", " df = pd.read_csv(path_to_csv)\n", " df = df[df.extension.isin(df.extension.value_counts().iloc[:EXTENSIONS_TOP_SIZE].index)]\n", " df.creation_date = pd.to_datetime(df.creation_date)\n", " df.modification_date = pd.to_datetime(df.modification_date)\n", " df = df[df.creation_date >= datetime(2021, 1, 1)]\n", "\n", " return df.reset_index(drop=True)" ] }, { "cell_type": "code", "execution_count": 7, "id": "7bdbb5ac", "metadata": {}, "outputs": [], "source": [ "def dt_breaks(df, dt_column, breaks_count=5):\n", " import numpy as np\n", "\n", " return pd.to_datetime(np.linspace(\n", " df[dt_column].min().value,\n", " df[dt_column].max().value,\n", " breaks_count\n", " )).round('1s').to_list()" ] }, { "cell_type": "code", "execution_count": 8, "id": "fdd4102f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(389, 12)\n" ] }, { "data": { "text/html": [ "
\n", " | filename | \n", "directory | \n", "extension | \n", "lines_count | \n", "words_count | \n", "symbols_count | \n", "commits_count | \n", "authors_count | \n", "creation_date | \n", "creation_author | \n", "modification_date | \n", "modification_author | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "DomEventMapper | \n", "base/src/jsMain/kotlin/jetbrains/datalore/base... | \n", "kt | \n", "110 | \n", "330 | \n", "4011 | \n", "1 | \n", "1 | \n", "2021-09-28 22:47:31 | \n", "I. Kupriyanov | \n", "2021-09-28 22:47:31 | \n", "I. Kupriyanov | \n", "
1 | \n", "DateTimeFormat | \n", "base-portable/src/commonMain/kotlin/jetbrains/... | \n", "kt | \n", "130 | \n", "443 | \n", "5221 | \n", "3 | \n", "1 | \n", "2021-08-18 00:34:33 | \n", "O. Larionova | \n", "2021-11-25 13:06:51 | \n", "O. Larionova | \n", "
2 | \n", "EventHandlerExt | \n", "base-portable/src/commonMain/kotlin/jetbrains/... | \n", "kt | \n", "15 | \n", "51 | \n", "431 | \n", "1 | \n", "1 | \n", "2021-09-27 22:29:05 | \n", "I. Kupriyanov | \n", "2021-09-27 22:29:05 | \n", "I. Kupriyanov | \n", "
3 | \n", "AdaptiveResampling | \n", "base-portable/src/commonMain/kotlin/jetbrains/... | \n", "kt | \n", "83 | \n", "276 | \n", "2381 | \n", "1 | \n", "1 | \n", "2021-08-23 14:01:25 | \n", "I. Kupriyanov | \n", "2021-08-23 14:01:25 | \n", "I. Kupriyanov | \n", "
4 | \n", "Transforms | \n", "base-portable/src/commonMain/kotlin/jetbrains/... | \n", "kt | \n", "107 | \n", "320 | \n", "3611 | \n", "1 | \n", "1 | \n", "2021-08-23 14:01:25 | \n", "I. Kupriyanov | \n", "2021-08-23 14:01:25 | \n", "I. Kupriyanov | \n", "