示例#1
0
        public void RaiseIfCreateDimensionAfterAddingData()
        {
            DataSet <int> set = new DataSet <int>("Data");

            set.CreateDimension("Country");
            set.AddData(
                new Dictionary <string, object>
            {
                { "Country", "Canada" }
            },
                100);
            set.CreateDimension("Category");
        }
示例#2
0
        public void GetTupleCount()
        {
            DataSet <int> sales = new DataSet <int>("Sales");

            sales.AddData(
                new Dictionary <string, object>()
            {
                { "Country", "Argentina" },
                { "Category", "Beverages" },
                { "Product", "Beer" }
            },
                100);

            sales.AddData(
                new Dictionary <string, object>()
            {
                { "Country", "Argentina" },
                { "Category", "Beverages" },
                { "Product", "Coke" }
            },
                200);

            Assert.AreEqual(2, sales.Tuples.Count());
        }
示例#3
0
        private static void GenerateValue(DataSet <int> set, IList <string> dimensions, Dictionary <string, object> values, IList <int> nvalues, int position)
        {
            if (position >= dimensions.Count)
            {
                set.AddData(values, 1);
                return;
            }

            for (int k = 0; k < nvalues[position]; k++)
            {
                string value = string.Format("Value {0}", k + 1);
                values[dimensions[position]] = value;

                GenerateValue(set, dimensions, values, nvalues, position + 1);
            }
        }
示例#4
0
        public void CreateTuple()
        {
            DataSet<int> sales = new DataSet<int>("Sales");
            sales.AddData(
                new Dictionary<string, object>
                {
                    { "Country", "Canada" },
                    { "Year", 2012 }
                },
                100);

            TupleObject<int> tuple = sales.Tuples.First();

            Assert.IsNotNull(tuple);
            Assert.AreEqual(2, sales.Dimensions.Count);
            Assert.AreEqual("Canada", tuple.GetValue("Country"));
            Assert.AreEqual(2012, tuple.GetValue("Year"));
            Assert.AreEqual(100, tuple.Data);
        }
示例#5
0
        public void CreateTuple()
        {
            DataSet <int> sales = new DataSet <int>("Sales");

            sales.AddData(
                new Dictionary <string, object>
            {
                { "Country", "Canada" },
                { "Year", 2012 }
            },
                100);

            TupleObject <int> tuple = sales.Tuples.First();

            Assert.IsNotNull(tuple);
            Assert.AreEqual(2, sales.Dimensions.Count);
            Assert.AreEqual("Canada", tuple.GetValue("Country"));
            Assert.AreEqual(2012, tuple.GetValue("Year"));
            Assert.AreEqual(100, tuple.Data);
        }
