コード例 #1
0
 public kFoldThreadParameter(DataLoader loader, Methodology methodology, int fold, int nIteration) 
 {
     this.loader = loader;
     this.methodology = methodology;
     this.fold = fold;
     this.nIteration = nIteration;
 }
コード例 #2
0
        public void LatestVersion_SingleVersionIsLatest()
        {
            var version = new MethodologyVersion
            {
                Id = Guid.NewGuid(),
                PreviousVersionId  = null,
                PublishingStrategy = Immediately,
                Status             = Draft,
                Version            = 0
            };

            var methodology = new Methodology
            {
                Versions = AsList(version)
            };

            Assert.Equal(version, methodology.LatestVersion());
        }
コード例 #3
0
ファイル: DataContainerManager.cs プロジェクト: payamad/Core
        public DataAttribute CreateDataAttribute(string shortName, string name, string description, bool isMultiValue, bool isBuiltIn, string scope, MeasurementScale measurementScale, DataContainerType containerType, string entitySelectionPredicate,
                                                 DataType dataType, Unit unit, Methodology methodology, Classifier classifier,
                                                 ICollection <AggregateFunction> functions, ICollection <GlobalizationInfo> globalizationInfos, ICollection <Constraint> constraints,
                                                 ICollection <ExtendedProperty> extendedProperies
                                                 )
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(shortName));
            Contract.Requires(dataType != null && dataType.Id >= 0);
            Contract.Requires(unit != null && unit.Id >= 0);


            Contract.Ensures(Contract.Result <DataAttribute>() != null && Contract.Result <DataAttribute>().Id >= 0);
            DataAttribute e = new DataAttribute()
            {
                ShortName                = shortName,
                Name                     = name,
                Description              = description,
                IsMultiValue             = isMultiValue,
                IsBuiltIn                = isBuiltIn,
                Scope                    = scope,
                MeasurementScale         = measurementScale,
                ContainerType            = containerType,
                EntitySelectionPredicate = entitySelectionPredicate,
                DataType                 = dataType,
                Unit                     = unit,
                Methodology              = methodology,
                AggregateFunctions       = functions,
                GlobalizationInfos       = globalizationInfos,
                Constraints              = constraints,
                ExtendedProperties       = extendedProperies,
            };

            if (classifier != null && classifier.Id > 0)
            {
                e.Classification = classifier;
            }
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <DataAttribute> repo = uow.GetRepository <DataAttribute>();
                repo.Put(e);
                uow.Commit();
            }
            return(e);
        }
コード例 #4
0
        public async Task ListAsync()
        {
            var methodology1 = new Methodology
            {
                Id     = Guid.NewGuid(),
                Title  = "Methodology 1",
                Status = Approved
            };

            var methodology2 = new Methodology
            {
                Id     = Guid.NewGuid(),
                Title  = "Methodology 2",
                Status = Draft
            };

            using (var context = DbUtils.InMemoryApplicationDbContext("List"))
            {
                await context.AddRangeAsync(new List <Methodology>
                {
                    methodology1, methodology2
                });

                await context.SaveChangesAsync();
            }

            using (var context = DbUtils.InMemoryApplicationDbContext("List"))
            {
                var methodologies = (await BuildMethodologyService(
                                         context,
                                         Mocks())
                                     .ListAsync()).Right;

                Assert.Contains(methodologies,
                                m => m.Id == methodology1.Id &&
                                m.Title == methodology1.Title &&
                                m.Status == methodology1.Status);

                Assert.Contains(methodologies,
                                m => m.Id == methodology2.Id &&
                                m.Title == methodology2.Title &&
                                m.Status == methodology2.Status);
            }
        }
コード例 #5
0
        public async void CreatePublication_FailsWithMethodologyAndExternalMethodology()
        {
            var topic = new Topic
            {
                Title = "Test topic"
            };
            var methodology = new Methodology
            {
                Title  = "Test methodology",
                Status = MethodologyStatus.Approved,
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = InMemoryApplicationDbContext(contextId))
            {
                context.Add(topic);
                context.Add(methodology);
                await context.SaveChangesAsync();
            }

            await using (var context = InMemoryApplicationDbContext(contextId))
            {
                var publicationService = BuildPublicationService(context, Mocks());

                // Service method under test
                var result = await publicationService.CreatePublication(
                    new SavePublicationViewModel()
                {
                    Title               = "Test title",
                    TopicId             = topic.Id,
                    MethodologyId       = methodology.Id,
                    ExternalMethodology = new ExternalMethodology
                    {
                        Title = "Test external",
                        Url   = "http://test.com"
                    }
                }
                    );

                Assert.True(result.IsLeft);
                AssertValidationProblem(result.Left, CannotSpecifyMethodologyAndExternalMethodology);
            }
        }
