Skip to content

Commit

Permalink
feat: Added support for perosnlaize in MEG
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamg1304 authored and Varun Malhotra committed Sep 27, 2024
1 parent f1b0798 commit 653744e
Show file tree
Hide file tree
Showing 15 changed files with 453 additions and 256 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] - 2024-09-27

### Added

- Feat: added support for Personalise rules within `Mutually Exclusive Groups`.

## [1.1.0] - 2024-08-14

Expand Down
12 changes: 6 additions & 6 deletions VWOFmeSdk.NetStandard2.0/VWOFmeSdk.NetStandard2.0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyName>VWOFmeSdk</AssemblyName>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>VWO.FME.Sdk</PackageId>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
<Authors>VWO devs</Authors>
<Company>Wingify</Company>
<Product>VWO</Product>
Expand Down Expand Up @@ -166,19 +166,19 @@
</ItemGroup>

<ItemGroup>
<None Update="Packages/Logger/Messages/debug-messages.json">
<None Update="..\VWOFmeSdk\Packages\Logger\Messages\debug-messages.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Packages/Logger/Messages/info-messages.json">
<None Update="..\VWOFmeSdk\Packages\Logger\Messages\info-messages.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Packages/Logger/Messages/error-messages.json">
<None Update="..\VWOFmeSdk\Packages\Logger\Messages\error-messages.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Packages/Logger/Messages/warn-messages.json">
<None Update="..\VWOFmeSdk\Packages\Logger\Messages\warn-messages.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Packages/Logger/Messages/trace-messages.json">
<None Update="..\VWOFmeSdk\Packages\Logger\Messages\trace-messages.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions VWOFmeSdk/Api/GetFlagApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static GetFlag GetFlag(string featureKey, Settings settings, VWOContext c
List<Campaign> rolloutRulesToEvaluate = new List<Campaign>();
foreach (var rule in rollOutRules)
{
Dictionary<string, object> evaluateRuleResult = RuleEvaluationUtil.EvaluateRule(settings, feature, rule, context, evaluatedFeatureMap, new Dictionary<int, int>(), storageService, decision);
Dictionary<string, object> evaluateRuleResult = RuleEvaluationUtil.EvaluateRule(settings, feature, rule, context, evaluatedFeatureMap, new Dictionary<int, string>(), storageService, decision);
bool preSegmentationResult = (bool)evaluateRuleResult["preSegmentationResult"];
if (preSegmentationResult)
{
Expand Down Expand Up @@ -183,7 +183,7 @@ public static GetFlag GetFlag(string featureKey, Settings settings, VWOContext c
{
List<Campaign> experimentRulesToEvaluate = new List<Campaign>();
List<Campaign> experimentRules = GetAllExperimentRules(feature);
Dictionary<int, int> megGroupWinnerCampaigns = new Dictionary<int, int>();
Dictionary<int, string> megGroupWinnerCampaigns = new Dictionary<int, string>();

foreach (var rule in experimentRules)
{
Expand Down
4 changes: 2 additions & 2 deletions VWOFmeSdk/Api/SetAttributeApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ namespace VWOFmeSdk.Api
{
public class SetAttributeAPI
{
public static void SetAttribute(Settings settings, string attributeKey, string attributeValue, VWOContext context)
public static void SetAttribute(Settings settings, string attributeKey, object attributeValue, VWOContext context)
{
CreateAndSendImpressionForSetAttribute(settings, attributeKey, attributeValue, context);
}

private static void CreateAndSendImpressionForSetAttribute(
Settings settings,
string attributeKey,
string attributeValue,
object attributeValue,
VWOContext context
)
{
Expand Down
2 changes: 2 additions & 0 deletions VWOFmeSdk/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ public static class Constants
public const string HTTPS_PROTOCOL = "https";

public const int RANDOM_ALGO = 1;

public const string VWO_META_MEG_KEY = "_vwo_meta_meg_";
}
}
28 changes: 19 additions & 9 deletions VWOFmeSdk/Models/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,52 @@

using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace VWOFmeSdk.Models
{
public class Groups
{
private string name;
private List<int> campaigns;
private int et;
private List<int> p;
private Dictionary<string, int> wt;
private List<string> campaigns;
private int? et;
private List<string> p = new List<string>();
private Dictionary<string, double> wt = new Dictionary<string, double>();

[JsonProperty("name")]
public string Name
{
get { return name; }
set { name = value; }
}

public List<int> Campaigns
[JsonProperty("campaigns")]
public List<string> Campaigns
{
get { return campaigns; }
set { campaigns = value; }
}

public int Et
[JsonProperty("et")]
public int? Et
{
get { return et; }
get
{
// set default to random
return et ?? 1;
}
set { et = value; }
}

public List<int> P
[JsonProperty("p")]
public List<string> P
{
get { return p; }
set { p = value; }
}

public Dictionary<string, int> Wt
[JsonProperty("wt")]
public Dictionary<string, double> Wt
{
get { return wt; }
set { wt = value; }
Expand Down
9 changes: 8 additions & 1 deletion VWOFmeSdk/Models/Variation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Variation
private List<Variation> variations = new List<Variation>();
private Dictionary<string, object> segments = new Dictionary<string, object>();
private string ruleKey;
private string type;

public int Id
{
Expand Down Expand Up @@ -93,5 +94,11 @@ public string RuleKey
get { return ruleKey; }
set { ruleKey = value; }
}

public string Type
{
get { return type; }
set { type = value; }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public bool EvaluateCustomVariableDSL(JToken dslOperandValue, Dictionary<string,

if (operandValue.Contains("inlist"))
{
var listIdPattern = new Regex("inlist\\((\\w+:\\d+)\\)");
var listIdPattern = new Regex("inlist\\(([^)]+)\\)");
var matcher = listIdPattern.Match(operandValue);
if (!matcher.Success)
{
Expand Down
28 changes: 22 additions & 6 deletions VWOFmeSdk/Services/CampaignDecisionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ public bool IsUserPartOfCampaign(string userId, Campaign campaign)
LoggerService.Log(LogLevelEnum.INFO, "USER_PART_OF_CAMPAIGN", new Dictionary<string, string>
{
{"userId", userId},
{"campaignKey", campaign.RuleKey},
{"notPart", isUserPart ? "" : "not"}
{"notPart", isUserPart ? "" : "not"},
{ "campaignKey",
campaign.Type == CampaignTypeEnum.AB.GetValue()
? campaign.Key
: campaign.Name + "_" + campaign.RuleKey
},
});

return isUserPart;
Expand Down Expand Up @@ -118,7 +122,11 @@ public Variation BucketUserToVariation(string userId, string accountId, Campaign
LoggerService.Log(LogLevelEnum.DEBUG, "USER_BUCKET_TO_VARIATION", new Dictionary<string, string>
{
{"userId", userId},
{"campaignKey", campaign.RuleKey},
{ "campaignKey",
campaign.Type == CampaignTypeEnum.AB.GetValue()
? campaign.Key
: campaign.Name + "_" + campaign.RuleKey
},
{"percentTraffic", percentTraffic.ToString()},
{"bucketValue", bucketValue.ToString()},
{"hashValue", hashValue.ToString()}
Expand Down Expand Up @@ -155,7 +163,11 @@ public bool GetPreSegmentationDecision(Campaign campaign, VWOContext context)
LoggerService.Log(LogLevelEnum.INFO, "SEGMENTATION_SKIP", new Dictionary<string, string>
{
{"userId", context.Id},
{"campaignKey", campaign.RuleKey}
{ "campaignKey",
campaign.Type == CampaignTypeEnum.AB.GetValue()
? campaign.Key
: campaign.Name + "_" + campaign.RuleKey
}
});
return true;
}
Expand All @@ -165,7 +177,11 @@ public bool GetPreSegmentationDecision(Campaign campaign, VWOContext context)
LoggerService.Log(LogLevelEnum.INFO, "SEGMENTATION_STATUS", new Dictionary<string, string>
{
{"userId", context.Id},
{"campaignKey", campaign.RuleKey},
{ "campaignKey",
campaign.Type == CampaignTypeEnum.AB.GetValue()
? campaign.Key
: campaign.Name + "_" + campaign.RuleKey
},
{"status", preSegmentationResult ? "passed" : "failed"}
});
return preSegmentationResult;
Expand All @@ -192,4 +208,4 @@ public Variation GetVariationAllotted(string userId, string accountId, Campaign
}
}
}
}
}
7 changes: 1 addition & 6 deletions VWOFmeSdk/Services/LoggerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public LoggerService(Dictionary<string, object> config)
// Read the log files from the specific directory
string messagesDirectory = Path.Combine(AppContext.BaseDirectory, "Packages", "Logger", "Messages");

if (!Directory.Exists(messagesDirectory))
{
Console.WriteLine("Directory does not exist.");
}

DebugMessages = ReadLogFiles(Path.Combine(messagesDirectory, "debug-messages.json"));
InfoMessages = ReadLogFiles(Path.Combine(messagesDirectory, "info-messages.json"));
ErrorMessages = ReadLogFiles(Path.Combine(messagesDirectory, "error-messages.json"));
Expand All @@ -65,7 +60,7 @@ private Dictionary<string, string> ReadLogFiles(string filePath)
}
catch (Exception ex)
{
Console.WriteLine($"Could not read log file {filePath}: {ex.Message}");
//Console.WriteLine($"Could not read log file {filePath}: {ex.Message}");
return new Dictionary<string, string>();
}
}
Expand Down
Loading

0 comments on commit 653744e

Please sign in to comment.