示例#6
0
        public async Task <int> CreateAsync(int surveyId, string surveyTitle, string surveyDescription)
        {
            var surveyReport = new SurveyReport(surveyId, surveyTitle, surveyDescription);
            await _surveyReportRepository.AddAsync(surveyReport);

            var survey = await _surveyRepository.GetByIdWithQuestionsAsync(surveyId);

            foreach (var question in survey.Questions)
            {
                var questionReport =
                    new QuestionReport(question.Content, question.Select, 0, question.QuestionPosition);
                surveyReport.AddQuestionReport(questionReport);
                await _questionReportRepository.AddAsync(questionReport);

                foreach (var fieldData in question.FieldData)
                {
                    switch (questionReport.Select)
                    {
                    case "short-answer":
                    case "long-answer":
                    {
                        var dataSet = new DataSet();
                        questionReport.AddDataSet(dataSet);
                        await _dataSetRepository.AddAsync(dataSet);

                        await _questionReportRepository.UpdateAsync(questionReport);

                        foreach (var label in questionReport.Labels)
                        {
                            dataSet.AddData("0");
                            await _dataSetRepository.UpdateAsync(dataSet);
                        }
                    }
                    break;

                    case "dropdown-menu":
                    {
                        foreach (var choiceOption in fieldData.ChoiceOptions)
                        {
                            questionReport.AddLabel(choiceOption.ViewValue);
                        }
                        var dataSet = new DataSet();
                        questionReport.AddDataSet(dataSet);
                        await _dataSetRepository.AddAsync(dataSet);

                        await _questionReportRepository.UpdateAsync(questionReport);

                        foreach (var label in questionReport.Labels)
                        {
                            dataSet.AddData("0");
                            await _dataSetRepository.UpdateAsync(dataSet);
                        }
                    }
                    break;

                    case "linear-scale":
                    {
                        for (var i = 1; i <= fieldData.MaxValue; i++)
                        {
                            questionReport.AddLabel(i.ToString());
                        }
                        var dataSet = new DataSet(question.Content);
                        questionReport.AddDataSet(dataSet);
                        await _dataSetRepository.AddAsync(dataSet);

                        await _questionReportRepository.UpdateAsync(questionReport);

                        foreach (var label in questionReport.Labels)
                        {
                            dataSet.AddData("0");
                            await _dataSetRepository.UpdateAsync(dataSet);
                        }
                    }
                    break;

                    case "multiple-grid":
                    case "single-grid":
                    {
                        foreach (var row in fieldData.Rows)
                        {
                            questionReport.AddLabel(row.Input);
                        }
                        foreach (var choiceOption in fieldData.ChoiceOptions)
                        {
                            var dataSet = new DataSet(choiceOption.ViewValue);
                            questionReport.AddDataSet(dataSet);
                            await _dataSetRepository.AddAsync(dataSet);

                            await _questionReportRepository.UpdateAsync(questionReport);

                            foreach (var row in fieldData.Rows)
                            {
                                dataSet.AddData("0");
                                await _dataSetRepository.UpdateAsync(dataSet);
                            }
                        }
                    }
                    break;

                    case "single-choice":
                    case "multiple-choice":
                    {
                        foreach (var choiceOption in fieldData.ChoiceOptions)
                        {
                            questionReport.AddLabel(choiceOption.ViewValue);
                        }
                        var dataSet = new DataSet(question.Content);
                        questionReport.AddDataSet(dataSet);
                        await _dataSetRepository.AddAsync(dataSet);

                        await _questionReportRepository.UpdateAsync(questionReport);

                        foreach (var label in questionReport.Labels)
                        {
                            dataSet.AddData("0");
                            await _dataSetRepository.UpdateAsync(dataSet);
                        }
                    }
                    break;
                    }
                }
            }
            return(surveyReport.Id);
        }
