예제 #1
0
        public static void ParseTest(SpssDataDocument doc, Test test, SpssFormat format = SpssFormat.Long)
        {
            int id = int.Parse(test.ID);

            //int overallAttempt = 0;

            if (format == SpssFormat.Long)
            {
                //UserID, AttemptNumber, Efficiency, Effectiveness, Accuracy, TargetSize, Direction, Technique, Experiment
                foreach (var type in AllTechniques)
                {
                    foreach (var attempt in test.Attempts[type])
                    {
                        SpssCase gestureAttempts = doc.Cases.New();
                        gestureAttempts[$"UserID"]        = id;
                        gestureAttempts[$"AttemptNumber"] = attempt.AttemptNumber;
                        gestureAttempts[$"Efficiency"]    = attempt.Time.TotalSeconds;
                        gestureAttempts[$"Effectiveness"] = attempt.Hit ? "Hit" : "Miss";
                        gestureAttempts[$"Accuracy"]      = MathHelper.GetDistance(attempt);
                        gestureAttempts[$"TargetSize"]    = attempt.Size.ToString().UppercaseFirst();
                        gestureAttempts[$"Direction"]     = attempt.Direction.ToString().UppercaseFirst();
                        gestureAttempts[$"Technique"]     = attempt.Type.ToString().UppercaseFirst();
                        gestureAttempts[$"Experiment"]    = attempt.Source.ToString().UppercaseFirst();
                        gestureAttempts.Commit();
                    }
                }
            }
        }
예제 #2
0
        public void GetSeveralRowsValues()
        {
            SpssCase case1 = this.docRead.Cases[0];
            SpssCase case2 = this.docRead.Cases[5];

            Assert.Equal(82d, case1["num"]);
            Assert.Equal(6d, case2["num"]);
            Assert.Equal(82d, case1["num"]);
        }
예제 #3
0
        public void New()
        {
            int      oldCount = this.docAppend.Cases.Count;
            SpssCase Case     = this.docAppend.Cases.New();

            Case["num"] = 5;
            Case.Commit();
            Assert.Equal(oldCount + 1, this.docAppend.Cases.Count);
        }
예제 #4
0
 public void SetStringTooLong()
 {
     using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
     {
         SpssStringVariable var = (SpssStringVariable)docAppend.Variables["charLabels"];
         Debug.Assert(var.Length == 8);
         SpssCase row = docAppend.Cases.New();
         Assert.Throws <ArgumentOutOfRangeException>(() => row["charLabels"] = new string('a', var.Length + 1));
     }
 }
예제 #5
0
        public static SpssCase AddTechniqueData(SpssCase gestureAttempt, GestureType type, Attempt attempt)
        {
            gestureAttempt[$"{type}Efficiency"]    = attempt.Time.TotalSeconds;
            gestureAttempt[$"{type}Effectiveness"] = attempt.Hit;
            gestureAttempt[$"{type}Accuracy"]      = MathHelper.GetDistance(attempt);
            gestureAttempt[$"{type}TargetSize"]    = attempt.Size;
            gestureAttempt[$"{type}Direction"]     = attempt.Direction;

            return(gestureAttempt);
        }
예제 #6
0
        public void SeveralNewRows()
        {
            int oldCount = this.docAppend.Cases.Count;

            for (int i = 1; i <= 5; i++)
            {
                SpssCase Case = this.docAppend.Cases.New();
                Case["num"] = i;
                Case.Commit();
                Assert.Equal(oldCount + i, this.docAppend.Cases.Count);
            }
        }
예제 #7
0
        public static void ReadSpssFile()
        {
            using (var doc = SpssDataDocument.Open("t.sav", SpssFileAccess.Append)) {
                SpssNumericVariable accuracy = new SpssNumericVariable {
                    Name             = $"Accuracy",
                    Label            = $"Distance in pixels from target",
                    MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_RAT
                };
                doc.Variables.Add(accuracy);

                SpssStringVariable var = (SpssStringVariable)doc.Variables["someLabel"];

                SpssCase row = doc.Cases.New();
                row[$"Accuracy"] = new string('a', var.Length + 1);
            }
        }
