public async Task <IActionResult> Filter(ProjectFilter filter)
        {
            bool includeDeleted = filter.IncludeDeleted && ClaimsExtension.IsAdmin(HttpContext);

            var projectsGroup =
                (from project in _context.Project
                 join user in _context.User on project.OwnerId equals user.Id
                 join sale in _context.Sale on project.Id equals sale.ProjectId into sales
                 from subsale in sales.DefaultIfEmpty()
                 where ((includeDeleted || (!project.IsDeleted && !user.IsDeleted)) &&
                        (!filter.UserId.HasValue || project.OwnerId == filter.UserId.Value) &&
                        project.Name.Contains(filter.Name ?? "") &&
                        (!filter.MaxPrice.HasValue || project.Price <= filter.MaxPrice.Value) &&
                        (!filter.MinPrice.HasValue || project.Price >= filter.MinPrice.Value) &&
                        (!filter.FieldOfStudyId.HasValue || project.FieldOfStudyId == filter.FieldOfStudyId.Value)
                        )
                 select new
            {
                Id = project.Id,
                Description = project.Description,
                Name = project.Name,
                Grade = subsale.Grade,
                Rank = subsale.Rank,
                OwnerName = user.FullName,
                OwnerId = user.Id
            })
                .GroupBy(x => new { x.Id, x.Description, x.Name, x.OwnerName, x.OwnerId });

            List <ProjectInStoreView> projects = new List <ProjectInStoreView>();

            foreach (var group in projectsGroup)
            {
                var proj = new ProjectInStoreView()
                {
                    Id          = group.Key.Id,
                    Description = group.Key.Description,
                    Name        = group.Key.Name,
                    OwnerName   = group.Key.OwnerName,
                    OwnerId     = group.Key.OwnerId
                };
                var grades = group.Where(x => x.Grade.HasValue);
                proj.AvgGrade = grades.Any() ? new double?(grades.Select(x => (double)x.Grade.Value).Average()) : null;
                var ranks = group.Where(x => x.Rank.HasValue);
                proj.Rank = ranks.Any() ? new double?(ranks.Select(x => (double)x.Rank.Value).Average()) : null;
                if (proj.AvgGrade.HasValue)
                {
                    proj.AvgGrade = (float)(Math.Round((double)proj.AvgGrade, 2));
                    proj.Rank     = (float)(Math.Round((double)proj.Rank, 2));
                }
                projects.Add(proj);
            }
            return(Json(projects));
        }
Esempio n. 2
0
        public async Task <IActionResult> Filter(UsersFilter filter)
        {
            bool includeDeleted = filter.IncludeDeleted && ClaimsExtension.IsAdmin(HttpContext);
            var  users          = (
                from u in _context.User
                where u.FirstName.Contains(filter.FirstName ?? "") &&
                u.LastName.Contains(filter.LastName ?? "") &&
                u.UserName.Contains(filter.UserName ?? "") &&
                (includeDeleted || !u.IsDeleted)
                select new { u.Id, u.UserName, u.FullName, u.EMail, u.IsAdmin, u.IsDeleted }
                );

            return(Json(users));
        }
Esempio n. 3
0
        // GET: Users/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _context.User
                       .FirstOrDefaultAsync(m => m.Id == id && (!m.IsDeleted || ClaimsExtension.IsAdmin(HttpContext)));

            if (user == null)
            {
                return(NotFound());
            }
            IEnumerable <FieldOfStudy> fieldsOfStudy = _context.FieldOfStudy.ToList();

            ViewData["FieldsOfStudy"] = fieldsOfStudy;

            return(View(user));
        }
        // GET: Projects/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            // Machine learning is awesome!

            List <IGrouping <int, int> > projectIdsPerUsersGroups = _context.Sale.Include("Project").Where(x => !x.Project.IsDeleted).GroupBy(x => x.BuyerId, y => y.ProjectId).ToList();

            SortedSet <int>[] projectsPerUserDataset = new SortedSet <int> [projectIdsPerUsersGroups.Count];
            int idx = 0;

            foreach (var group in projectIdsPerUsersGroups)
            {
                projectsPerUserDataset[idx++] = new SortedSet <int>(group);
            }

            Apriori apriori = new Apriori(threshold: 3, confidence: 0);
            AssociationRuleMatcher <int> classifier = apriori.Learn(projectsPerUserDataset);

            AssociationRule <int>[] rules = classifier.Rules;

            ViewData["suggested"] = rules.Where(x => x.Y.First() != id).Select(x => _context.Project.First(y => y.Id == x.Y.First()));

            var project = await _context.Project
                          .Include(x => x.AcademicInstitute)
                          .Include(x => x.FieldOfStudy)
                          .Include(x => x.Owner)
                          .FirstOrDefaultAsync(m => m.Id == id &&
                                               ((!m.Owner.IsDeleted && !m.IsDeleted) || ClaimsExtension.IsAdmin(HttpContext)));

            if (project == null)
            {
                return(NotFound());
            }

            return(View(project));
        }