示例#7
0
        protected override void Context()
        {
            _dataImporterSettings = new DataImporterSettings();
            base.Context();
            _mapper = A.Fake <IDataSetToDataRepositoryMapper>();
            var cache   = new Cache <string, IDataSet>();
            var dataSet = new DataSet();

            dataSet.AddData(new List <ParsedDataSet>()
            {
                new ParsedDataSet(new List <string>(), A.Fake <DataSheet>(), new List <UnformattedRow>(), new Dictionary <ExtendedColumn, IList <SimulationPoint> >())
            });
            _dataSource = A.Fake <IDataSource>();
            A.CallTo(() => _dataSource.DataSets).Returns(cache);
            cache.Add("sheet1", dataSet);
            var dataRepository = new DataRepository {
                Name = "name"
            };

            dataRepository.ExtendedProperties.Add(new ExtendedProperty <string>()
            {
                Name = "Molecule", Value = "Molecule1"
            });
            dataRepository.ExtendedProperties.Add(new ExtendedProperty <string>()
            {
                Name = "Mol weight", Value = 22.0.ToString()
            });

            var dataColumn = new BaseGrid("Time", A.Fake <IDimension>());
            var dataInfo   = new DataInfo(ColumnOrigins.Undefined);

            dataColumn.DataInfo = dataInfo;
            dataRepository.Add(dataColumn);

            var moleculeDataColumn = new DataColumn("Measurement", A.Fake <IDimension>(), dataColumn);

            dataColumn.DataInfo = dataInfo;
            dataRepository.Add(moleculeDataColumn);
            A.CallTo(() => _mapper.ConvertImportDataSet(A <ImportedDataSet> .Ignored)).Returns(new DataSetToDataRepositoryMappingResult(dataRepository));

            var moleculeMetaDataCategory = createMetaDataCategory <string>("Molecule", isMandatory: true);

            moleculeMetaDataCategory.IsListOfValuesFixed = true;
            moleculeMetaDataCategory.DefaultValue        = "Molecule1";
            moleculeMetaDataCategory.ListOfValues.Add("Molecule1", 6.0.ToString());
            moleculeMetaDataCategory.ShouldListOfValuesBeIncluded = true;
            moleculeMetaDataCategory.SelectDefaultValue           = true;

            _metaDataCategories = new List <MetaDataCategory>()
            {
                moleculeMetaDataCategory,
                createMetaDataCategory <string>("Mol weight", isMandatory: false)
            };
            var dataFormat = A.Fake <IDataFormat>();

            A.CallTo(() => dataFormat.Parameters).Returns(new List <DataFormatParameter>());
            _dataSourceFile = A.Fake <IDataSourceFile>();
            A.CallTo(() => _dataSourceFile.Format).Returns(dataFormat);
            _importerDataPresenter = A.Fake <IImporterDataPresenter>();
            A.CallTo(() => _importerDataPresenter.SetDataSource(A <string> .Ignored)).Returns(_dataSourceFile);
            _importerView = A.Fake <IImporterView>();
            _importer     = A.Fake <IImporter>();
            _nanPresenter = A.Fake <INanPresenter>();
            _importConfirmationPresenter = A.Fake <IImportConfirmationPresenter>();
            _columnMappingPresenter      = A.Fake <IColumnMappingPresenter>();
            _sourceFilePresenter         = A.Fake <ISourceFilePresenter>();
            _dialogCreator = A.Fake <IDialogCreator>();
            _pkmlPeristor  = A.Fake <IPKMLPersistor>();

            sut = new ImporterPresenterForTest(
                _importerView,
                _mapper,
                _importer,
                _nanPresenter,
                _importerDataPresenter,
                _importConfirmationPresenter,
                _columnMappingPresenter,
                _sourceFilePresenter,
                _dialogCreator,
                _pkmlPeristor,
                _dataSource);
            _importerConfiguration = A.Fake <ImporterConfiguration>();
            sut.LoadConfiguration(_importerConfiguration, "");
            sut.SetSettings(_metaDataCategories, new ColumnInfoCache(), _dataImporterSettings);
        }
示例#8
0
        protected override void Context()
        {
            base.Context();
            var parsedData = new Dictionary <ExtendedColumn, IList <SimulationPoint> >()
            {
                {
                    new ExtendedColumn()
                    {
                        Column = new Column()
                        {
                            Name = "Time",
                            Unit = new UnitDescription("s")
                        },
                        ColumnInfo = _columnInfos["Time"]
                    },
                    new List <SimulationPoint>()
                    {
                        new SimulationPoint()
                        {
                            Unit        = "s",
                            Measurement = 0,
                            Lloq        = double.NaN
                        }
                    }
                },
                {
                    new ExtendedColumn()
                    {
                        Column = new Column()
                        {
                            Name      = "Concentration",
                            Unit      = new UnitDescription("pmol/l"),
                            Dimension = null
                        },
                        ColumnInfo = _columnInfos["Concentration"]
                    },
                    new List <SimulationPoint>()
                    {
                        new SimulationPoint()
                        {
                            Unit        = "s",
                            Measurement = 10,
                            Lloq        = 1
                        },
                        new SimulationPoint()
                        {
                            Unit        = "no unit",
                            Measurement = 10,
                            Lloq        = 1
                        }
                    }
                }
            };

            _dataSet = new DataSet();
            _dataSet.AddData(new List <ParsedDataSet>()
            {
                { new ParsedDataSet(new List <string>(), A.Fake <DataSheet>(), new List <UnformattedRow>(), parsedData) }
            });
            sut.DataSets.Clear();
        }
