Skip to content

Commit 85a1960

Browse files
authoredMar 10, 2025··
Merge pull request #11 from lgabs/evolver-janus-multivariant
Refactor Janus to support Multivariant
2 parents 66a91e9 + f0f62cc commit 85a1960

40 files changed

+1399
-4943
lines changed
 

‎.github/workflows/ci.yml

+44-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
build:
10+
test:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
@@ -29,4 +29,46 @@ jobs:
2929
3030
- name: Run tests
3131
run: |
32-
python -m unittest discover tests
32+
pytest
33+
34+
build:
35+
needs: test
36+
runs-on: ubuntu-latest
37+
permissions:
38+
contents: read
39+
packages: write
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v2
44+
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@v1
47+
48+
- name: Log in to GitHub Container Registry
49+
uses: docker/login-action@v1
50+
with:
51+
registry: ghcr.io
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Extract metadata for Docker
56+
id: meta
57+
uses: docker/metadata-action@v3
58+
with:
59+
images: ghcr.io/${{ github.repository }}
60+
tags: |
61+
type=sha,format=long
62+
type=ref,event=branch
63+
type=ref,event=tag
64+
latest
65+
66+
- name: Build and push Docker image
67+
uses: docker/build-push-action@v2
68+
with:
69+
context: .
70+
push: true
71+
tags: ${{ steps.meta.outputs.tags }}
72+
labels: ${{ steps.meta.outputs.labels }}
73+
cache-from: type=gha
74+
cache-to: type=gha,mode=max

‎Dockerfile

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ RUN pip install --no-cache-dir -r requirements.txt
88

99
COPY . .
1010

11-
EXPOSE 8501
11+
EXPOSE 8000
1212

13-
ENV PYTHONPATH=/app
14-
15-
CMD ["streamlit", "run", "Homepage.py"]
13+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

‎Makefile

-20
This file was deleted.

‎README.md

