public IHttpActionResult PutWeightModel(int id, WeightModel weightModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != weightModel.ID)
            {
                return(BadRequest());
            }

            db.Entry(weightModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WeightModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
 public ActionResult Details(UserDetail model)
 {
     if (Request.IsAuthenticated)
     {
         var         user = UserViewModel.GetUser(model.User.Id);
         WeightModel wm   = new WeightModel();
         DateTime    dt   = new DateTime();
         foreach (var g in _db.Goal.Where(x => x.UserId == user.Id))
         {
             if (Convert.ToDateTime(g.Date).Date > dt.Date)
             {
                 dt = Convert.ToDateTime(g.Date);
             }
         }
         if (!_db.Weight.ToList().Any(x => x.UserId == user.Id && x.Date == DateTime.Now.ToString()))
         {
             wm.Id     = Guid.NewGuid().ToString();
             wm.UserId = user.Id;
             wm.Date   = DateTime.Now.ToString();
             wm.Weight = Convert.ToDecimal(model.User.Weight);
             _db.Weight.Add(wm);
             _db.SaveChanges();
         }
         model.Goal         = _db.Goal.ToList().First(x => x.UserId == user.Id && x.Date == dt.ToString());
         model.Activity     = _db.Activity;
         user.Weight        = model.User.Weight;
         user.ActivityLevel = model.User.ActivityLevel;
         user.Name          = model.User.Name;
         UserManager.Update(user);
         return(View(model));
     }
     return(RedirectToAction("Index"));
 }
Example #3
0
        public async Task <IActionResult> Create([Bind("Date,Weight,Comment")] WeightViewModel weightViewModel)
        {
            if (ModelState.IsValid)
            {
                // First save weight to table
                WeightModel weight = new WeightModel()
                {
                    UserName = User.Identity.GetUserId(),
                    Date     = weightViewModel.Date,
                    Weight   = weightViewModel.Weight
                };
                _context.Add(weight);
                await _context.SaveChangesAsync();

                // Check if comment is added and save to database
                if (weightViewModel.Comment != null)
                {
                    int          lastWeightId = _context.Weights.Max(item => item.Id);
                    CommentModel comment      = new CommentModel()
                    {
                        WeightModelId = lastWeightId,
                        Comment       = weightViewModel.Comment
                    };
                    _context.Add(comment);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(weightViewModel));
        }
        protected override async Task Submit()
        {
            var newModel = new WeightModel(model.Id, Weight, Date.Add(Time));
            await RepositoryService.UpdateWeight(newModel);

            MessagingCenter.Send(this, Messages.WeightsUpdated);
            await NavigationService.GoBackAsync();
        }
Example #5
0
        public async Task UpdateWeight(WeightModel model)
        {
            var weightEntity = new WeightEntity {
                Id = model.Id, Value = model.Value, At = model.At
            };
            await database.Save(weightEntity);

            weightEntities = await database.GetWeights();
        }
        public String GetSignature()
        {
            String output = WeightModel.GetSignature(); //functionSettings.GetSignature();

            if (limit > 0)
            {
                output += limit.ToString();
            }
            return(output);
        }
        public IHttpActionResult GetWeightModel(int id)
        {
            WeightModel weightModel = db.Weights.Find(id);
            string      owner       = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (weightModel == null || weightModel.Owner != owner)
            {
                return(NotFound());
            }

            return(Ok(weightModel));
        }
Example #8
0
        public IActionResult Excel(IFormFile file, [FromServices] IWebHostEnvironment hostingEnvironment)
        {
            // Save file and read values
            string fileName = $"{hostingEnvironment.WebRootPath}\\files\\{file.FileName}";

            using (FileStream fileStream = System.IO.File.Create(fileName))
            {
                file.CopyTo(fileStream);
                fileStream.Flush();
            }
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
            using (var stream = System.IO.File.Open(fileName, FileMode.Open, FileAccess.Read))
            {
                using (var reader = ExcelReaderFactory.CreateReader(stream))
                {
                    while (reader.Read())
                    {
                        // Get values from excel start from a1 cell
                        string   stringDate = reader.GetValue(0).ToString();
                        DateTime date       = DateTime.Parse(stringDate);

                        string  stringWeight = reader.GetValue(1).ToString();
                        Decimal weight       = Decimal.Parse(stringWeight);

                        // First save to Weights table
                        WeightModel weightModel = new WeightModel()
                        {
                            UserName = User.Identity.GetUserId(),
                            Date     = date,
                            Weight   = weight
                        };
                        _context.Add(weightModel);
                        _context.SaveChanges();

                        // If comment exist save to Comments table
                        if (reader.GetValue(2) != null)
                        {
                            int          lastWeightId = _context.Weights.Max(item => item.Id);
                            CommentModel commentModel = new CommentModel()
                            {
                                WeightModelId = lastWeightId,
                                Comment       = reader.GetValue(2).ToString()
                            };
                            _context.Add(commentModel);
                            _context.SaveChanges();
                        }
                    }
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult FromPounds(double valueInPounds)
        {
            try
            {
                Results = _weightConvertingOperations.FromPounds(valueInPounds);

                return(Ok(Results));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Example #10
0
        public WeightModel UpdateWeight(WeightModel updatedWeight)
        {
            var weight = weights.SingleOrDefault(r => r.Id == updatedWeight.Id);

            if (weight != null)
            {
                weight.Id     = updatedWeight.Id;
                weight.PetId  = updatedWeight.PetId;
                weight.Weight = updatedWeight.Weight;
                weight.Date   = updatedWeight.Date;
            }

            return(weight);
        }
Example #11
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Account"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("../Account/Index"));
                }

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Name = model.Name, Height = model.Height, Weight = model.Weight, DietId = "", DietDate = "", FitnessId = "", FitnessDate = "", Birthday = model.Birthday, Gender = model.Gender
                };

                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, false, false);

                        return(RedirectToLocal(returnUrl));
                    }

                    WeightModel wm = new WeightModel
                    {
                        Id     = Guid.NewGuid().ToString(),
                        UserId = user.Id,
                        Date   = DateTime.Now.ToString(),
                        Weight = Convert.ToDecimal(user.Weight)
                    };
                    _db.Weight.Add(wm);
                    _db.SaveChanges();
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Example #12
0
 public void SetupUpdateWeight(WeightModel model = null)
 {
     if (model != null)
     {
         Setup(x => x.UpdateWeight(model))
         .Returns(model)
         .Verifiable();
     }
     else
     {
         Setup(x => x.UpdateWeight(It.IsAny <WeightModel>()))
         .Returns(new WeightModel())
         .Verifiable();
     }
 }
        public IHttpActionResult PostWeightModel(WeightModel weightModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;

            weightModel.Owner = owner;
            //weightModel.Logged = DateTime.UtcNow;
            db.Weights.Add(weightModel);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = weightModel.ID }, weightModel));
        }
        private static void LoadKerasLayers(WeightModel model, List <Layer> layers)
        {
            var weightValueTuples = new List <Tuple <Tensor, Array> >();

            foreach (var layer in layers)
            {
                var weightNames = model.WeightNameDictionary[layer.name];

                var symbolic_weights = layer.weights;
                var weightValues     = weightNames.Select(n => model.WeightValueDictionary[n]).ToArray();

                weightValueTuples.AddRange(symbolic_weights.Select((w, i) => Tuple.Create(w, weightValues[i])));
            }

            KerasSharp.Backends.Current.K.batch_set_value(weightValueTuples);
        }
