Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class AnalyticsQuery {
public static final String BLOCKED_FRAUD_PAYMENTS_COUNT =
"""
SELECT
countIf(status = 'failed' AND errorCode='no_route_found:risk_score_is_too_high') AS count
uniqExactIf(id,
Comment thread
stdevman91 marked this conversation as resolved.
status = 'failed'
AND errorCode = 'no_route_found:risk_score_is_too_high') AS count
FROM fraud.payment
WHERE
timestamp >= toDate(:from)
Expand All @@ -19,12 +21,15 @@ AND toDateTime(eventTime) <= toDateTime(:to)
AND currency = :currency
AND like(shopId, :shopId)
AND like(partyId, :partyId)
AND shopId != 'TEST'
""";

public static final String BLOCKED_FRAUD_PAYMENTS_COUNT_RATIO =
"""
SELECT
countIf(status = 'failed' AND errorCode='no_route_found:risk_score_is_too_high') / count() AS ratio
uniqExactIf(id,
status = 'failed'
AND errorCode = 'no_route_found:risk_score_is_too_high') / uniqExact(id) AS ratio
FROM fraud.payment
WHERE
timestamp >= toDate(:from)
Expand All @@ -34,6 +39,7 @@ AND toDateTime(eventTime) <= toDateTime(:to)
AND currency = :currency
AND like(shopId, :shopId)
AND like(partyId, :partyId)
AND shopId != 'TEST'
""";

public static final String BLOCKED_FRAUD_PAYMENTS_SUM =
Expand All @@ -51,12 +57,13 @@ AND toDateTime(eventTime) <= toDateTime(:to)
AND currency = :currency
AND like(shopId, :shopId)
AND like(partyId, :partyId)
AND shopId != 'TEST'
""";

public static final String FRAUD_PAYMENTS_COUNT =
"""
SELECT
count(*) AS count
uniqExact(id) AS count
FROM fraud.payment
WHERE
timestamp >= toDate(:from)
Expand All @@ -66,6 +73,7 @@ AND toDateTime(eventTime) <= toDateTime(:to)
AND currency = :currency
AND like(shopId, :shopId)
AND like(partyId, :partyId)
AND shopId != 'TEST'
""";

public static final String FRAUD_PAYMENTS_RESULTS_SUMMARY =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.vality.fraudbusters.management.service.clickhouse;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class AnalyticsQueryTest {

@Test
void shouldCountUniqueAttemptedPayments() {
assertThat(AnalyticsQuery.FRAUD_PAYMENTS_COUNT)
.contains("uniqExact(id) AS count")
.contains("shopId != 'TEST'")
.doesNotContain("count(*) AS count");
}

@Test
void shouldCalculateBlockedMetricsUsingUniquePayments() {
assertThat(AnalyticsQuery.BLOCKED_FRAUD_PAYMENTS_COUNT)
.contains("uniqExactIf(id,")
.contains("shopId != 'TEST'");
assertThat(AnalyticsQuery.BLOCKED_FRAUD_PAYMENTS_COUNT_RATIO)
.contains("uniqExactIf(id,")
.contains("/ uniqExact(id) AS ratio")
.contains("shopId != 'TEST'");
}
}
Loading