예제 #1
0
 public DatasetQueryRecord(DatasetQuery dq)
 {
     Id           = dq.Id;
     UniversalId  = dq.UniversalId?.ToString();
     Shape        = dq.Shape;
     Name         = dq.Name;
     Category     = dq.Category;
     Description  = dq.Description;
     SqlStatement = dq.SqlStatement;
 }
예제 #2
0
 public DatasetQueryDTO(DatasetQuery dq)
 {
     Id          = dq.Id.Value.ToString();
     UniversalId = dq.UniversalId?.ToString();
     Shape       = dq.Shape;
     Name        = dq.Name;
     Category    = dq.Category;
     Description = dq.Description;
     Tags        = dq.Tags;
 }
예제 #3
0
        public async Task <QueryResult <Dataset> > ListAsync(DatasetQuery query)
        {
            // Here I try to get the datasets list from the memory cache. If there is no data in cache, the anonymous method will be
            // called, setting the cache to expire one minute ahead and returning the Task that lists the datasets from the repository.

            // var datasets = await _cache.GetOrCreateAsync(CacheKeys.DatasetList, (entry) => {
            //     entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(0.01);
            //     return _datasetRepository.ListAsync();
            // });

            return(await _datasetRepository.ListAsync(query));
        }
예제 #4
0
        public ActionResult Submit_Data(Submitmodel model)
        {
            if (ModelState.IsValid)
            {
                WebModel _web = new WebModel();
                string result = null;

                TempData["notice"] = "Data was successfully Submitted";

                var Datacollection = new DatasetQuery();
                Datacollection.comment = model._comment;
                Datacollection.format = model._format;
                Datacollection.doiNumber = model._doiNumber;
                Datacollection.method = model._method;
                Datacollection.projectile = model._projectile;
                Datacollection.stateOfAggregation = model._stateOfAggregation;
                Datacollection.targetMaterial = model._targetMaterial;
                Datacollection.email = User.Identity.Name;

                if (model._uploadedfile != null)
                {
                    result = new StreamReader(model._uploadedfile.InputStream).ReadToEnd();
                }

                if (result != null)
                {
                    Datacollection.datapoints = result;
                }
                else
                {
                    Datacollection.datapoints = model._manualString;
                }

                result = _web.SetDataset(Datacollection);

                TempData["notice"] = "Submission was " + result;
                return RedirectToAction("Submit_Data", "Data");

            }

            return View();
        }
예제 #5
0
 string CteDatasetInternals(DatasetQuery datasetQuery) => datasetQuery.SqlStatement;
        public async Task <QueryResult <Dataset> > ListAsync(DatasetQuery query)
        {
            IQueryable <Dataset> queryable = _context.Datasets
                                             .Include(d => d.Publisher)
                                             .Include(d => d.Category)
                                             .Include(d => d.Distributions)
                                             .Include(d => d.Coordination)
                                             .Include(d => d.Subscriptions)
                                             .Include(d => d.DatasetTags)
                                             .ThenInclude(d => d.Tags)
                                             .AsNoTracking();

            // Filter on multiple publishers
            if (!String.IsNullOrEmpty(query.PublisherIds))
            {
                // Parses the list of publisher ids from string to list of ints
                List <int> publisherIds = new List <int>();
                foreach (string idString in query.PublisherIds.Split(','))
                {
                    if (idString == null || idString == "")
                    {
                        continue;
                    }
                    int id = Int32.Parse(idString.Trim());
                    publisherIds.Add(id);
                }

                // Filters on the chosen publisher ids
                queryable = queryable.Where(d => publisherIds.Contains(d.PublisherId));
            }


            // Filter on Category
            if (!String.IsNullOrEmpty(query.CategoryIds))
            {
                // Parses the list of category ids from string to list of ints
                List <int> categoryIds = new List <int>();
                foreach (string idString in query.CategoryIds.Split(','))
                {
                    if (idString == null || idString == "")
                    {
                        continue;
                    }
                    int id = Int32.Parse(idString.Trim());
                    categoryIds.Add(id);
                    Category c = await getCategoryWithNarrowers(id);

                    categoryIds.AddRange(getNarrowerIds(c));
                }

                queryable = queryable.Where(d => categoryIds.Contains(d.CategoryId));
            }


            // Filter on Access Level
            if (!String.IsNullOrEmpty(query.AccessLevels))
            {
                // Parses the list of Access levels from string to list of EAccessLevels
                List <EAccessLevel> accessLevels = new List <EAccessLevel>();
                foreach (string accessLevel in query.AccessLevels.Split(','))
                {
                    if (accessLevel == null || accessLevel == "")
                    {
                        continue;
                    }
                    Enum.TryParse(accessLevel.Trim(), out EAccessLevel aLevel);
                    accessLevels.Add(aLevel);
                }
                queryable = queryable.Where(d => accessLevels.Contains(d.AccessLevel));
            }

            // Filter on Publication status
            if (!String.IsNullOrEmpty(query.PublicationStatuses))
            {
                // Parses the list of Publications statuses from string to list of EPublicationStatus
                List <EPublicationStatus> pubStatuses = new List <EPublicationStatus>();
                foreach (string pubStatus in query.PublicationStatuses.Split(','))
                {
                    if (pubStatus == null || pubStatus == "")
                    {
                        continue;
                    }
                    Enum.TryParse(pubStatus.Trim(), out EPublicationStatus status);
                    pubStatuses.Add(status);
                }
                queryable = queryable.Where(d => pubStatuses.Contains(d.PublicationStatus));
            }


            // Checks if the search string is in the title, description, publisher name, and tags of the dataset
            if (!String.IsNullOrEmpty(query.Search))
            {
                queryable = queryable.Where(d =>
                                            d.Title.ToLower().Contains(query.Search.Trim().ToLower()) ||
                                            d.Description.ToLower().Contains(query.Search.Trim().ToLower()) ||
                                            d.Publisher.Name.ToLower().Contains(query.Search.Trim().ToLower()) ||
                                            d.DatasetTags.Any(dt => dt.Tags.Name.ToLower().Contains(query.Search.Trim().ToLower())
                                                              ));
            }

            // Sorts the datasets. Default order by date ascending
            string sortOrder = String.IsNullOrEmpty(query.SortOrder) ? "date_asc" : query.SortOrder.Trim().ToLower();

            switch (sortOrder)
            {
            case "title_desc":
                queryable = queryable.OrderByDescending(d => d.Title);
                break;

            case "title_asc":
                queryable = queryable.OrderBy(d => d.Title);
                break;

            case "date_desc":
                queryable = queryable.OrderByDescending(d => d.DatePublished);
                break;

            case "date_asc":
                queryable = queryable.OrderBy(d => d.DatePublished);
                break;

            default:
                queryable = queryable.OrderBy(d => d.DatePublished);
                break;
            }

            // Here I count all items present in the database for the given query, to return as part of the pagination data.
            int totalItems = await queryable.CountAsync();

            List <Dataset> datasets = await queryable.Skip((query.Page - 1) *query.ItemsPerPage)
                                      .Take(query.ItemsPerPage)
                                      .ToListAsync();

            // Finally I return a query result, containing all items and the amount of items in the database (necessary for client-side calculations ).
            return(new QueryResult <Dataset>
            {
                Items = datasets,
                TotalItems = totalItems,
            });
        }
