Skip to content

Commit

Permalink
chore: code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnaikjuspay committed Jan 6, 2025
1 parent a40f221 commit ac68697
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,26 @@ let parseResponse = (response, key) => {

let setValue = (dict, ~data, ~ids: array<overviewColumns>, ~metricType, ~currency) => {
open LogicUtils
open NewAnalyticsTypes
open NewAnalyticsUtils
ids->Array.forEach(id => {
let key = id->getStringFromVariant
let amountSuffix =
currency->NewAnalyticsFiltersUtils.getTypeValue == #all_currencies ? "_in_usd" : ""

let value = switch id {
| Total_Smart_Retried_Amount
| Total_Payment_Processed_Amount => {
let id = metricType == Smart_Retry ? key : `${key}_without_smart_retries`
data->NewAnalyticsUtils.getAmountValue(~id={`${id}${amountSuffix}`})->JSON.Encode.float
}
| Total_Payment_Processed_Amount =>
data
->getAmountValue(~id=key->modifyKey(~isSmartRetryEnabled=metricType, ~currency))
->JSON.Encode.float
| Total_Refund_Processed_Amount =>
data
->NewAnalyticsUtils.getAmountValue(~id={`${key}${amountSuffix}`})
->getAmountValue(~id={key->modifyKey(~currency)})
->JSON.Encode.float
| Total_Dispute =>
data
->getFloat(key, 0.0)
->JSON.Encode.float
| _ => {
let id = metricType == Smart_Retry ? key : `${key}_without_smart_retries`
let id = key->modifyKey(~isSmartRetryEnabled=metricType)
data
->getFloat(id, 0.0)
->JSON.Encode.float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ let getMetaDataMapper = (key, ~currency) => {
let field = key->getVariantValueFromString
switch field {
| Payment_Processed_Amount => {
let amountSuffix =
currency->NewAnalyticsFiltersUtils.getTypeValue == #all_currencies ? "_in_usd" : ""
`${Total_Payment_Processed_Amount->getStringFromVariant}${amountSuffix}`
let key = Total_Payment_Processed_Amount->getStringFromVariant
key->NewAnalyticsUtils.modifyKey(~currency)
}
| Payment_Processed_Count | _ => Total_Payment_Processed_Count->getStringFromVariant
}
}

let modifyQueryData = (data, ~isSmartRetryEnabled=Smart_Retry, ~currency) => {
open NewAnalyticsUtils
let dataDict = Dict.make()

data->Array.forEach(item => {
Expand All @@ -173,14 +173,12 @@ let modifyQueryData = (data, ~isSmartRetryEnabled=Smart_Retry, ~currency) => {

switch dataDict->Dict.get(time) {
| Some(prevVal) => {
let keySuffix = isSmartRetryEnabled == Default ? "_without_smart_retries" : ""
let amountSuffix =
currency->NewAnalyticsFiltersUtils.getTypeValue == #all_currencies ? "_in_usd" : ""
let key = Payment_Processed_Count->getStringFromVariant
let paymentProcessedCount = valueDict->getInt(`${key}${keySuffix}`, 0)
let paymentProcessedCount = valueDict->getInt(key->modifyKey(~isSmartRetryEnabled), 0)
let prevProcessedCount = prevVal->getInt(key, 0)
let key = Payment_Processed_Amount->getStringFromVariant
let paymentProcessedAmount = valueDict->getFloat(`${key}${keySuffix}${amountSuffix}`, 0.0)
let paymentProcessedAmount =
valueDict->getFloat(key->modifyKey(~isSmartRetryEnabled, ~currency), 0.0)
let prevProcessedAmount = prevVal->getFloat(key, 0.0)

let totalPaymentProcessedCount = paymentProcessedCount + prevProcessedCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,20 @@ let modifySmartRetryQueryData = data => {
let paymentProcessedCount = valueDict->getInt(key, 0)

let key = Payment_Processed_Amount->getStringFromVariant
let paymentProcessedAmount = valueDict->getFloat(`${key}_in_usd`, 0.0)

let key = `${Payment_Processed_Amount->getStringFromVariant}_without_smart_retries_in_usd`
let paymentProcessedAmountWithoutSmartRetries = valueDict->getFloat(key, 0.0)
let paymentProcessedAmount =
valueDict->getFloat(key->modifyKey(~currency="all_currencies"), 0.0)

let key = `${Payment_Processed_Count->getStringFromVariant}_without_smart_retries`
let paymentProcessedCountWithoutSmartRetries = valueDict->getInt(key, 0)
let key = Payment_Processed_Amount->getStringFromVariant
let paymentProcessedAmountWithoutSmartRetries =
valueDict->getFloat(
key->modifyKey(~isSmartRetryEnabled=Smart_Retry, ~currency="all_currencies"),
0.0,
)

let key = Payment_Processed_Count->getStringFromVariant
let paymentProcessedCountWithoutSmartRetries =
valueDict->getInt(key->modifyKey(~isSmartRetryEnabled=Smart_Retry), 0)

let totalPaymentProcessedCount =
paymentProcessedCount - paymentProcessedCountWithoutSmartRetries
Expand Down Expand Up @@ -201,11 +208,13 @@ let modifyQueryData = data => {
let key = Payment_Processed_Amount->getStringFromVariant
let paymentProcessedAmount = valueDict->getFloat(key, 0.0)
let prevProcessedAmount = prevVal->getFloat(key, 0.0)
let key = `${Payment_Processed_Amount->getStringFromVariant}_without_smart_retries`
let paymentProcessedAmountWithoutSmartRetries = valueDict->getFloat(key, 0.0)
let key = Payment_Processed_Amount->getStringFromVariant
let paymentProcessedAmountWithoutSmartRetries =
valueDict->getFloat(key->modifyKey(~isSmartRetryEnabled=Smart_Retry), 0.0)
let prevProcessedAmountWithoutSmartRetries = prevVal->getFloat(key, 0.0)
let key = `${Payment_Processed_Count->getStringFromVariant}_without_smart_retries`
let paymentProcessedCountWithoutSmartRetries = valueDict->getInt(key, 0)
let key = Payment_Processed_Count->getStringFromVariant
let paymentProcessedCountWithoutSmartRetries =
valueDict->getInt(key->modifyKey(~isSmartRetryEnabled=Smart_Retry), 0)
let prevProcessedCountWithoutSmartRetries = prevVal->getInt(key, 0)

let totalPaymentProcessedCount = paymentProcessedCount + prevProcessedCount
Expand All @@ -224,11 +233,15 @@ let modifyQueryData = data => {
totalPaymentProcessedAmount->JSON.Encode.float,
)
prevVal->Dict.set(
`${Payment_Processed_Amount->getStringFromVariant}_without_smart_retries`,
Payment_Processed_Amount
->getStringFromVariant
->modifyKey(~isSmartRetryEnabled=Smart_Retry),
totalPaymentProcessedAmountWithoutSmartRetries->JSON.Encode.float,
)
prevVal->Dict.set(
`${Payment_Processed_Count->getStringFromVariant}_without_smart_retries`,
Payment_Processed_Count
->getStringFromVariant
->modifyKey(~isSmartRetryEnabled=Smart_Retry),
totalPaymentProcessedCountWithoutSmartRetries->JSON.Encode.int,
)

Expand All @@ -249,13 +262,19 @@ let modifySmartRetryMetaData = data => {
let paymentProcessedCount = valueDict->getInt(key, 0)

let key = Total_Payment_Processed_Amount->getStringFromVariant
let paymentProcessedAmount = valueDict->getFloat(`${key}_in_usd`, 0.0)
let paymentProcessedAmount =
valueDict->getFloat(key->modifyKey(~currency="all_currencies"), 0.0)

let key = `${Total_Payment_Processed_Amount->getStringFromVariant}_without_smart_retries_in_usd`
let paymentProcessedAmountWithoutSmartRetries = valueDict->getFloat(key, 0.0)
let key = Total_Payment_Processed_Amount->getStringFromVariant
let paymentProcessedAmountWithoutSmartRetries =
valueDict->getFloat(
key->modifyKey(~isSmartRetryEnabled=Smart_Retry, ~currency="all_currencies"),
0.0,
)

let key = `${Total_Payment_Processed_Count->getStringFromVariant}_without_smart_retries`
let paymentProcessedCountWithoutSmartRetries = valueDict->getInt(key, 0)
let key = Total_Payment_Processed_Count->getStringFromVariant
let paymentProcessedCountWithoutSmartRetries =
valueDict->getInt(key->modifyKey(~isSmartRetryEnabled=Smart_Retry), 0)

let totalPaymentProcessedCount =
paymentProcessedCount - paymentProcessedCountWithoutSmartRetries
Expand Down

0 comments on commit ac68697

Please sign in to comment.