Esempio n. 1
0
 public VariableVM()
 {
     this.variable = new Variable();
     this.Response = new ResponseVM(variable.Response)
     {
         IsQuestionDesignMode = false
     };
 }
Esempio n. 2
0
 public VariableVM(Variable variable)
 {
     this.variable = variable;
 }
Esempio n. 3
0
 public void BeginEdit()
 {
     if (inEdit)
     {
         return;
     }
     inEdit = true;
     bakVariable = variable.Clone() as Variable;
     bakResponseTypeCode = response.TypeCode;
 }
Esempio n. 4
0
        public void EndEdit()
        {
            if (!inEdit)
            {
                return;
            }
            inEdit = false;

            bakVariable = null;
            bakResponseTypeCode = null;
            Memorize();
        }
Esempio n. 5
0
 private StudyUnit FindStudyUnitModel(Variable variable)
 {
     foreach (StudyUnitVM studyUnit in Main.StudyUnits)
     {
         if (studyUnit.StudyUnitModel.Variables.Contains(variable))
         {
             return studyUnit.StudyUnitModel;
         }
     }
     return null;
 }
Esempio n. 6
0
        public bool Read(string path, StudyUnitVM studyUnit)
        {
            Debug.Assert(!string.IsNullOrEmpty(path));
            StudyUnit studyUnitModel = studyUnit.StudyUnitModel;
            FileStream stream = File.OpenRead(path);
            SavFileParser parser = new SavFileParser(stream);
            List<Variable> variables = new List<Variable>();
            foreach (SpssLib.SpssDataset.Variable v in parser.Variables)
            {
                Variable variable = new Variable();
                variable.Title = v.Name;
                variable.Label = v.Label;
                variables.Add(variable);
                if (v.Type == SpssLib.SpssDataset.DataType.Text)
                {
                    variable.Response.TypeCode = Options.RESPONSE_TYPE_FREE_CODE;
                }
                else
                {
                    if (v.ValueLabels.Count > 0)
                    {
                        CategoryScheme categoryScheme = new CategoryScheme();
                        categoryScheme.Title = v.Label;
                        studyUnitModel.CategorySchemes.Add(categoryScheme);
                        CodeScheme codeScheme = new CodeScheme();
                        codeScheme.Title = v.Label; ;
                        studyUnitModel.CodeSchemes.Add(codeScheme);

                        variable.Response.TypeCode = Options.RESPONSE_TYPE_CHOICES_CODE;
                        variable.Response.CodeSchemeId = codeScheme.Id;
                        // 選択肢の作成
                        foreach (KeyValuePair<double, string> pair in v.ValueLabels)
                        {
                            Category category = new Category();
                            categoryScheme.Categories.Add(category);
                            category.Title = pair.Value;
                            category.CategorySchemeId = categoryScheme.Id;

                            Code code = new Code();
                            codeScheme.Codes.Add(code);
                            code.CategoryId = category.Id;
                            code.CodeSchemeId = codeScheme.Id;
                            code.Value = pair.Key.ToString();
                        }
                        // 欠損値の追加
                        if (v.MissingValues.Count > 0)
                        {
                            foreach (double missingValue in v.MissingValues)
                            {
                                string missingValueStr = missingValue.ToString();
                                if (ExistValue(codeScheme, missingValueStr))
                                {
                                    continue;
                                }
                                Category category = new Category();
                                categoryScheme.Categories.Add(category);
                                category.Title = Resources.MissingValue; //欠損値
                                category.IsMissingValue = true;
                                category.CategorySchemeId = categoryScheme.Id;

                                Code code = new Code();
                                codeScheme.Codes.Add(code);
                                code.CategoryId = category.Id;
                                code.CodeSchemeId = codeScheme.Id;
                                code.Value = missingValueStr;
                            }
                        }
                    }
                    else
                    {
                        variable.Response.TypeCode = Options.RESPONSE_TYPE_NUMBER_CODE;
                    }
                }
            }

            if (variables.Count > 0)
            {
                ConceptScheme conceptScheme = new ConceptScheme();
                conceptScheme.Title = EDOUtils.UniqueLabel(ConceptScheme.GetTitles(studyUnitModel.ConceptSchemes), Resources.ImportVariable); //インポートした変数
                string name = Path.GetFileName(path);
                conceptScheme.Memo = EDOUtils.UniqueLabel(ConceptScheme.GetMemos(studyUnitModel.ConceptSchemes), string.Format(Resources.ImportVariableFrom, name)); //{0}からインポートした変数

                Concept concept = new Concept();
                concept.Title = EDOUtils.UniqueLabel(ConceptScheme.GetConceptTitles(studyUnitModel.ConceptSchemes), Resources.ImportVariable);//インポートした変数
                concept.Content = EDOUtils.UniqueLabel(ConceptScheme.GetConceptContents(studyUnitModel.ConceptSchemes), string.Format(Resources.ImportVariableFrom, name));//{0}からインポートした変数
                conceptScheme.Concepts.Add(concept);
                studyUnitModel.ConceptSchemes.Add(conceptScheme);

                foreach (Variable variable in variables)
                {
                    Question question = new Question();
                    question.Title = variable.Label;
                    question.ConceptId = concept.Id;
                    question.Response.TypeCode = variable.Response.TypeCode;
                    question.Response.CodeSchemeId = variable.Response.CodeSchemeId;
                    studyUnitModel.Questions.Add(question);

                    variable.ConceptId = concept.Id;
                    variable.QuestionId = question.Id;
                    studyUnitModel.Variables.Add(variable);

                }
            }
            return true;
        }
Esempio n. 7
0
        public static Variable CreateVariable(XElement variableElem)
        {
            string id = (string)variableElem.Attribute(ATTR_ID);
            if (id == null)
            {
                return null;
            }
            Variable variable = new Variable();
            variable.Id = id;
            variable.Title = (string)variableElem.Element(l + TAG_VARIABLE_NAME);
            variable.Label = (string)variableElem.Element(r + TAG_LABEL);
            variable.ConceptId = ReadReferenceID(variableElem, l + TAG_CONCEPT_REFERENCE);
            variable.QuestionId = ReadReferenceID(variableElem, l + TAG_QUESTION_REFERENCE);
            variable.UniverseId = ReadReferenceID(variableElem, r + TAG_UNIVERSE_REFERENCE);
            XElement representationElem = variableElem.Element(l + TAG_REPRESENTATION);
            if (representationElem != null)
            {
                //種類
                XElement codeRepresentationElem = representationElem.Element(l + TAG_CODE_REPRESENTATION);
                XElement numericRepresentationElem = representationElem.Element(l + TAG_NUMERIC_REPRESENTATION);
                XElement textRepresentationElem = representationElem.Element(l + TAG_TEXT_REPRESENTATION);
                XElement dateTimeRepresentationElem = representationElem.Element(l + TAG_DATE_TIME_REPRESENTATION);
                if (codeRepresentationElem != null)
                {
                    variable.Response.TypeCode = Options.RESPONSE_TYPE_CHOICES_CODE;
                    variable.Response.CodeSchemeId = ReadReferenceID(codeRepresentationElem, r + TAG_CODE_SCHEME_REFERENCE);

                }
                else if (numericRepresentationElem != null)
                {
                    //数値の場合の回答
                    variable.Response.TypeCode = Options.RESPONSE_TYPE_NUMBER_CODE;
                    variable.Response.Title = (string)numericRepresentationElem.Element(d + TAG_LABEL);
                    string numericTypeLabel = (string)numericRepresentationElem.Attribute(ATTR_TYPE);
                    variable.Response.DetailTypeCode = Options.NumberTypeCode(numericTypeLabel);
                    XElement numerRangeElem = numericRepresentationElem.Element(r + TAG_NUMBER_RANGE);
                    if (numerRangeElem != null)
                    {
                        variable.Response.Min = (decimal?)numerRangeElem.Element(r + TAG_LOW);
                        variable.Response.Max = (decimal?)numerRangeElem.Element(r + TAG_HIGH);
                    }
                    variable.Response.MissingValues = CreateMissingValues(numericRepresentationElem);
                }
                else if (textRepresentationElem != null)
                {
                    //自由テキストの回答
                    variable.Response.TypeCode = Options.RESPONSE_TYPE_FREE_CODE;
                    variable.Response.Title = (string)textRepresentationElem.Element(r + TAG_LABEL);
                    variable.Response.Min = (decimal?)textRepresentationElem.Attribute(ATTR_MIN_LENGTH);
                    variable.Response.Max = (decimal?)textRepresentationElem.Attribute(ATTR_MAX_LENGTH);
                    variable.Response.MissingValues = CreateMissingValues(textRepresentationElem);
                }
                else if (dateTimeRepresentationElem != null)
                {
                    //日付の回答
                    variable.Response.TypeCode = Options.RESPONSE_TYPE_DATETIME_CODE;
                    variable.Response.Title = (string)dateTimeRepresentationElem.Element(d + TAG_LABEL);
                    string typeLabel = (string)dateTimeRepresentationElem.Attribute(ATTR_TYPE);
                    variable.Response.DetailTypeCode = Options.DateTimeTypeCode(typeLabel);
                    variable.Response.MissingValues = CreateMissingValues(dateTimeRepresentationElem);
                }
                else
                {
                    return null;
                }
            }
            return variable;
        }
Esempio n. 8
0
        private Variable CloneVariable(Variable orgVariable)
        {
            Variable newVariable = (Variable)orgVariable.Clone();
            newVariable.Id = IDUtils.NewGuid();

            Response newResponse = (Response)orgVariable.Response.Clone();
            newResponse.Id = IDUtils.NewGuid();

            newVariable.Response = newResponse;

            return newVariable;
        }
