Skip to content

Instantly share code, notes, and snippets.

@emailrhoads
Last active February 9, 2024 15:33
Show Gist options
  • Save emailrhoads/9c6f7a4881e67de8d2f5189c3ee8334e to your computer and use it in GitHub Desktop.
Save emailrhoads/9c6f7a4881e67de8d2f5189c3ee8334e to your computer and use it in GitHub Desktop.
FJ Public
res_hash = {}
['A', 'B', 'C'].each do |variant|
build_terms = []
build_terms << { range: { expires: { gte: Time.zone.now } } }
build_terms << { term: { ab_test_variant_list: variant } }
build_query = {
bool: {
must: build_terms
}
}
query = {
track_total_hits: true,
query: build_query,
}
search_results = Job.__elasticsearch__.search(query)
res_hash[variant] = search_results.results.total
end
res_hash
# latest docker stuff ...
- I am using the MariaDB docker image
- am I using elasticsearch??
# Connect to Stagign server
#ssh [email protected] -i ~/.ssh/CI.pem
ssh fj-staging
cd john
dcf docker-compose.john.yml exec fj rails console
# to enter master
dcf docker-compose.master.yml exec fj rails console
dcf docker-compose.release.yml exec fj rails console
# Restore Database in Docker if dead
docker ps
docker exec -it f2db0b322a24 bash
mysql --user root < /docker-entrypoint-initdb.d/fjstaging.sql
docker exec -i f2db0b322a24 sh -c 'exec mariadb -u root' < docker/db/fjstaging.sql
docker exec -i f2db0b322a24 sh -c 'exec mariadb -u root --database=flexjobs' < docker/db/fjstaging.sql
# Fix VITE issues I think
cd john && dcf docker-compose.john.yml down && docker rmi john_fj && sudo rm -rf Gemfile.lock yarn.lock node_modules
dcf docker-compose.alessandra2.yml down && docker rmi alessandra2_fj && sudo rm -rf Gemfile.lock yarn.lock node_modules
dcf docker-compose.alessandra.yml down && docker rmi alessandra_fj && sudo rm -rf Gemfile.lock yarn.lock node_modules
# What's going on with user agents on an experiment
select agent, annotation, count(1) from
(
select
-- pv.session_id,
-- data,
RIGHT(annotation,1) as annotation,
SUBSTRING_INDEX(
SUBSTRING_INDEX(data, '"agent":"', -1),
'"',
1
) as agent
from page_views pv
JOIN sessions s
ON CONCAT('2::', SHA2(pv.session_id, 256)) = s.session_id
where page_kind=9 and annotation like 'FJ-16965%' and pv.created_at>'2023-8-20 13:30' and pv.created_at<'2023-8-20 14:00'
and s.created_at > '2023-08-20' and s.created_at < '2023-08-21'
) subQuery
group by agent, annotation
order by count(1) desc
# Experiment Summary
select agent, annotation, count(1) from
(
select
-- pv.session_id,
-- data,
RIGHT(annotation,1) as annotation,
SUBSTRING_INDEX(
SUBSTRING_INDEX(data, '"agent":"', -1),
'"',
1
) as agent
from page_views pv
JOIN sessions s
ON CONCAT('2::', SHA2(pv.session_id, 256)) = s.session_id
where page_kind=9 and annotation like 'FJ-16965%' and pv.created_at>'2023-8-20 13:30' and pv.created_at<'2023-8-20 14:00'
and s.created_at > '2023-08-20' and s.created_at < '2023-08-21'
) subQuery
group by agent, annotation
order by count(1) desc
# Find a busy hour where an experiment was running to look for a big bot spike
select
DATE_FORMAT(pv.created_at, '%Y-%m-%d %H:00:00'),
count(1)
from page_views pv
where page_kind=9 and annotation like 'FJ-17611%' and pv.created_at>'2023-10-20' and pv.created_at<'2023-10-24'
group by DATE_FORMAT(pv.created_at, '%Y-%m-%d %H:00:00')
order by count(1) desc
# See summary of an experiment outcomes
select event_date, annotation, count(1) from
(
select
DATE(created_at) as event_date,
RIGHT(annotation,1) as annotation
from page_views pv
where page_kind=9 and annotation like 'FJ-17017%'
/* keep where clause for efficiency */
and pv.created_at > '2023-09-01' and pv.created_at < '2023-09-26'
) subQuery
group by DATE(created_at), annotation
order by event_date, count(1) desc
/* see hourly breakdown of an experiment */
select event_date, count(1) from
(
select
DATE_FORMAT(created_at, '%Y-%m-%d %H:00:00') as event_date,
RIGHT(annotation,1) as annotation
from page_views pv
where page_kind=9 and annotation like 'FJ-17611%'
/* keep where clause for efficiency */
and pv.created_at > '2023-10-26' and pv.created_at < '2023-10-27'
) subQuery
group by event_date
order by event_date, count(1) desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment