Exemplo n.º 1
0
 static DB()
 {
     ActiveEvents        = new ActiveEvents();
     ActiveGiveaways     = new ActiveGiveaways();
     BackgroundInventory = new BackgroundInventory();
     Cooldowns           = new Cooldowns();
     Events             = new Database.Events();
     EventLogs          = new EventLogs();
     EventSchedule      = new EventSchedule();
     GiveawayLogs       = new GiveawayLogs();
     Giveaways          = new Giveaways();
     Inventory          = new Inventory();
     LeagueData         = new LeagueData();
     Mappings           = new Mappings();
     ModerationLogs     = new ModerationLogs();
     PendingUsers       = new PendingUsers();
     ProfileBackgrounds = new ProfileBackgrounds();
     Rewards            = new Rewards();
     RoleInventory      = new RoleInventory();
     Roles        = new Roles();
     Settings     = new Settings();
     Statistics   = new Statistics();
     Streamers    = new Streamers();
     SystemTimers = new SystemTimers();
     TempRoles    = new TempRoles();
     Toxicity     = new Toxicity();
     Users        = new Users();
 }
Exemplo n.º 2
0
        public static void TestModel(string text)
        {
            var    asm     = new FileInfo(typeof(Program).Assembly.Location);
            string rootdir = asm.Directory.FullName;

            var sentfs = new FileStream(path: $"{rootdir}/Model/Model.zip", mode: FileMode.Open);
            var califs = new FileStream(path: $"{rootdir}/Model/CaliModel.zip", mode: FileMode.Open);

            var sentpipe = mlctx.Model.Load(sentfs, out _);

            sentfs.Close();
            sentfs.Dispose();

            var calipipe = mlctx.Model.Load(califs, out _);

            califs.Close();
            califs.Dispose();

            var sentpredengine = mlctx.Model.CreatePredictionEngine <Toxicity, ToxicRawScore>(sentpipe);
            var sample         = new Toxicity()
            {
                Text = text
            };
            var results = sentpredengine.Predict(sample);

            var calipredengine = mlctx.Model.CreatePredictionEngine <ToxicRawScore, ToxicPrediction>(calipipe);
            var calires        = calipredengine.Predict(results);

            Console.WriteLine($"\n\nPrediction Results: Text: {sample.Text} || Prediction: {(calires.Prediction ? "Toxic": "Not Toxic")}\n\nScore: {calires.RawScore} || Probability: {calires.ProbabilityOfBeingToxic}");
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="toxicityId"></param>
        private void PopulateForm(int?toxicityId)
        {
            if (toxicityId.HasValue)
            {
                // populate toxicity
                Toxicity biz = new Toxicity();
                biz.Get(toxicityId.Value);
                base.PopulateForm(ToxicityFields, biz);

                // Determine if SAE fields need to be displayed when records exits
                //SeriousAdverseEvent adverseEvents = new SeriousAdverseEvent();
                //adverseEvents.GetByParent(toxicityId);
                //if (adverseEvents.RecordCount > 0)
                //{
                //    ShowSAEField.Value = bool.TrueString.ToLower();
                //    base.PopulateForm(SAEFields, adverseEvents);
                //}

                SeriousAdverseEvent adverseEvent = BusinessObject.GetByParent <SeriousAdverseEvent>(toxicityId.Value).FirstOrDefault();
                if (adverseEvent != null)
                {
                    base.PopulateForm(this, adverseEvent);
                }

                int       patientItemId  = int.Parse(base.DecrypyValue(PatientItemId.Value));
                DataTable relatedRecords = RelatedRecordsDa.GetRecord("ProtocolMgr_PatientItems", patientItemId, "Toxicities", toxicityId.Value);
                if (relatedRecords.Rows.Count > 0)
                {
                    RelatedRecordId.Value = relatedRecords.Rows[0][RelatedRecord.RelatedRecordId].ToString();
                }
            }
            PopulateAttributions(toxicityId);
        }
Exemplo n.º 4
0
        private void SaveForm(bool registerUpdateScript)
        {
            // only update dirty record
            if (isToxicityRecordDirty)
            {
                int patientId = int.Parse(BaseDecryptedPatientId);
                // save toxicity
                Toxicity tox        = new Toxicity();
                int      toxicityId = SaveRecord(ToxicityFields, tox, ToxicityIdField, patientId);

                // PatientItem Record
                PatientItem item = new PatientItem();
                int         patientItemId;
                if (!string.IsNullOrEmpty(PatientItemId.Value))
                {
                    item.Get(int.Parse(base.DecrypyValue(PatientItemId.Value)));
                }
                else
                {
                    item[PatientItem.PatientSchemaId] = PatientSchemaId;
                    item[PatientItem.Status]          = "Unplanned";
                }
                item[PatientItem.ScheduledDate] = ToxDate.Value;
                item.Save();
                patientItemId       = (int)item[item.PrimaryKeyName];
                PatientItemId.Value = base.EncryptValue(patientItemId.ToString());

                // Related Record
                int relatedRecordId = PatientProtocolController.CreateUnplannedVisitRelatedRecord(patientItemId, tox.TableName, toxicityId);
                RelatedRecordId.Value = relatedRecordId.ToString();

                // if visible to user and record dirty
                if (isSAERecordDirty)
                {
                    // SAE Record
                    SeriousAdverseEvent sae = new SeriousAdverseEvent();
                    SaveRecord(SAEFields, sae, ToxicityIdField, toxicityId);
                }
            }
            // no need to update parent Toxicity, update child record if needed
            else if (isSAERecordDirty && !string.IsNullOrEmpty(ToxicityIdField.Value))
            {
                int toxicityId          = int.Parse(ToxicityIdField.Value);
                SeriousAdverseEvent sae = new SeriousAdverseEvent();
                SaveRecord(SAEFields, sae, ToxicityIdField, toxicityId);
            }
            // save attributions
            if (!string.IsNullOrEmpty(ToxicityIdField.Value) && ToxAttributionGrid.DirtyRows.Count > 0)
            {
                int toxicityId = int.Parse(ToxicityIdField.Value);
                ToxAttributionGrid.Save(toxicityId);
            }
            // register client update script (close form from popup)
            if (registerUpdateScript)
            {
                RegisterUpdateScript(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Transfer to SAE Details where relevant details entered
        /// </summary>
        /// <param name="toxicityId"></param>
        private void CheckSAEDetails(int toxicityId)
        {
            Toxicity tox = new Toxicity();

            tox.Get(toxicityId);
            // if is SAE, transfer
            if (!tox.IsNull(Toxicity.ToxSAE) && PageUtil.IsTrueString(tox[Toxicity.ToxSAE] + ""))
            {
                TransferToSAEDetails(toxicityId);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void DeleteClick(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(ToxicityIdField.Value))
     {
         // delete main tox record
         Toxicity biz = new Toxicity();
         biz.Delete(int.Parse(ToxicityIdField.Value));
         RegisterUpdateScript(true);
         // delete associated record
         RelatedRecord relatedRecord = new RelatedRecord();
         relatedRecord.Delete(int.Parse(RelatedRecordId.Value));
     }
 }
Exemplo n.º 7
0
        public static void TrainBinaryModel()
        {
            var    asm     = new FileInfo(typeof(Program).Assembly.Location);
            string rootdir = asm.Directory.FullName;

            //Config - Convert text data into format of type Sentiment
            IDataView dataView = mlctx.Data.LoadFromTextFile <Toxicity>($"{rootdir}/Data/TestData.tsv", hasHeader: false);

            //Split test data set into training and testing data sets
            var trainTestData = mlctx.Data.TrainTestSplit(dataView, 0.4);
            var trainingData  = trainTestData.TrainSet;
            var testingData   = trainTestData.TestSet;

            var aasdas = dataView.Preview();

            //Transform text into usable binary set
            var dataPipline = mlctx.Transforms.Text.FeaturizeText("Features", "Text");

            //Set the algorithm and config model builder
            var trainer         = mlctx.BinaryClassification.Trainers.AveragedPerceptron("Label", "Features", new SmoothedHingeLoss(), 5F, true, numberOfIterations: 5000).AppendCacheCheckpoint(mlctx);
            var trainingPipline = dataPipline.Append(trainer);

            int elapsedsecs = 0;
            var timer       = new Timer((_) =>
            {
                elapsedsecs++;
                Console.Clear();
                Console.WriteLine($"Training Model -> Elapsed Time: {elapsedsecs}s");
            }, null, 0, 1000);

            //Fit model to training data
            var trainedModel = trainingPipline.Fit(trainingData);

            timer.Dispose();

            //Evaluate and show results
            Console.WriteLine("Testing and Evaluating Model");
            var pred = trainedModel.Transform(testingData);

            var sentment = mlctx.BinaryClassification.EvaluateNonCalibrated(pred);

            var caliest        = mlctx.BinaryClassification.Calibrators.Platt();
            var calitrans      = caliest.Fit(pred);
            var finaldatatrans = calitrans.Transform(pred);

            //Save Model
            Console.WriteLine("Saving Model");
            mlctx.Model.Save(trainedModel, trainingData.Schema, $"{rootdir}/Model/Model.zip");

            //Sample sentence prediction
            var sample = new Toxicity {
                Text = "Hello, how are you today?"
            };

            var predengine = mlctx.Model.CreatePredictionEngine <Toxicity, ToxicRawScore>(trainedModel);
            var results    = predengine.Predict(sample);

            var predent = mlctx.Model.CreatePredictionEngine <ToxicRawScore, ToxicPrediction>(calitrans);
            var rest    = predent.Predict(results);

            mlctx.Model.Save(calitrans, predent.OutputSchema, $"{rootdir}/Model/CaliModel.zip");

            Console.WriteLine($"Metrics -> Accuracy: {sentment.Accuracy} || Negative Precision: {sentment.NegativePrecision} || Positive Precision: {sentment.PositivePrecision}");
            Console.WriteLine($"\n\nPrediction Results: Text: {sample.Text} || Prediction: {(rest.Prediction ? "Toxic" : "Not Toxic")} || Probility: {rest.ProbabilityOfBeingToxic}");
        }