Example #15
0
 public ActionResult Weight(WeightModel model)
 {
     if (model.BodyWeight == 0)
     {
         TempData["Error"] = "Please provide your body weight";
         return(RedirectToAction("../Main/Home"));
     }
     try {
         Body b = new Body(this.db, this.user);
         b.AddBodyWeight(model.BodyWeight);
         this.user.Measurements.BodyWeight = model.BodyWeight;
         TempData["Status"] = "Body weight successfully recorded";
     } catch {
         TempData["Error"] = "Unable to record body weight - Please try again later";
     }
     return(RedirectToAction("../Main/Home"));
 }
        public override async Task Initialize(object parameter)
        {
            try
            {
                IsBusy = true;
                if (parameter == null)
                {
                    return;
                }
                var id      = (int)parameter;
                var weights = await RepositoryService.GetWeights();

                model  = weights.Single(w => w.Id == id);
                Weight = model.Value;
                Date   = model.At.Date;
                Time   = model.At.TimeOfDay;
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #17
0
        /// <summary>
        ///     Calls the deserialize method to initialize the weightlist.
        /// </summary>
        /// <returns></returns>
        private async Task InitializeModel()
        {
            Debug.WriteLine("USER DEBUG: Initializing model");

            weights = new WeightModel();
            try
            {
                await weights.deserializeJsonAsync();
            }
            catch (FileNotFoundException e)
            {
                ToastPrompt toast = new ToastPrompt();
                toast.Title   = "Easy Weight";
                toast.Message = "No file to load. ";
                toast.MillisecondsUntilHidden = 2000;
                toast.ImageSource             = new BitmapImage(new Uri("ApplicationIcon.png", UriKind.RelativeOrAbsolute));

                toast.Show();
            }

            Debug.WriteLine("USER DEBUG: Model initialized");
        }
        private static WeightModel SaveKerasLayers(List <KerasSharp.Engine.Topology.Layer> layers)
        {
            var weightModel = new WeightModel();

            weightModel.WeightValueDictionary = new Dictionary <string, Array>();
            weightModel.LayerNames            = layers.Select(x => x.name).ToArray();

            foreach (var layer in layers)
            {
                var g            = layer.name;
                var weightValues = KerasSharp.Backends.Current.K.batch_get_value(layer.weights);

                List <string> weightNames = new List <string>();
                for (var i = 0; i < weightValues.Count; i++)
                {
                    var w   = layer.weights[i];
                    var val = weightValues[i];

                    var name = "";
                    if (!string.IsNullOrEmpty(w.name))
                    {
                        name = w.name;
                    }
                    else
                    {
                        name = $"param_{i}";
                    }
                    weightNames.Add(name);

                    weightModel.WeightValueDictionary.Add(name, val);
                }

                weightModel.WeightNameDictionary.Add(g, weightNames);
            }

            return(weightModel);
        }
 protected WeightFacade(WeightModel model) : base(model)
 {
 }
        //public Boolean ComputeFeatureScores(WeightDictionary featureScores, SpaceModel space, ILogBuilder log, folderNode folder = null)
        //{



        //    return doAll;

        //}


        /// <summary>
        /// Selects the top <see cref="limit"/> terms, ranked by <see cref="function"/>
        /// </summary>
        /// <param name="space">The space.</param>
        /// <returns></returns>
        public List <KeyValuePair <string, double> > SelectFeatures(SpaceModel space, ILogBuilder log, folderNode folder = null, WeightDictionary featureScores = null)
        {
            Dictionary <String, Double> rank = new Dictionary <string, double>();
            Boolean doAll = false;

            if (limit == -1)
            {
                doAll = true;
            }

            if (featureScores == null)
            {
                featureScores = new WeightDictionary();
            }

            var tokens = space.terms_known_label.GetTokens();

            if (precompiledSelection != null && precompiledSelection.Count > 0)
            {
                log.log("Using precompiled selection filter from [" + outputFilename + "]");
                featureScores.Merge(precompiledSelection);
            }
            else
            {
                WeightModel.PrepareTheModel(space, log);

                featureScores = WeightModel.GetElementFactors(tokens, space);
            }


            if (tokens.Count() <= limit)
            {
                doAll = true;
            }

            if (doAll)
            {
                List <KeyValuePair <string, double> > outAll = new List <KeyValuePair <string, double> >();

                foreach (String tkn in tokens)
                {
                    outAll.Add(new KeyValuePair <string, double>(tkn, 1));
                }
                return(outAll);
            }

            //function.PrepareTheModel(space, log);



            if (!outputFilename.isNullOrEmpty())
            {
                if (folder != null)
                {
                    String p_m = folder.pathFor(outputFilename, imbSCI.Data.enums.getWritableFileMode.none, "", false);
                    featureScores.Save(folder, log, outputFilename);
                    //precompiledSelection = WeightDictionary.LoadFile(p_m, logger);
                }
            }


            foreach (WeightDictionaryEntry en in featureScores.index.Values)
            {
                //   rank.Add(en.name, en.weight);
                Double v = 0;

                if (featureScores.nDimensions > 1)
                {
                    v = en.CompressNumericVector(nVectorValueSelectionOperation);
                }
                else
                {
                    v = en.weight;
                }


                Boolean ok = true;

                if (RemoveZero)
                {
                    if (v == 0)
                    {
                        ok = false;
                    }
                }


                if (ok)
                {
                    rank.Add(en.name, v);
                }
            }

            var rankSorted = rank.OrderByDescending(x => x.Value).ToList();
            List <KeyValuePair <string, double> > top = rankSorted.Take(Math.Min(limit, rankSorted.Count)).ToList();

            return(top);
        }
Example #21
0
 public WeightModel AddWeight(WeightModel model)
 {
     weights.Add(model);
     model.Id = weights.Max(r => r.Id) + 1;
     return(model);
 }
Example #22
0
        private static void SetupObjects()
        {
            People = new PersonModel[]
            {
                new PersonModel()
                {
                    Name = "Dalinar",
                    PreferredClassification = PetClassification.Mammal,
                    PreferredType           = PetType.Snake,
                    PreferredWeight         = WeightModel.Create(WeightType.Medium)
                },
                new PersonModel()
                {
                    Name = "Kaladin",
                    PreferredClassification = PetClassification.Bird,
                    PreferredType           = PetType.Goldfish,
                    PreferredWeight         = WeightModel.Create(WeightType.ExtraSmall)
                }
            };

            Pets = new PetModel[]
            {
                new PetModel()
                {
                    Name           = "Garfield",
                    Classification = PetClassification.Mammal,
                    Type           = PetType.Cat,
                    Weight         = 20.0
                },
                new PetModel()
                {
                    Name           = "Odie",
                    Classification = PetClassification.Mammal,
                    Type           = PetType.Dog,
                    Weight         = 15.0
                },
                new PetModel()
                {
                    Name           = "Peter Parker",
                    Classification = PetClassification.Arachnid,
                    Type           = PetType.Spider,
                    Weight         = 0.5
                },
                new PetModel()
                {
                    Name           = "Kaa",
                    Classification = PetClassification.Reptile,
                    Type           = PetType.Snake,
                    Weight         = 25.0
                },
                new PetModel()
                {
                    Name           = "Nemo",
                    Classification = PetClassification.Fish,
                    Type           = PetType.Goldfish,
                    Weight         = 0.5
                },
                new PetModel()
                {
                    Name           = "Alpha",
                    Classification = PetClassification.Fish,
                    Type           = PetType.Betta,
                    Weight         = 0.1
                },
                new PetModel()
                {
                    Name           = "Splinter",
                    Classification = PetClassification.Mammal,
                    Type           = PetType.Rat,
                    Weight         = 0.5
                },
                new PetModel()
                {
                    Name           = "Coco",
                    Classification = PetClassification.Bird,
                    Type           = PetType.Parrot,
                    Weight         = 6.0
                },
                new PetModel()
                {
                    Name           = "Tweety",
                    Classification = PetClassification.Bird,
                    Type           = PetType.Canary,
                    Weight         = 0.05
                }
            };
        }
Example #23
0
 public WeightViewModel(WeightModel data)
 {
     WeightModel = data;
 }