コード例 #6
0
        public async void UpdatePublication_FailsWithUnapprovedMethodology()
        {
            var methodology = new Methodology
            {
                Title  = "Test methodology",
                Status = MethodologyStatus.Draft,
            };
            var publication = new Publication
            {
                Topic = new Topic
                {
                    Title = "Test topic"
                },
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = InMemoryApplicationDbContext(contextId))
            {
                context.Add(methodology);
                context.Add(publication);
                await context.SaveChangesAsync();
            }

            await using (var context = InMemoryApplicationDbContext(contextId))
            {
                var publicationService = BuildPublicationService(context, Mocks());

                // Service method under test
                var result = await publicationService.UpdatePublication(
                    publication.Id,
                    new SavePublicationViewModel()
                {
                    Title         = "Test publication",
                    TopicId       = publication.TopicId,
                    MethodologyId = methodology.Id,
                }
                    );

                Assert.True(result.IsLeft);
                AssertValidationProblem(result.Left, MethodologyMustBeApproved);
            }
        }
コード例 #7
0
        public async Task UpdateAsync()
        {
            var methodology = new Methodology
            {
                Id     = Guid.NewGuid(),
                Slug   = "pupil-absence-statistics-methodology",
                Status = Draft,
                Title  = "Pupil absence statistics: methodology"
            };

            var request = new UpdateMethodologyRequest
            {
                InternalReleaseNote = null,
                Status = Draft,
                Title  = "Pupil absence statistics (updated): methodology"
            };

            await using (var context = DbUtils.InMemoryApplicationDbContext("Update"))
            {
                context.Add(methodology);
                await context.SaveChangesAsync();
            }

            await using (var context = DbUtils.InMemoryApplicationDbContext("Update"))
            {
                var viewModel = (await BuildMethodologyService(context,
                                                               Mocks())
                                 .UpdateMethodologyAsync(methodology.Id, request)).Right;

                var model = await context.Methodologies.FindAsync(methodology.Id);

                Assert.False(model.Live);
                Assert.Equal("pupil-absence-statistics-updated-methodology", model.Slug);
                Assert.True(model.Updated.HasValue);
                Assert.InRange(DateTime.UtcNow.Subtract(model.Updated.Value).Milliseconds, 0, 1500);

                Assert.Equal(methodology.Id, viewModel.Id);
                Assert.Null(viewModel.InternalReleaseNote);
                Assert.Null(viewModel.Published);
                Assert.Equal(request.Status, viewModel.Status);
                Assert.Equal(request.Title, viewModel.Title);
            }
        }
コード例 #8
0
        public async Task <Either <ActionResult, MethodologySummaryViewModel> > CreateMethodologyAsync(
            CreateMethodologyRequest request)
        {
            var slug = SlugFromTitle(request.Title);

            return(await _userService.CheckCanCreateMethodology()
                   .OnSuccess(() => ValidateMethodologySlugUnique(slug))
                   .OnSuccess(async() =>
            {
                var model = new Methodology
                {
                    Title = request.Title,
                    Slug = slug
                };

                var saved = await _context.Methodologies.AddAsync(model);
                await _context.SaveChangesAsync();
                return await GetSummaryAsync(saved.Entity.Id);
            }));
        }
コード例 #9
0
ファイル: MethodologyManager.cs プロジェクト: payamad/Core
        public Methodology Create(string appliedStandards, string tools, string tolerance, string procedure)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(procedure));
            Contract.Ensures(Contract.Result <Methodology>() != null && Contract.Result <Methodology>().Id >= 0);

            Methodology u = new Methodology()
            {
                AppliedStandards = appliedStandards,
                Tools            = tools,
                Tolerance        = tolerance,
                Procedure        = procedure,
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <Methodology> repo = uow.GetRepository <Methodology>();
                repo.Put(u);
                uow.Commit();
            }
            return(u);
        }
コード例 #10
0
 public static Task <Either <ActionResult, Methodology> > CheckCanMarkMethodologyAsDraft(
     this IUserService userService, Methodology methodology)
 {
     return(userService.CheckPolicy(methodology, SecurityPolicies.CanMarkSpecificMethodologyAsDraft));
 }
コード例 #11
0
 private async Task <Either <ActionResult, IContentBlockViewModel> > UpdateHtmlBlock(HtmlBlock blockToUpdate,
                                                                                     string body, Methodology methodology)
 {
     blockToUpdate.Body = body;
     return(await SaveMethodology <HtmlBlockViewModel>(blockToUpdate, methodology));
 }
コード例 #12
0
 public personalizedPageRankThreadParamters(int kFold, int nIteration, Methodology methodology)
 {
     this.kFold = kFold;
     this.nIteration = nIteration;
     this.methodology = methodology;
 }
