Skip to content

Commit

Permalink
added weekdays plot
Browse files Browse the repository at this point in the history
  • Loading branch information
cehbrecht committed Aug 2, 2024
1 parent c34eeb9 commit 6795dfd
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 112 deletions.
138 changes: 29 additions & 109 deletions notebooks/dashboard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "59109053-8451-421a-930c-534bfe75e2f8",
"metadata": {},
"outputs": [],
Expand All @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "7384ef24-299e-42c9-8a7a-fc990a02ce14",
"metadata": {},
"outputs": [],
Expand All @@ -22,142 +22,62 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "1cd42832-c7fe-405a-b927-663d996fddff",
"metadata": {},
"outputs": [],
"source": [
"dash.load(\n",
" \"http://rook3.cloud.dkrz.de:80/outputs/rook/34369610-d351-11eb-8f86-fa163e466023/wps_requests.csv\",\n",
" \"http://rook8.cloud.dkrz.de:80/outputs/rook/ba7a8b60-50b6-11ef-a299-fa163e934c9b/wps_requests.csv\",\n",
" filter=\"orchestrate\",\n",
" )\n",
"\n",
"dash.load_downloads(\n",
" \"http://rook3.cloud.dkrz.de:80/outputs/rook/34369610-d351-11eb-8f86-fa163e466023/downloads.csv\",\n",
" \"http://rook8.cloud.dkrz.de:80/outputs/rook/ba7a8b60-50b6-11ef-a299-fa163e934c9b/downloads.csv\",\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "9fc29c58-067b-409b-b047-1c7ae1e5d3c8",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/pingu/Documents/GitHub/roocs/rook/rook/dashboard/tables/overview.py:32: FutureWarning: The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n",
" tdf = self.df_downloads.groupby(pd.Grouper(key=\"datetime\", freq=\"1D\")).sum()\n"
]
},
{
"data": {
"text/plain": [
"'/tmp/dashboard.html'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dash.write()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3175d999-2052-4741-b19d-3ec371e0713c",
"metadata": {},
"outputs": [],
"source": [
"import IPython\n",
"IPython.display.HTML(\"/tmp/dashboard.html\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80388a16-d341-416b-8b9c-940fb0cd77e9",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78d6ebd9-6717-4f9f-a608-f7fec855bac1",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from io import StringIO\n",
"ghc_url = \"https://geohealthcheck.cloud.dkrz.de/resource/45/history/csv\"\n",
"req = requests.get(ghc_url, verify=False)\n",
"df_ghc = pd.read_csv(StringIO(req.text), parse_dates=['checked_datetime'])\n",
"df_ghc"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dbb74983-ba8e-41c6-8224-3a28f01a0b8f",
"metadata": {},
"outputs": [],
"source": [
"df_ghc[\"down\"] = df_ghc.status.apply(lambda x: 1 if x=='False' else 0)\n",
"gdf = df_ghc.groupby(pd.Grouper(key=\"checked_datetime\", freq=\"1D\"))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c229d50b-c852-4db5-a9d0-e5455a5680df",
"metadata": {},
"outputs": [],
"source": [
"df = gdf.sum()\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "98058ba3-8ead-4618-bceb-1c62d62a2fea",
"metadata": {},
"outputs": [],
"source": [
"from bokeh.plotting import figure, show\n",
"from bokeh.models import ColumnDataSource"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "90d07d4c-9534-461a-89a7-91e6bfa2584f",
"metadata": {},
"outputs": [],
"source": [
"plot = figure(\n",
" title=\"Up\",\n",
" tools=\"\",\n",
" toolbar_location=None,\n",
" # x_axis_label=\"Date\",\n",
" x_axis_type=\"datetime\",\n",
" # y_axis_label=\"Requests per day\",\n",
" sizing_mode=\"scale_width\",\n",
" plot_height=100,\n",
" )\n",
"plot.line(x=\"checked_datetime\", y=\"down\", source=ColumnDataSource(df), color=\"green\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aaf0dab6-97a2-4065-83ba-8cf3040607ad",
"metadata": {},
"outputs": [],
"source": [
"show(plot)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "15846309-44f1-407d-ab45-9df83b803486",
"id": "51ed711f-cd44-4597-8320-3cb99fb287f2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -171,7 +91,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions rook/dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import humanize
import bokeh

from .plots import ActivityPlot, DurationPlot, ConcurrencyPlot, PulsePlot
from .plots import ActivityPlot, DurationPlot, ConcurrencyPlot, DayPlot
from .plots import DownloadsPlot, TransferPlot
from .tables import OverviewTable, MessageTable

Expand Down Expand Up @@ -56,7 +56,7 @@ def render(self):
script_p1, plot_1 = ActivityPlot(self.df).components()
script_p2, plot_2 = ConcurrencyPlot(self.df).components()
script_p3, plot_3 = DurationPlot(self.df).components()
script_p4, plot_4 = PulsePlot(self.df).components()
script_p4, plot_4 = DayPlot(self.df).components()
script_p5, plot_5 = DownloadsPlot(self.df_downloads).components()
script_p6, plot_6 = TransferPlot(self.df_downloads).components()
script_t1, table_1 = OverviewTable(self.df, self.df_downloads).components()
Expand Down
2 changes: 1 addition & 1 deletion rook/dashboard/plots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .activity import ActivityPlot
from .duration import DurationPlot
from .concurrency import ConcurrencyPlot
from .pulse import PulsePlot
from .day import DayPlot
from .downloads import DownloadsPlot
from .transfer import TransferPlot
48 changes: 48 additions & 0 deletions rook/dashboard/plots/day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pandas as pd
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource

from .base import PlotView

DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]


class DayPlot(PlotView):
def data(self):
pdf = pd.DataFrame()
pdf["day"] = self.df["time_start"].dt.dayofweek
pdf["day"] = pdf["day"].apply(lambda x: DAYS[x])
# pdf["time"] = self.df["time_start"].dt.time

day_counts = pdf["day"].value_counts().sort_index()
# total_count = day_counts.sum()
# day_percentages = (day_counts / total_count) * 100
data_ = dict(days=day_counts.index, counts=day_counts.values)
return data_

def plot(self):
plot = figure(
title="Requests per weekday",
tools="",
toolbar_location=None,
x_range=DAYS,
# x_axis_type="datetime",
# sizing_mode="scale_width",
plot_height=300,
)
plot.vbar(
x="days",
top="counts",
source=ColumnDataSource(self.data()),
width=0.9,
color="blue",
alpha=0.5,
)
plot.y_range.start = 0
# plot.x_range.range_padding = 0.1
plot.xgrid.grid_line_color = None
plot.axis.minor_tick_line_color = None
plot.outline_line_color = None
# plot.legend.location = "top_left"
# plot.legend.orientation = "horizontal"
return plot

0 comments on commit 6795dfd

Please sign in to comment.