Ejemplo n.º 1
0
        /// <summary>
        /// Delete a trained model.
        /// Documentation https://developers.google.com/prediction/v1.6/reference/trainedmodels/delete
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Prediction service.</param>
        /// <param name="project">The project associated with the model.</param>
        /// <param name="id">The unique name for the predictive model.</param>
        public static void Delete(PredictionService service, string project, string id)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (id == null)
                {
                    throw new ArgumentNullException(id);
                }

                // Make the request.
                service.Trainedmodels.Delete(project, id).Execute();
            }
            catch (Exception ex)
            {
                throw new Exception("Request Trainedmodels.Delete failed.", ex);
            }
        }
        private async void Save()
        {
            try
            {
                DialogService.ShowLoading("Saving...");
                var result = await PredictionService.SavePredictionAsync(new SavePredictionModel()
                {
                    PredictionId   = Prediction.PredictionId,
                    WeekId         = Prediction.WeekId,
                    GameId         = Prediction.GameId,
                    AwayPrediction = AwayPredictedScore.AsInt(0),
                    HomePrediction = HomePredictedScore.AsInt(0)
                });

                if (result != null && Prediction != null)
                {
                    MessageBus.Publish(new RefreshPredictionsMessage(result.PredictionId,
                                                                     Prediction.HomeTeam, Prediction.AwayTeam,
                                                                     AwayPredictedScore.AsInt(0), HomePredictedScore.AsInt(0)));
                    await Navigation.PopModalAsync(true);
                }
            }
            catch (Exception ex)
            {
                DialogService.Alert("Failed to save Prediction");
            }
            finally
            {
                DialogService.HideLoading();
            }
        }
        private async Task LoadPredictionsAsync()
        {
            _predictions = await PredictionService.GetCurrentWeekPredictions();

            OnPropertyChanged(nameof(PredictionGroups));
            OnPropertyChanged(nameof(NoGames));
        }
        /// <summary>
        /// Submit input and request an output against a hosted model.
        /// Documentation https://developers.google.com/prediction/v1.6/reference/hostedmodels/predict
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Prediction service.</param>
        /// <param name="project">The project associated with the model.</param>
        /// <param name="hostedModelName">The name of a hosted model.</param>
        /// <param name="body">A valid Prediction v1.6 body.</param>
        /// <returns>OutputResponse</returns>
        public static Output Predict(PredictionService service, string project, string hostedModelName, Input body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (hostedModelName == null)
                {
                    throw new ArgumentNullException(hostedModelName);
                }

                // Make the request.
                return(service.Hostedmodels.Predict(body, project, hostedModelName).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Hostedmodels.Predict failed.", ex);
            }
        }
        public double getForecastCow(int idCow)
        {
            predictionService = new PredictionService();
            double forecastValue = predictionService.ForecastYieldCow(idCow);

            return(forecastValue);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Begin training your model
        /// Documentation https://developers.google.com/prediction/v1.2/reference/training/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Prediction service.</param>
        /// <param name="body">A valid Prediction v1.2 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>TrainingResponse</returns>
        public static Training Insert(PredictionService service, Training body, TrainingInsertOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }

                // Building the initial request.
                var request = service.Training.Insert(body);

                // Applying optional parameters to the request.
                request = (TrainingResource.InsertRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Training.Insert failed.", ex);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add new data to a trained model
        /// Documentation https://developers.google.com/prediction/v1.2/reference/training/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Prediction service.</param>
        /// <param name="data">mybucket/mydata resource in Google Storage</param>
        /// <param name="body">A valid Prediction v1.2 body.</param>
        /// <returns>TrainingResponse</returns>
        public static Training Update(PredictionService service, string data, Update body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (data == null)
                {
                    throw new ArgumentNullException(data);
                }

                // Make the request.
                return(service.Training.Update(body, data).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Training.Update failed.", ex);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add new data to a trained model.
        /// Documentation https://developers.google.com/prediction/v1.6/reference/trainedmodels/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Prediction service.</param>
        /// <param name="project">The project associated with the model.</param>
        /// <param name="id">The unique name for the predictive model.</param>
        /// <param name="body">A valid Prediction v1.6 body.</param>
        /// <returns>Insert2Response</returns>
        public static Insert2 Update(PredictionService service, string project, string id, Update body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (id == null)
                {
                    throw new ArgumentNullException(id);
                }

                // Make the request.
                return(service.Trainedmodels.Update(body, project, id).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Trainedmodels.Update failed.", ex);
            }
        }
Ejemplo n.º 9
0
        public void WhenRunWithAllPossibleMapping_ShouldHavePredictResult()
        {
            var scores = new Score[]
            {
                Score.Dragon,
                Score.Dragon,
                Score.Dragon,
                Score.Tiger,
                Score.Dragon,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Dragon,
                Score.Tiger,
                //Score.Tiger,
            };

            var predictors = new IPredictor[]
            {
                new SameDifferentPredictor(),
                new Anti12Predictor(),
                new Anti2Predictor()
            };

            var resultPredictor = new DummyPredictor();

            var predictService = new PredictionService(predictors, resultPredictor);
            var tableSize      = 8;
            var result         = predictService.Predict(scores.Select(x => new GameStateInput(x, None)), tableSize, 15)
                                 .GameStatesWithScorePrediction
                                 .ToList();

            Assert.AreEqual((int)Math.Pow(2, tableSize), result.Count());
            Assert.AreEqual(scores.Count() + 1, result.First().GameStates.Count());
        }
        public void MakePredictionFromSample_NullArgument_ThrowArgumentException()
        {
            var predictionService = new PredictionService(_openExchangeClient.Object, _cache.Object);

            Assert.Throws <ArgumentException>(() =>
                                              predictionService.MakePredictionFromSample("USD", "VND", DateTime.Today, null));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// List available models.
        /// Documentation https://developers.google.com/prediction/v1.6/reference/trainedmodels/list
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Prediction service.</param>
        /// <param name="project">The project associated with the model.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>ListResponse</returns>
        public static List List(PredictionService service, string project, TrainedmodelsListOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }

                // Building the initial request.
                var request = service.Trainedmodels.List(project);

                // Applying optional parameters to the request.
                request = (TrainedmodelsResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Trainedmodels.List failed.", ex);
            }
        }
 public GetExpertStatsHandler(PredictionsContext context, IMapper mapper)
 {
     _context           = context;
     _mapper            = mapper;
     _statService       = new StatService();
     _predictionService = new PredictionService();
 }
        /// <summary>
        /// Submit model id and request a prediction.
        /// Documentation https://developers.google.com/prediction/v1.5/reference/trainedmodels/predict
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Prediction service.</param>
        /// <param name="id">The unique name for the predictive model.</param>
        /// <param name="body">A valid Prediction v1.5 body.</param>
        /// <returns>OutputResponse</returns>
        public static Output Predict(PredictionService service, string id, Input body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (id == null)
                {
                    throw new ArgumentNullException(id);
                }

                // Make the request.
                return(service.Trainedmodels.Predict(body, id).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Trainedmodels.Predict failed.", ex);
            }
        }
Ejemplo n.º 14
0
 public PredictionsController()
 {
     _context           = new PredictionsContext();
     _expertService     = new ExpertService(_context);
     _tourService       = new TourService(_context);
     _predictionService = new PredictionService(_context);
     _matchService      = new MatchService(_context);
 }
        public void GetAmlPredictions_case1()
        {
            var storedDemand         = DataSource.GetSalesHistory();
            var singleProductHistory = storedDemand.Where(d => d.Plu == 2480).Take(10).ToArray();
            var predictionService    = new PredictionService(MlSettings.Endpoint, MlSettings.Key);

            var actual = predictionService.GetAmlPredictions(singleProductHistory).Result;
        }
Ejemplo n.º 16
0
 public PredictionGradeViewModel(Student s)
 {
     student        = s;
     PredictCommand = new Command(async() =>
     {
         var grade = await PredictionService.PredictGrade(student);
         G3        = grade;
     });
 }
Ejemplo n.º 17
0
        //public PredictionServiceTests()
        //{
        //    var predictionRepository = new Mock<IPredictionRepository>();
        //    predictionRepository.Setup(x => x.CheckTypeResult(It.IsAny<string>())).ReturnsAsync((string result) =>
        //   {
        //       if (Convert.ToInt32(result.Substring(0, 1)) > Convert.ToInt32(result.Substring(2, 1))) return TypeResult.WinTeam1;
        //       else if (Convert.ToInt32(result.Substring(0, 1)) < Convert.ToInt32(result.Substring(2, 1))) return TypeResult.WinTeam2;
        //       else if (Convert.ToInt32(result.Substring(0, 1)) == Convert.ToInt32(result.Substring(2, 1))) return TypeResult.Draw;
        //       else return TypeResult.NNB;
        //   });

        //    predictionRepository.Setup(x => x.CompareResultsAsync(It.IsAny<Game>(), It.IsAny<Prediction>())).ReturnsAsync((Game z, Prediction y) =>
        //   {
        //       if (y.PredictedResult == z.Result)
        //           return 3;
        //       else if (y.PredictedTypeResult == z.typeResult)
        //           return 1;
        //       else
        //           return 0;
        //   });
        //    _predictionService = new PredictionService(predictionRepository.Object);
        //}

        public async Task CreateDb()
        {
            var options = new DbContextOptionsBuilder <StrikeNetDbContext>()
                          .UseInMemoryDatabase(databaseName: "StrikeNetTestDb")
                          .EnableSensitiveDataLogging()
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var dbContext = new StrikeNetDbContext(options);

            if (await dbContext.Predictions.CountAsync() <= 0)
            {
                Prediction p1 = new Prediction()
                {
                    Id                  = 1,
                    GameId              = 1,
                    UserId              = User1,
                    PredictedResult     = "3-0",
                    PredictedTypeResult = TypeResult.WinTeam1
                };
                Prediction p2 = new Prediction()
                {
                    Id                  = 2,
                    GameId              = 3,
                    UserId              = User2,
                    PredictedResult     = "2-0",
                    PredictedTypeResult = TypeResult.WinTeam1
                };
                Prediction p3 = new Prediction()
                {
                    Id                  = 3,
                    GameId              = 3,
                    UserId              = User3,
                    PredictedResult     = "0-1",
                    PredictedTypeResult = TypeResult.WinTeam2
                };
                Prediction p4 = new Prediction()
                {
                    Id                  = 4,
                    GameId              = 4,
                    UserId              = User4,
                    PredictedResult     = "1-1",
                    PredictedTypeResult = TypeResult.Draw
                };
                dbContext.Predictions.Add(p1);
                dbContext.Predictions.Add(p2);
                dbContext.Predictions.Add(p3);
                dbContext.Predictions.Add(p4);
                await dbContext.SaveChangesAsync();
            }

            var identityRepository   = new IdentityRepository(_userManager, _roleManager, _signInManager);
            var predictionRepository = new PredictionRepository(identityRepository, dbContext);

            _predictionService2 = new PredictionService(predictionRepository);
        }
Ejemplo n.º 18
0
        async Task LoadPredictionHistoryAsync()
        {
            var predictions = await PredictionService.GetPredictionsForYearAsync(Year);

            Predictions = new ObservableCollection <SummaryPredictionGroup>(
                predictions.GroupBy(x => x.WeekNumber)
                .OrderBy(x => x.Key)
                .Select(x => new SummaryPredictionGroup(x.Key.ToString(), x.ToList()))
                );
        }
Ejemplo n.º 19
0
        private async Task EvaluateImage()
        {
            IsBusy = true;
            await Task.Run(() =>
            {
                PredictionDetailsViewModel.PredictionResult = PredictionService.Predict(PredictionDetailsViewModel.Path);
            });

            IsBusy = false;
        }
Ejemplo n.º 20
0
        public void WhenRunWithAllTiger_ShouldHave100PercentPredictResult()
        {
            var scores = new Score[]
            {
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger
            };

            var predictors = new IPredictor[]
            {
                new SameDifferentPredictor(),
                new Anti12Predictor(),
                new Anti2Predictor()
            };

            var resultPredictor = new DummyPredictor();

            var predictService = new PredictionService(predictors, resultPredictor);
            var mappingScores  = new Score[]
            {
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger
            };

            var gameStates = scores.Select(s => new GameStateInput(s, None));

            var result = predictService.PredictScore(gameStates, mappingScores)
                         .ToList();

            Assert.AreEqual(scores.Count() + 1, result.Count());

            var sdResult = result
                           .Select(r => r.ScorePredictions.Find(Constants.SameDiffPredictionName).Bind(p => p.Result))
                           .Where(r => r.IsSome)
                           .Map(r => r.IfNone(Result.Lose));

            var stat = StatService.Calculate(
                Constants.SameDiffPredictionName,
                sdResult);

            Assert.AreEqual(100, stat.WinRate);
        }
Ejemplo n.º 21
0
        public void WhenRunWithSpecificMapping_ShouldHavePredictResult()
        {
            var scores = new Score[]
            {
                Score.Dragon,
                Score.Dragon,
                Score.Dragon,
                Score.Tiger,
                Score.Dragon,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Dragon,
                Score.Tiger,
            };

            var predictors = new IPredictor[]
            {
                new SameDifferentPredictor(),
                new Anti12Predictor(),
                new Anti2Predictor()
            };

            var resultPredictor = new DummyPredictor();

            var predictService = new PredictionService(predictors, resultPredictor);
            var mappingScores  = new Score[]
            {
                Score.Tiger,
                Score.Dragon,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger,
                Score.Tiger
            };

            var gameStates = scores.Select(s => new GameStateInput(s, None));

            var result = predictService.PredictScore(gameStates, mappingScores)
                         .ToList();

            Assert.AreEqual(scores.Count() + 1, result.Count());

            var predictResult = result.Last();

            Assert.AreEqual(Score.Dragon, predictResult.ScorePredictions.Find(Constants.MappingTablePredctionName).Map(x => x.Score));
            Assert.AreEqual(Score.Dragon, predictResult.ScorePredictions.Find(Constants.SameDiffPredictionName).Map(x => x.Score));
            Assert.AreEqual(Score.Tiger, predictResult.ScorePredictions.Find(Constants.Anti12PredictionName).Map(x => x.Score));
            Assert.AreEqual(Score.Dragon, predictResult.ScorePredictions.Find(Constants.Anti2PredictionName).Map(x => x.Score));
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            var imgFile = @"C:\Users\ch489gt\Pictures\Snag-Auto\TestSnag.png";

            var predictService = new PredictionService();
            var predictRes     = predictService.Predict(imgFile);

            var ocrService = new OcrService();
            var ocrRes     = ocrService.DoOcr(imgFile);

            var analyzer = new VisionAnalyzer();
            var result   = analyzer.GetResult(imgFile, predictRes.Data);
        }
Ejemplo n.º 23
0
        //private readonly IMapper _mapper;

        public CurrentTournamentToursController(IPredictionsContext context, IMapper mapper)
        {
            _expertService     = new ExpertService(context);
            _tourService       = new TourService(context);
            _predictionService = new PredictionService(context);
            _matchService      = new MatchService(context, mapper);
            _teamService       = new TeamService(context);
            _tournamentService = new TournamentService(context);

            _context = context;

            // _mapper = mapper;

            _fileService = new FileService();
        }
 public async Task GetServiceAsync()
 {
     var trainingService = new PredictionService();
     var response        = await trainingService.PredictProfile(new UserInteraction()
     {
         Tier     = 2,
         Picture  = 1,
         Summary  = 1,
         Specs    = 1,
         Reviews  = 1,
         Comments = 1,
         Share    = 1,
         Buy      = 0,
         Related  = 0
     });
 }
        public void CreatePredictionService(string authJsonFile)
        {
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", authJsonFile);
            var credentials = Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync().Result;
            if (credentials.IsCreateScopedRequired)
            {
                credentials = credentials.CreateScoped(PredictionService.Scope.DevstorageFullControl, PredictionService.Scope.Prediction);
            }
            var serviceInitializer = new BaseClientService.Initializer()
            {
                ApplicationName = "Prediction Sample",
                HttpClientInitializer = credentials
            };

            PredictionService = new PredictionService(serviceInitializer);
        }
        public void MakePredictionFromSample_DoesNotHaveToCurrencyInSample_ThrowCurrencyNotFoundException()
        {
            var predictionService = new PredictionService(_openExchangeClient.Object, _cache.Object);

            Assert.Throws <CurrencyNotFoundException>(() =>
                                                      predictionService.MakePredictionFromSample("USD", "VND", new DateTime(2019, 12, 31),
                                                                                                 new List <OpenExchangeRateResult>
            {
                new OpenExchangeRateResult
                {
                    Base      = "USD",
                    Rates     = new Dictionary <string, double>(),
                    TimeStamp = 123234
                }
            }));
        }
Ejemplo n.º 27
0
        public void CreatePredictionService(string authJsonFile)
        {
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", authJsonFile);
            var credentials = Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync().Result;

            if (credentials.IsCreateScopedRequired)
            {
                credentials = credentials.CreateScoped(PredictionService.Scope.DevstorageFullControl, PredictionService.Scope.Prediction);
            }
            var serviceInitializer = new BaseClientService.Initializer()
            {
                ApplicationName       = "Prediction Sample",
                HttpClientInitializer = credentials
            };

            PredictionService = new PredictionService(serviceInitializer);
        }
Ejemplo n.º 28
0
        private async Task Predict()
        {
            Trip = new TaxiTrip()
            {
                FareAmount     = FareAmount,
                PassengerCount = PassengerCount,
                PaymentType    = PaymentType,
                RateCode       = RateCode,
                TripDistance   = TripDistance,
                TripTime       = TripTime,
                VendorId       = VendorId
            };

            var amount = await PredictionService.Predict(Trip);

            await App.Current.MainPage.DisplayAlert("Prediction", $"Trip Fare: {amount:C2}", "OK");
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            // Display the header and initialize the sample.
            CommandLine.EnableExceptionHandling();
            CommandLine.DisplayGoogleSampleHeader("Prediction API");

            CommandLine.WriteLine();

            // Register the authenticator.
            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
            provider.ClientIdentifier = ClientCredentials.ClientID;
            provider.ClientSecret = ClientCredentials.ClientSecret;
            var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);

            // Create the service.
            var service = new PredictionService(auth);
            RunPrediction(service);
            CommandLine.PressAnyKeyToExit();
        }
Ejemplo n.º 30
0
        private static void RunPrediction(PredictionService service)
        {
            // Make a prediction.
            CommandLine.WriteAction("Performing a prediction...");
            string text = "mucho bueno";

            CommandLine.RequestUserInput("Text to analyze", ref text);

            var input = new Input {
                InputValue = new Input.InputData {
                    CsvInstance = new List <string> {
                        text
                    }
                }
            };
            Output result = service.Hostedmodels.Predict(input, "sample.languageid").Fetch();

            CommandLine.WriteResult("Language", result.OutputLabel);
        }
        public void MakePredictionFromSample_HaveCorrectNoneUSDSample_ReturnCorrectResultFromConvertedRates()
        {
            var predictionService = new PredictionService(_openExchangeClient.Object, _cache.Object);

            var result = predictionService.MakePredictionFromSample("CNY", "VND",
                                                                    DateTimeOffset.FromUnixTimeSeconds(40).UtcDateTime,
                                                                    new List <OpenExchangeRateResult>
            {
                new OpenExchangeRateResult
                {
                    Base  = "USD",
                    Rates = new Dictionary <string, double>()
                    {
                        { "VND", 23050 },
                        { "CNY", 6.5434 }
                    },
                    TimeStamp = 10
                },
                new OpenExchangeRateResult
                {
                    Base  = "USD",
                    Rates = new Dictionary <string, double>()
                    {
                        { "VND", 23100 },
                        { "CNY", 6.6434 }
                    },
                    TimeStamp = 20
                },
                new OpenExchangeRateResult
                {
                    Base  = "USD",
                    Rates = new Dictionary <string, double>()
                    {
                        { "VND", 23150 },
                        { "CNY", 6.7434 }
                    },
                    TimeStamp = 30
                }
            });

            //Assert.Equal(3387.9378, result);
        }
Ejemplo n.º 32
0
        public async Task CreateDbWithMockIdentity()
        {
            var options = new DbContextOptionsBuilder <StrikeNetDbContext>()
                          .UseInMemoryDatabase(databaseName: "StrikeNetTestDb")
                          .EnableSensitiveDataLogging()
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var _dbContext = new StrikeNetDbContext(options);

            TestUser = new UserIdentity {
                Score = 0
            };
            var identityRepository = new Mock <IIdentityRepository>();

            identityRepository.Setup(x => x.GetUserAsync(It.IsAny <Guid?>())).ReturnsAsync(TestUser);
            var predictionRepository = new PredictionRepository(identityRepository.Object, _dbContext);

            _predictionService = new PredictionService(predictionRepository);
        }
Ejemplo n.º 33
0
        private static void RunPrediction(PredictionService service)
        {
            // Make a prediction.
            CommandLine.WriteAction("Performing a prediction...");
            string text = "mucho bueno";
            CommandLine.RequestUserInput("Text to analyze", ref text);

            var input = new Input { InputValue = new Input.InputData { CsvInstance = new List<string> { text } } };
            Output result = service.Hostedmodels.Predict(input, "sample.languageid").Fetch();
            CommandLine.WriteResult("Language", result.OutputLabel);
        }
Ejemplo n.º 34
0
        private static void RunPrediction(PredictionService service)
        {
            // Train the service with the existing bucket data.
            string id = ClientCredentials.BucketPath;
            CommandLine.WriteAction("Performing training of the service ...");
            CommandLine.WriteResult("Bucket", id);
            Training training = new Training { Id = id };
            training = service.Training.Insert(training).Fetch();

            // Wait until the training is complete.
            while (training.TrainingStatus == "RUNNING")
            {
                CommandLine.Write("..");
                Thread.Sleep(1000);
                training = service.Training.Get(id).Fetch();
            }
            CommandLine.WriteLine();
            CommandLine.WriteAction("Training complete!");
            CommandLine.WriteLine();
         
            // Make a prediction.
            CommandLine.WriteAction("Performing a prediction...");
            string text = "mucho bueno";
            CommandLine.RequestUserInput("Text to analyze", ref text);

            var input = new Input { InputValue = new Input.InputData { CsvInstance = new List<string> { text } } };
            Output result = service.Training.Predict(input, id).Fetch();
            CommandLine.WriteResult("Language", result.OutputLabel);
        }