protected static void WriteRareEventExpressionInfo(BiasingParameters parameters, StringBuilder builder)
 {
     builder.AppendLine("        \"EXPRESSION\" : {");
     builder.AppendFormat("            \"LOCALE\" : \"{0}\",", parameters.RareEvent.ExpressionLocale).AppendLine();
     builder.AppendFormat("            \"NAME\" : \"{0}\"", parameters.RareEvent.ExpressionName).AppendLine();
     builder.AppendLine("        },");
 }
 public static void WriteParametersToJsonFile(BiasingParameters parameters, string jsonFilename)
 {
     using (TextWriter writer = new StreamWriter(jsonFilename))
     {
         string serializedParameters = StringFromParameters(parameters);
         writer.Write(serializedParameters);
     }
 }
 protected static void WriteRareEventSpec(BiasingParameters parameters, StringBuilder builder)
 {
     builder.AppendLine("    \"RARE_EVENT\" : {");
     WriteRareEventExpressionInfo(parameters, builder);
     builder.AppendFormat("        \"IRE_COUNT\" : {0},", parameters.RareEvent.IntermediateRareEventCount).AppendLine();
     builder.AppendLine("        \"THRESHOLDS\" :");
     WriteRareEventThresholds(parameters, builder);
     builder.AppendLine("    },");
 }
示例#4
0
        protected static void ReadLocalesArray(JObject root, ref BiasingParameters parameters)
        {
            var locales = (JArray)root["LOCALES"];

            foreach (JToken token in locales)
            {
                var locale     = (JObject)token;
                var localeInfo = ReadLocaleInformation(locale, parameters);
                parameters.Locales.Add(localeInfo);
            }
        }
        protected static string StringFromParameters(BiasingParameters parameters)
        {
            var builder = new StringBuilder();

            builder.AppendLine("{");
            WriteRareEventSpec(parameters, builder);
            WriteLocalesArray(parameters, builder);
            builder.AppendLine("}");

            return(builder.ToString());
        }
        protected static void WriteRareEventThresholds(BiasingParameters parameters, StringBuilder builder)
        {
            builder.Append("            [ ");
            int count = 0;

            foreach (var value in parameters.RareEvent.Thresholds)
            {
                builder.Append(value);
                if (++count < parameters.RareEvent.IntermediateRareEventCount)
                {
                    builder.Append(", ");
                }
            }
            builder.AppendLine(" ]");
        }
        protected static void WriteLocalesArray(BiasingParameters parameters, StringBuilder builder)
        {
            builder.AppendLine("    \"LOCALES\" : [");
            int count = 0;

            foreach (var locale in parameters.Locales)
            {
                WriteLocaleInformation(locale, builder);
                if (++count < parameters.Locales.Count)
                {
                    builder.AppendLine(",");
                }
                else
                {
                    builder.AppendLine();
                }
            }
            builder.AppendLine("    ]");
        }
示例#8
0
        protected static BiasingParameters ParametersFromString(string serializedParameters)
        {
            var     parameters = new BiasingParameters();
            JObject root;

            try
            {
                root = (JObject)JsonConvert.DeserializeObject(serializedParameters);
            }
            catch (JsonReaderException jre)
            {
                Console.Error.WriteLine("Error parsing JSON data: '{0}'", jre.Message);
                throw new ArgumentException("Error parsing JSON data.", jre);
            }

            ReadRareEventSpec(root, ref parameters);
            ReadLocalesArray(root, ref parameters);

            return(parameters);
        }
示例#9
0
        protected static void ReadRareEventSpec(JObject root, ref BiasingParameters parameters)
        {
            JToken rareEventSpecToken = root["RARE_EVENT"];
            var    rareEventSpec      = rareEventSpecToken as JObject;

            if (rareEventSpec == null)
            {
                throw new MissingRareEventSpecificationException("JSON data doesn't contain correct 'RARE_EVENT' section.");
            }
            var rareEventExpressionInfo = rareEventSpec["EXPRESSION"] as JObject;

            if (rareEventExpressionInfo == null)
            {
                throw new ExpressionSpecificationException("JSON data doesn't contain correct 'EXPRESSION' section.");
            }
            ReadRareEventExpressionInfo(rareEventExpressionInfo, ref parameters);
            var intermediateRareEventCount = (int)rareEventSpec["IRE_COUNT"];
            var thresholds = (JArray)rareEventSpec["THRESHOLDS"];

            for (int i = 0; i < intermediateRareEventCount; i++)
            {
                parameters.RareEvent.Thresholds.Add((float)thresholds[i]);
            }
        }
示例#10
0
        protected static BiasingParameters.LocaleInfo ReadLocaleInformation(JObject locale, BiasingParameters parameters)
        {
            var localeInfo = new BiasingParameters.LocaleInfo {
                Name = (string)locale["NAME"]
            };
            var reactionCount = (int)locale["REACTION_COUNT"];
            var reactions     = (JArray)locale["REACTIONS"];

            if (reactionCount != reactions.Count)
            {
                throw new ReactionArrayCountException(string.Format("JSON data for locale '{0}' invalid, REACTION_COUNT doesn't match REACTION array size.", localeInfo.Name), localeInfo.Name);
            }
            foreach (JToken token in reactions)
            {
                var reaction     = (JObject)token;
                var reactionInfo = ReadReactionInformation(reaction, parameters.RareEvent.IntermediateRareEventCount);
                localeInfo.Reactions.Add(reactionInfo);
            }

            return(localeInfo);
        }
示例#11
0
 protected static void ReadRareEventExpressionInfo(JObject rareEventExpressionInfo, ref BiasingParameters parameters)
 {
     parameters.RareEvent.ExpressionLocale = (string)rareEventExpressionInfo["LOCALE"];
     parameters.RareEvent.ExpressionName   = (string)rareEventExpressionInfo["NAME"];
 }