Skip to content

Commit

Permalink
adding support for where clause in user_journey (#446)
Browse files Browse the repository at this point in the history
* adding support for where clause in user_journey

* making correction for where clause
  • Loading branch information
joker2411 authored Sep 12, 2024
1 parent 84bb7cf commit b2630b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions samples/attribution_project/models/profiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ models:
conversion:
touchpoints: # Defines the user journey sequence allowing us to evaluatel first, last and multi-touch models
- from: inputs/rsMarketingPages
where: 4 < {{user.Var('first_invoice_amount')}}
conversion_vars: # What are the activities, outcomes, etc. that we actually want to measure. You can define more than 1. You can also define a value in addition to the count.
- name: sf_order
timestamp: user.Var('first_order_date')
value: user.Var('first_invoice_amount') # Optional - adding this creates an extra column called <conversion>_<model>_value (ex: signup_first_touch_value)
conversion_window: 60d
- name: sf_subscription
timestamp: user.Var('subscription_start_date')
campaign:
Expand Down
16 changes: 13 additions & 3 deletions src/predictions/profiles_mlcorelib/py_native/attribution_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AttributionModel(BaseModelType):
"type": "object",
"properties": {
"from": {"type": "string"},
"where": {"type": "string"},
},
"required": ["from"],
"additionalProperties": False,
Expand Down Expand Up @@ -565,9 +566,18 @@ def _create_user_journey_cte(
journey_info_timestamp = material.de_ref(
journey_info["from"]
).model.time_filtering_column()
select_info = f"SELECT {entity_id_column_name}, {campaign_id_column_name}, {journey_info_timestamp} AS timestamp"
from_info = f"FROM {{{{{prefix}{counter}}}}}"
where_info = f"WHERE {campaign_id_column_name} is not NULL"
select_info = f"SELECT a.{entity_id_column_name}, a.{campaign_id_column_name}, a.{journey_info_timestamp} AS timestamp"
from_info = f"FROM {{{{{prefix}{counter}}}}} a"
where_info = f"WHERE (a.{campaign_id_column_name} is not NULL)"

if "where" in journey_info:
if ".Var" in journey_info["where"]:
join_info = f"JOIN {{{{entity_var_table}}}} ON a.{entity_id_column_name} = {{{{entity_var_table}}}}.{entity_id_column_name}"
else:
join_info = ""

from_info += f" {join_info}"
where_info += f" AND ( {journey_info['where']} )"

journey_query = f"""{journey_query}
{union_op}
Expand Down

0 comments on commit b2630b1

Please sign in to comment.