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

Ajout de nouveaux modèles de fraude #2792

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion dbt/.sqlfluff
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ align_within = select_clause
# in this example would likely be the boundary of a CTE. Stopping
# when we hit brackets is usually a good rule of thumb for this
# configuration.
align_scope = bracketed
align_scope = bracketed

[sqlfluff:indentation]
indent_unit = space
tab_space_size = 2
132 changes: 132 additions & 0 deletions dbt/models/fraud/trips/simultaneous_group_trips.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{{
config(
materialized = 'incremental',
unique_key = [
'start_geo_code',
'end_geo_code',
'start_datetime',
'distance_50m'
],
indexes = [
{
'columns':[
'start_geo_code',
'end_geo_code',
'start_datetime',
'distance_50m'
],
'unique':true

}
]
)
}}

with incentives as (
select
carpool_id,
sum(i.amount) as total_amount,
count(distinct i._id) as num_incitations
from {{ source('carpool', 'operator_incentives') }} as i
inner join
{{ source('carpool', 'carpools') }} as c
on
i.carpool_id = c._id
{% if is_incremental() %}
and c.start_datetime
>= (
select date_trunc('week', max(start_datetime))
from {{ this }}
)
{% else %}
and c.start_datetime >= now() - interval '1 year'
{% endif %}
group by 1
),

groups as (
select
g.start_geo_code,
g.end_geo_code,
c.start_datetime,
(
c.distance / 50
)::int as distance_50m,
count(
*
) as num_journeys,
sum(
driver_revenue
) as total_driver_revenue,
sum(
passenger_contribution
) as total_passengers_contributions,
sum(
i.total_amount
) as total_incentives,
sum(
i.num_incitations
) as num_incitations,
array_agg(
distinct c.operator_id
) as operators,
sum(
(s.fraud_status = 'failed')::int
) as num_fraud_journeys,
sum(
(s.anomaly_status = 'failed')::int
) as num_anomaly_journeys,
max(
case when tvel._id is not null then 'yes' else 'no' end
) as has_fraud_labels,
json_agg(tvel.labels) filter (
where tvel.labels is not null
) as fraud_labels,
1 as link
from
{{ source('carpool', 'carpools') }} as c
inner join {{ source('carpool', 'geo') }} as g
on
c._id = g.carpool_id
left join incentives as i
on
c._id = i.carpool_id
left join
{{ source('carpool', 'status') }} as s
on
c._id = s.carpool_id
left join
{{ source('carpool', 'terms_violation_error_labels') }} as tvel
on c._id = tvel.carpool_id
{% if is_incremental() %}
where
c.start_datetime
>= (select date_trunc('week', max(start_datetime)) from {{ this }})
{% else %}
where c.start_datetime >= now() - interval '1 year'
{% endif %}
group by
1,
2,
3,
4
having
count(*) >= 3
)

select
start_geo_code,
end_geo_code,
start_datetime,
distance_50m,
num_journeys,
total_driver_revenue,
total_passengers_contributions,
total_incentives,
num_incitations,
operators,
num_fraud_journeys,
num_anomaly_journeys,
has_fraud_labels
from groups
order by date_trunc('week', start_datetime) desc, total_driver_revenue desc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ select
avg(
count_consecutive_changes
) as avg_daily_consecutives_intraday_role_changes,
max(count_consecutive_changes) as max_daily_consecutives_intraday_role_changes
max(
count_consecutive_changes
) as max_daily_consecutives_intraday_role_changes
from intraday_stats
group by 1
1 change: 1 addition & 0 deletions dbt/models/sources/carpool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,4 @@ sources:
data_type: USER-DEFINED
- name: anomaly_status
data_type: USER-DEFINED
- name: terms_violation_error_labels
2 changes: 1 addition & 1 deletion notebooks/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ repos:
- id: jupyter-nb-clear-output
name: jupyter-nb-clear-output
files: \.ipynb$
stages: [commit]
stages: [pre-commit]
language: system
entry: jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace
Loading
Loading