Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SER-1898] data populator distribute the probabilities equally #5750

Draft
wants to merge 3 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@
selectedKey: this.selectedProperty,
selectedValue: this.selectedValue,
conditionType: this.conditionType,
values: [{key: "", probability: 0}]
values: [{key: "", probability: 100}],
"isProbabilitiesEqual": true,
});
this.$emit('input', conditions);
}
Expand Down Expand Up @@ -328,7 +329,7 @@
data: function() {
return {
users: [],
conditionPropertyValues: []
conditionPropertyValues: [],
};
},
created() {
Expand Down Expand Up @@ -373,11 +374,13 @@
onAddUserProperty: function() {
this.users.push({
"key": "",
"values": [{key: "", probability: 0}],
"values": [{key: "", probability: 100}],
"isProbabilitiesEqual": true,
});
},
onAddAnotherValue: function(index) {
this.users[index].values.push({key: "", probability: 0});
this.calculatePropertyProbabilities(index);
},
checkRemoveValue: function(key, value) {
let usedProperties = [];
Expand Down Expand Up @@ -435,6 +438,7 @@
}
try {
this.users[index].values.splice(valueIndex, 1);
this.calculatePropertyProbabilities(index);
}
catch (error) {
CountlyHelpers.notify({
Expand All @@ -451,9 +455,11 @@
try {
if (this.users[index].conditions[conditionIndex].values.length === 1) {
this.users[index].conditions.splice(conditionIndex, 1);
this.calculateConditionProbabilities(index, conditionIndex);
}
else {
this.users[index].conditions[conditionIndex].values.splice(valueIndex, 1);
this.calculateConditionProbabilities(index, conditionIndex);
}
}
catch (error) {
Expand All @@ -467,6 +473,7 @@
onAddAnotherConditionValue: function(index, conditionIndex) {
try {
this.users[index].conditions[conditionIndex].values.push({key: "", probability: 0});
this.calculateConditionProbabilities(index, conditionIndex);
}
catch (error) {
CountlyHelpers.notify({
Expand All @@ -481,6 +488,28 @@
if (item) {
this.conditionPropertyValues = item.values.map(valueItem => valueItem.key || null);
}
},
calculatePropertyProbabilities: function(index) {
if (this.users[index].isProbabilitiesEqual) {
var valueCount = Object.keys(this.users[index].values).length,
equalProbability = 100 / valueCount;
const updatedValues = this.users[index].values.map(item => ({
...item,
probability: equalProbability // Set the new probability value
}));
this.users[index].values = updatedValues;
}
},
calculateConditionProbabilities: function(index, conditionIndex) {
if (this.users[index].conditions[conditionIndex].isProbabilitiesEqual) {
var valueCount = Object.keys(this.users[index].conditions[conditionIndex].values).length,
equalProbability = 100 / valueCount;
const updatedValues = this.users[index].conditions[conditionIndex].values.map(item => ({
...item,
probability: equalProbability // Set the new probability value
}));
this.users[index].conditions[conditionIndex].values = updatedValues;
}
}
},
template: CV.T("/populator/templates/sections/users.html")
Expand Down Expand Up @@ -542,7 +571,8 @@
onAddEventSegmentation: function(index) {
this.events[index].segmentations.push({
"key": "",
"values": [{key: "", probability: 0}],
"values": [{key: "", probability: 100}],
"isProbabilitiesEqual": true,
});
},
checkRemoveValue: function(key, value, index) {
Expand Down Expand Up @@ -599,6 +629,7 @@
return;
}
this.events[index].segmentations[segmentIndex].values.splice(valueIndex, 1);
this.calculateSegmentProbabilities(index, segmentIndex);
}
catch (error) {
CountlyHelpers.notify({
Expand All @@ -611,6 +642,7 @@
onAddAnotherValue: function(index, segmentIndex) {
try {
this.events[index].segmentations[segmentIndex].values.push({key: "", probability: 0});
this.calculateSegmentProbabilities(index, segmentIndex);
}
catch (error) {
CountlyHelpers.notify({
Expand All @@ -622,6 +654,7 @@
},
onAddAnotherConditionValue: function(index, segmentIndex, conditionIndex) {
this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.push({key: "", probability: 0});
this.calculateConditionProbabilities(index, segmentIndex, conditionIndex);
},
onRemoveConditionValue: function(index, segmentIndex, valueIndex, conditionIndex) {
try {
Expand All @@ -630,6 +663,7 @@
}
else {
this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.splice(valueIndex, 1);
this.calculateConditionProbabilities(index, segmentIndex, conditionIndex);
}
}
catch (error) {
Expand All @@ -648,6 +682,30 @@
if (item) {
this.conditionPropertyValues = item.values.map(valueItem => valueItem.key || null);
}
},
calculateSegmentProbabilities: function(index, segmentIndex) {
if (this.events[index].segmentations[segmentIndex].isProbabilitiesEqual) {
var valueCount = Object.keys(this.events[index].segmentations[segmentIndex].values).length,
equalProbability = 100 / valueCount;
const updatedValues = this.events[index].segmentations[segmentIndex].values.map(item => ({
...item,
probability: equalProbability // Set the new probability value
}));
this.events[index].segmentations[segmentIndex].values = updatedValues;
this.events[index].segmentations[segmentIndex].probabilitySum = equalProbability * valueCount;
}
},
calculateConditionProbabilities: function(index, segmentIndex, conditionIndex) {
if (this.events[index].segmentations[segmentIndex].conditions[conditionIndex].isProbabilitiesEqual) {
var valueCount = Object.keys(this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values).length,
equalProbability = 100 / valueCount;
const updatedValues = this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.map(item => ({
...item,
probability: equalProbability // Set the new probability value
}));
this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values = updatedValues;
this.events[index].segmentations[segmentIndex].conditions[conditionIndex].probabilitySum = equalProbability * valueCount;
}
}
},
created() {
Expand Down
14 changes: 10 additions & 4 deletions plugins/populator/frontend/public/templates/sections/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@
</div>
<div>
<div>
<span class="text-smallish bu-has-text-weight-medium">{{i18n('populator-template.probability')}}</span>
<span class="text-smallish bu-has-text-weight-medium">
<el-switch v-model="segment.isProbabilitiesEqual" class="bu-mr-2" @change="calculateSegmentProbabilities(index)"></el-switch>
{{i18n('populator-template.probability')}}
</span>
<cly-tooltip-icon :tooltip="i18n('populator-template.probability-tooltip')" icon="ion ion-help-circled"></cly-tooltip-icon>
</div>
<div v-for="(value, valueIndex) in segment.values">
<div class="bu-is-flex">
<div class="bu-mt-2">
<validation-provider name="probability" rules="required|integer|min_value:0|max_value:100" v-slot="v">
<el-input class="input" v-model="value.probability" :class="{'is-error': v.errors.length > 0}">
<el-input class="input" v-model="value.probability" :class="{'is-error': v.errors.length > 0}" :disabled="!!segment.isProbabilitiesEqual">
<template slot="suffix">
<span class="text-medium color-cool-gray-50">%</span>
</template>
Expand Down Expand Up @@ -109,14 +112,17 @@
</div>
<div>
<div>
<span class="text-smallish bu-has-text-weight-medium">{{i18n('populator-template.probability')}}</span>
<span class="text-smallish bu-has-text-weight-medium">
<el-switch v-model="condition.isProbabilitiesEqual" class="bu-mr-2" @change="calculateConditionProbabilities(index, conditionIndex)"></el-switch>
{{i18n('populator-template.probability')}}
</span>
<cly-tooltip-icon :tooltip="i18n('populator-template.probability-tooltip')" icon="ion ion-help-circled"></cly-tooltip-icon>
</div>
<div>
<div class="bu-is-flex" v-for="(segmentValue, segmentValueIndex) in condition.values">
<div class="bu-mt-2">
<validation-provider name="probability" rules="required|integer|min_value:0|max_value:100" v-slot="v">
<el-input class="input" v-model="segmentValue.probability" :class="{'is-error': v.errors.length > 0}">
<el-input class="input" v-model="segmentValue.probability" :class="{'is-error': v.errors.length > 0}" :disabled="!!condition.isProbabilitiesEqual">
<template slot="suffix">
<span class="text-medium color-cool-gray-50">%</span>
</template>
Expand Down
14 changes: 10 additions & 4 deletions plugins/populator/frontend/public/templates/sections/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
</div>
<div>
<div>
<span class="text-smallish bu-has-text-weight-medium">{{i18n('populator-template.probability')}}</span>
<span class="text-smallish bu-has-text-weight-medium">
<el-switch v-model="user.isProbabilitiesEqual" class="bu-mr-2" @change="calculatePropertyProbabilities(index)"></el-switch>
{{i18n('populator-template.probability')}}
</span>
<cly-tooltip-icon :tooltip="i18n('populator-template.probability-tooltip')" icon="ion ion-help-circled"></cly-tooltip-icon>
</div>
<div>
<div class="bu-is-flex" v-for="(value, valueIndex) in user.values">
<div class="bu-mt-2">
<validation-provider name="probability" v-slot="v" rules="required|integer|min_value:0|max_value:100">
<el-input class="input" v-model="value.probability" :class="{'is-error': v.errors.length > 0}">
<el-input class="input" v-model="value.probability" :class="{'is-error': v.errors.length > 0}" :disabled="!!user.isProbabilitiesEqual">
<template slot="suffix">
<span class="text-medium color-cool-gray-50">%</span>
</template>
Expand Down Expand Up @@ -66,14 +69,17 @@
</div>
<div>
<div>
<span class="text-smallish bu-has-text-weight-medium">{{i18n('populator-template.probability')}}</span>
<span class="text-smallish bu-has-text-weight-medium">
<el-switch v-model="condition.isProbabilitiesEqual" class="bu-mr-2" @change="calculateConditionProbabilities(index, conditionIndex)"></el-switch>
{{i18n('populator-template.probability')}}
</span>
<cly-tooltip-icon :tooltip="i18n('populator-template.probability-tooltip')" icon="ion ion-help-circled"></cly-tooltip-icon>
</div>
<div>
<div class="bu-is-flex" v-for="(value, valueIndex) in condition.values">
<div class="bu-mt-2">
<validation-provider name="probability" v-slot="v" rules="required|integer|min_value:0|max_value:100">
<el-input class="input" v-model="value.probability" :class="{'is-error': v.errors.length > 0}">
<el-input class="input" v-model="value.probability" :class="{'is-error': v.errors.length > 0}" :disabled="!!condition.isProbabilitiesEqual">
<template slot="suffix">
<span class="text-medium color-cool-gray-50">%</span>
</template>
Expand Down
Loading