Skip to content

Commit eb4fed2

Browse files
authored
Merge pull request #153 from airtai/dev
2 PRs
2 parents f3b7ef9 + 2233b80 commit eb4fed2

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

google_sheets/data_processing/processing.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,23 @@ def _replace_values(
177177
return new_row
178178

179179

180+
def _replace_headline_values(new_row: pd.Series, station: Dict[str, Any]) -> pd.Series:
181+
# Filter columns that start with "Headline"
182+
headline_columns = [col for col in new_row.index if col.startswith("Headline")]
183+
184+
# Perform replacements only in the headline columns
185+
for col in headline_columns:
186+
new_row[col] = (
187+
new_row[col]
188+
.replace(INSERT_STATION_FROM, station["Station From"])
189+
.replace(INSERT_STATION_TO, station["Station To"])
190+
)
191+
return new_row
192+
193+
194+
USE_ORIGINAL_STATION_FROM = ["Transfer", "Taxi"]
195+
196+
180197
def _process_row(
181198
new_campaign_row: pd.Series,
182199
template_row: pd.Series,
@@ -214,6 +231,10 @@ def _process_row(
214231
language_code=new_row["Language Code"],
215232
include_locations=include_locations,
216233
)
234+
if new_row["Category"] in USE_ORIGINAL_STATION_FROM:
235+
# Use the original Station From in headlines for both directions
236+
new_row = _replace_headline_values(new_row, stations[0])
237+
217238
new_row = _replace_values(new_campaign_row, new_row, station)
218239

219240
if target_resource == "ad":

tests/data_processing/test_processing.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
_copy_all_with_prefixes,
88
_get_target_location,
99
_process_row,
10+
_replace_headline_values,
1011
_replace_values,
1112
_update_campaign_name,
1213
_validate_language_codes,
@@ -58,13 +59,39 @@ def test_validate_input_data(df: pd.DataFrame, expected: str) -> None:
5859
assert validate_input_data(df, mandatory_columns, "name") == expected
5960

6061

62+
def test_replace_headline_values() -> None:
63+
row = pd.Series(
64+
{
65+
"Name": "{INSERT_STATION_FROM}",
66+
"Headline 1": "{INSERT_STATION_FROM} - {INSERT_STATION_TO}",
67+
"Headline 2": "{INSERT_STATION_FROM}",
68+
}
69+
)
70+
station = {
71+
"Station From": "A",
72+
"Station To": "B",
73+
}
74+
75+
row = _replace_headline_values(row, station)
76+
expected_row = pd.Series(
77+
{
78+
"Name": "{INSERT_STATION_FROM}",
79+
"Headline 1": "A - B",
80+
"Headline 2": "A",
81+
}
82+
)
83+
84+
assert row.equals(expected_row)
85+
86+
6187
@pytest.mark.parametrize(
6288
("category", "expected_length"),
6389
[
6490
(
6591
"Bus",
6692
1,
6793
),
94+
("Transfer", 1),
6895
],
6996
)
7097
def test_process_row(
@@ -82,10 +109,10 @@ def test_process_row(
82109
"Level": "",
83110
"Keyword Match Type": "Exact",
84111
"Match Type": "Exact",
85-
"Category": "Bus",
112+
"Category": category,
86113
"Target Category": "False",
87-
"Ad Group Category": "Bus",
88-
"Real Category": "Bus",
114+
"Ad Group Category": category,
115+
"Real Category": category,
89116
}
90117
)
91118
new_campaign_row = pd.Series(

0 commit comments

Comments
 (0)