예제 #1
0
        public virtual ActionResult DeleteConfirmed(int id)
        {
            SymbolDrawing symbolDrawing = db.SymbolDrawings.Find(id);

            db.SymbolDrawings.Remove(symbolDrawing);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
 public virtual ActionResult Edit([Bind(Include = "Id,Email,EmailConfirmed,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] ApplicationUser applicationUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(applicationUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(applicationUser));
 }
예제 #3
0
        public virtual ActionResult Create([Bind(Include = "SymbolStr,Name")] Symbol symbol)
        {
            if (ModelState.IsValid)
            {
                db.Symbols.Add(symbol);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(symbol));
        }
예제 #4
0
        private SymbolDrawing insertSymbolDrawingFromJson(string jsonData, Symbol symbol, bool drawnUsingTouch)
        {
            RawDrawing drawing;

            try {
                var lines = JsonConvert.DeserializeObject <RawPoint[][]>(jsonData);
                drawing = new RawDrawing()
                {
                    Lines = lines
                };
            }
            catch (Exception ex) {
                return(null);
            }

            new RawDataProcessor().CleanData(drawing);

            if (drawing.LinesCount == 0)
            {
                return(null);
            }
            var             userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
            ApplicationUser author      = User.Identity.IsAuthenticated ? userManager.FindById(User.Identity.GetUserId()) : null;
            var             sd          = new SymbolDrawing()
            {
                Symbol          = symbol,
                CreatedDateTime = DateTime.UtcNow,
                DrawnUsingTouch = drawnUsingTouch,
                Creator         = author,
                Approved        = (author == null || userManager.IsInRole(author.Id, RolesHelper.Teacher) == false) ? null : (bool?)true
            };

            sd.SetRawDrawing(drawing);
            sd = db.SymbolDrawings.Add(sd);
            db.SaveChanges();

            Logger.LogInfo <TeachController>("New symbol drawing [{0}].", sd.SymbolDrawingId);

            return(sd);
        }
예제 #5
0
        public virtual ActionResult Predict(PredictModel model)
        {
            if (!ModelState.IsValid)
            {
                return(HttpNotFound());
            }

            var sw = Stopwatch.StartNew();

            RawDrawing rawDrawing;

            try {
                var lines = JsonConvert.DeserializeObject <RawPoint[][]>(model.JsonData);
                rawDrawing = new RawDrawing()
                {
                    Lines = lines
                };
            }
            catch (Exception ex) {
                return(HttpNotFound());
            }

            if (rawDrawing.LinesCount == 0)
            {
                return(Json(new {
                    Results = new int[0],                      // Any empty array will do (C# meets JS :).
                    Duration = (float)sw.Elapsed.TotalMilliseconds,
                }));
            }

            List <Tuple <Symbol, float> > rawResults = predict(rawDrawing);

            var minTime = DateTime.UtcNow.AddSeconds(-GUID_CHECK_WINDOW_SECONDS);

            Drawing drawing = null;

            if (model.IsFollowupDraw)
            {
                drawing = db.Drawings
                          .Where(d => d.ClientGuid == model.Guid && DateTime.Compare(d.DrawnDateTime, minTime) > 0)
                          .FirstOrDefault();
            }

            if (drawing == null)
            {
                drawing = new Drawing();
                drawing.DrawnDateTime = DateTime.UtcNow;
                drawing.ClientGuid    = model.Guid;
                db.Drawings.Add(drawing);
            }
#if DEBUG
            else
            {
                // Delete potentially cached image - this does not happen ofthen but it is annoying when it does happen.
                new DrawingsController(db, DependencyResolver.Current.GetService <AppSettingsProvider>())
                .ClearCachedImage(drawing.DrawingId);
            }
#endif
            var firstResult = rawResults.FirstOrDefault();

            drawing.TopSymbol       = firstResult == null ? null : firstResult.Item1;
            drawing.TopSymbolScore  = firstResult == null ? null : (double?)firstResult.Item2;
            drawing.DrawnUsingTouch = model.DrawnUsingTouch;
            drawing.SetRawDrawing(rawDrawing);

            db.SaveChanges();

            return(Json(new {
                Results = rawResults.Select(x => new {
                    SymbolId = x.Item1.SymbolId,
                    Symbol = x.Item1.SymbolStr,
                    SymbolName = x.Item1.Name,
                    Rating = x.Item2,
                    HtmlEntity = x.Item1.HtmlEntity ?? "",
                    UtfCode = char.ConvertToUtf32(x.Item1.SymbolStr, 0),
                }),
                Duration = (float)sw.Elapsed.TotalMilliseconds,
            }));
        }