ai-prop is a Rust-based statistical microservice that exposes statistical calculation logic via both REST (axum) and gRPC (tonic) APIs. It interacts with a PostgreSQL database via the ai-infra dependency for certain operations.
The service exposes the following endpoints (available on both REST and gRPC):
/calculate_proportions/calculate_pooled_estimate/calculate_z_statistics
- REST (Axum): Port 3000 (by default) or configured via the
PORTenvironment variable. - gRPC (Tonic): Port 50051 (by default)
The REST API is currently deployed on Render and is accessible at: https://ai-prop-service.onrender.com
curl -s -X POST https://ai-prop-service.onrender.com/calculate_proportions \
-H "Content-Type: application/json" \
-d '{"overall": {"m": 10.0, "n": 20.0}, "group1": {"m": 5.0, "n": 10.0}, "group2": {"m": 5.0, "n": 10.0}}'Response:
{"p_population":0.5,"p1":0.5,"p2":0.5}This project contains two primary binaries:
server: The main microservice providing the REST and gRPC endpoints (run by default withcargo run).divide_population_by_s: A utility binary for dividing population data into database partitions. (run withcargo run --bin divide_population_by_s).
- Docker container running with the
postgresimage - To connect to the database and check tables content:
docker exec -it <container id> psql -U postgres
Run the following commands in the ai-infra repository:
diesel migration run(to create the partitioned table and partitions)diesel migration revert(to use the runtime partitions from step 3 below)
- Add a
.envat the root of the infra project with:DATABASE_URL=postgres://usr:pwd@localhost:5432/name-postgres(change for the name of your PostgreSQL database and usr/pwd) cargo buildcargo run --bin divide_population_by_s