This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH customers AS ( | |
SELECT 'Customer1' AS customer_id UNION ALL | |
SELECT 'Customer2' AS customer_id UNION ALL | |
SELECT 'Customer3' AS customer_id UNION ALL | |
SELECT 'Customer4' AS customer_id | |
) | |
SELECT | |
c.customer_id, | |
CONVERT(BIGINT, SUBSTRING(HASHBYTES('MD5', c.customer_id), 1, 5)) % 100 AS assigned_bucket | |
FROM customers c; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS customers AS | |
SELECT 'Customer1' AS customer_id UNION ALL | |
SELECT 'Customer2' AS customer_id UNION ALL | |
SELECT 'Customer3' AS customer_id UNION ALL | |
SELECT 'Customer4' AS customer_id; | |
SELECT | |
c.customer_id, | |
('0x' || md5(c.customer_id)[:10])::int64 % 100 as assigned_bucket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
probability_assignments = {"Control": 50, "Variant 1": 30, "Variant 2": 20} | |
random_customer_ids = ["Customer1", "Customer2", "Customer3", "Customer4"] | |
def get_hash(customer_id): | |
hash_object = hashlib.md5(customer_id.encode()) | |
return hash_object.hexdigest()[:10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function adapted from https://github.com/AfricaBirdData/ABAP/ | |
# Only pulls presence data | |
library("tidyverse") | |
library("purrr") | |
jsonToTibble <- function(jsonfile) { | |
out <- jsonfile %>% | |
lapply(function(x) { | |
x[sapply(x, is.null)] <- NA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0. set up --------------------------------------------------------------- | |
# libraries | |
library(rabm) | |
library(tidyverse) | |
library(geojsonio) | |
library(broom) | |
library(ggplot2) | |
library(gganimate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
files <- list.files(path = "./data/", pattern = "*.csv") | |
df <- files %>% | |
map(function(x) { | |
read_csv(paste0("./data/", x)) | |
}) %>% | |
reduce(rbind) | |