Exemplo n.º 1
0
        private string HandlePredictCommand(PredictOption opts)
        {
            JObject       currencies    = _reader.ReadCurrencies();
            StringBuilder stringBuilder = new StringBuilder();

            if (!currencies.ContainsKey(opts.From))
            {
                stringBuilder.AppendLine($"Currency code {opts.From} is invalid.");
            }

            if (!currencies.ContainsKey(opts.To))
            {
                stringBuilder.AppendLine($"Currency code {opts.To} is invalid.");
            }

            if (stringBuilder.Length > 0)
            {
                throw new ArgumentException(stringBuilder.ToString());
            }

            PredictorOption option = new PredictorOption
            {
                FromDate     = DateTime.ParseExact("15/01/2016", "dd/MM/yyyy", CultureInfo.InvariantCulture),
                ToDate       = DateTime.ParseExact("15/12/2016", "dd/MM/yyyy", CultureInfo.InvariantCulture),
                PredictDate  = DateTime.ParseExact("15/01/2017", "dd/MM/yyyy", CultureInfo.InvariantCulture),
                FromCurrency = opts.From,
                ToCurrency   = opts.To
            };

            decimal rate = _predictor.Predict(option);

            string result = $"The predicted currency exchange from {opts.From} to {opts.To} for 15/1/2017 is {rate}";

            return(result);
        }