Changes between Version 13 and Version 14 of AdvancedReports


Ignore:
Timestamp:
06/05/26 16:32:30 (6 days ago)
Author:
232012
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v13 v14  
    330330{{{
    331331DiscountEvents <-
    332 σ m.type_of_modification = 'DISCOUNT'
    333 (
    334   MODIFICATIONS m ⨝ (m.modification_id = mp.modification_id) MODIFICATION_PRODUCTS mp
     332π m.modification_id,
     333  m.admin_id,
     334  m.date_modified,
     335  discount_percentage := m.discount,
     336  mp.product_id
     337(
     338  σ m.type_of_modification = 'DISCOUNT'
     339  (
     340    MODIFICATIONS m ⨝ (m.modification_id = mp.modification_id) MODIFICATION_PRODUCTS mp
     341  )
    335342)
    336343
    337344PrePromoSales <-
    338 γ modification_id, product_id;
    339   units_sold_before := SUM(op.quantity),
    340   revenue_before := SUM(op.quantity * op.price_at_purchase)
    341 (
    342   σ o.purchase_date ∈ [m.date_modified - 30 days, m.date_modified)
    343     ∧ o.status ∈ {PAID, SHIPPED, DELIVERED}
    344   (
    345     DiscountEvents de ⨝ ORDER_PRODUCTS op ⨝ ORDERS o
    346   )
     345γ de.modification_id, de.product_id;
     346  units_sold_before := COALESCE(SUM(op.quantity), 0),
     347  revenue_before := COALESCE(SUM(op.quantity * op.price_at_purchase), 0.00)
     348(
     349  (
     350    DiscountEvents de
     351    ⟕ (de.product_id = op.product_id) ORDER_PRODUCTS op
     352  )
     353  ⟕ (
     354      op.order_id = o.order_id
     355      ∧ o.purchase_date >= de.date_modified - 30 days
     356      ∧ o.purchase_date < de.date_modified
     357      ∧ o.status ∈ {PAID, SHIPPED, DELIVERED}
     358    ) ORDERS o
    347359)
    348360
    349361PostPromoSales <-
    350 γ modification_id, product_id;
    351   units_sold_after := SUM(op.quantity),
    352   revenue_after := SUM(op.quantity * op.price_at_purchase)
    353 (
    354   σ o.purchase_date ∈ (m.date_modified, m.date_modified + 30 days]
    355     ∧ o.status ∈ {PAID, SHIPPED, DELIVERED}
    356   (
    357     DiscountEvents de ⨝ ORDER_PRODUCTS op ⨝ ORDERS o
    358   )
     362γ de.modification_id, de.product_id;
     363  units_sold_after := COALESCE(SUM(op.quantity), 0),
     364  revenue_after := COALESCE(SUM(op.quantity * op.price_at_purchase), 0.00)
     365(
     366  (
     367    DiscountEvents de
     368    ⟕ (de.product_id = op.product_id) ORDER_PRODUCTS op
     369  )
     370  ⟕ (
     371      op.order_id = o.order_id
     372      ∧ o.purchase_date > de.date_modified
     373      ∧ o.purchase_date <= de.date_modified + 30 days
     374      ∧ o.status ∈ {PAID, SHIPPED, DELIVERED}
     375    ) ORDERS o
    359376)
    360377
    361378PromoSummary <-
    362 π product_id,
     379π de.product_id,
    363380  release_title := r.title,
    364381  product_format := p.format,
    365382  promotion_start_date := de.date_modified,
    366383  discount_applied := de.discount_percentage,
     384  pre.units_sold_before,
     385  post.units_sold_after,
    367386  volume_change := post.units_sold_after - pre.units_sold_before,
    368   net_revenue_impact := post.revenue_after - pre.revenue_before,
    369   units_sold_before := pre.units_sold_before,
    370   units_sold_after := post.units_sold_after,
    371   revenue_before := pre.revenue_before,
    372   revenue_after := post.revenue_after
     387  pre.revenue_before,
     388  post.revenue_after,
     389  net_revenue_impact := post.revenue_after - pre.revenue_before
    373390(
    374391  DiscountEvents de
    375   ⨝ PRODUCTS p
    376   ⨝ RELEASES r
    377   ⨝ PrePromoSales pre
    378   ⨝ PostPromoSales post
     392  ⨝ (de.product_id = p.product_id) PRODUCTS p
     393  ⨝ (p.release_id = r.release_id) RELEASES r
     394  ⨝ (de.modification_id = pre.modification_id ∧ de.product_id = pre.product_id) PrePromoSales pre
     395  ⨝ (de.modification_id = post.modification_id ∧ de.product_id = post.product_id) PostPromoSales post
    379396)
    380397
    381398Result <-
    382 τ promotion_start_date ↓, net_revenue_impact ↓
    383 (
    384   π *,
    385     promotion_verdict :=
    386       CASE
    387         WHEN net_revenue_impact > 0 ∧ volume_change > 0
    388           THEN 'SUCCESS'
    389         WHEN net_revenue_impact < 0 ∧ volume_change > 0
    390           THEN 'MARGIN LOSS'
    391         WHEN volume_change <= 0
    392           THEN 'FAILURE'
    393         ELSE 'NEUTRAL'
    394       END
    395   (
    396     PromoSummary
    397   )
    398 )
     399π product_id,
     400  release_title,
     401  product_format,
     402  promotion_start_date,
     403  discount_applied,
     404  units_sold_before,
     405  units_sold_after,
     406  volume_change,
     407  revenue_before,
     408  revenue_after,
     409  net_revenue_impact,
     410  promotion_verdict :=
     411    CASE
     412      WHEN net_revenue_impact > 0 ∧ volume_change > 0
     413        THEN 'SUCCESS: Volume generated profit'
     414      WHEN net_revenue_impact < 0 ∧ volume_change > 0
     415        THEN 'MARGIN LOSS: Volume rose but lost overall revenue'
     416      WHEN volume_change <= 0
     417        THEN 'FAILURE: No demand increase observed'
     418      ELSE 'NEUTRAL'
     419    END
     420(
     421  PromoSummary
     422)
     423
     424τ promotion_start_date ↓, net_revenue_impact ↓ (Result)
    399425}}}
    400426
     
    480506{{{
    481507UserPurchaseMetrics <-
    482 γ user_id;
    483   total_orders_placed := COUNT(order_id),
    484   lifetime_points_earned := SUM(points_earned),
    485   lifetime_points_burned := SUM(points_used),
    486   total_monetary_spend := SUM(op.quantity * op.price_at_purchase)
    487 (
    488   σ o.purchase_date >= NOW - 2 years
     508γ o.user_id;
     509  total_orders_placed := COUNT(o.order_id),
     510  lifetime_points_earned := COALESCE(SUM(o.points_earned), 0),
     511  lifetime_points_burned := COALESCE(SUM(o.points_used), 0),
     512  total_monetary_spend := COALESCE(SUM(op.quantity * op.price_at_purchase), 0.00)
     513(
     514  σ o.purchase_date >= CURRENT_DATE - 2 years
    489515    ∧ o.status ∈ {PAID, SHIPPED, DELIVERED}
    490516  (
    491     ORDERS o ⟕ ORDER_PRODUCTS op
     517    ORDERS o ⟕ (o.order_id = op.order_id) ORDER_PRODUCTS op
    492518  )
    493519)
     
    500526  registration_date := u.date_created,
    501527  orders_count_2yr := COALESCE(um.total_orders_placed, 0),
    502   lifetime_spend_amount := COALESCE(um.total_monetary_spend, 0),
     528  lifetime_spend_amount := ROUND(COALESCE(um.total_monetary_spend, 0.00), 2),
    503529  current_unspent_points_balance := c.points_collected,
    504530  points_earned_2yr := COALESCE(um.lifetime_points_earned, 0),
    505531  points_burned_2yr := COALESCE(um.lifetime_points_burned, 0)
    506532(
    507   CONSUMERS c ⨝ USERS u ⟕ UserPurchaseMetrics um
     533  σ u.date_created >= CURRENT_DATE - 2 years
     534  (
     535    (CONSUMERS c ⨝ (c.user_id = u.user_id) USERS u)
     536    ⟕ (c.user_id = um.user_id) UserPurchaseMetrics um
     537  )
    508538)
    509539
     
    521551
    522552Result <-
    523 τ account_creation_vintage ↓, current_unspent_points_balance ↓
    524 (
    525   π user_id, username, email,
    526     account_creation_vintage,
    527     registration_date,
    528     orders_count_2yr,
    529     lifetime_spend_amount,
    530     current_unspent_points_balance,
    531     points_earned_2yr,
    532     points_burned_2yr,
    533     customer_retention_segment :=
    534       CASE
    535         WHEN is_vip = 1 THEN 'VIP'
    536         WHEN is_hoarder = 1 THEN 'HOARDER'
    537         WHEN is_churned = 1 THEN 'CHURNED'
    538         ELSE 'STANDARD'
    539       END
    540   (
    541     UserFlags
    542   )
    543 )
    544 }}}
    545 
    546 
     553π user_id,
     554  username,
     555  email,
     556  account_creation_vintage,
     557  registration_date,
     558  orders_count_2yr,
     559  lifetime_spend_amount,
     560  current_unspent_points_balance,
     561  points_earned_2yr,
     562  points_burned_2yr,
     563  customer_retention_segment :=
     564    CASE
     565      WHEN is_vip = 1 THEN 'VIP Tier: High Future Discount Liability'
     566      WHEN is_hoarder = 1 THEN 'Points Hoarder: Inactive Burn (High Risk)'
     567      WHEN is_churned = 1 THEN 'Churned After Reward Use (No Retention)'
     568      ELSE 'Standard Active Engagement Profile'
     569    END
     570(
     571  UserFlags
     572)
     573
     574τ account_creation_vintage ↓, current_unspent_points_balance ↓ (Result)
     575}}}
     576
     577