Created
October 27, 2022 23:01
-
-
Save arafattehsin/d85bfb1f580bf9a3de23691f71dfc550 to your computer and use it in GitHub Desktop.
This is a sample User Simulator class for Azure Personalizer
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Simulator | |
{ | |
public class UserSimulator | |
{ | |
Random randomIndex; | |
string[] possibleActionIds = new string[] { "chocolate_cake", "banoffee_pie", "the_original", "fruit_trifle", "mango_delight", "nutella_cupcake", "vanilla_cupcake" }; | |
private new Dictionary<string, string> responses = new Dictionary<string, string>(); | |
public UserSimulator(Random rand) | |
{ | |
randomIndex = rand; | |
InitializeResponses(); | |
} | |
public void InitializeResponses() | |
{ | |
AddSimulatedResponse("birthday", "cake", "chocolate_cake"); | |
AddSimulatedResponse("birthday", "dessert", "fruit_trifle"); | |
AddSimulatedResponse("birthday", "cupcake", "vanilla_cupcake"); | |
AddSimulatedResponse("birthday", "shake", "mango_delight"); | |
AddSimulatedResponse("meal", "cake", "chocolate_cake"); | |
AddSimulatedResponse("meal", "dessert", "banoffee_pie"); | |
AddSimulatedResponse("meal", "cupcake", "nutella_cupcake"); | |
AddSimulatedResponse("meal", "shake", "the_original"); | |
AddSimulatedResponse("catchup", "cake", "chocolate_cake"); | |
AddSimulatedResponse("catchup", "dessert", "fruit_trifle"); | |
AddSimulatedResponse("catchup", "cupcake", "nutella_cupcake"); | |
AddSimulatedResponse("catchup", "shake", "the_original"); | |
} | |
public string ReturnSimulatedAction(IList<object> context) | |
{ | |
return GetResponse((Dictionary<string,string>)context[0]); | |
} | |
public string GetResponse(Dictionary<string,string> ctx) | |
{ | |
string key = GetKey(ctx); | |
if (responses.ContainsKey(key)) | |
{ | |
return responses[key]; | |
} | |
else | |
{ | |
return GetRandomResponse(); | |
} | |
} | |
public string GetRandomResponse() | |
{ | |
return possibleActionIds[randomIndex.Next(possibleActionIds.Length)]; | |
} | |
public void AddSimulatedResponse(string occassion, string variety, string foodChoice) | |
{ | |
responses.Add(GetKey(occassion, variety), foodChoice); | |
} | |
public string GetKey(string occassion, string variety) | |
{ | |
return occassion + "_" + variety; | |
} | |
public string GetKey(Dictionary<string,string> ctx) | |
{ | |
return GetKey(ctx["occassion"], ctx["variety"]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment