Exemple #1
0
        private static HeirarchyModel CalculateHierarchyMatching()
        {
            var returnResult = new HeirarchyModel();
            if (Sessions.activitiesContainer?.HasChildActivity == true)
            {
                var H1Acts = Sessions.activitiesContainer?.iatiActivities.FindAll(f => f.hierarchy == 1);
                var H2Acts = Sessions.activitiesContainer?.iatiActivities.FindAll(f => f.hierarchy == 2);

                var AimsProjects = Sessions.activitiesContainer?.AimsProjects;

                var matchedH1 = (decimal)(GetMatchedProjects(H1Acts, AimsProjects)).Count();

                var matchedH2 = (decimal)(GetMatchedProjects(H2Acts, AimsProjects)).Count();


                returnResult.H1Percent = H1Acts.Count > 0 ? Math.Round((decimal)(matchedH1 / H1Acts.Count) * 100, 2) : 0;
                returnResult.H2Percent = H2Acts.Count > 0 ? Math.Round((decimal)(matchedH2 / H2Acts.Count) * 100, 2) : 0;



                #region Populate relatedActivities of the first activity as sample data
                var parentActivities = Sessions.activitiesContainer?.iatiActivities.FindAll(x => x.hierarchy == 1);
                foreach (var pa in parentActivities)
                {
                    if (pa.relatedactivity != null)
                    {
                        foreach (var ra in pa.relatedactivity.Where(r => r.type == "2"))
                        {
                            //load related activities
                            var ha = Sessions.activitiesContainer?.iatiActivities.Find(f => f.IatiIdentifier == ra.@ref);

                            if (ha != null)
                            {
                                pa.childActivities.Add(ha);
                            }
                        }
                        returnResult.SampleIatiActivity = pa;
                        break; //we have to show only one hierarchycal project as a sample
                    }
                }
                #endregion

                returnResult.SelectedHierarchy = returnResult.H1Percent >= returnResult.H2Percent ? 1 : 2;

                Sessions.CurrentStage = Stage.Hierarchy;

            }
            else
            {
                returnResult = null;
                Sessions.CurrentStage = Stage.FilterBD;
            }

            return returnResult;
        }
Exemple #2
0
        public FilterBDModel SubmitHierarchy(HeirarchyModel heirarchyModel)
        {
            if (Sessions.activitiesContainer.IsHierarchyLoaded == true)
                return null;

            var returnResult = new FilterBDModel();
            heirarchyModel = heirarchyModel ?? Sessions.heirarchyModel;

            var iatiActivities = Sessions.activitiesContainer?.iatiActivities;
            if (heirarchyModel == null)
            {
                returnResult.iatiActivities = ToMinifiedIatiActivitiesModel(Sessions.activitiesContainer?.iatiActivities);
            }
            else
            {

                if (heirarchyModel.SelectedHierarchy == 1)
                {
                    iatiActivities = ImportLogic.LoadH1ActivitiesWithChild(iatiActivities);
                    returnResult.iatiActivities = ToMinifiedIatiActivitiesModel(iatiActivities, false, true);
                }
                else
                {
                    iatiActivities = ImportLogic.LoadH2ActivitiesWithParent(iatiActivities);
                    returnResult.iatiActivities = ToMinifiedIatiActivitiesModel(iatiActivities);
                }
                Sessions.activitiesContainer.IsHierarchyLoaded = true;
            }
            returnResult.iatiActivities = returnResult.iatiActivities.OrderByDescending(k => k.IsRelevant).ToList();

            Sessions.CurrentStage = Stage.FilterBD;
            Sessions.heirarchyModel = heirarchyModel;
            Sessions.filterBDModel = returnResult;
            Sessions.activitiesContainer.iatiActivities = iatiActivities;
            return returnResult;
        }