示例#1
0
 public int GetNumOfSamples(ExtractRITCharInfo rite)
 {
     if (DLMSetting.UseSubSampling == true)
     {
         float originWeight = GetOriginWeight(rite, DLMSetting);
         return((int)Math.Max(DLMSetting.MinSampleBldgs,
                              Math.Floor(rite.NumUnits * DLMSetting.NmbrSampleBldgScaleFactor * originWeight)));
     }
     else
     {
         return(rite.NumBuildings);
     }
 }
示例#2
0
        public float GetOriginWeight(ExtractRITCharInfo rite, SubSamplingAnalysisSetting DLMSetting)
        {
            string geoId            = GetGEOId(rite, DLMSetting);
            string lob              = rite.OriginWEightsLOBLookupCode;
            int    disAggResolution = rite.DisAggResolutionIntCode;

            if (DLMSetting.OriginWeightsDict.ContainsKey(Tuple.Create(disAggResolution, lob, geoId)))
            {
                return(DLMSetting.OriginWeightsDict[Tuple.Create(disAggResolution, lob, geoId)]);
            }
            else
            {
                return(1);
            }
        }
示例#3
0
        private int GetNumOfSamplesForRITE(ExtractRITCharInfo rite)
        {
            int NumSamples;
            AggNumSamplesGenerator sampleNumGen = new AggNumSamplesGenerator(SubSamplingSettings);

            if (rite.IsAggregateLowRes)
            {
                //NumSamples = 200;
                NumSamples = sampleNumGen.GetNumOfSamples(rite);
            }
            else
            {
                NumSamples = Math.Min(MaxNumSamplesPerHiResLocation, rite.NumBuildings);
            }

            return(NumSamples);
        }
示例#4
0
        private Dictionary <long, ExtractRITCharInfo> AggregateRITChars(Dictionary <long, ExtractRITCharInfo> CoverageIdAttrMap)
        {
            Dictionary <long, ExtractRITCharInfo> AggregatedRITCharsOutput = new Dictionary <long, ExtractRITCharInfo>();

            var AggreagateRITCharGroups = EDSDataExtract.CoverageIdAttrMap.GroupBy(pair => pair.Value.OriginalRITECharacteristicId);

            foreach (var AggRITCharGroup in AggreagateRITCharGroups)
            {
                ExtractRITCharInfo SampleDisAggCharInfo = AggRITCharGroup.First().Value;
                ExtractRITCharInfo AggRITCharInfo       = new ExtractRITCharInfo(SampleDisAggCharInfo);


                if (AggRITCharGroup.Key != AggRITCharGroup.First().Key)
                {
                    AggRITCharInfo.IsAggregateLowRes = true;
                }

                AggRITCharInfo.NumBuildings = 0;
                AggRITCharInfo.Value        = 0;
                //AggRITCharInfo.NumSamples = 0;
                //AggRITCharInfo.Factor = 1;
                AggRITCharInfo.RITExposureId = AggRITCharInfo.OriginalRITExposureId;
                AggRITCharInfo.OriginalRITECharacteristicId = AggRITCharGroup.Key;


                AggregateIDtoDisaggIDs.Add(AggRITCharInfo.OriginalRITECharacteristicId, new HashSet <long>());

                foreach (KeyValuePair <long, ExtractRITCharInfo> pair in AggRITCharGroup)
                {
                    AggRITCharInfo.NumBuildings += pair.Value.NumBuildings;
                    AggRITCharInfo.Value        += pair.Value.Value;

                    RiskCharIDtoAggregateID.Add(pair.Key, AggRITCharInfo.OriginalRITECharacteristicId);
                    AggregateIDtoDisaggIDs[AggRITCharInfo.OriginalRITECharacteristicId].Add(pair.Key);

                    DisaggRitCharToDisAggRIT.Add(pair.Key, pair.Value.RITExposureId);
                }

                AggregatedRITCharsOutput.Add(AggRITCharGroup.Key, AggRITCharInfo);
            }

            return(AggregatedRITCharsOutput);
        }