コード例 #13
0
        // Primary Methods
        public void startPersonalizedPageRank(object parameterObject)
        {
            Stopwatch pageRankStopwatch = Stopwatch.StartNew();
            // PageRank Environment Setting
            personalizedPageRankThreadParamters parameters = (personalizedPageRankThreadParamters)parameterObject;
            int         nFold       = parameters.kFold;
            int         nIteration  = parameters.nIteration;
            Methodology methodology = parameters.methodology;

            try
            {
                // Get ego user's ID and his like count
                long egoID = long.Parse(Path.GetFileNameWithoutExtension(this.dbPath));

                // Final result to put the experimental result per fold together
                this.finalResult = new Dictionary <EvaluationMetric, double>(); // <'HIT(0)', double> or <'AVGPRECISION(1)', double>
                foreach (EvaluationMetric metric in Enum.GetValues(typeof(EvaluationMetric)))
                {
                    this.finalResult.Add(metric, 0d); // Initialization
                }
                // Need to avoid the following error: "Collection was modified; enumeration operation may not execute"
                metrics = new List <EvaluationMetric>(this.finalResult.Keys);

                // K-Fold Cross Validation
                kFoldSemaphore = new Semaphore(nFold, nFold);
                List <Thread> kFoldThreadList = new List <Thread>(); // 'Thread': Standard Library Class
                for (int fold = 0; fold < 1; fold++)                 // One fold to One thread
                {
                    // Load graph information from database and then configurate the graph
                    DataLoader loader = new DataLoader(this.dbPath);
                    loader.setEgoNetwork();
                    loader.setEgoTimeline();
                    loader.splitTimelineToKfolds(nFold);
                    // |Friend|
                    this.numOfFriend = loader.getNumOfFriend();
                    // Multi-Threading
                    kFoldSemaphore.WaitOne();                                                                               // Wait until Semaphore released
                    Thread thread = new Thread(new ParameterizedThreadStart(runKfoldCrossValidation));
                    kFoldThreadParameter kFoldparameters = new kFoldThreadParameter(loader, methodology, fold, nIteration); // 'ThreadParams': defined in 'Experiment.cs'
                    thread.Start(kFoldparameters);
                    kFoldThreadList.Add(thread);
                }
                // Synchronization: Wait until threads be terminated
                foreach (Thread thread in kFoldThreadList)
                {
                    thread.Join();
                }

                if (Program.isValidTrainSet == false)
                {
                    return;
                }
                // Result: <Ego ID>\t<Experi Code>\t<N-fold>\t<iteration>\t<MAP>\t<Recall>\t<|LIKE|>\t<|HIT|>\t<|Friend|>
                pageRankStopwatch.Stop();
                lock (Program.outFileLocker)
                {
                    Program.logger.Write(egoID + "\t" + (int)methodology + "\t" + nFold + "\t" + nIteration);
                    foreach (EvaluationMetric metric in metrics)
                    {
                        switch (metric)
                        {
                        case EvaluationMetric.MAP:
                            Program.logger.Write("\t{0:F15}", (finalResult[metric] / 1));
                            break;

                        case EvaluationMetric.RECALL:
                            Program.logger.Write("\t{0:F15}", (finalResult[metric] / 1));
                            break;

                        case EvaluationMetric.LIKE:
                            Program.logger.Write("\t" + (finalResult[metric]));
                            break;

                        case EvaluationMetric.HIT:
                            Program.logger.Write("\t" + (finalResult[metric]));
                            break;
                        }
                    }
                    // |Friend|
                    Program.logger.Write("\t" + this.numOfFriend);
                    // Output Execution Time
                    Program.logger.WriteLine("\t" + Tools.getExecutionTime(pageRankStopwatch));
                    Program.logger.Flush();
                    // Console Output
                    Console.WriteLine("|Friend|: " + this.numOfFriend);
                    Console.WriteLine("Excution Time: " + Tools.getExecutionTime(pageRankStopwatch));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Program.dbSemaphore.Release();
            }
        }
コード例 #14
0
 private Task <Either <ActionResult, Methodology> > CheckCanUpdateMethodology(Methodology methodology)
 {
     return(_userService.CheckCanUpdateMethodology(methodology));
 }
コード例 #15
0
        public async void CreatePublication()
        {
            var topic = new Topic
            {
                Title = "Test topic"
            };
            var methodology = new Methodology
            {
                Title  = "Test methodology",
                Status = MethodologyStatus.Approved,
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = InMemoryApplicationDbContext(contextId))
            {
                context.Add(topic);
                context.Add(methodology);
                await context.SaveChangesAsync();
            }

            await using (var context = InMemoryApplicationDbContext(contextId))
            {
                var publicationService = BuildPublicationService(context, Mocks());

                // Service method under test
                var result = await publicationService.CreatePublication(
                    new SavePublicationViewModel
                {
                    Title   = "Test publication",
                    Contact = new SaveContactViewModel
                    {
                        ContactName  = "John Smith",
                        ContactTelNo = "0123456789",
                        TeamName     = "Test team",
                        TeamEmail    = "*****@*****.**",
                    },
                    TopicId       = topic.Id,
                    MethodologyId = methodology.Id
                }
                    );

                var publicationViewModel = result.Right;
                Assert.Equal("Test publication", publicationViewModel.Title);

                Assert.Equal("John Smith", publicationViewModel.Contact.ContactName);
                Assert.Equal("0123456789", publicationViewModel.Contact.ContactTelNo);
                Assert.Equal("Test team", publicationViewModel.Contact.TeamName);
                Assert.Equal("*****@*****.**", publicationViewModel.Contact.TeamEmail);

                Assert.Equal(topic.Id, publicationViewModel.TopicId);

                Assert.Equal(methodology.Id, publicationViewModel.Methodology.Id);
                Assert.Equal("Test methodology", publicationViewModel.Methodology.Title);

                // Do an in depth check of the saved release
                var createdPublication = await context.Publications.FindAsync(publicationViewModel.Id);

                Assert.False(createdPublication.Live);
                Assert.Equal("test-publication", createdPublication.Slug);
                Assert.False(createdPublication.Updated.HasValue);
                Assert.Equal("Test publication", createdPublication.Title);

                Assert.Equal("John Smith", createdPublication.Contact.ContactName);
                Assert.Equal("0123456789", createdPublication.Contact.ContactTelNo);
                Assert.Equal("Test team", createdPublication.Contact.TeamName);
                Assert.Equal("*****@*****.**", createdPublication.Contact.TeamEmail);

                Assert.Equal(topic.Id, createdPublication.TopicId);
                Assert.Equal("Test topic", createdPublication.Topic.Title);

                Assert.Equal(methodology.Id, createdPublication.Methodology.Id);
                Assert.Equal("Test methodology", createdPublication.Methodology.Title);
            }
        }
コード例 #16
0
        private void runKfoldCrossValidation(object parameters)
        {
            try
            {
                // Setting environment for experiments
                kFoldThreadParameter p           = (kFoldThreadParameter)parameters;
                DataLoader           loader      = p.loader;
                Methodology          methodology = p.methodology;
                int fold       = p.fold;
                int nIteration = p.nIteration;

                // #1 Core Part: 'EgoNetwork DB' --> 'Graph Strctures(Node, Edge)'
                loader.setTrainTestSet(fold);
                if (Program.isValidTrainSet == false)
                {
                    return;
                }
                List <Feature> features = loader.getFeaturesOnMethodology(methodology);
                loader.setGraphConfiguration(features);

                // Graph Elements: Nodes and edges
                Dictionary <int, Node> nodes = loader.allNodes;
                Dictionary <int, List <ForwardLink> > edges = loader.allLinksFromNodes;

                // Incase: Mention Count(O), Friendship(X)
                if (methodology == Methodology.INCL_MENTIONCOUNT ||
                    methodology == Methodology.INCL_AUTHORSHIP_AND_MENTIONCOUNT ||
                    methodology == Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY_AND_MENTIONCOUNT ||
                    methodology == Methodology.EXCL_FRIENDSHIP)
                {
                    foreach (List <ForwardLink> forwardLinks in edges.Values)
                    {
                        for (int i = 0; i < forwardLinks.Count; i++)
                        {
                            if (forwardLinks[i].type == EdgeType.FRIENDSHIP)
                            {
                                ForwardLink revisedForwardLink = forwardLinks[i];
                                revisedForwardLink.type = EdgeType.UNDEFINED; // FRIENDSHIP --> UNDEFINED
                                forwardLinks[i]         = revisedForwardLink;
                            }
                        }
                    }
                }

                // #2 Core Part: 'Graph Strcture(Nodes, Edges)' --> 'PageRank Matrix(2D-ragged array)'
                Graph graph = new Graph(nodes, edges);
                graph.buildGraph();

                // #3 Core Part: Recommendation list(Personalized PageRanking Algorithm)
                Recommender recommender    = new Recommender(graph);
                var         recommendation = recommender.Recommendation(0, 0.15f, nIteration); // '0': Ego Node's Index, '0.15f': Damping Factor

                // #4 Core Part: Validation - AP(Average Precision)
                DataSet        testSet = loader.getTestSet();
                HashSet <long> egoLikedTweets = testSet.getEgoLikedTweets();
                int            hit = 0, like = 0;
                double         AP = 0.0, recall = 0.0; // Average Precision
                for (int i = 0; i < recommendation.Count; i++)
                {
                    if (egoLikedTweets.Contains(((Tweet)recommendation[i]).ID))
                    {
                        hit += 1;
                        AP  += (double)hit / (i + 1);
                    }
                }
                // LIKE
                like = (int)egoLikedTweets.Count;
                // Average Precision & Recall
                if (hit != 0)
                {
                    AP    /= hit;
                    recall = (double)hit / like;
                }
                else
                {
                    AP     = 0.0;
                    recall = 0.0;
                }

                // Add current result to final one
                lock (kFoldLocker)
                {
                    foreach (EvaluationMetric metric in this.metrics)
                    {
                        switch (metric)
                        {
                        case EvaluationMetric.MAP:
                            this.finalResult[metric] += AP;
                            break;

                        case EvaluationMetric.RECALL:
                            this.finalResult[metric] += recall;
                            break;

                        case EvaluationMetric.LIKE:
                            this.finalResult[metric] += like;
                            break;

                        case EvaluationMetric.HIT:
                            this.finalResult[metric] += hit;
                            break;
                        }
                    }
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                kFoldSemaphore.Release();
            }
        }
コード例 #17
0
 private Either <ActionResult, Tuple <Methodology, List <ContentSection> > > FindContentList(Methodology methodology,
                                                                                             params Guid[] contentSectionIds)
 {
     return(FindContentList(methodology, contentSectionIds.ToList()));
 }
コード例 #18
0
        private Task <Either <ActionResult, Methodology> > CheckCanUpdateMethodologyStatus(Methodology methodology,
                                                                                           MethodologyStatus status)
        {
            if (methodology.Status == status)
            {
                // Status unchanged
                return(Task.FromResult(new Either <ActionResult, Methodology>(methodology)));
            }

            return(status switch
            {
                MethodologyStatus.Draft => _userService.CheckCanMarkMethodologyAsDraft(methodology),
                MethodologyStatus.Approved => _userService.CheckCanApproveMethodology(methodology),
                _ => throw new ArgumentOutOfRangeException(nameof(status), "Unexpected status")
            });
コード例 #19
0
        private async Task <Either <ActionResult, IContentBlockViewModel> > AddContentBlockToContentSectionAndSaveAsync(int?order,
                                                                                                                        ContentSection section,
                                                                                                                        ContentBlock newContentBlock, Methodology methodology)
        {
            var orderForNewBlock = OrderValueForNewlyAddedContentBlock(order, section);

            section.Content
            .FindAll(contentBlock => contentBlock.Order >= orderForNewBlock)
            .ForEach(contentBlock => contentBlock.Order++);

            newContentBlock.Order = orderForNewBlock;
            section.Content.Add(newContentBlock);

            _context.Methodologies.Update(methodology);
            await _context.SaveChangesAsync();

            return(new Either <ActionResult, IContentBlockViewModel>(_mapper.Map <IContentBlockViewModel>(newContentBlock)));
        }
コード例 #20
0
        protected override void Seed(Probnik.ProbnikContext context)
        {
            User user = new User();

            user.Login    = "******";
            user.Email    = "*****@*****.**";
            user.IsAdmin  = true;
            user.Password = "******";
            user.Id       = 1;

            context.Users.AddOrUpdate(user);

            User probant = new User();

            probant.Login    = "******";
            probant.Email    = "*****@*****.**";
            probant.IsAdmin  = false;
            probant.Password = "******";
            probant.Id       = 2;
            context.Users.AddOrUpdate(probant);


            Person person = new Person("Wiktor", "Matecki", "18-08-1997");

            person.Id = 1;

            UserToPersonConnection upc = new UserToPersonConnection(1, 1, ConnectionType.PersonToOwner);

            person.Users.Add(upc);


            //context.People.AddOrUpdate(person);

            //context.SaveChanges();

            Methodology HS = new Methodology();

            HS.Name = "Harcerze Starsi";
            HS.Id   = 1;

            //context.Methodologies.AddOrUpdate(HS);

            Methodology w = new Methodology();

            w.Name = "Wêdrownicy";
            w.Id   = 2;
            //context.Methodologies.AddOrUpdate(w);

            Patron patron = new Patron();

            patron.Person = person;
            patron.Id     = 1;

            Team b = new Team();

            b.Name = "Berserk";
            b.Methodologies.Add(HS);
            b.Patrons.Add(patron);
            b.Owner = person;
            b.Id    = 1;

            context.Teams.AddOrUpdate(b);

            Team e = new Team();

            e.Name = "Emilki";
            e.Methodologies.Add(w);
            context.Teams.AddOrUpdate(e);
            e.Owner = person;
            e.Id    = 2;

            //context.SaveChanges();

            //HS = context.Methodologies.First(m => m.Name == "Harcerze Starsi");
            TaskContent task1 = new TaskContent();

            task1.Content         = "W³¹czy³em siê do prowadzenia gospodarstwa domowego. W trakcie próby przej¹³em na siebie dodatkowe obowi¹zki";
            task1.TaskNumber      = 1;
            task1.Id              = 2;
            task1.ChallangeTypeId = 1;

            var task2 = new TaskContent()
            {
                Content         = "Jestem wra¿liwy na potrzeby drugiego cz³owieka – œwiadomie i odpowiedzialnie podejmujê sta³¹ s³u¿bê.",
                TaskNumber      = 2,
                Id              = 1,
                ChallangeTypeId = 1
            };

            ChallangeType challengeType = new ChallangeType();

            challengeType.Methodologies.Add(HS);
            challengeType.Name = "Odkrywca";
            challengeType.Tasks.Add(task1);
            challengeType.Tasks.Add(task2);
            challengeType.Id = 1;

            context.ChallangeTypes.AddOrUpdate(challengeType);

            TaskContent task3 = new TaskContent();

            task3.Content         = "Orientuje siê w bie¿¹cych wydarzeniach politycznych, gospodarczych i kulturalnych kraju.";
            task3.TaskNumber      = 1;
            task3.Id              = 3;
            task3.ChallangeTypeId = 2;

            var task4 = new TaskContent()
            {
                Content         = "Znam najwa¿niejsze prawa i obowi¹zki obywateli RP. ",
                TaskNumber      = 2,
                Id              = 4,
                ChallangeTypeId = 2
            };

            ChallangeType challengeType2 = new ChallangeType();

            challengeType2.Methodologies.Add(w);
            challengeType2.Name = "Samarytanka";
            challengeType2.Tasks.Add(task3);
            challengeType2.Tasks.Add(task4);
            challengeType2.Id = 2;



            context.ChallangeTypes.AddOrUpdate(challengeType2);

            context.SaveChanges();



            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
        }
コード例 #21
0
 private List <ContentSection> FindContentList(Methodology methodology,
                                               params ContentSection[] contentSections)
 {
     return(FindContentList(methodology, contentSections.Select(section => section.Id).ToList()).Right.Item2);
 }
コード例 #22
0
        private Either <ActionResult, Tuple <Methodology, List <ContentSection> > > FindContentList(Methodology methodology,
                                                                                                    List <Guid> contentSectionIds)
        {
            if (ContentListContainsAllSectionIds(methodology.Content, contentSectionIds))
            {
                return(new Tuple <Methodology, List <ContentSection> >(methodology, methodology.Content));
            }

            if (ContentListContainsAllSectionIds(methodology.Annexes, contentSectionIds))
            {
                return(new Tuple <Methodology, List <ContentSection> >(methodology, methodology.Annexes));
            }

            return(new NotFoundResult());
        }
コード例 #23
0
        public async void UpdatePublication_AlreadyPublished()
        {
            var topic = new Topic
            {
                Title = "New topic"
            };
            var methodology = new Methodology
            {
                Title  = "New methodology",
                Status = MethodologyStatus.Approved,
            };
            var publication = new Publication
            {
                Slug  = "old-title",
                Title = "Old title",
                Topic = new Topic
                {
                    Title = "Old topic"
                },
                Methodology = new Methodology
                {
                    Title = "Old methodology"
                },
                Contact = new Contact
                {
                    ContactName  = "Old name",
                    ContactTelNo = "0987654321",
                    TeamName     = "Old team",
                    TeamEmail    = "*****@*****.**",
                },
                Published = new DateTime(2020, 8, 12),
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = InMemoryApplicationDbContext(contextId))
            {
                context.Add(topic);
                context.Add(methodology);
                context.Add(publication);

                await context.SaveChangesAsync();
            }

            await using (var context = InMemoryApplicationDbContext(contextId))
            {
                var publicationService = BuildPublicationService(context, Mocks());

                // Service method under test
                var result = await publicationService.UpdatePublication(
                    publication.Id,
                    new SavePublicationViewModel()
                {
                    Title   = "New title",
                    Contact = new SaveContactViewModel
                    {
                        ContactName  = "John Smith",
                        ContactTelNo = "0123456789",
                        TeamName     = "Test team",
                        TeamEmail    = "*****@*****.**",
                    },
                    TopicId       = topic.Id,
                    MethodologyId = methodology.Id,
                }
                    );

                Assert.Equal("New title", result.Right.Title);

                Assert.Equal("John Smith", result.Right.Contact.ContactName);
                Assert.Equal("0123456789", result.Right.Contact.ContactTelNo);
                Assert.Equal("Test team", result.Right.Contact.TeamName);
                Assert.Equal("*****@*****.**", result.Right.Contact.TeamEmail);

                Assert.Equal(topic.Id, result.Right.TopicId);

                Assert.Equal(methodology.Id, result.Right.Methodology.Id);
                Assert.Equal("New methodology", result.Right.Methodology.Title);

                // Do an in depth check of the saved release
                var updatedPublication = await context.Publications.FindAsync(result.Right.Id);

                Assert.True(updatedPublication.Live);
                Assert.True(updatedPublication.Updated.HasValue);
                Assert.InRange(DateTime.UtcNow.Subtract(updatedPublication.Updated.Value).Milliseconds, 0, 1500);
                // Slug remains unchanged
                Assert.Equal("old-title", updatedPublication.Slug);
                Assert.Equal("New title", updatedPublication.Title);

                Assert.Equal("John Smith", updatedPublication.Contact.ContactName);
                Assert.Equal("0123456789", updatedPublication.Contact.ContactTelNo);
                Assert.Equal("Test team", updatedPublication.Contact.TeamName);
                Assert.Equal("*****@*****.**", updatedPublication.Contact.TeamEmail);

                Assert.Equal(topic.Id, updatedPublication.TopicId);
                Assert.Equal("New topic", updatedPublication.Topic.Title);

                Assert.Equal(methodology.Id, updatedPublication.MethodologyId);
                Assert.Equal("New methodology", updatedPublication.Methodology.Title);
            }
        }
コード例 #24
0
 public static Task <Either <ActionResult, Methodology> > CheckCanApproveMethodology(
     this IUserService userService, Methodology methodology)
 {
     return(userService.CheckPolicy(methodology, SecurityPolicies.CanApproveSpecificMethodology));
 }
コード例 #25
0
        private Either <ActionResult, Methodology> EnsureMethodologyContentAndAnnexListsNotNull(Methodology methodology)
        {
            if (methodology.Content == null)
            {
                methodology.Content = new List <ContentSection>();
            }

            if (methodology.Annexes == null)
            {
                methodology.Annexes = new List <ContentSection>();
            }

            return(methodology);
        }
コード例 #26
0
 public personalizedPageRankThreadParamters(int kFold, int nIteration, Methodology methodology)
 {
     this.kFold       = kFold;
     this.nIteration  = nIteration;
     this.methodology = methodology;
 }
コード例 #27
0
        public void graphConfiguration(Methodology type, int fold)
        {
            List<Feature> features = new List<Feature>();
            switch (type) {
                case Methodology.BASELINE:                          // 0
                    break;
                case Methodology.INCL_FRIENDSHIP:                   // 1
                    features.Add(Feature.FRIENDSHIP);
                    break;
                case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY:     // 2
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    break;
                case Methodology.INCL_AUTHORSHIP:                   // 3
                    features.Add(Feature.AUTHORSHIP);
                    break;
                case Methodology.INCL_MENTIONCOUNT:                 // 4
                    features.Add(Feature.FRIENDSHIP);               // temporarily included
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.INCL_ALLFOLLOWSHIP:                // 5
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    break;
                case Methodology.INCL_FRIENDSHIP_AUTHORSHIP:        // 6
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.AUTHORSHIP);
                    break;
                case Methodology.INCL_FRIENDSHIP_MENTIONCOUNT:      // 7
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.ALL:                               // 8
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.AUTHORSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.EXCL_FRIENDSHIP:                   // 9
                    features.Add(Feature.FRIENDSHIP);               // temporarily included
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.AUTHORSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.EXCL_FOLLOWSHIP_ON_THIRDPARTY:     // 10
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.AUTHORSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.EXCL_AUTHORSHIP:                   // 11
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.EXCL_MENTIONCOUNT:                 // 12
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.AUTHORSHIP);
                    break;
                case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY_AND_AUTHORSHIP:      // 13
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.AUTHORSHIP);
                    break;
                case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY_AND_MENTIONCOUNT:    // 14
                    features.Add(Feature.FRIENDSHIP);                               // temporarily included
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.INCL_AUTHORSHIP_AND_MENTIONCOUNT:                  // 15
                    features.Add(Feature.AUTHORSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
            }

            // Run graph configuration
            graphConfiguration(features, fold);

            // Close database connection
            dbAdapter.closeDB();
        }
コード例 #28
0
        // #1 Main Part
        public List<Feature> getFeaturesOnMethodology(Methodology type)
        {
            List<Feature> features = new List<Feature>();
            switch (type)
            {
                case Methodology.BASELINE:                          // 0
                    break;
                case Methodology.INCL_FRIENDSHIP:                   // 1
                    features.Add(Feature.FRIENDSHIP);
                    break;
                case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY:     // 2
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    break;
                case Methodology.INCL_AUTHORSHIP:                   // 3
                    features.Add(Feature.AUTHORSHIP);
                    break;
                case Methodology.INCL_MENTIONCOUNT:                 // 4
                    features.Add(Feature.FRIENDSHIP);               // temporarily included
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.INCL_ALLFOLLOWSHIP:                // 5
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    break;
                case Methodology.INCL_FRIENDSHIP_AUTHORSHIP:        // 6
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.AUTHORSHIP);
                    break;
                case Methodology.INCL_FRIENDSHIP_MENTIONCOUNT:      // 7
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY_AND_AUTHORSHIP:      // 8
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.AUTHORSHIP);
                    break;
                case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY_AND_MENTIONCOUNT:    // 9
                    features.Add(Feature.FRIENDSHIP);                               // temporarily included
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.INCL_AUTHORSHIP_AND_MENTIONCOUNT:                  // 10
                    features.Add(Feature.FRIENDSHIP);               // temporarily included
                    features.Add(Feature.AUTHORSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.EXCL_FRIENDSHIP:                   // 11
                    features.Add(Feature.FRIENDSHIP);               // temporarily included
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.AUTHORSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.EXCL_FOLLOWSHIP_ON_THIRDPARTY:     // 12
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.AUTHORSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.EXCL_AUTHORSHIP:                   // 13
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
                case Methodology.EXCL_MENTIONCOUNT:                 // 14
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.AUTHORSHIP);
                    break;
                case Methodology.ALL:                               // 15
                    features.Add(Feature.FRIENDSHIP);
                    features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                    features.Add(Feature.AUTHORSHIP);
                    features.Add(Feature.MENTIONCOUNT);
                    break;
            }

            return features;
        }
