|
571 | 571 | onAddEventSegmentation: function(index) { |
572 | 572 | this.events[index].segmentations.push({ |
573 | 573 | "key": "", |
574 | | - "values": [{key: "", probability: 0}], |
| 574 | + "values": [{key: "", probability: 100}], |
| 575 | + "isProbabilitiesEqual": true, |
575 | 576 | }); |
576 | 577 | }, |
577 | 578 | checkRemoveValue: function(key, value, index) { |
|
628 | 629 | return; |
629 | 630 | } |
630 | 631 | this.events[index].segmentations[segmentIndex].values.splice(valueIndex, 1); |
| 632 | + this.calculateSegmentProbabilities(index, segmentIndex); |
631 | 633 | } |
632 | 634 | catch (error) { |
633 | 635 | CountlyHelpers.notify({ |
|
640 | 642 | onAddAnotherValue: function(index, segmentIndex) { |
641 | 643 | try { |
642 | 644 | this.events[index].segmentations[segmentIndex].values.push({key: "", probability: 0}); |
| 645 | + this.calculateSegmentProbabilities(index, segmentIndex); |
643 | 646 | } |
644 | 647 | catch (error) { |
645 | 648 | CountlyHelpers.notify({ |
|
651 | 654 | }, |
652 | 655 | onAddAnotherConditionValue: function(index, segmentIndex, conditionIndex) { |
653 | 656 | this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.push({key: "", probability: 0}); |
| 657 | + this.calculateConditionProbabilities(index, segmentIndex, conditionIndex); |
654 | 658 | }, |
655 | 659 | onRemoveConditionValue: function(index, segmentIndex, valueIndex, conditionIndex) { |
656 | 660 | try { |
|
659 | 663 | } |
660 | 664 | else { |
661 | 665 | this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.splice(valueIndex, 1); |
| 666 | + this.calculateConditionProbabilities(index, segmentIndex, conditionIndex); |
662 | 667 | } |
663 | 668 | } |
664 | 669 | catch (error) { |
|
677 | 682 | if (item) { |
678 | 683 | this.conditionPropertyValues = item.values.map(valueItem => valueItem.key || null); |
679 | 684 | } |
| 685 | + }, |
| 686 | + calculateSegmentProbabilities: function(index, segmentIndex) { |
| 687 | + if (this.events[index].segmentations[segmentIndex].isProbabilitiesEqual) { |
| 688 | + var valueCount = Object.keys(this.events[index].segmentations[segmentIndex].values).length, |
| 689 | + equalProbability = 100 / valueCount; |
| 690 | + const updatedValues = this.events[index].segmentations[segmentIndex].values.map(item => ({ |
| 691 | + ...item, |
| 692 | + probability: equalProbability // Set the new probability value |
| 693 | + })); |
| 694 | + this.events[index].segmentations[segmentIndex].values = updatedValues; |
| 695 | + this.events[index].segmentations[segmentIndex].probabilitySum = equalProbability * valueCount; |
| 696 | + } |
| 697 | + }, |
| 698 | + calculateConditionProbabilities: function(index, segmentIndex, conditionIndex) { |
| 699 | + if (this.events[index].segmentations[segmentIndex].conditions[conditionIndex].isProbabilitiesEqual) { |
| 700 | + var valueCount = Object.keys(this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values).length, |
| 701 | + equalProbability = 100 / valueCount; |
| 702 | + const updatedValues = this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values.map(item => ({ |
| 703 | + ...item, |
| 704 | + probability: equalProbability // Set the new probability value |
| 705 | + })); |
| 706 | + this.events[index].segmentations[segmentIndex].conditions[conditionIndex].values = updatedValues; |
| 707 | + this.events[index].segmentations[segmentIndex].conditions[conditionIndex].probabilitySum = equalProbability * valueCount; |
| 708 | + } |
680 | 709 | } |
681 | 710 | }, |
682 | 711 | created() { |
|
0 commit comments