示例#5
0
        public string GetGEOId(ExtractRITCharInfo rite, SubSamplingAnalysisSetting DLMSetting)
        {
            if (DLMSetting.ResolutionIntCodeToFieldDict.ContainsKey(rite.OriginWeightsGeoIDLookupIntCode))
            {
                string       field = DLMSetting.ResolutionIntCodeToFieldDict[rite.OriginWeightsGeoIDLookupIntCode];
                Type         type  = rite.Address.GetType();
                PropertyInfo info  = type.GetProperty(field);
                if (info == null)
                {
                    return(null);
                }

                object value = info.GetValue(rite.Address, null);

                return(value.ToString());
            }
            else
            {
                throw new InvalidOperationException("Resolution Int code " + rite.OriginWeightsGeoIDLookupIntCode + " not found");
            }
        }
示例#6
0
        public ExtractRITCharInfo(ExtractRITCharInfo ra)
            : this()
        {
            if (ra != null)
            {
                this.ExposureType        = ra.ExposureType;
                this.NumBuildings        = ra.NumBuildings;
                this.RITExposureId       = ra.RITExposureId;
                this.ParentRITExposureId = ra.ParentRITExposureId;
                this.Value    = ra.Value;
                this.IsCampus = ra.IsCampus;
                this.OriginalRITExposureId        = ra.OriginalRITExposureId;
                this.OriginalRITECharacteristicId = ra.OriginalRITECharacteristicId;
                this.IsAggregateLowRes            = ra.IsAggregateLowRes;

                this.NumUnits          = ra.NumUnits;
                this.HazardScaleFactor = ra.HazardScaleFactor;
                this.OriginWeightsGeoIDLookupIntCode = ra.OriginWeightsGeoIDLookupIntCode;
                this.OriginWEightsLOBLookupCode      = ra.OriginWEightsLOBLookupCode;
                this.DisAggResolutionIntCode         = ra.DisAggResolutionIntCode;
                this.Address = ra.Address;
            }
        }