コード例 #29
0
        // #1 Main Part
        public List <Feature> getFeaturesOnMethodology(Methodology type)
        {
            List <Feature> features = new List <Feature>();

            switch (type)
            {
            case Methodology.BASELINE:                              // 0
                break;

            case Methodology.INCL_FRIENDSHIP:                       // 1
                features.Add(Feature.FRIENDSHIP);
                break;

            case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY:         // 2
                features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                break;

            case Methodology.INCL_AUTHORSHIP:                       // 3
                features.Add(Feature.AUTHORSHIP);
                break;

            case Methodology.INCL_MENTIONCOUNT:                     // 4
                features.Add(Feature.FRIENDSHIP);                   // temporarily included
                features.Add(Feature.MENTIONCOUNT);
                break;

            case Methodology.INCL_ALLFOLLOWSHIP:                    // 5
                features.Add(Feature.FRIENDSHIP);
                features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                break;

            case Methodology.INCL_FRIENDSHIP_AUTHORSHIP:            // 6
                features.Add(Feature.FRIENDSHIP);
                features.Add(Feature.AUTHORSHIP);
                break;

            case Methodology.INCL_FRIENDSHIP_MENTIONCOUNT:          // 7
                features.Add(Feature.FRIENDSHIP);
                features.Add(Feature.MENTIONCOUNT);
                break;

            case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY_AND_AUTHORSHIP:          // 8
                features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                features.Add(Feature.AUTHORSHIP);
                break;

            case Methodology.INCL_FOLLOWSHIP_ON_THIRDPARTY_AND_MENTIONCOUNT:        // 9
                features.Add(Feature.FRIENDSHIP);                                   // temporarily included
                features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                features.Add(Feature.MENTIONCOUNT);
                break;

            case Methodology.INCL_AUTHORSHIP_AND_MENTIONCOUNT:      // 10
                features.Add(Feature.FRIENDSHIP);                   // temporarily included
                features.Add(Feature.AUTHORSHIP);
                features.Add(Feature.MENTIONCOUNT);
                break;

            case Methodology.EXCL_FRIENDSHIP:                       // 11
                features.Add(Feature.FRIENDSHIP);                   // temporarily included
                features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                features.Add(Feature.AUTHORSHIP);
                features.Add(Feature.MENTIONCOUNT);
                break;

            case Methodology.EXCL_FOLLOWSHIP_ON_THIRDPARTY:         // 12
                features.Add(Feature.FRIENDSHIP);
                features.Add(Feature.AUTHORSHIP);
                features.Add(Feature.MENTIONCOUNT);
                break;

            case Methodology.EXCL_AUTHORSHIP:                       // 13
                features.Add(Feature.FRIENDSHIP);
                features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                features.Add(Feature.MENTIONCOUNT);
                break;

            case Methodology.EXCL_MENTIONCOUNT:                     // 14
                features.Add(Feature.FRIENDSHIP);
                features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                features.Add(Feature.AUTHORSHIP);
                break;

            case Methodology.ALL:                                   // 15
                features.Add(Feature.FRIENDSHIP);
                features.Add(Feature.FOLLOWSHIP_ON_THIRDPARTY);
                features.Add(Feature.AUTHORSHIP);
                features.Add(Feature.MENTIONCOUNT);
                break;
            }

            return(features);
        }