-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/usage-report-celery-queue
- Loading branch information
Showing
51 changed files
with
5,973 additions
and
272 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import unittest | ||
from ee.clickhouse.queries.experiments.funnel_experiment_result import validate_event_variants | ||
from rest_framework.exceptions import ValidationError | ||
|
||
|
||
class TestExperiments(unittest.TestCase): | ||
def test_validate_event_variants_no_events(self): | ||
expected_code = "no-events" | ||
with self.assertRaises(ValidationError) as context: | ||
validate_event_variants([], ["test", "control"]) | ||
|
||
self.assertEqual(expected_code, context.exception.detail[0].code) | ||
|
||
def test_validate_event_variants_missing_variants(self): | ||
funnel_results = [ | ||
[ | ||
{ | ||
"action_id": "step-a-1", | ||
"name": "step-a-1", | ||
"custom_name": None, | ||
"order": 0, | ||
"people": [], | ||
"count": 1, | ||
"type": "events", | ||
"average_conversion_time": None, | ||
"median_conversion_time": None, | ||
"breakdown": ["test"], | ||
"breakdown_value": ["test"], | ||
}, | ||
{ | ||
"action_id": "step-a-2", | ||
"name": "step-a-2", | ||
"custom_name": None, | ||
"order": 1, | ||
"people": [], | ||
"count": 0, | ||
"type": "events", | ||
"average_conversion_time": None, | ||
"median_conversion_time": None, | ||
"breakdown": ["test"], | ||
"breakdown_value": ["test"], | ||
}, | ||
] | ||
] | ||
|
||
expected_code = "missing-flag-variants::control" | ||
with self.assertRaises(ValidationError) as context: | ||
validate_event_variants(funnel_results, ["test", "control"]) | ||
|
||
self.assertEqual(expected_code, context.exception.detail[0].code) | ||
|
||
def test_validate_event_variants_ignore_old_variant(self): | ||
funnel_results = [ | ||
[ | ||
{ | ||
"action_id": "step-a-1", | ||
"name": "step-a-1", | ||
"custom_name": None, | ||
"order": 0, | ||
"people": [], | ||
"count": 1, | ||
"type": "events", | ||
"average_conversion_time": None, | ||
"median_conversion_time": None, | ||
"breakdown": ["test"], | ||
"breakdown_value": ["test"], | ||
}, | ||
{ | ||
"action_id": "step-a-2", | ||
"name": "step-a-2", | ||
"custom_name": None, | ||
"order": 1, | ||
"people": [], | ||
"count": 0, | ||
"type": "events", | ||
"average_conversion_time": None, | ||
"median_conversion_time": None, | ||
"breakdown": ["old-variant"], | ||
"breakdown_value": ["old-variant"], | ||
}, | ||
] | ||
] | ||
|
||
expected_code = "missing-flag-variants::control" | ||
with self.assertRaises(ValidationError) as context: | ||
validate_event_variants(funnel_results, ["test", "control"]) | ||
|
||
self.assertEqual(expected_code, context.exception.detail[0].code) |
2 changes: 1 addition & 1 deletion
2
ee/clickhouse/views/test/__snapshots__/test_clickhouse_experiment_secondary_results.ambr
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// from https://gist.github.com/t1grok/a0f6d04db569890bcb57 | ||
|
||
interface rgb { | ||
r: number | ||
g: number | ||
b: number | ||
} | ||
interface yuv { | ||
y: number | ||
u: number | ||
v: number | ||
} | ||
|
||
function hexToRgb(hexColor: string): rgb | null { | ||
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i | ||
hexColor = hexColor.replace(shorthandRegex, function (_, r, g, b) { | ||
return r + r + g + g + b + b | ||
}) | ||
|
||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexColor) | ||
return result | ||
? { | ||
r: parseInt(result[1], 16), | ||
g: parseInt(result[2], 16), | ||
b: parseInt(result[3], 16), | ||
} | ||
: null | ||
} | ||
|
||
function rgbToYuv(rgbColor: rgb): yuv { | ||
let y, u, v | ||
|
||
y = rgbColor.r * 0.299 + rgbColor.g * 0.587 + rgbColor.b * 0.114 | ||
u = rgbColor.r * -0.168736 + rgbColor.g * -0.331264 + rgbColor.b * 0.5 + 128 | ||
v = rgbColor.r * 0.5 + rgbColor.g * -0.418688 + rgbColor.b * -0.081312 + 128 | ||
|
||
y = Math.floor(y) | ||
u = Math.floor(u) | ||
v = Math.floor(v) | ||
|
||
return { y: y, u: u, v: v } | ||
} | ||
|
||
export const isLight = (hexColor: string): boolean => { | ||
const rgbColor = hexToRgb(hexColor) | ||
if (!rgbColor) { | ||
return false | ||
} | ||
const yuvColor = rgbToYuv(rgbColor) | ||
return yuvColor.y > 128 | ||
} |
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
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
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
Oops, something went wrong.