Adding coordinates and distance to ADCE
Browse files- queries/process_neighbors.py +34 -5
queries/process_neighbors.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import pandas as pd
|
|
|
|
| 2 |
|
|
|
|
| 3 |
from utils.convert_to_excel import convert_dfs, save_dataframe
|
| 4 |
from utils.utils_vars import UtilsVars
|
| 5 |
|
|
@@ -16,10 +18,14 @@ ADJS_INITIAL_COLUMNS = [
|
|
| 16 |
BTS_SOURCE = [
|
| 17 |
"ID_BTS",
|
| 18 |
"name",
|
|
|
|
|
|
|
| 19 |
]
|
| 20 |
BTS_TARGET = [
|
| 21 |
"lac_id",
|
| 22 |
"name",
|
|
|
|
|
|
|
| 23 |
]
|
| 24 |
|
| 25 |
WCEL_SOURCE = [
|
|
@@ -88,11 +94,12 @@ def process_neighbors_data(file_path: str):
|
|
| 88 |
df_adce = df_adce[ADCE_INITIAL_COLUMNS]
|
| 89 |
|
| 90 |
# Process BTS data
|
| 91 |
-
df_bts =
|
| 92 |
-
df_bts.columns = df_bts.columns.str.replace(r"[ ]", "", regex=True)
|
| 93 |
-
df_bts["ID_BTS"] = df_bts[["BSC", "BCF", "BTS"]].astype(str).apply("_".join, axis=1)
|
| 94 |
df_bts["lac_id"] = (
|
| 95 |
-
df_bts[["locationAreaIdLAC", "cellId"]]
|
|
|
|
|
|
|
|
|
|
| 96 |
)
|
| 97 |
|
| 98 |
df_bts_source = df_bts[BTS_SOURCE]
|
|
@@ -103,14 +110,36 @@ def process_neighbors_data(file_path: str):
|
|
| 103 |
|
| 104 |
# #create final adce
|
| 105 |
df_adce_final = pd.merge(df_adce, df_bts_source, on="ID_BTS", how="left")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
df_adce_final = pd.merge(
|
| 107 |
df_adce_final, df_bts_target, on="lac_id", how="left"
|
| 108 |
).dropna()
|
| 109 |
df_adce_final.rename(
|
| 110 |
-
columns={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
)
|
| 112 |
df_adce_final = check_symmetry(df_adce_final)
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
# process ADJS data
|
| 115 |
df_adjs = dfs["ADJS"]
|
| 116 |
df_adjs.columns = df_adjs.columns.str.replace(r"[ ]", "", regex=True)
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
from geopy.distance import geodesic
|
| 3 |
|
| 4 |
+
from queries.process_gsm import process_gsm_data
|
| 5 |
from utils.convert_to_excel import convert_dfs, save_dataframe
|
| 6 |
from utils.utils_vars import UtilsVars
|
| 7 |
|
|
|
|
| 18 |
BTS_SOURCE = [
|
| 19 |
"ID_BTS",
|
| 20 |
"name",
|
| 21 |
+
"Longitude",
|
| 22 |
+
"Latitude",
|
| 23 |
]
|
| 24 |
BTS_TARGET = [
|
| 25 |
"lac_id",
|
| 26 |
"name",
|
| 27 |
+
"Longitude",
|
| 28 |
+
"Latitude",
|
| 29 |
]
|
| 30 |
|
| 31 |
WCEL_SOURCE = [
|
|
|
|
| 94 |
df_adce = df_adce[ADCE_INITIAL_COLUMNS]
|
| 95 |
|
| 96 |
# Process BTS data
|
| 97 |
+
df_bts = process_gsm_data(file_path)
|
|
|
|
|
|
|
| 98 |
df_bts["lac_id"] = (
|
| 99 |
+
df_bts[["locationAreaIdLAC", "cellId"]]
|
| 100 |
+
.astype(str)
|
| 101 |
+
.apply("_".join, axis=1)
|
| 102 |
+
.str.replace(".0", "")
|
| 103 |
)
|
| 104 |
|
| 105 |
df_bts_source = df_bts[BTS_SOURCE]
|
|
|
|
| 110 |
|
| 111 |
# #create final adce
|
| 112 |
df_adce_final = pd.merge(df_adce, df_bts_source, on="ID_BTS", how="left")
|
| 113 |
+
|
| 114 |
+
# Rename SOURCELongitude and Latitude columns
|
| 115 |
+
df_adce_final.rename(
|
| 116 |
+
columns={"Longitude": "SOURCE_Longitude", "Latitude": "SOURCE_Latitude"},
|
| 117 |
+
inplace=True,
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
df_adce_final = pd.merge(
|
| 121 |
df_adce_final, df_bts_target, on="lac_id", how="left"
|
| 122 |
).dropna()
|
| 123 |
df_adce_final.rename(
|
| 124 |
+
columns={
|
| 125 |
+
"ID_BTS": "SOURCE_ID",
|
| 126 |
+
"lac_id": "TARGET_LAC_ID",
|
| 127 |
+
"Longitude": "TARGET_Longitude",
|
| 128 |
+
"Latitude": "TARGET_Latitude",
|
| 129 |
+
},
|
| 130 |
+
inplace=True,
|
| 131 |
)
|
| 132 |
df_adce_final = check_symmetry(df_adce_final)
|
| 133 |
|
| 134 |
+
# create distance column
|
| 135 |
+
df_adce_final["distance"] = df_adce_final.apply(
|
| 136 |
+
lambda row: geodesic(
|
| 137 |
+
(row["SOURCE_Latitude"], row["SOURCE_Longitude"]),
|
| 138 |
+
(row["TARGET_Latitude"], row["TARGET_Longitude"]),
|
| 139 |
+
).kilometers,
|
| 140 |
+
axis=1,
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
# process ADJS data
|
| 144 |
df_adjs = dfs["ADJS"]
|
| 145 |
df_adjs.columns = df_adjs.columns.str.replace(r"[ ]", "", regex=True)
|