---
# System prepended metadata

title: AB Test (IOW Hackaton)

---

# AB Test (IOW Hackaton)

## Brief
Proposal is to make a library to make a configurable code for testing a hypothesis. 
Environment will be consist of two parts:
 - TypeScript Library
 - Config File

### TypeScript Part
#### Functions
- function decorator
- getter of test hash
- getter of test state on request

### Config File
#### Structure
```json
[
...
    {
        "GroupName": str,
        "Cases": {
            "CaseName1":{
                "Weight": int,
                "Obj": any
            },
            "CaseName2":{
                "Weight": int,
                "Obj": any
            }
        }
    
    }
...

]
```

## Schemas
```mermaid
    flowchart LR
    Con[Config]
    TM[TeamMembers]
    Cod[Code]
    Dev[Developers]
    Prod[Production]
    Log[Logs]
    Slicer[Slicer]
    
    Dev --Mark Test Participants--> Cod
    Dev --Make Logs schema--> Cod
    Cod -->Prod
    TM --Change Test Weights-->Con
    TM --Change Test Case Params-->Con
    Con --> Prod
    Prod --> Log
    Log --> Slicer    
```

## Examples

### Config
```jsonld=
{
    "GroupName": "Imp2Click"
    "Cases": {
        "up2_lamda_100": {
            "weight": 1,
            "obj": {
                "pcache": "imp2click_v1_100_up2"
            }
        },
        "up1_lamda_100": {
            "weight": 3,
            "obj": {
                "pcache": "imp2click_v20_100"
            }
        },
        "up2_lamda_unset": {
            "weight": 2,
            "obj": {
                "pcache": "imp2click_v2_up2"
            }
        }
    }
}
```

### Code
```typescript=
@abtest("Imp2Click")
function get_click_prob(case: PredictSetting, cap: number): number {
     const prob = this.predictors[case.pcache].getProb()
     return prob > cap ? prob : 0
}
//...

{
//...
    click2install = get_click_prob(constants.click_cap);
//...
    logRecord = {
        predict: {
            click2instll_prob: click2install,
            imp2click_test_config_hash: getTestHash("Imp2Click"),
            imp2click_test_case: getTestCaseName("Imp2Click")
        }
    }
//...
}
```

### Log
```jsonld
    [
        "predict": {
            "click2instll_prob": 0.00132,
            "imp2click_test_config_hash":  408923709,
            "imp2click_test_case": "imp2click_v20_100"
        },
        "predict": {
            "click2instll_prob": 0.00094498,
            "imp2click_test_config_hash":  408923709,
            "imp2click_test_case": "up2_lamda_100"
        },
        "predict": {
            "click2instll_prob": 0.0005686,
            "imp2click_test_config_hash":  408923709,
            "imp2click_test_case": "imp2click_v2_up2"
        },
        "predict": {
            "click2instll_prob": 0.008710,
            "imp2click_test_config_hash":  408923709,
            "imp2click_test_case": "imp2click_v20_100"
        },
        "predict": {
            "click2instll_prob": 0.000244,
            "imp2click_test_config_hash":  408923709,
            "imp2click_test_case": "imp2click_v2_up2"
        },
    ]
```

### Slicer
![](https://i.imgur.com/PmYIT6I.png)
