Exemple #1
0
        //
        // GET: /Risk/


        private ActionResult GenerateRiskFactor(string getinfor)
        {
            RiskCalculator _rcal = new RiskCalculator();

            //string[] getrisks = str.Split('_');
            int Diabetes    = 0;
            int Periodontal = 0;
            int Sleep       = 0;

            foreach (char item in getinfor)
            {
                if (item == 't')
                {
                    Periodontal++;
                }
                else if (item == 'e')
                {
                    Diabetes++;
                }
                else
                {
                    Sleep++;
                }
            }

            _rcal.DiabetisResult    = 84 + (84 * Diabetes) + "px";
            _rcal.PeriodontalResult = 46.6 + (46.6 * Periodontal) + "px";
            _rcal.SleepResult       = 60 + (60 * Sleep) + "px";
            System.IO.StreamReader myFile = new System.IO.StreamReader(Server.MapPath("~/Files/MedicalDisclaimer.txt"));
            _rcal.MedicalDisclaimer = myFile.ReadToEnd();
            System.IO.StreamReader myresult = new System.IO.StreamReader(Server.MapPath("~/Files/results.txt"));
            _rcal.Results = myresult.ReadToEnd();
            return(View(_rcal));
        }
Exemple #2
0
        public void Init()
        {
            _riskCalculator  = new RiskCalculator();
            _exposureKeyMock = new ExposureKeyMock();
            _rndGenerator    = new MockRandomGenerator();

            _key = _exposureKeyMock.CreateMockedExposureKey();
        }
 public Contracts.Control.Control Update(Contracts.Control.UpdateControl updateControl)
 {
     using (var db = new RAAPEntities(GetConnectionString()))
     {
         var process = db.Controls.FirstOrDefault(a => a.ControlId == updateControl.ControlId);
         if (process == null)
         {
             throw new RAAPNotFoundException("Item not found.");
         }
         RiskCalculator.CheckRiskTypes(updateControl, db);
         process.ApplyUpdate(updateControl, db);
         db.SaveChanges();
         return(process.ToContract(_userService));
     }
 }
        public Contracts.Control.Control Create(Contracts.Control.CreateControl createControl)
        {
            using (var db = new RAAPEntities(GetConnectionString()))
            {
                if (db.Controls.Any(a => a.Name == createControl.Name))
                {
                    throw new RAAPConflictException("Name is already in use, please try another name.");
                }
                RiskCalculator.CheckRiskTypes(createControl, db);
                var process = createControl.ToDataModel(db);
                db.Controls.Add(process);

                db.SaveChanges();

                return(process.ToContract(_userService));
            }
        }
 public Contracts.Process.Process Update(Contracts.Process.UpdateProcess updateProcess)
 {
     using (var db = new RAAPEntities(GetConnectionString()))
     {
         var process = db.Processes.FirstOrDefault(a => a.ProcessId == updateProcess.ProcessId);
         if (process == null)
         {
             throw new RAAPNotFoundException("Item not found.");
         }
         RiskCalculator.CheckRiskTypes(updateProcess, db);
         process.ApplyUpdate(updateProcess, db);
         RemoveUnusedAssets(process, updateProcess);
         AddAssets(db, process, updateProcess.Assets);
         RiskCalculator.CalculateRisk(process);
         db.SaveChanges();
         return(process.ToContract(_userService));
     }
 }
        public Contracts.Threat.Threat Create(Contracts.Threat.CreateThreat createThreat)
        {
            using (var db = new RAAPEntities(GetConnectionString()))
            {
                if (db.Threats.Any(a => a.Name == createThreat.Name))
                {
                    throw new RAAPConflictException("Name is already in use, please try another name.");
                }
                RiskCalculator.CheckRiskTypes(createThreat, db);
                RiskCalculator.CalculateRisk(createThreat);
                var threat = createThreat.ToDataModel(db);
                db.Threats.Add(threat);
                AddControls(db, threat, createThreat.Controls);
                db.SaveChanges();

                return(threat.ToContract(_userService));
            }
        }
Exemple #7
0
        private EuGatewayService CreateGatewayServiceAndDependencies(IGatewayHttpClient httpClient)
        {
            _keysRepository = new TemporaryExposureKeyRepository(_dbContext, _countryRepository, _temporaryExposureKeyRepositoryLogger.Object);

            var signatureServiceMock = new Mock <ISignatureService>(MockBehavior.Strict);

            var webContextReader = new GatewayWebContextReader(_autoMapper, _loggerGatewayWebContextReader.Object);

            var epochConverter = new EpochConverter();

            var keyValidator        = new KeyValidator(epochConverter);
            var exposureKeyMapper   = new ExposureKeyMapper(_epochConverter);
            var keyFilterLoggerMock = new Mock <ILogger <KeyFilter> >(MockBehavior.Loose);
            var keyFilter           = new KeyFilter(_autoMapper, keyValidator, exposureKeyMapper, keyFilterLoggerMock.Object, _keysRepository);

            var storeServiceLoggerMock = new Mock <ILogger <EFGSKeyStoreService> >();

            var riskCalculator = new RiskCalculator();
            var dsosDecoder    = new DaysSinceOnsetOfSymptomsDecoder();
            var addTemporaryExposureKeyService = new Mock <IAddTemporaryExposureKeyService>(MockBehavior.Strict);

            addTemporaryExposureKeyService
            .Setup(x => x.FilterDuplicateKeysAsync(It.IsAny <List <TemporaryExposureKey> >()))
            .ReturnsAsync((List <TemporaryExposureKey> argument) =>
            {
                return(argument);
            });
            var storeService             = new EFGSKeyStoreService(keyFilter, _keysRepository, storeServiceLoggerMock.Object, riskCalculator, epochConverter, dsosDecoder, addTemporaryExposureKeyService.Object);
            var gatewayServiceLoggerMock = new Mock <ILogger <EuGatewayService> >(MockBehavior.Loose);

            return(CreateGatewayService(
                       _keysRepository,
                       signatureServiceMock.Object,
                       _autoMapper,
                       httpClient,
                       keyFilter,
                       webContextReader,
                       storeService,
                       gatewayServiceLoggerMock.Object,
                       epochConverter,
                       _config
                       ));
        }
 public Contracts.Threat.Threat Update(Contracts.Threat.UpdateThreat updateThreat)
 {
     using (var db = new RAAPEntities(GetConnectionString()))
     {
         var threat = db.Threats.Include("Controls").FirstOrDefault(a => a.ThreatId == updateThreat.ThreatId);
         if (threat == null)
         {
             throw new RAAPNotFoundException("Item not found.");
         }
         RiskCalculator.CheckRiskTypes(updateThreat, db);
         threat.ApplyUpdate(updateThreat, db);
         RemoveUnusedControls(threat, updateThreat);
         AddControls(db, threat, updateThreat.Controls);
         RiskCalculator.ResetCalculatedRisk(threat);
         RiskCalculator.CalculateRisk(threat);
         db.SaveChanges();
         return(threat.ToContract(_userService));
     }
 }
Exemple #9
0
        public void Init()
        {
            _riskCalulator     = new RiskCalculator();
            _exposureKeyMock   = new ExposureKeyMock();
            _webContextMock    = new WebContextMock();
            _mockSetup         = new SetupMockedServices();
            _webContextReader  = new Mock <IGatewayWebContextReader>(MockBehavior.Strict);
            _keyFilter         = new Mock <IKeyFilter>(MockBehavior.Strict);
            _tempKeyRepository = new Mock <ITemporaryExposureKeyRepository>(MockBehavior.Strict);
            _logger            = new Mock <ILogger <EFGSKeyStoreService> >();
            _epochConverter    = new EpochConverter();
            _onsetDaysDecoder  = new DaysSinceOnsetOfSymptomsDecoder();

            _mockSetup.SetupWebContextReaderMock(_webContextReader);
            _mockSetup.SetupKeyFilterMock(_keyFilter);
            _mockSetup.SetupTemopraryExposureKeyRepositoryMock(_tempKeyRepository);

            _keyStoreService = new EFGSKeyStoreService(_webContextReader.Object, _keyFilter.Object, _tempKeyRepository.Object, _logger.Object, _riskCalulator, _epochConverter, _onsetDaysDecoder);
        }
        public async Task <ActionResult <PortfolioRiskStatsViewDto> > GetPortfolioMinuteRiskInfo(int id)
        {
            DateTime baseDate = DateTime.Now;

#if DEBUG
            baseDate = new DateTime(2018, 08, 01);
#endif

            List <double> fullReturnSet = await _portfolioContext.PortfolioMinuteReturns
                                          .Where(p => p.PortfolioId == id)
                                          .Where(p => p.DateTime < baseDate && p.DateTime >= baseDate.AddMonths(-1))
                                          .OrderBy(p => p.Return)
                                          .Select(p => p.Return)
                                          .ToListAsync();

            var partialResult = await RiskCalculator.GetAssetRiskStats(fullReturnSet);

            PortfolioRiskStatsViewDto result = new PortfolioRiskStatsViewDto(
                id, partialResult);

            return(result);
        }
        public ScanResult ScanBrowsers()
        {
            var items = new ScanItem[]
            {
                new ScanItem("google.com", "*****@*****.**", "duplicate"),
                new ScanItem("Site2.com", "User2", "duplicate"),
                new ScanItem("Site3.com", "User3", "Password3"),
                new ScanItem("Site4.com", "User1", "VERY_Str0ngPassword_And_long_as_fantasy_lets_to_type_as_much_letters_as_we_can!!!!"),
                new ScanItem("Site5.com", "User2", "wek"),
                new ScanItem("Site6.com", "User3", "wek"),
                new ScanItem("Site7.com", "User1", "wek"),
                new ScanItem("Site8.com", "User2", "weak4duplicate"),
                new ScanItem("Site9.com", "User3", "weak4duplicate"),
            };

            items = new RiskCalculator().MarkDuplicates(items);
            var res = new ScanResult(items);

            new RegistryManager().PutScanSummaryToRegistry(res);

            return(res);
        }
        public Contracts.Process.Process Create(Contracts.Process.CreateProcess createProcess)
        {
            using (var db = new RAAPEntities(GetConnectionString()))
            {
                if (db.Processes.Any(a => a.Name == createProcess.Name))
                {
                    throw new RAAPConflictException("Name is already in use, please try another name.");
                }

                if (createProcess.Category == null)
                {
                    throw new RAAPConflictException("Category is not selected.");
                }
                RiskCalculator.CheckRiskTypes(createProcess, db);
                var process = createProcess.ToDataModel(db);
                AddAssets(db, process, createProcess.Assets);
                db.Processes.Add(process);
                RiskCalculator.CalculateRisk(process);
                db.SaveChanges();

                return(process.ToContract(_userService));
            }
        }
 public ActionScoreController(RiskCalculator riskScoreCalculator)
 {
     this.riskScoreCalculator = riskScoreCalculator;
 }
Exemple #14
0
        public Contracts.Risk.RiskType CreateRiskType(Contracts.Risk.RiskType riskType)
        {
            if (string.IsNullOrWhiteSpace(riskType.Name))
            {
                throw new RAAPConflictException("Invalid/missing name");
            }
            using (var db = new RAAPEntities(GetConnectionString()))
            {
                if (db.RiskTypes.Any(r => r.Name == riskType.Name.Trim()))
                {
                    throw new RAAPConflictException("Name is already in use, please try another name.");
                }
                var dbRiskType = riskType.ToDataModel();
                db.RiskTypes.Add(dbRiskType);
                foreach (var asset in db.Assets)
                {
                    var threatRisk = new ThreatRisk()
                    {
                        RiskType = dbRiskType,
                    };
                    RiskCalculator.ResetRisk(threatRisk);
                    asset.ThreatRisks.Add(threatRisk);
                }
                foreach (var threat in db.Threats)
                {
                    var threatRisk = new ThreatRisk()
                    {
                        RiskType = dbRiskType,
                    };
                    RiskCalculator.ResetRisk(threatRisk);
                    threat.ThreatRisks.Add(threatRisk);
                }

                foreach (var assetThreat in db.Asset_Threat)
                {
                    var threatRisk = new ThreatRisk()
                    {
                        RiskType = dbRiskType,
                    };
                    RiskCalculator.ResetRisk(threatRisk);
                    assetThreat.ThreatRisks.Add(threatRisk);
                }

                foreach (var control in db.Controls)
                {
                    var controlRisk = new ControlRisk()
                    {
                        RiskType = dbRiskType,
                    };
                    control.ControlRisks.Add(controlRisk);
                }

                foreach (var assetThreatControl in db.AssetThreat_Control)
                {
                    var controlRisk = new ControlRisk()
                    {
                        RiskType = dbRiskType,
                    };
                    assetThreatControl.ControlRisks.Add(controlRisk);
                }

                db.SaveChanges();
                return(dbRiskType.ToContract());
            }
        }
 public PositiveRiskCheckBoxViewModel(int risk)
 {
     Risk = risk;
     RiskCalculator.Note(this);// this - передаем тип самого класса, который унаследовани от соответсвующего позитивного или негативного интерфейса и тамк студия понимает метод реализации калькулятора , т.к. в зависимости от позитивного или негативного (есть два конструктора с разной реализацией методов)
 }
Exemple #16
0
        internal static void RiskCalc(
            int riskIndex,
            int currentAge,
            int projectionAge,
            int menarcheAge,
            int firstLiveBirthAge,
            int everHadBiopsy,
            int numberOfBiopsy,
            int hyperPlasia,
            int firstDegRelatives,
            int race,
            out double absoluteRisk,
            out double averageRisk)
        {
            int    ageIndicator;
            double rHyperPlasia;

            currentAge        = BcptConvert.GetCurrentAge(currentAge);
            menarcheAge       = BcptConvert.MenarcheAge(menarcheAge);
            firstLiveBirthAge = BcptConvert.FirstLiveBirthAge(firstLiveBirthAge);
            everHadBiopsy     = BcptConvert.EverHadBiopsy(everHadBiopsy);
            numberOfBiopsy    = BcptConvert.NumberOfBiopsy(numberOfBiopsy, everHadBiopsy);
            hyperPlasia       = BcptConvert.Hyperplasia(hyperPlasia, everHadBiopsy);
            //firstDegRelatives = BcptConvert.FirstDegRelatives(firstDegRelatives);
            race = BcptConvert.GetRace(race.ToString());

            if (race < 7)
            {
                firstDegRelatives = BcptConvert.FirstDegRelatives(firstDegRelatives);
            }
            else
            {
                firstDegRelatives = BcptConvert.FirstDegRelatives(firstDegRelatives, race);
            }

            ageIndicator = BcptConvert.CurrentAgeIndicator(currentAge);
            rHyperPlasia = BcptConvert.RHyperplasia(hyperPlasia, everHadBiopsy);

            riskIndex = 1;  //get absolute risk
            RiskCalculator oBcpt = new RiskCalculator();

            absoluteRisk = oBcpt.CalculateAbsoluteRisk(
                currentAge          //[t1]
                , projectionAge     //[t2]
                , ageIndicator      //[i0]
                , numberOfBiopsy    //[i2]
                , menarcheAge       //[i1]
                , firstLiveBirthAge //[i3]
                , firstDegRelatives //[i4]
                , everHadBiopsy     //[iever]
                , hyperPlasia       //[ihyp]
                , rHyperPlasia      //[rhyp]
                , race              //[race]
                );
            riskIndex   = 2;        //get average risk also
            averageRisk = oBcpt.CalculateAeverageRisk(
                currentAge          //[t1]
                , projectionAge     //[t2]
                , ageIndicator      //[i0]
                , numberOfBiopsy    //[i2]
                , menarcheAge       //[i1]
                , firstLiveBirthAge //[i3]
                , firstDegRelatives //[i4]
                , everHadBiopsy     //[iever]
                , hyperPlasia       //[ihyp]
                , rHyperPlasia      //[rhyp]
                , race              //[race]
                );
        }