title: "When to call each segment?"
category: "acme"
tags:
  - repair
  - sales
  - printers
train:
  dataset:
    csv:
      filename: "csv/printer_repairs_callstats.csv"
      hasHeader: true
      separator: ","
    fields:
      - quarter
      - segment
      - callTime
      - isComplete
      - isContact
      - value
  when: "!hasRun || sinceLastRunMinutes > 40"
  ruleGeneration:
    fields:
      - quarter
      - segment
    combinationLength: 2
aggregators:
  - name: "totalContacts"
    kind: "count"
    arg: "isContact"
  - name: "totalClientValue"
    kind: "sum"
    arg: "value"
    # 5% commission on all repair contracts
  - name: "totalClientCommission"
    kind: "calc"
    arg: "totalClientValue * 0.05"
    # £2 charge per contact
  - name: "totalClientContactCharge"
    kind: "calc"
    arg: "totalContacts * 2"
  - name: "totalClientCharge"
    kind: "calc"
    arg: "totalClientCommission + totalClientContactCharge"
  - name: "totalClientROI"
    kind: "calc"
    arg: "iferr(roundto(totalClientValue / totalClientCharge, 2), 0)"
  - name: "numSignups"
    kind: "count"
    arg: "value > 0"
  - name: "totalCallCentreCost"
    kind: "sum"
    # £0.04/min call cost, plus £10/hr caller cost, plus £10/hr overheads
    # Equal: (0.04/60) + (10/60/60) + (10/60/60) = 0.0062
    arg: "callTime * 0.0062"
  - name: "totalCallCentreProfit"
    kind: "calc"
    arg: "totalClientCharge - totalCallCentreCost"
  - name: "conversion"
    kind: "calc"
    arg: "iferr(roundto(numSignups / totalContacts, 2), 0)"
  - name: "totalCallCentreROI"
    kind: "calc"
    arg: "iferr(roundto(totalClientCharge / totalCallCentreCost, 2), 0)"
goals:
  - "totalCallCentreROI >= 1.10"
  - "totalClientROI >= 15"
  - "conversion > 0.25"
  - "totalCallCentreROI >= 1.30"
sortOrder:
  - aggregator: "goalsScore"
    direction: "descending"
  - aggregator: "totalClientValue"
    direction: "descending"
  - aggregator: "totalCallCentreROI"
    direction: "descending"
  - aggregator: "conversion"
    direction: "descending"
