public ResTBHazardMapLayer(int Project, bool IsBeforeMitigationMeasure, NatHazard NatHazard, int Index) : base()
        {
            this.Project   = Project;
            this.NatHazard = NatHazard;
            this.Index     = Index;
            LayerType      = LayerType.ProjectLayer;
            if (IsBeforeMitigationMeasure)
            {
                ResTBPostGISType = ResTBPostGISType.HazardMapBefore;
            }
            else
            {
                ResTBPostGISType = ResTBPostGISType.HazardMapAfter;
            }
            ExportImportFileName = "HazardMap";
            this.SQL             = "select * from \"HazardMap\" where \"Project_Id\" = " + Project + " and \"NatHazard_ID\" = " + NatHazard.ID + " and \"BeforeAction\" = " + IsBeforeMitigationMeasure + " and \"Index\" = " + Index;
            SQL_Layer            = "HazardMap";
            ProjectID            = "Project_Id";
            if (IsBeforeMitigationMeasure)
            {
                VisibilityExpression = "[Project_Id] = " + Project + " AND [NatHazard_ID] = " + NatHazard.ID + " AND [Index] = " + Index + " AND [BeforeAction] = 1";
            }
            else
            {
                VisibilityExpression = "[Project_Id] = " + Project + " AND [NatHazard_ID] = " + NatHazard.ID + " AND [Index] = " + Index + " AND [BeforeAction] = 0";
            }

            Style = new Style.HazardMapStyle();
        }
        public static Tuple <double, string> computeResilienceFactor(List <ResilienceValues> allResilienceList, Intensity intensity)
        {
            NatHazard natHazard    = intensity.NatHazard;
            bool      beforeAction = intensity.BeforeAction; //--> to distinguish the before/after resilience

            int _resilienceHazardID;

            if (natHazard?.ID == 1) // Sequia
            {
                _resilienceHazardID = 1;
            }
            else //other nathazards
            {
                _resilienceHazardID = 2;
            }

            // use only resilience values of given nathazard
            List <ResilienceValues> _resilienceList = allResilienceList
                                                      .Where(r => r.ResilienceWeight.NatHazard.ID == _resilienceHazardID && r.ResilienceWeight.BeforeAction == beforeAction).ToList();

            List <string> _logString1   = new List <string>();
            List <string> _logString2   = new List <string>();
            List <string> _logIDStrings = new List <string>();

            //if list is empty: factor = 0
            if (_resilienceList == null || !_resilienceList.Any())
            {
                return(new Tuple <double, string>(0.0d, "no resiliece values found"));
            }

            double _sumWeight      = 0;
            double _sumValueWeight = 0;

            foreach (ResilienceValues item in _resilienceList)
            {
                _sumValueWeight += item.Value * item.Weight;
                var string1 = $" ({item.Value} * {item.Weight}) ";
                _logString1.Add(string1);

                _sumWeight += item.Weight;
                var string2 = $" {item.Weight} ";
                _logString2.Add(string2);

                _logIDStrings.Add(item.ResilienceWeight.ResilienceFactor_ID + $" V{item.Value:F2} W{item.Weight:F1}");
            }

            string _logResilienceFactor = $"ResilienceFactor (c{_resilienceHazardID}) = " +
                                          String.Join("+", _logString1) + " / (" + String.Join("+", _logString2) + ")" +
                                          ";\n         ResilienceValues: " + String.Join("; \n", _logIDStrings);;

            if (_sumWeight == 0) //avoid division by 0
            {
                return(new Tuple <double, string>(0.0d, _logResilienceFactor));
            }
            else
            {
                double _resilienceFactor = _sumValueWeight / _sumWeight;

                var _result = new Tuple <double, string>(_resilienceFactor, _logResilienceFactor);
                return(_result);
            }
        }