From 029458c2b3db900284eecff7aec6197ab279d53f Mon Sep 17 00:00:00 2001 From: bytedream Date: Tue, 5 Nov 2024 17:16:34 +0100 Subject: [PATCH] switch last and first price positions --- plot.ipynb | 123 ++++++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 59 deletions(-) diff --git a/plot.ipynb b/plot.ipynb index e5a6017..8b57064 100644 --- a/plot.ipynb +++ b/plot.ipynb @@ -6,8 +6,8 @@ "metadata": { "collapsed": true, "ExecuteTime": { - "end_time": "2024-10-02T15:04:24.676647Z", - "start_time": "2024-10-02T15:04:24.261802Z" + "end_time": "2024-11-05T16:07:15.513969Z", + "start_time": "2024-11-05T16:07:15.067921Z" } }, "source": [ @@ -21,7 +21,12 @@ "execution_count": 1 }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-11-05T16:07:50.716467Z", + "start_time": "2024-11-05T16:07:15.529909Z" + } + }, "cell_type": "code", "source": [ "sqlite_file = input(\"Sqlite file: \")\n", @@ -29,7 +34,7 @@ ], "id": "2a888e85f7940c39", "outputs": [], - "execution_count": null + "execution_count": 2 }, { "metadata": {}, @@ -77,46 +82,11 @@ { "metadata": { "ExecuteTime": { - "end_time": "2024-10-02T17:15:27.885991Z", - "start_time": "2024-10-02T17:15:27.304499Z" + "end_time": "2024-11-05T16:15:04.396443Z", + "start_time": "2024-11-05T16:15:04.040184Z" } }, "cell_type": "code", - "source": [ - "query = '''\n", - "SELECT timestamp, price, filament_variant_id, region\n", - " FROM prices\n", - " LEFT JOIN measurements ON prices.measurement_id = measurements.id\n", - " LEFT JOIN filament_variants ON prices.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", - "# average price changes\n", - "fig = go.Figure()\n", - "for region in list(df['region'].dropna().unique()):\n", - " changed = 0\n", - " unchanged = 0\n", - " price_changes = []\n", - " \n", - " for _, rows in df.query(f'(price > 0) and (region == \"{region}\")').groupby('filament_variant_id'):\n", - " if len(rows) == 1:\n", - " unchanged += 1\n", - " continue\n", - " else:\n", - " changed += 1\n", - " \n", - " first_price = rows.iloc[0].iloc[1]\n", - " last_price = rows.iloc[-1].iloc[1]\n", - " \n", - " price_changes.append((last_price - first_price) / first_price * 100)\n", - " \n", - " price_changes_percent = sum(price_changes) / len(price_changes)\n", - " fig.add_trace(go.Bar(name=region, text=f'{price_changes_percent:.2f}%', x=[region], y=[price_changes_percent]))\n", - "fig.update_layout(title='Average price changes', xaxis_title='Region', yaxis_title='Average price change in %', yaxis_range=[-100, 100])\n", - "fig.show()" - ], - "id": "820c18682316ff52", "outputs": [ { "data": { @@ -124,78 +94,78 @@ "data": [ { "name": "global", - "text": "-18.46%", + "text": "22.88%", "x": [ "global" ], "y": [ - -18.458616872672106 + 22.883728044845427 ], "type": "bar" }, { "name": "us", - "text": "-8.48%", + "text": "11.00%", "x": [ "us" ], "y": [ - -8.480182725236773 + 10.997112892532591 ], "type": "bar" }, { "name": "eu", - "text": "-13.49%", + "text": "18.65%", "x": [ "eu" ], "y": [ - -13.485178053111488 + 18.65437220343727 ], "type": "bar" }, { "name": "uk", - "text": "-15.14%", + "text": "19.59%", "x": [ "uk" ], "y": [ - -15.144255958319178 + 19.591141813187818 ], "type": "bar" }, { "name": "au", - "text": "-15.87%", + "text": "19.66%", "x": [ "au" ], "y": [ - -15.872951435144182 + 19.65659002293262 ], "type": "bar" }, { "name": "ca", - "text": "-13.73%", + "text": "17.50%", "x": [ "ca" ], "y": [ - -13.726501965955093 + 17.503974848392822 ], "type": "bar" }, { "name": "jp", - "text": "-20.16%", + "text": "24.41%", "x": [ "jp" ], "y": [ - -20.155943058563096 + 24.405606489166075 ], "type": "bar" } @@ -1031,7 +1001,7 @@ "text": "Average price change in %" }, "range": [ - -100, + 0, 100 ] }, @@ -1049,9 +1019,9 @@ } }, "text/html": [ - "