Skip to content

Commit

Permalink
Adding two new mediums
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-moore-97 committed Apr 5, 2024
1 parent 6b21a9d commit b5813af
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
34 changes: 33 additions & 1 deletion gdrive/idva/flow_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ def preprocess_report(df: pd.DataFrame) -> pd.DataFrame:
"twitter",
"linked.com",
"lnkd.in",
"pllpl",
"ffg",
]
tracked_mediums = ["fb", "cl", "rd", "tx", "ln"]
tracked_mediums = ["fb", "cl", "rd", "tx", "ln", "pllpl", "ffg"]

for event in tracked_events:
tracked_df = df[df[0] == event]
Expand Down Expand Up @@ -134,6 +136,8 @@ def create_pivot_tables(df: pd.DataFrame, names_to_id: dict, sheets_id: str):
twitter_x_pivot(sheets_id, names_to_id, col_dict)
linkedin_pivot(sheets_id, names_to_id, col_dict)
linked_pivot(sheets_id, names_to_id, col_dict)
pllpl_pivot(sheets_id, names_to_id, col_dict)
ffg_pivot(sheets_id, names_to_id, col_dict)

sheets_client.add_pivot_tables(
sheets_id, names_to_id[SheetsEnum.GSA.value], idva.clicks(col_dict)
Expand Down Expand Up @@ -425,6 +429,34 @@ def linked_pivot(sheets_id, names_to_id, col_dict):
)


def pllpl_pivot(sheets_id, names_to_id, col_dict):
sheets_client.update_cell_value(
sheets_id, SheetsEnum.REKREWT.value, "A23", "PLLPL"
) # Pivot table Label

sheets_client.add_pivot_tables(
sheets_id,
names_to_id[SheetsEnum.REKREWT.value],
idva.pllpl(col_dict),
row_idx=23,
col_idx=0,
)


def ffg_pivot(sheets_id, names_to_id, col_dict):
sheets_client.update_cell_value(
sheets_id, SheetsEnum.REKREWT.value, "A35", "FFG"
) # Pivot table Label

sheets_client.add_pivot_tables(
sheets_id,
names_to_id[SheetsEnum.REKREWT.value],
idva.ffg(col_dict),
row_idx=35,
col_idx=0,
)


def generate_filename(date: datetime, end_date: datetime = None):
"""
Return filename for the new spreadsheet to be saved as
Expand Down
76 changes: 76 additions & 0 deletions gdrive/idva/pivot_director.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,79 @@ def linked(self, col_dict: dict) -> dict:
)

return builder.render()

def pllpl(self, col_dict: dict) -> dict:
builder = PivotTableBuilder(0, col_dict)
builder.add_row("eventName", SortOrderEnum.ASCENDING, show_totals=False)
builder.add_row("firstUserMedium", SortOrderEnum.ASCENDING)
builder.add_row("firstUserSource", SortOrderEnum.ASCENDING)
builder.add_row(
"firstUserCampaignName", SortOrderEnum.ASCENDING, show_totals=False
)

builder.add_value("eventCount", SummarizeFunctionEnum.SUM)

# =OR(regexmatch(eventName,"session_start"),regexmatch(eventName,"first_visit"))
sessions = FormulaBuilder(
FormulaEnum.OR,
[
FormulaBuilder(
FormulaEnum.REGEX_MATCH,
["eventName", StringLiteral("session_start")],
),
FormulaBuilder(
FormulaEnum.REGEX_MATCH, ["eventName", StringLiteral("first_visit")]
),
],
)

builder.add_filter(
"firstUserMedium",
FilterTypeEnum.TEXT_CONTAINS,
values=[UserEnteredValue("pllpl")],
)
builder.add_filter(
"eventName",
FilterTypeEnum.CUSTOM,
values=[UserEnteredValue(sessions.render())],
)

return builder.render()

def ffg(self, col_dict: dict) -> dict:
builder = PivotTableBuilder(0, col_dict)
builder.add_row("eventName", SortOrderEnum.ASCENDING, show_totals=False)
builder.add_row("firstUserMedium", SortOrderEnum.ASCENDING)
builder.add_row("firstUserSource", SortOrderEnum.ASCENDING)
builder.add_row(
"firstUserCampaignName", SortOrderEnum.ASCENDING, show_totals=False
)

builder.add_value("eventCount", SummarizeFunctionEnum.SUM)

# =OR(regexmatch(eventName,"session_start"),regexmatch(eventName,"first_visit"))
sessions = FormulaBuilder(
FormulaEnum.OR,
[
FormulaBuilder(
FormulaEnum.REGEX_MATCH,
["eventName", StringLiteral("session_start")],
),
FormulaBuilder(
FormulaEnum.REGEX_MATCH, ["eventName", StringLiteral("first_visit")]
),
],
)

builder.add_filter(
"firstUserMedium",
FilterTypeEnum.TEXT_CONTAINS,
values=[UserEnteredValue("ffg")],
)
builder.add_filter(
"eventName",
FilterTypeEnum.CUSTOM,
values=[UserEnteredValue(sessions.render())],
)

return builder.render()

0 comments on commit b5813af

Please sign in to comment.