{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Analysis of Multiple Games\n", "First run `HotS replays to dataframe.ipynb` to form `hero_died_all.csv` and `building_position_all.csv`" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\compat\\_optional.py:138: UserWarning: Pandas requires version '2.7.0' or newer of 'numexpr' (version '2.6.9' currently installed).\n", " warnings.warn(msg, UserWarning)\n" ] } ], "source": [ "import pandas as pd\n", "import plotly.express as px\n", "import base64\n", "\n", "from replay_to_dataframe import *" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# import data\n", "hero_died_all = pd.read_csv(\"hero_died_all.csv\")\n", "building_position_all = pd.read_csv(\"building_position_all.csv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "-------\n", "### Calibrate points to map\n", "\n", "Mannually look at the map and the building poition of forts and spawn location " ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "map_axis_scaling_df = pd.DataFrame(columns=['map_name','xmax','ymax',\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale'])\n", "\n", "map_axis_scaling_df.loc[:,\"map_name\"] = list(set(hero_died_all.map))\n", "map_axis_scaling_df.loc[:,[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0, 1, 0, 1]\n", "\n", "for map_i in map_axis_scaling_df.index:\n", " building_position = building_position_all.loc[building_position_all.map_name == \n", " map_axis_scaling_df.loc[map_i,\"map_name\"]]\n", " \n", " # set axis max\n", " map_axis_scaling_df.loc[map_i, [\"xmax\", \"ymax\"]] = [\n", " max(building_position.x) + min(building_position.x),\n", " max(building_position.y) + min(building_position.y) \n", " ]" ] }, { "cell_type": "code", "execution_count": 309, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
map_namexmaxymaxxaxes_translatexaxes_scaleyaxes_translateyaxes_scale
0Tomb of the Spider Queen24719801.331.50.83
1Garden of Terror248216-0.51.073.50.74
2Volskaya Foundry248187-0.050.98-2.80.92
3Alterac Pass2482150.351.182857-1.51.15625
4Sky Temple247205-0.250.995.750.9
5Infernal Shrines248192-0.916.650.9
6Towers of Doom24718100.9610.91
7Dragon Shire248194-1.111.150.94
8Cursed Hollow248215-10.98-0.250.84
\n", "
" ], "text/plain": [ " map_name xmax ymax xaxes_translate xaxes_scale \\\n", "0 Tomb of the Spider Queen 247 198 0 1.33 \n", "1 Garden of Terror 248 216 -0.5 1.07 \n", "2 Volskaya Foundry 248 187 -0.05 0.98 \n", "3 Alterac Pass 248 215 0.35 1.182857 \n", "4 Sky Temple 247 205 -0.25 0.99 \n", "5 Infernal Shrines 248 192 -0.9 1 \n", "6 Towers of Doom 247 181 0 0.96 \n", "7 Dragon Shire 248 194 -1.1 1 \n", "8 Cursed Hollow 248 215 -1 0.98 \n", "\n", " yaxes_translate yaxes_scale \n", "0 1.5 0.83 \n", "1 3.5 0.74 \n", "2 -2.8 0.92 \n", "3 -1.5 1.15625 \n", "4 5.75 0.9 \n", "5 6.65 0.9 \n", "6 1 0.91 \n", "7 1.15 0.94 \n", "8 -0.25 0.84 " ] }, "execution_count": 309, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_axis_scaling_df" ] }, { "cell_type": "code", "execution_count": 310, "metadata": {}, "outputs": [], "source": [ "## manual tweek\n", "# Alterac Pass\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Alterac Pass\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0.35, 1.18, -1.5, 1.16]\n", "\n", "# Battlefield of Eternity\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Battlefield of Eternity\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0, 1, 0, 1]\n", "\n", "# Blackhearts Bay\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Blackhearts Bay\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0, 1, 0, 1]\n", "\n", "# Braxis Holdout\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Braxis Holdout\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0, 1, 0, 1]\n", "\n", "# Cursed Hollow\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Cursed Hollow\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [-1, 0.98, -0.25, 0.84]\n", "\n", "# Dragon Shire\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Dragon Shire\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [-1.1, 1, 1.15, 0.94]\n", "\n", "# Garden of Terror\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Garden of Terror\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [-0.5, 1.07, 3.5, 0.74]\n", "\n", "# Hanamura Temple\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Hanamura Temple\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0, 1, 0, 1]\n", "\n", "# Infernal Shrines\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Infernal Shrines\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [-0.9, 1, 6.65, 0.90]\n", "\n", "# Sky Temple\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Sky Temple\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [-0.25, 0.99, 5.75, 0.90]\n", "\n", "# Tomb of the Spider Queen\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Tomb of the Spider Queen\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0, 1.33, 1.5, 0.83]\n", "\n", "# Towers of Doom\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Towers of Doom\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0, 0.96, 1, 0.91]\n", "\n", "# Volskaya Foundry\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Volskaya Foundry\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [-0.05, 0.98, -2.8, 0.92]\n", "\n", "# Warhead Junction\n", "map_axis_scaling_df.loc[map_axis_scaling_df.map_name == \"Warhead Junction\",[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [0, 1, 0, 1]" ] }, { "cell_type": "code", "execution_count": 311, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "hovertemplate": "%{hovertext}

x=%{x}
y=%{y}
m_upkeepPlayerId=%{marker.color}", "hovertext": [ "TownTownHallL2", "TownTownHallL2", "TownTownHallL2", "TownTownHallL2", "TownTownHallL2", "TownTownHallL2", "HallOfStormsLocationUnit", "HallOfStormsLocationUnit" ], "legendgroup": "", "marker": { "color": [ 11, 11, 11, 12, 12, 12, 11, 12 ], "coloraxis": "coloraxis", "symbol": "circle" }, "mode": "markers", "name": "", "orientation": "v", "showlegend": false, "type": "scatter", "x": [ 92, 89, 101, 155, 158, 146, 30, 218 ], "xaxis": "x", "y": [ 107, 153, 52, 108, 62, 163, 91, 124 ], "yaxis": "y" } ], "layout": { "coloraxis": { "colorbar": { "title": { "text": "m_upkeepPlayerId" } }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "images": [ { "layer": "below", "opacity": 0.5, "sizex": 292.64, "sizey": 249.39999999999998, "sizing": "stretch", "source": "Maps/Alterac Pass.jpeg", "x": 124.35, "xanchor": "center", "xref": "x", "y": 106, "yanchor": "middle", "yref": "y" } ], "legend": { "tracegroupgap": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Map:Alterac Pass" }, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "x" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "y" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "map_i = 3\n", "\n", "# map info\n", "map_name = map_axis_scaling_df.loc[map_i,\"map_name\"]\n", "building_position = building_position_all.loc[building_position_all.map_name == map_name].copy()\n", "map_details = map_axis_scaling_df.iloc[map_i]\n", "\n", "# plot using plotly\n", "building_position.loc[:,'m_unitTypeName'] = building_position['m_unitTypeName'].astype(str)\n", "\n", "image_filename = \"Maps/\" + map_name + \".jpeg\"\n", "\n", "fig_buildings = px.scatter(\n", " building_position, # Data source\n", " x = 'x', # Horizontal axis\n", " y = 'y', # Vertical axis\n", " color = 'm_upkeepPlayerId',\n", " hover_name = 'm_unitTypeName',\n", " title = \"Map:\" + map_name)\n", "\n", "# add background\n", "fig_buildings.add_layout_image(dict(\n", " source = image_filename,\n", " xref = \"x\",\n", " yref = \"y\",\n", " x = map_details.xmax / 2 + map_details.xaxes_translate,\n", " y = map_details.ymax / 2 + map_details.yaxes_translate,\n", " xanchor = \"center\", #\"left\",\n", " yanchor = \"middle\", #\"bottom\",\n", " sizex = map_details.xmax * map_details.xaxes_scale, # length of x\n", " sizey = map_details.ymax * map_details.yaxes_scale , # length of y\n", " sizing = \"stretch\",\n", " opacity = 0.5,\n", " layer = \"below\")\n", ")\n", "\n", "fig_buildings.show()" ] }, { "cell_type": "code", "execution_count": 307, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "axis xtranslate:0.3499999999999943\n", "axis xscale:1.1828571428571428\n", "axis ytranslate:-1.5\n", "axis yscale:1.15625\n" ] } ], "source": [ "# calculator of axis resize\n", "# look for corner keeps\n", "# can iterate after looking at the updated map above\n", "\n", "keeps_position = building_position[building_position.m_unitTypeName == \"TownTownHallL2\"]\n", "\n", "# manually change these 4 values by looking at the map\n", "max_map_keep_x = 157.5\n", "max_map_keep_y = 157\n", "\n", "min_map_keep_x = 87.5\n", "min_map_keep_y = 61\n", "\n", "# don't touch\n", "# old scaling\n", "old_xtranslate = map_axis_scaling_df.loc[map_i,\"xaxes_translate\"]\n", "old_xscale = map_axis_scaling_df.loc[map_i,\"xaxes_scale\"]\n", "\n", "old_ytranslate = map_axis_scaling_df.loc[map_i,\"yaxes_translate\"]\n", "old_yscale = map_axis_scaling_df.loc[map_i,\"yaxes_scale\"]\n", "\n", "# center of map\n", "center_x = map_axis_scaling_df.loc[map_i,\"xmax\"] / 2 + old_xtranslate\n", "center_y = map_axis_scaling_df.loc[map_i,\"ymax\"] / 2 + old_ytranslate\n", "\n", "# new scaling\n", "axis_xscale = old_xscale * (max(keeps_position.x) - min(keeps_position.x)) / (max_map_keep_x - min_map_keep_x)\n", "axis_yscale = old_yscale * (max(keeps_position.y) - min(keeps_position.y)) / (max_map_keep_y - min_map_keep_y)\n", "\n", "axis_xtranslate = old_xtranslate - (max_map_keep_x + min_map_keep_x)/2 + (max(keeps_position.x) + min(keeps_position.x))/2\n", "axis_ytranslate = old_ytranslate - (max_map_keep_y + min_map_keep_y)/2 + (max(keeps_position.y) + min(keeps_position.y))/2\n", "\n", "print(\"axis xtranslate:\" + str(axis_xtranslate))\n", "print(\"axis xscale:\" + str(axis_xscale))\n", "print(\"axis ytranslate:\" + str(axis_ytranslate))\n", "print(\"axis yscale:\" + str(axis_yscale))\n", "\n", "\n", "map_axis_scaling_df.loc[map_i,[\n", " 'xaxes_translate', 'xaxes_scale',\n", " 'yaxes_translate', 'yaxes_scale']] = [axis_xtranslate, axis_xscale,\n", " axis_ytranslate, axis_yscale]" ] }, { "cell_type": "code", "execution_count": 336, "metadata": {}, "outputs": [], "source": [ "# export map_axis_scaling_df\n", "map_axis_scaling_df.to_csv(\"map_axis_scaling_df.csv\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }