示例#1
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); }
        }
示例#2
0
        public bool GenerateRITELoss(int eventID)
        {
            bool   success = true;
            double factor  = 1.0;
            //generate factor from FactorGenerator
            FactorGenerator fGen = new FactorGenerator();

            GULosses = new Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > >();
            Dictionary <long, Tuple <double, uint, List <float> > > temp;

            foreach (string subperil in subperils)
            {
                temp = new Dictionary <long, Tuple <double, uint, List <float> > >();
                foreach (RITCharacteristic RITChar in expData.Characteristics)
                {
                    long RITCharID = RITChar.ID;

                    if (expData.UseAggregatedRITEs)
                    {
                        HashSet <long> DisAggRITChars = expData.AggregateIDtoDisaggIDs[RITCharID];

                        Dictionary <long, int> NumOfSamplesByRITChar;
                        if (RITChar.ParentRITE.IsAggregate)
                        {
                            NumOfSamplesByRITChar = BuildNumOfSampleDictionary(RITChar, DisAggRITChars, eventID, RITChar.ParentRITE.ActNumOfSampleBldgs);
                        }
                        else
                        {
                            NumOfSamplesByRITChar = new Dictionary <long, int> {
                                { RITCharID, RITChar.ParentRITE.ActNumOfSampleBldgs }
                            }
                        };

                        double FactorForAggLoc = RITChar.ParentRITE.Factor;

                        foreach (long DisAggRITCharID in DisAggRITChars)
                        {
                            int IntialnumSamples = NumOfSamplesByRITChar[DisAggRITCharID];
                            int FinalnumSamples  = Math.Min(expData.MaxNumSamplesPerHiResLocation, IntialnumSamples);

                            double AdjustementForFactor = 1;
                            if (FinalnumSamples > 0)
                            {
                                AdjustementForFactor = (double)IntialnumSamples / FinalnumSamples;
                            }

                            double FactorForDisaggLoc = FactorForAggLoc * AdjustementForFactor;
                            float  RITCharTIV         = (float)RITChar.TIVPerBuilding;

                            List <float> LossList     = GenerateRandomLossForRITE(eventID, subperil, DisAggRITCharID, FinalnumSamples, RITCharTIV);
                            uint         eventNumDays = GenerateRandomDateTimeForRITE(eventID, subperil, DisAggRITCharID);
                            ////factor generator
                            //FactorInfo fInfo= fGen.GetFactor(RITChar.ParentRITE.ExposureID); //the sample of size is for RIT (location)
                            temp.Add(DisAggRITCharID, Tuple.Create(FactorForDisaggLoc, eventNumDays, LossList));
                        }
                    }
                    else
                    {
                        int   numSamples = RITChar.ParentRITE.ActNumOfSampleBldgs;
                        float RITCharTIV = (float)RITChar.TIVPerBuilding;

                        List <float> LossList     = GenerateRandomLossForRITE(eventID, subperil, RITCharID, numSamples, RITCharTIV);
                        uint         eventNumDays = GenerateRandomDateTimeForRITE(eventID, subperil, RITCharID);
                        ////factor generator
                        //FactorInfo fInfo= fGen.GetFactor(RITChar.ParentRITE.ExposureID); //the sample of size is for RIT (location)
                        temp.Add(RITCharID, Tuple.Create((double)RITChar.ParentRITE.Factor, eventNumDays, LossList));
                    }
                }

                GULosses.Add(subperil.ToString(), new Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > >()
                {
                    { 0, temp }
                });
            }

            return(success);
        }