示例#7
0
        public void ExtractRiteMap()
        {
            if (AreMapsExtracted())
            {
                return;
            }
            try
            {
                bool flag0 = false, flag1 = false, flag2 = false;

                CoverageIdAttrMap = null;

                if (ConExp != null)
                {
                    #region Extraction of Subschedule and preparation of ResolvedSchedule
                    if (null != ConExp.Subschedules)
                    {
                        var ser = new ProtoCompressedSerializer();
                        Dictionary <string, Subschedule> dss =
                            ser.Deserialize <Dictionary <string, Subschedule> >(ConExp.Subschedules, 0, ConExp.Subschedules.Length);
                        if (null != dss)
                        {
                            SubSchedule = dss.Where(p => p.Value != null && p.Value.Type != null && (p.Value.Ids != null || p.Value.CompressedIds != null))
                                          .ToDictionary(p => p.Key, p => p.Value);

                            ResolvedSchedule = SubSchedule.ToDictionary(p => p.Key,
                                                                        p => ((p.Value.Ids != null) ? p.Value.Ids : new HashSet <long>(p.Value.CompressedIds.Enumerable())));
                        }

                        if (ResolvedSchedule == null || ResolvedSchedule.Count() == 0)
                        {
                            BugLog("Error: Contract Exposure Schedules couldn't be deserialized.");
                        }
                    }
                    else
                    {
                        BugLog("Error: Contract Exposure doesn't contain Schedules.");
                    }
                    #endregion

                    #region Extraction of Rite Attributes
                    if (ConExp.ContractSubjectExposures != null)
                    {
                        flag0 = true;
                        FactorGenerator generator = new FactorGenerator();

                        foreach (ContractSubjectExposureOfRiteSchedule cseRites in ConExp.ContractSubjectExposures)
                        {
                            if (null != cseRites.RITECollectionExposure && null != cseRites.RITECollectionExposure.RITExposures)
                            {
                                flag1 = true;

                                foreach (RITExposure ritExposure in cseRites.RITECollectionExposure.RITExposures)
                                {
                                    if (ritExposure.RiskitemCharacteristicsList != null && ritExposure.RiskitemCharacteristicsList.Items != null)
                                    {
                                        flag2 = true;
                                        foreach (RiskItemCharacteristicsValuation idxEntry in ritExposure.RiskitemCharacteristicsList.Items)
                                        {
                                            if (null == CoverageIdAttrMap)
                                            {
                                                CoverageIdAttrMap = new Dictionary <long, ExtractRITCharInfo>();
                                            }

                                            if (!CoverageIdAttrMap.ContainsKey(idxEntry.Id))
                                            {
                                                var P = new ExtractRITCharInfo();
                                                P.ExposureType  = idxEntry.RiteTypeId;
                                                P.NumBuildings  = ritExposure.CommonCharacteristics.NumBuildings;
                                                P.RITExposureId = ritExposure.ExposureID;
                                                P.Value         = idxEntry.RITExposureValuationList.First().Value;
                                                P.OriginalRITECharacteristicId = idxEntry.ParentId;
                                                P.NumSamples = generator.GetFactor(ritExposure).NumOfSamples;
                                                //P.NumSamples = generator.GetNumOfSamples(ritExposure);
                                                P.Factor = generator.GetFactor(ritExposure).Factor;

                                                //needed for NumSamples algorithm
                                                P.NumUnits          = ritExposure.CommonCharacteristics.NumUnits;
                                                P.HazardScaleFactor = ritExposure.CommonCharacteristics.TaxValue;
                                                P.OriginWeightsGeoIDLookupIntCode = ritExposure.CommonCharacteristics.FireAlarm;
                                                P.OriginWEightsLOBLookupCode      = ritExposure.CommonCharacteristics.FirePlace;
                                                P.DisAggResolutionIntCode         = ritExposure.CommonCharacteristics.NumberOfEscalators;
                                                P.Address = ritExposure.Address;
                                                //--

                                                if (ritExposure.ClonedExposureId != null)
                                                {
                                                    P.OriginalRITExposureId = (long)ritExposure.ClonedExposureId;
                                                }
                                                //else
                                                //    throw new InvalidOperationException("Clone Exposure ID is null!");
                                                CoverageIdAttrMap.Add(idxEntry.Id, P);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        BugLog("Error: Contract Exposure Subject isn't exist.");
                    }
                    #endregion
                }

                if (!flag0)
                {
                    BugLog("Error: Contract Exposure data wasn't uploaded from extract file.");
                }
                else if (!flag1)
                {
                    BugLog("Error: Contract Exposure Risk Item Collection isn't exist.");
                }
                else if (!flag2)
                {
                    BugLog("Error: Contract Exposure Risk Item Characteristics List isn't exist.");
                }

                #region Check
                //HashSet<long> coverageIDs1 = null, coverageIDs2 = null;

                //if (null != ResolvedSchedule)
                //    coverageIDs1 =
                //        ResolvedSchedule.Aggregate(new HashSet<long>(), (a, b) => { a.UnionWith(b.Value); return a; });
                //if (null != RiskItemCharacteristicIDAttributeMap)
                //    coverageIDs2 = new HashSet<long>(RiskItemCharacteristicIDAttributeMap.Keys);

                //int n1 = (null != coverageIDs1) ? coverageIDs1.Count() : 0;
                //int n2 = (null != coverageIDs2) ? coverageIDs2.Count() : 0;
                //if (n1 != n2)
                //{
                //    string msg = string.Format("Number of RITEs({0}) in Subschedules is not equal to number of RITEs({1}) in Collection of ContractSubjectExposures", n1, n2);
                //    throw new Exception(msg);
                //}
                #endregion
            }
            catch (Exception ex) { BugLog("Error: " + ex.Message); }
        }