Ejemplo n.º 1
0
        public static ItemViewModel Create(EvaluationItem model)
        {
            if (model == null)
            {
                return(new UndefinedViewModel());
            }
            if (string.IsNullOrEmpty(model.Id))
            {
                return(new NewItemViewModel());
            }
            if (model.Status == "deleted")
            {
                return(new DeletedViewModel {
                    Id = model.Id, Name = model.Name, StatisticalWay = model.StatisticalWay
                });
            }

            if (model.Links != null && model.Links.Any(o => o.Method == "PATCH"))
            {
                var vm = new ItemEditViewModel(model);

                return(vm);
            }

            return(new ItemViewModel
            {
                Id = model.Id,
                Name = model.Name,
                StatisticalWay = model.StatisticalWay,
                FormulaParams = model.FormulaParams.ConvertTo <IFormulaParams>()
            });
        }
        public async Task <IActionResult> Answer(IFormCollection form)
        {
            var user = await _userManager.GetUserAsync(User);

            try // kinda sorta abusing try catches, there is a better way to do this...
            {
                int evalItemId = int.Parse(form["evalItemId"]);
                int answerVal  = int.Parse(form["answer"]);
                //int answerVal = int.Parse(HttpContext.Request.Query["inlineRadioOptions"]);

                EvaluationItem answeredEvalItem = _dbContext.EvaluationItem.First(i => i.Id == evalItemId);

                if (_dbContext.UserAnswer.Where(u => u.User.Id == user.Id && u.EvalItem.Id == evalItemId).Count() == 0)
                {
                    UserAnswer answer = new UserAnswer();
                    answer.User     = user;
                    answer.EvalItem = answeredEvalItem;
                    answer.Answer   = answerVal;
                    _dbContext.UserAnswer.Add(answer);
                    _dbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception parsing POST Answer: " + e);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public EvaluationResult Evaluate(EvaluationItem item)
        {
            FunctionStack <Real> nn = new FunctionStack <Real>(
                new Linear <Real>(NumInput, NumMiddle, false, _parameter.MiddleLayerWeight),
                new Linear <Real>(NumMiddle, NumOutput, false, _parameter.OutputLayerWeight)
                );
            NdArray <Real> result = nn.Predict(item.GetReal())[0];

            return(new EvaluationResult(result.Data[0]));
        }
Ejemplo n.º 4
0
    public Evaluator()
    {
        EvaluationItem evaluetionItem;

        evaluetionItem = new EvaluationItem();
        evaluetionItem.AddType(new Action(ObjectType.Variable, MotionType.Read));
        AddItem(evaluetionItem);
        evaluetionItem = new EvaluationItem();
        evaluetionItem.AddType(new Action(ObjectType.Operator, MotionType.Execute));
        AddItem(evaluetionItem);
    }
        public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(User);

            EvaluationItem evalItem = new EvaluationItem();

            try
            {
                // get user answer eval ids
                var answered = _dbContext.UserAnswer.Where(u => u.User.Id == user.Id).Select(a => a.EvalItem.Id);
                var items    = _dbContext.EvaluationItem.Where(i => !answered.Contains(i.Id));
                evalItem = items.Take(1).First();
                System.Diagnostics.Debug.WriteLine("The eval item title is: '" + evalItem.Title + "'");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                evalItem.Title = "You have answered everything!";
            }

            return(View(evalItem));
        }
Ejemplo n.º 6
0
            public static EvaluationItem GetEvaluationItem(RoundResult result)
            {
                Field        field     = result.FieldAtEnd;
                List <Point> holes     = field.GetHoles();
                int          holeDepth = holes.Count == 0 ? 0 : holes.Select(x => x.X)
                                         .Distinct()
                                         .Select(x => holes.Where(y => y.X == x).OrderBy(y => y.Y).First())
                                         .Select(x =>
                {
                    int r     = 0;
                    int[] col = field.ToArrays().Rows(x.X).ToArray();
                    for (int i = x.Y; i >= 0; i--)
                    {
                        if (col[i] != 0)
                        {
                            r++;
                        }
                    }
                    return(r);
                }).Aggregate((x, y) => x + y);
                int numRowWithHoles = Enumerable.Range(0, field.Row - 1)
                                      .Select(x => holes.Where(y => y.X == x)
                                              .ToList().Count != 0)
                                      .Where(x => x)
                                      .Count();
                int rowTransition = GetTotalElementChange(
                    field.ToArrays()
                    .Flatten(SquareDirection.Column)
                    .ToArray());
                int colTransition = GetTotalElementChange(
                    field.ToArrays()
                    .Flatten(SquareDirection.Row)
                    .ToArray());

                EvaluationItem ev = new EvaluationItem(result.Object.GetHeight(), holes.Count, holeDepth, field.GetDeadSpace().Count, field.GetWells().Select(x => Enumerable.Range(1, x.ToArray().Count()).Aggregate(1, (p, item) => p * item)).Aggregate((x, y) => x + y), result.ErodedObjectCells, numRowWithHoles, rowTransition, colTransition);

                return(ev);
            }
Ejemplo n.º 7
0
 /// <summary>
 /// 検証結果の追加
 /// </summary>
 /// <param name="item"></param>
 private void AddItem(EvaluationItem item)
 {
     Items.Add(item);
     _items.Add(item);
 }
Ejemplo n.º 8
0
 void AddItem(EvaluationItem evlauetionItem)
 {
     this.items.Add(evlauetionItem);
 }
Ejemplo n.º 9
0
 public Task <EvaluationResult> EvaluateAsync(EvaluationItem item)
 {
     return(Task.Run(() => { return Evaluate(item); }));
 }
Ejemplo n.º 10
0
        public async void OnRoundStart(object sender)
        {
            await Task.Run(() =>
            {
                Field field = (Field)sender;
                List <BlockPosition> positions         = field.GetPlaceablePositions(field.Object.Unit);
                List <Task <RoundResult> > field_tasks = positions
                                                         .Select(x => ExecuteFieldAsync(field, x))
                                                         .ToList();
                this._logger.Debug("Round Start");

                RoundResult[] round_result = Task.WhenAll(field_tasks.Where(x => x.Status != TaskStatus.Canceled)).Result;
                field_tasks.ForEach(x => x.Dispose());

                List <Tuple <BlockPosition, EvaluationResult> > results = round_result
                                                                          .Select(x => new Tuple <BlockPosition, EvaluationResult>(x.Position, _evaluator.Evaluate(EvaluationItem.GetEvaluationItem(x))))
                                                                          .OrderByDescending(x => x.Item2.EvaluationValue)
                                                                          .ToList();

                if (results.Count == 0)
                {
                    return;
                }
                var dest = results
                           .GroupBy(x => x.Item2.EvaluationValue)
                           .First()
                           .GetRandom();
                TryPlaceAsync(field, dest.Item1);
            });
        }
Ejemplo n.º 11
0
        public ItemEditViewModel(EvaluationItem model)
        {
            Id             = model.Id;
            _Name          = model.Name;
            StatisticalWay = model.StatisticalWay;
            FormulaParams  = model.FormulaParams.ConvertTo <IFormulaParams>();
            Description    = model.Description.ConvertTo <IEvaluationItemDescription>();

            var obsvr = Observer.Create <FormulaInfo>(o =>
            {
                if (_updateValues == null)
                {
                    return;
                }
                _updateValues.Formula = o;
            });

            Observable.FromEventPattern <PropertyChangedEventArgs>(Description, "PropertyChanged")
            .Select(args => args.Sender)
            .OfType <IEvaluationItemDescription>()
            .Subscribe(o =>
            {
                if (_updateValues == null)
                {
                    return;
                }
                _updateValues.Description = o;
            });

            SetFormulaOptions = model.FormulaOptions.Select(o =>
            {
                var vm = o.ConvertTo <IFormulaParams>();
                if (vm != null)
                {
                    Observable.FromEventPattern <PropertyChangedEventArgs>(vm, "PropertyChanged")
                    .Select(args => args.Sender)
                    .OfType <IFormulaParams>().Select(p => new FormulaInfo().PopulateWith(p))
                    .Subscribe(obsvr);
                }

                return(vm ?? new UnknownFormulaParams());
            }).ToList();

            _SelectedFormula = SetFormulaOptions.FirstOrDefault(o => FormulaParams != null && FormulaParams.GetType() == o.GetType());


            this.WhenAny(x => x.SelectedFormula, x => x.Value)
            .Select(o => o == null ? null : new FormulaInfo().PopulateWith(o))
            .Subscribe(obsvr);


            this.WhenAny(x => x.Name, x => x.Value)
            .Subscribe(o =>
            {
                if (_updateValues == null)
                {
                    return;
                }
                _updateValues.Name = o;
            });

            IsEditing     = true;
            _updateValues = new UpateRequestBody();
        }