예제 #7
0
파일: WebModel.cs 프로젝트: entvex/Sem4
        public string SetDataset(DatasetQuery dataq)
        {
            CSVData[] result;

            try
            {
                result = engine.ReadString(dataq.datapoints);
            }
            catch (Exception e)
            {
                return "not successful. Reason: invalid datapoints";
            }

            List<DataPoint> data = new List<DataPoint>();
            DataPoint temp = new DataPoint();

            foreach (var d in result)
            {
                temp.ConvertetData = d.ConvertetData;
                temp.EqEnergy = d.EqEnergy;
                temp.Error = d.Error;
                temp.ProjectileCharge = d.ProjectileCharge;
                temp.StoppingPower = d.StoppingPower;

                data.Add(temp);
            }

            var tm = _dalRetrieve.GetTargetMaterialByName(dataq.targetMaterial);
            if (tm.Id == 0)
                return "not successful. Reason: invalid target material";
            var pjt = _dalRetrieve.GetProjectileByName(dataq.projectile);
            if (pjt.Id == 0)
                return "not successful. Reason: invalid projectile";
            var fmt = _dalRetrieve.GetDataformatByNotation(dataq.format);
            if (fmt.Id == 0)
                return "not successful. Reason: invalid format";
            var soa = _dalRetrieve.GetStateOfAggregationByForm(dataq.stateOfAggregation);
            if (soa.Id == 0)
                return "not successful. Reason: invalid physical state";
            var article = _dalRetrieve.GetArticleReferences(new ParametersForArticelreferences() { DOINumber = dataq.doiNumber });
            if (!article.Any())
                return "not successful. Reason: invalid article references";
            var md = _dalRetrieve.GetMethodByName(dataq.method);
            if (md.Id == 0)
            {
                _dalInsert.InsertMethod(new Method { Name = dataq.method });
                md = _dalRetrieve.GetMethodByName(dataq.method);
            }

            Revision revision = new Revision();
            revision.Date = DateTime.Now;
            revision.Comment = dataq.comment;

            var users = _dalRetrieve.GetUsers(new ParametersForUsers() { Email = dataq.email });
            if (!users.Any())
                return "not successful. Reason: invalid user";

            try
            {
                _dalInsert.InsertDataset(data, tm, pjt, fmt, fmt, revision, users[0], null, article[0], md, soa);
                return "successful";
            }
            catch (DALInfoNotSpecifiedException e)
            {
                return e.ToString();
            }
            catch (DALAlreadyExistsException e)
            {
                return e.ToString();
            }
        }