+76-26
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,103 @@
44
![Python Version](https://img.shields.io/badge/python-3.7%20%7C%203.8-brightgreen.svg)
55
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
66

7-
> **Warning**
8-
> We're making a major breaking change in the project to use the [bayesian-testing](https://github.com/Matt52/bayesian-testing) library for better experiment management, and a full stack application will be developed to build a website for Janus.
9-
> Please, consider using the distributed [package in pypi](https://pypi.org/project/janus-web-ab-testing/), which comes from the `evolve-janus-backend` branch.
7+
Janus is a Bayesian A/B Testing application that supports multivariant experiments. It's designed to help you make data-driven decisions by analyzing conversion rates, revenue, and ARPU (Average Revenue Per User) across multiple variants.
108

9+
## Features
1110

12-
Janus is an A/B Test Engine to be used in a variety use cases, especially to measure conversion, ticket and ARPU difference between variants, i.e, typical metrics for tests in marketplaces. The engine name is an analogy to _Janus_, the god of changes and transitions.
13-
14-
This library came as an ideia of separate the statistical calculations in A/B Tests from other code that is typically used to manage tests and execute queries over the company's database, and hence usually carry proprietary code and even business logic, which should not be open sourced. There was the bud to build this library and get it open sourced.
15-
16-
Checkout the [streamlit app](https://lgabs-janus-homepage-31diny.streamlit.app/) from this repo.
11+
- **Multivariant Testing**: Compare multiple variants simultaneously (not just A vs B)
12+
- **Bayesian Statistics**: Get more insightful results faster than traditional frequentist methods
13+
- **Key Metrics Analysis**:
14+
- Conversion rate
15+
- Revenue for conversions
16+
- Average revenue per impression (ARPU)
17+
- **Modern Web Interface**: Clean, responsive UI built with Bootstrap
18+
- **FastAPI Backend**: High-performance API for experiment analysis
1719

1820
## Installation
1921

20-
Open a terminal, clone this repository into your machine and stay into the project directory.
21-
22-
Using a virtual environment is a good practice, but it is optional. If you enjoy it, go ahead and create a virtual environment by typing:
23-
```
24-
python3 -m venv venv -r requirements.txt
25-
```
26-
Once it is created, you must now activate the environment by using:
27-
```
28-
source venv/bin/activate
22+
1. Clone this repository:
23+
```bash
24+
git clone https://github.com/lgabs/janus.git
25+
cd janus
2926
```
30-
Now, you can install our lib (if you are not using virtual env, go straight to this command):
27+
28+
2. Create a virtual environment (optional but recommended):
29+
```bash
30+
python -m venv venv
31+
source venv/bin/activate # On Windows: venv\Scripts\activate
3132
```
32-
make install
33+
34+
3. Install dependencies:
35+
```bash
36+
pip install -r requirements.txt
3337
```
3438

35-
And that's it! Now, inside our environment, we can import the `janus` lib inside our scripts with plain `import janus` etc. Try to test using the same code on `experiment_example.ipynb` notebook here or in a plain terminal.
39+
## Running the Application
40+
41+
### Using Python directly:
42+
43+
```bash
44+
uvicorn main:app --reload
45+
```
3646

37-
## Using as an Application
47+
Then open your browser and navigate to `http://localhost:8000`
3848

39-
You can use _janus_ as a streamlit product in two ways:
49+
### Using Docker:
4050

41-
### 1. Using Docker (Recommended)
42-
Build and run the application locally using Docker:
4351
```bash
4452
# Build the Docker image
4553
docker build -t janus .
4654

4755
# Run the container
48-
docker run -p 8501:8501 janus
56+
docker run -p 8000:8000 janus
4957
```
50-
Or use `make run`. Then open your browser and navigate to `http://localhost:8501`
5158

59+
### Using Docker Compose (Recommended):
60+
61+
```bash
62+
# Start the application
63+
docker-compose up -d
64+
65+
# View logs
66+
docker-compose logs -f
67+
68+
# Stop the application
69+
docker-compose down
70+
```
71+
72+
Then open your browser and navigate to `http://localhost:8000`
73+
74+
## How to Use
75+
76+
1. Enter your baseline variant name (e.g., "A" or "Control")
77+
2. Add your variants with their respective data:
78+
- Name: A unique identifier for the variant
79+
- Impressions: Total number of users/sessions exposed to this variant
80+
- Conversions: Number of successful conversions
81+
- Revenue: Total revenue generated by this variant
82+
83+
3. Click "Run Analysis" to see the results:
84+
- Summary statistics for each variant
85+
- Conversion statistics with probability of being the best variant
86+
- ARPU statistics with probability of being the best variant
87+
88+
4. Export your results as CSV if needed
89+
90+
## API Documentation
91+
92+
The API documentation is available at `/docs` when the application is running.
93+
94+
## Technical Details
95+
96+
This application uses:
97+
- [FastAPI](https://fastapi.tiangolo.com/) for the backend
98+
- [Bayesian-Testing](https://github.com/Matt52/bayesian-testing) for statistical calculations
99+
- Bootstrap 5 for the frontend UI
100+
- Jinja2 for HTML templating
52101

53102
## References
103+
54104
* [What is A/B Testing](https://en.wikipedia.org/wiki/A/B_testing)
55105
* The bayesian calculations were implemented based on [this VWO white paper](https://vwo.com/downloads/VWO_SmartStats_technical_whitepaper.pdf)
56106
* [Agile A/B testing with Bayesian Statistics and Python](https://web.archive.org/web/20150419163005/http://www.bayesianwitch.com/blog/2014/bayesian_ab_test.html)

‎docker-compose.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3.8'
2+
3+
services:
4+
janus:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- "8000:8000"
10+
volumes:
11+
- .:/app
12+
environment:
13+
- PYTHONPATH=/app
14+
restart: unless-stopped
15+
healthcheck:
16+
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
17+
interval: 30s
18+
timeout: 10s
19+
retries: 3
20+
start_period: 10s

0 commit comments

Comments
 (0)
Please sign in to comment.