Ai
3 Star 6 Fork 0

Gitee 极速下载/codepilot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/CodePilotai/codepilot
克隆/下载
_split-test.js 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
petebytes 提交于 2018-11-02 01:07 +08:00 . Initial MIT release v5.0.0
import path from 'path'
import settings from 'electron-settings'
import sample from 'lodash/sample'
import isEqual from 'lodash/isEqual'
import camelCase from 'lodash/camelCase'
export default ({ key, hypotheses }) => {
const keyPath = camelCase(path.basename(key))
// Where in settings the test will be saved
const testPath = `splitTest.${keyPath}`
// Check if we've already saved this test
const savedTest = settings.get(testPath)
// If we've saved the test, using the same hypotheses...
if (savedTest && isEqual(savedTest.hypotheses, hypotheses)) {
// Return the value that was saved, ensuring that
// each user will always see the same result.
return savedTest.hypothesis
} else {
// Pick a random hypothesis
const hypothesis = chooseHypothesis({ key, hypotheses })
// Save random value for this test in settings
settings.set(testPath, { hypotheses, hypothesis })
// Return the random hypothesis
return hypothesis
}
}
// Guarantees that all exported hypotheses contain
// a valid `name` and `value` property.
function chooseHypothesis({ key, hypotheses }) {
const hypothesis = {}
const hypothesesIsArray = Array.isArray(hypotheses)
hypothesis.name = sample(
hypothesesIsArray ? hypotheses : Object.keys(hypotheses)
)
if (hypothesesIsArray) {
hypothesis.value = hypothesis.name
} else {
hypothesis.value = hypotheses[hypothesis.name]
}
return hypothesis
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/codepilot.git
git@gitee.com:mirrors/codepilot.git
mirrors
codepilot
codepilot
master

搜索帮助