예제 #8
0
        public static void CreateData(SpssDataDocument doc)
        {
            SpssCase case1 = doc.Cases.New();

            case1.SetDBValue("v1", "Andrew");
            case1.SetDBValue("v2", 24);
            case1.SetDBValue("v3", 1);
            case1.SetDBValue("v4", DateTime.Parse("1/1/1982 7:32 PM"));
            case1.Commit();
            SpssCase case2 = doc.Cases.New();

            case2.SetDBValue("v1", "Cindy");
            case2.SetDBValue("v2", 21);
            case2.SetDBValue("v3", 2);
            case2.SetDBValue("v4", DateTime.Parse("12/31/2002"));
            case2.Commit();
        }
예제 #9
0
        public void SetMissingValueDateByNull()
        {
            int rowIndex;

            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
            {
                SpssCase row = docAppend.Cases.New();
                rowIndex       = row.Position;
                row["dateVar"] = null;
                row.Commit();
            }
            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Read))
            {
                SpssCase row = docAppend.Cases[rowIndex];
                DateTime?val = (DateTime?)row["dateVar"];
                Assert.False(val.HasValue);
            }
        }
예제 #10
0
        public void SetMissingValueNumeric()
        {
            int rowIndex;

            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
            {
                SpssCase row = docAppend.Cases.New();
                rowIndex   = row.Position;
                row["num"] = double.NaN;
                row.Commit();
            }
            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Read))
            {
                SpssCase row = docAppend.Cases[rowIndex];
                double   val = (double)row["num"];
                Assert.Equal(double.NaN, val);
            }
        }
예제 #11
0
        private void CreateJournalRows(SpssDataDocument doc, IAnswerBook journalAnswers)
        {
            var journalInfo = journalAnswers.AnswerMetadataList;

            var answers = journalAnswers.Answers.OrderBy(a => a.AnswerMetadata.Besvarelsesdato);
            // check if any of the answers is from the same survey

            //var lastAnswerDate = answers.First().JournalInfo.Besvarelsesdato;

            SpssCase case1            = doc.Cases.New(); // row. Can contain multiple answers. TODO: if more answers to the same survey, split answers into multiple rows
            bool     isSetJournalData = false;

            foreach (var answer in answers)
            {
                //var answerDateDiff = answer.JournalInfo.Besvarelsesdato.Subtract(lastAnswerDate);
                //if(answerDateDiff.Days > 120) { // if more than 120 days difference between answers, we assume it's not the same followup, and thus a new row
                //    case1.Commit();
                //    case1 = doc.Cases.New();
                //    isSetJournalData = false;
                //}

                int varIndex = 0;
                foreach (var variable in answer.Variables)
                {
                    if (variable.Datatype == "Date")
                    {
                        var d = variable.Value.ToDate();
                        //variable.Value = string.Format("{0,2}{1,2}{2}", d.Day, d.Month, d.Year.ToString().Replace("20", "").Replace("19", "").ToInt()).Replace(" ", "0");
                        case1.SetDBValue(variable.Name, d); //variable.Value);
                        continue;
                    }
                    if (variable.Name == "Pid")
                    {
                        //variable.Datatype = "String";
                        case1.SetDBValue(variable.Name, variable.Value);
                    }
                    if (variable.Datatype == "String" && variable.Value == "#NULL!")
                    {
                        variable.Value = "";
                        case1.SetDBValue(variable.Name, variable.Value);
                    }
                    if (variable.Datatype == "Numeric" && variable.Value == "" || variable.Value == "#NULL!")
                    {
                        variable.Value = "9";
                        case1.SetDBValue(variable.Name, variable.Value);
                    }
                    if (variable.Datatype != "Date" && variable.Value.StartsWith("0"))
                    {
                        variable.Value = "0.0";
                    }
                    try {
                        if (!isSetJournalData || varIndex > 9) // first 9 vars are journalInfo vars
                        {
                            case1.SetDBValue(variable.Name, variable.Value);
                        }
                    } catch (FormatException ex) {
                        var message = string.Format("Variable name '{0}' could not set value: {1}. Label: {2} Answer: {3}. journalId: {4}",
                                                    variable.Name, variable.Value, variable.Label, answer.Id, answer.Key);
                        throw new FormatException(message, ex);
                    }
                    varIndex++;
                }
                isSetJournalData = true;
            }
            case1.Commit();
        }
예제 #12
0
        public void GetMiddleRowValue()
        {
            SpssCase Case = this.docRead.Cases[5];

            Assert.Equal(6d, Case["num"]);
        }
예제 #13
0
        public void GetFirstRowValue()
        {
            SpssCase Case = this.docRead.Cases[0];

            Assert.Equal(82d, Case["num"]);
        }