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

fix (export): Removing drive id from interaction model #203

Closed
wants to merge 3 commits into from
Closed
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
1 change: 0 additions & 1 deletion gdrive/export_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ async def find(find: FindModel):
# ------------------------------- Archive API --------------------------------------
class InteractionModel(BaseModel):
interactionId: str
driveId: str


@router.post("/export/interaction-files")
Expand Down
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()