Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update templates #53

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions google_sheets/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ async def get_all_sheet_titles(

MANDATORY_KEYWORD_TEMPLATE_COLUMNS = [
"Keyword",
"Keyword Match Type",
"Level",
"Negative",
]


Expand Down
26 changes: 23 additions & 3 deletions google_sheets/data_processing/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,24 @@ def process_data_f(

if target_resource == "ad":
new_row["Final URL"] = station["Final Url"]
elif (
target_resource == "keyword"
and new_row["Negative"]
and new_row["Negative"].lower() == "true"
):
new_row["Match Type"] = new_row["Keyword Match Type"]

if new_row["Level"] == "Campaign":
new_row["Ad Group Name"] = None

final_df = pd.concat(
[final_df, pd.DataFrame([new_row])], ignore_index=True
)

if target_resource == "keyword":
final_df = final_df.drop(columns=["Keyword Match Type"])
final_df = final_df.drop_duplicates(ignore_index=True)

final_df = final_df.sort_values(
by=["Campaign Name", "Ad Group Name"], ignore_index=True
)
Expand All @@ -99,6 +112,8 @@ def process_data_f(
MAX_HEADLINE_LENGTH = 30
MAX_DESCRIPTION_LENGTH = 90

MAX_PATH_LENGTH = 15


def _validate_output_data_ad(df: pd.DataFrame) -> pd.DataFrame: # noqa: C901
df["Issues"] = ""
Expand Down Expand Up @@ -152,9 +167,14 @@ def _validate_output_data_ad(df: pd.DataFrame) -> pd.DataFrame: # noqa: C901
f"Description length should be less than {MAX_DESCRIPTION_LENGTH} characters, found {len(description)} in column {description_column}.\n"
)

# TODO: Check for the final URL
# if not row["Final URL"]:
# df.loc[index, "Issues"] += "Final URL is missing.\n"
for path in ["Path 1", "Path 2"]:
if row[path] and len(row[path]) > MAX_PATH_LENGTH:
df.loc[index, "Issues"] += (
f"{path} length should be less than {MAX_PATH_LENGTH} characters, found {len(row[path])}.\n"
)

if not row["Final URL"]:
df.loc[index, "Issues"] += "Final URL is missing.\n"

if not df["Issues"].any():
df = df.drop(columns=["Issues"])
Expand Down
20 changes: 19 additions & 1 deletion tests/app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,12 @@ class TestProcessData:
values=[
[
"Keyword",
"Keyword Match Type",
"Level",
"Negative",
],
["Keyword A"],
["Keyword A", "Exact", None, "False"],
["Keyword N", "Broad", "Campaign", "True"],
]
),
GoogleSheetValues(
Expand Down Expand Up @@ -257,18 +261,32 @@ class TestProcessData:
"Ad Group Name",
"Match Type",
"Keyword",
"Level",
"Negative",
],
[
"India - Delhi - Mumbai",
"Delhi - Mumbai",
"Exact",
"Keyword A",
None,
"False",
],
[
"India - Delhi - Mumbai",
"Mumbai - Delhi",
"Exact",
"Keyword A",
None,
"False",
],
[
"India - Delhi - Mumbai",
None,
"Broad",
"Keyword N",
"Campaign",
"True",
],
],
),
Expand Down
3 changes: 3 additions & 0 deletions tests/data_processing/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ def test_validate_output_data(issues_column: Optional[List[str]]) -> None:
"Headline 3": ["H3", "H3", "H3", ""],
"Description 1": ["D1", "D1", "D2", "D3"],
"Description 2": ["D1", "D1", "D3", ""],
"Path 1": ["P1", "P1", "P1", "P1"],
"Path 2": ["P2", "P2", "P2", "P2"],
"Final URL": ["URL", "URL", "URL", "URL"],
}
)
result = validate_output_data(df, "ad")
Expand Down
Loading