Esempio n. 9
0
        private void CreateVariableFor(QuestionVM question)
        {
            if (question.IsCreatedVariable)
            {
                //既に生成済みの場合作らない
                return;
            }
            VariableVM variable = VariableVM.FindByQuestionId(Variables, question.Id);
            if (variable != null)
            {
                //既に存在している場合は作らない(フラグで処理しているので念のため?)
                return;
            }
            question.IsCreatedVariable = true;

            Variable variableModel = new Variable();
            variableModel.Title = "V" + (Variables.Count + 1);
            variableModel.Label = question.Title;
            variableModel.ConceptId = question.Question.ConceptId;
            variableModel.QuestionId = question.Id;
            variableModel.UniverseId = StudyUnit.DefaultUniverseGuid;
            variableModel.Response = question.DupResponseModel();
            variableModel.Response.Title = null; //変数の回答法にはタイトル設定はできないのでnullにしておく。こうしておくことで変数設計画面で1からコードをいれたときのコード群名の生成が正しくなる。

            VariableVM newVariable = new VariableVM(variableModel);
            InitVariable(newVariable);
            newVariable.Response = CreateResponse(variableModel.Response);
            variables.Add(newVariable);
        }
Esempio n. 10
0
 private string JoinDataSetIds(Variable variable)
 {
     List<DataSetVM> dataSets = studyUnit.FindDataSetsByVariableId(variable.Id);
     IEnumerable<string> ids = DataSetVM.GetIds(dataSets);
     IEnumerable<string> safeIds = ids.Select(p => ConvertId(p));
     return string.Join(" ", safeIds);
 }
Esempio n. 11
0
        private static VariableItem CreateVariableItem(XElement varElem, ReaderContext context)
        {
            string id = (string)varElem.Attribute(ATTR_ID);
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            string title = (string)varElem.Attribute(ATTR_NAME);
            if (string.IsNullOrEmpty(title))
            {
                return null;
            }
            string representationType = (string)varElem.Attribute(ATTR_REPRESENTATION_TYPE);
            string responseTypeCode = GetTypeFromRepresentationType(representationType);
            if (responseTypeCode == null)
            {
                return null;
            }

            string files = (string)varElem.Attribute(ATTR_FILES);
            if (!string.IsNullOrEmpty(files))
            {
                //データセットのIDを記憶(データセット読み込み時に利用)
                context.DataSetIds[id] = SplitIds(files);
            }

            Variable variable = new Variable();
            variable.Id = id;
            variable.Title = title;
            variable.Label = (string)varElem.Element(cb + TAG_LABL);
            variable.Response.TypeCode = responseTypeCode;

            variable.ConceptId = context.FindConceptIdByVarId(variable.Id);
            Question question =  null;
            if (variable.ConceptId != null)
            {
                //対応するConceptがないとViewModel生成時に例外で落ちる(落ちなくても画面に表示できない)
                question = CreateQuestion(varElem);
                if (question != null)
                {
                    question.ConceptId = variable.ConceptId;
                    variable.QuestionId = question.Id;
                }
            }

            CategorySchemeItem categorySchemeItem = null;
            if (variable.Response.IsTypeChoices)
            {
                categorySchemeItem = CreateCategorySchemeItem(varElem, variable);
            }
            else if (variable.Response.IsTypeNumber)
            {
                SetupRange(varElem, variable.Response);
            }
            else if (variable.Response.IsTypeFree)
            {
                SetupRange(varElem, variable.Response);
            }
            else if (variable.Response.IsTypeDateTime)
            {

            }
            return new VariableItem(variable, question, categorySchemeItem);
        }
Esempio n. 12
0
        private static CategorySchemeItem CreateCategorySchemeItem(XElement varElem, Variable variable)
        {
            XElement catgryGrpElem = varElem.Element(cb + TAG_CATGRY_GRP);
            if (catgryGrpElem == null)
            {
                return null;
            }
            string title = (string)catgryGrpElem.Element(cb + TAG_LABL);
            if (string.IsNullOrEmpty(title))
            {
                return null;
            }
            string memo = (string)catgryGrpElem.Element(cb + TAG_TXT);
            CategoryScheme categoryScheme = new CategoryScheme()
            {
                Title = title,
                Memo = memo
            };
            CodeScheme codeScheme = new CodeScheme()
            {
                Title = title,
                Memo = memo
            };
            IEnumerable<XElement> catgryElems = varElem.Elements(cb + TAG_CATGRY);
            foreach (XElement catgryElem in catgryElems)
            {
                title = (string)catgryElem.Element(cb + TAG_LABL);
                memo = (string)catgryElem.Element(cb + TAG_TXT);
                string v = (string)catgryElem.Element(cb + TAG_CAT_VALU);

                Category category = new Category() {
                    Title = title,
                    Memo = memo
                };
                category.CategorySchemeId = categoryScheme.Id;
                categoryScheme.Categories.Add(category);

                Code code = new Code()
                {
                    Value = v
                };
                code.CodeSchemeId = codeScheme.Id;
                code.CategoryId = category.Id;
                codeScheme.Codes.Add(code);
            }
            variable.Response.CodeSchemeId = codeScheme.Id;
            return new CategorySchemeItem(categoryScheme, codeScheme);
        }
Esempio n. 13
0
 public VariableItem(Variable variable, Question question, CategorySchemeItem categorySchemeItem)
 {
     Variable = variable;
     Question = question;
     CategorySchemeItem = categorySchemeItem;
 }