Beispiel #1
0
        public Solvent TransformToSolvent()
        {
            Solvent result = new Solvent();

            result.MoleculeCAS = MoleculeCAS;
            result.v           = VValue;

            return(result);
        }
Beispiel #2
0
        // SolventMix is a mix of Weed-leaves and chemical(s).
        public SolventMix(IChronic chronic, IChemical chemical)
            : base(chronic.Name + " " + chemical.Name, chronic.Description + " " + chemical.Description, chronic.Weight + chemical.Weight, chronic.Value)
        {
            Type = ItemType.SolventMix;

            _extractedOils = new Random().NextDouble() * (0.85 - 0.75) + 0.75;
            Chronic = chronic;
            Chemical = chemical;
            Solvent = new Solvent(Chronic, Chemical);
        }
Beispiel #3
0
        public void EmptySolventTest()
        {
            Solvent item = new Solvent();

            List <OutputMessage> errors = new List <OutputMessage>();

            errors = item.Validate();

            Assert.AreNotEqual(0, errors.Count);
        }
Beispiel #4
0
        private Solvent LoadSolvent(IDataReader reader)
        {
            Solvent model = new Solvent();

            model.SolventId   = reader.GetInt32("solvent_id");
            model.Name        = reader.GetString("name");
            model.Description = reader.GetString("description");
            model.ImageName   = reader.GetString("image_name");
            model.DateEntry   = reader.GetDateTime("date_entry");
            model.DateUpdated = reader.GetDateTime("date_updated");

            return(model);
        }
Beispiel #5
0
        public void SelectedSolventTest()
        {
            molecules.Add(new SelectedMolecule()
            {
                Name = "MoleculeA", CAS = "AAAAA-AA-A", Location = "Q2", VAvailable = 25.2
            });

            Solvent item = new Solvent(molecules[0]);

            List <OutputMessage> errors = new List <OutputMessage>();

            errors = item.Validate();

            Assert.AreNotEqual(0, errors.Count);
        }
Beispiel #6
0
        public void SelectedAndNumberVInputSolventTest()
        {
            molecules.Add(new SelectedMolecule()
            {
                Name = "MoleculeA", CAS = "AAAAA-AA-A", Location = "Q2", VAvailable = 674
            });

            Solvent item = new Solvent(molecules[0]);

            item.VValueString = "21";
            List <OutputMessage> errors = new List <OutputMessage>();

            errors = item.Validate();

            Assert.AreEqual(0, errors.Count);
        }
Beispiel #7
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] SustainableChemistryWeb.Models.Solvent solvent)
        {
            try
            {
                Solvent appSolvent = new Solvent()
                {
                    Name        = solvent.Name,
                    Description = solvent.Description
                };
                if (ModelState.IsValid)
                {
                    _context.Add(appSolvent);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #8
0
        public static Algorithm ParseJson(String jsonString, List <MinMaxValue> minMaxValues)
        {
            dynamic   jsonModel = JsonConvert.DeserializeObject(jsonString);
            Algorithm algorithm = new Algorithm()
            {
                AlgorithmName = jsonModel.algorithm,
                Models        = new List <Model>()
            };
            Model model = new Model()
            {
                Clusters         = new List <Cluster>(),
                DataSet          = jsonModel.dataSet,
                Date             = DateTime.Now,
                NumberOfSolvents = 0,
                NumberOfFeatures = 0,
                ModelPath        = jsonModel.modelPath,
                AlgorithmName    = jsonModel.algorithm
            };

            foreach (var cluster in jsonModel.clusters)
            {
                Cluster clusterTemp = new Cluster()
                {
                    DistanceToClusters = new List <ClusterDistanceCenter>(),
                    Number             = cluster.clusterNumber,
                    Solvents           = new List <Solvent>(),
                    VectorData         = new List <VectorData>(),
                };
                foreach (var vector in cluster.vectorData)
                {
                    VectorData vectorData = new VectorData()
                    {
                        Value       = vector.value,
                        FeatureName = vector.name
                    };

                    clusterTemp.VectorData.Add(vectorData);
                }

                foreach (var distance in cluster.distanceToCluster)
                {
                    ClusterDistanceCenter clusterDistanceCenter = new ClusterDistanceCenter()
                    {
                        ToClusterId = distance.clusterId,
                        Distance    = distance.distance
                    };
                    clusterTemp.DistanceToClusters.Add(clusterDistanceCenter);
                }

                foreach (var solvent in cluster.solvents)
                {
                    Solvent solventTemp = new Solvent()
                    {
                        CasNumber = solvent.casNumber,
                        Name      = solvent.name,
                        DistanceToClusterCenter = solvent.distanceToCluster,
                        Features = new List <Feature>(),
                        MetaData = new SolventMetaData()
                        {
                            Label       = solvent.predictLabel,
                            IdCasNr     = solvent.iD_CAS_Nr_1,
                            IdEgNr      = solvent.iD_EG_Nr,
                            IdEgAnnexNr = solvent.iD_EG_Annex_Nr,
                            Input       = solvent.input,
                            IdName1     = solvent.iD_Name_1
                        }
                    };
                    solventTemp.CasNumber = solventTemp.CasNumber.Replace("\"", "");
                    solventTemp.Name      = solventTemp.Name.Replace("\"", "");
                    foreach (var feature in solvent.features)
                    {
                        FeatureName featureName;
                        Enum.TryParse <FeatureName>(feature.name.ToString(), out featureName);
                        var     value       = minMaxValues.FirstOrDefault(a => a.FeatureName == featureName);
                        Feature featureTemp = new Feature()
                        {
                            FeatureName = feature.name,
                            Value       = feature.value
                        };
                        featureTemp.MinMaxValue = value;
                        solventTemp.Features.Add(featureTemp);
                    }
                    clusterTemp.Solvents.Add(solventTemp);
                    model.NumberOfFeatures = solventTemp.Features.Count;
                }
                model.NumberOfSolvents += clusterTemp.Solvents.Count;
                model.Clusters.Add(clusterTemp);
            }
            algorithm.Models.Add(model);
            return(algorithm);
        }