mirror of
https://github.com/bytedream/bambulab-store-tracker.git
synced 2025-12-15 18:30:44 +01:00
98 lines
3.2 KiB
Plaintext
98 lines
3.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "initial_id",
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from datetime import datetime\n",
|
|
"import sqlite3\n",
|
|
"\n",
|
|
"import plotly.graph_objects as go\n",
|
|
"import pandas as pd"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"sqlite_file = input(\"Sqlite file: \")\n",
|
|
"conn = sqlite3.connect(sqlite_file)"
|
|
],
|
|
"id": "f012f6430726f03c"
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"query = '''\n",
|
|
"SELECT timestamp, filament_variant_id, available, region\n",
|
|
" FROM availability\n",
|
|
" LEFT JOIN measurements ON availability.measurement_id = measurements.id\n",
|
|
" LEFT JOIN filament_variants ON availability.filament_variant_id = filament_variants.id\n",
|
|
" LEFT JOIN filaments ON filament_variants.filament_id = filaments.id\n",
|
|
"'''\n",
|
|
"df = pd.read_sql(query, conn)\n",
|
|
"\n",
|
|
"all_timestamps = list(df['timestamp'].unique())\n",
|
|
"all_regions = list(df['region'].unique())\n",
|
|
"# idk why there is a None in the dataset. when I manually review it there is no None region\n",
|
|
"all_regions.remove(None)\n",
|
|
"\n",
|
|
"available = {region: [] for region in all_regions}\n",
|
|
"not_available = {region: [] for region in all_regions}\n",
|
|
"\n",
|
|
"for timestamp in all_timestamps:\n",
|
|
" values = df.query(f'timestamp <= {timestamp}').drop(columns=['timestamp']).drop_duplicates(keep='last', subset=['filament_variant_id', 'region'])\n",
|
|
" \n",
|
|
" for region in all_regions:\n",
|
|
" available[region].append(len(values.query(f'(available == 1) and (region == \"{region}\")')))\n",
|
|
" not_available[region].append(len(values.query(f'(available == 0) and (region == \"{region}\")')))\n",
|
|
"\n",
|
|
"fig = go.Figure()\n",
|
|
"for region in all_regions:\n",
|
|
" timestamp_datetime = [datetime.fromtimestamp(timestamp) for timestamp in all_timestamps]\n",
|
|
" ratios = []\n",
|
|
" ratio_texts = []\n",
|
|
" for i in range(len(available[region])):\n",
|
|
" ratios.append(round((available[region][i] / (available[region][i] + not_available[region][i])) * 100, 2))\n",
|
|
" ratio_texts.append(f'({available[region][i]} / {available[region][i] + not_available[region][i]})')\n",
|
|
" \n",
|
|
" fig.add_trace(go.Scatter(x=timestamp_datetime, y=ratios, text=ratio_texts, mode='lines', name=region.upper()))\n",
|
|
"fig.update_layout(title='Availability', xaxis_title='Time', yaxis_title='Availability in %', yaxis_range=[0, 100], yaxis_ticksuffix = '%', hovermode='x unified')\n",
|
|
"fig.show()"
|
|
],
|
|
"id": "28dd4fe644bc6a1d",
|
|
"outputs": [],
|
|
"execution_count": null
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|