示例#9
0
        protected override void Context()
        {
            base.Context();
            _columnInfos = new ColumnInfoCache
            {
                new ColumnInfo()
                {
                    DisplayName = "Time", Name = "Time", IsMandatory = true, BaseGridName = "Time"
                },
                new ColumnInfo()
                {
                    DisplayName = "Concentration", Name = "Concentration", IsMandatory = true, BaseGridName = "Time"
                },
                new ColumnInfo()
                {
                    DisplayName = "Error", Name = "Error", IsMandatory = false, RelatedColumnOf = "Concentration", BaseGridName = "Time"
                }
            };
            var parsedData = new Dictionary <ExtendedColumn, IList <SimulationPoint> >()
            {
                {
                    new ExtendedColumn()
                    {
                        Column = new Column()
                        {
                            Name = "Time",
                            Unit = new UnitDescription("s")
                        },
                        ColumnInfo = _columnInfos["Time"]
                    },
                    new List <SimulationPoint>()
                    {
                    }
                },
                {
                    new ExtendedColumn()
                    {
                        Column = new Column()
                        {
                            Name = "Concentration",
                            Unit = new UnitDescription("mol")
                        },
                        ColumnInfo = _columnInfos["Concentration"]
                    },
                    new List <SimulationPoint>()
                    {
                    }
                },
                {
                    new ExtendedColumn()
                    {
                        Column = new Column()
                        {
                            Name = "Error",
                            Unit = new UnitDescription("")
                        },
                        ColumnInfo = _columnInfos["Error"]
                    },
                    new List <SimulationPoint>()
                    {
                    }
                }
            };
            var dataSet = new DataSet();

            dataSet.AddData(new List <ParsedDataSet>()
            {
                { new ParsedDataSet(new List <string>(), A.Fake <DataSheet>(), new List <UnformattedRow>(), parsedData) }
            });
            _dimensionFactory = A.Fake <IDimensionFactory>();
            var fractionDimension = A.Fake <IDimension>();

            A.CallTo(() => fractionDimension.Name).Returns(Constants.Dimension.FRACTION);
            var otherDimension = A.Fake <IDimension>();

            A.CallTo(() => otherDimension.Name).Returns("mol");
            A.CallTo(() => _dimensionFactory.DimensionForUnit("")).Returns(fractionDimension);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("mol")).Returns(otherDimension);
            sut.DataSets.Clear();
            sut.DataSets.Add("sheet1", dataSet);
        }
示例#10
0
        private static void GenerateValue(DataSet<int> set, IList<string> dimensions, Dictionary<string, object> values, IList<int> nvalues, int position)
        {
            if (position >= dimensions.Count)
            {
                set.AddData(values, 1);
                return;
            }

            for (int k = 0; k < nvalues[position]; k++)
            {
                string value = string.Format("Value {0}", k + 1);
                values[dimensions[position]] = value;

                GenerateValue(set, dimensions, values, nvalues, position + 1);
            }
        }
示例#11
0
 public void RaiseIfCreateDimensionAfterAddingData()
 {
     DataSet<int> set = new DataSet<int>("Data");
     set.CreateDimension("Country");
     set.AddData(
         new Dictionary<string, object>
         {
             { "Country", "Canada" }
         },
         100);
     set.CreateDimension("Category");
 }
示例#12
0
        public void GetTupleCount()
        {
            DataSet<int> sales = new DataSet<int>("Sales");

            sales.AddData(
                new Dictionary<string, object>()
                {
                    { "Country", "Argentina" },
                    { "Category", "Beverages" },
                    { "Product", "Beer" }
                },
                100);

            sales.AddData(
                new Dictionary<string, object>()
                {
                    { "Country", "Argentina" },
                    { "Category", "Beverages" },
                    { "Product", "Coke" }
                },
                200);

            Assert.AreEqual(2, sales.Tuples.Count());
        }