Exemplo n.º 1
0
        /// <summary>
        /// Creates a new SPSS data document, initializing its dictionary
        /// by copying the dictionary from an existing SPSS data file.
        /// </summary>
        /// <param name="filename">
        /// The filename of the new document to create.
        /// </param>
        /// <param name="copyDictionaryFromFileName">
        /// The filename of the existing SPSS data file to copy the dictionary from.
        /// </param>
        /// <returns>
        /// The newly created <see cref="SpssDataDocument">SPSS data document</see>.
        /// </returns>
        public static SpssDataDocument Create(string filename, string copyDictionaryFromFileName)
        {
            if (File.Exists(filename))
            {
                throw new InvalidOperationException("File to create already exists.");
            }

            if (!File.Exists(copyDictionaryFromFileName))
            {
                throw new FileNotFoundException("File to copy does not exist.", copyDictionaryFromFileName);
            }

            using (SpssDataDocument read = SpssDataDocument.Open(copyDictionaryFromFileName, SpssFileAccess.Read))
            {
                SpssDataDocument toReturn = new SpssDataDocument(filename, SpssFileAccess.Create);

                foreach (SpssVariable var in read.Variables)
                {
                    toReturn.Variables.Add(var.Clone());
                }

                toReturn.CommitDictionary();
                return(toReturn);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Call to convert data to SPSS format using a passed in SQL query to provide the data.
 /// </summary>
 /// <param name="dataTable">The DataTable to convert to SPSS format</param>
 /// <param name="data">An enumerable list of DataRows.</param>
 /// <param name="spssSavFilename">The fully-qualified target .SAV file to save results to</param>
 /// <param name="fillInMetaDataCallBack">Callback function to provide per-variable metadata</param>
 public static void ToFile(DataTable dataTable, IEnumerable <DataRow> data,
                           string spssSavFilename, Action <SpssVariable> fillInMetaDataCallBack)
 {
     // Remove the file if it already exists.
     if (File.Exists(spssSavFilename))
     {
         File.Delete(spssSavFilename);
     }
     // Open up the document with "using" so that it will definitely close afterward.
     using (SpssDataDocument Sav = SpssDataDocument.Create(spssSavFilename))
     {
         // Create the schema from the table, passing in a callback
         // function for filling in each variable's metadata
         Sav.Variables.ImportSchema(dataTable, fillInMetaDataCallBack);
         // Import data
         Sav.CommitDictionary();
         Sav.ImportData(dataTable, data);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new SPSS data document, initializing its dictionary 
        /// by copying the dictionary from an existing SPSS data file.
        /// </summary>
        /// <param name="filename">
        /// The filename of the new document to create.
        /// </param>
        /// <param name="copyDictionaryFromFileName">
        /// The filename of the existing SPSS data file to copy the dictionary from.
        /// </param>
        /// <returns>
        /// The newly created <see cref="SpssDataDocument">SPSS data document</see>.
        /// </returns>
        public static SpssDataDocument Create(string filename, string copyDictionaryFromFileName)
        {
            if (File.Exists(filename))
            {
                throw new InvalidOperationException("File to create already exists.");
            }
            if (!File.Exists(copyDictionaryFromFileName))
            {
                throw new FileNotFoundException("File to copy does not exist.", copyDictionaryFromFileName);
            }
            using (SpssDataDocument read = SpssDataDocument.Open(copyDictionaryFromFileName, SpssFileAccess.Read))
            {
                SpssDataDocument toReturn = new SpssDataDocument(filename, SpssFileAccess.Create);

                foreach (SpssVariable var in read.Variables)
                {
                    toReturn.Variables.Add(var.Clone());
                }

                toReturn.CommitDictionary();
                return toReturn;
            }
        }
Exemplo n.º 4
0
        public static void CreateMetaData(SpssDataDocument doc, SpssFormat format = SpssFormat.Long)
        {
            SpssNumericVariable vID = new SpssNumericVariable();
            vID.Name = "UserID";
            vID.Label = "The user's ID";
            vID.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_RAT;
            doc.Variables.Add(vID);

            if(format == SpssFormat.Long)
            {

                SpssNumericVariable attemptNumber = new SpssNumericVariable();
                attemptNumber.Name = $"AttemptNumber";
                attemptNumber.Label = $"The continuous number of this attempt";
                attemptNumber.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_RAT;
                doc.Variables.Add(attemptNumber);

                SpssNumericVariable time = new SpssNumericVariable();
                time.Name = $"Efficiency";
                time.Label = $"Time taken in seconds for the attempt";
                time.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_RAT;
                doc.Variables.Add(time);

                SpssStringVariable hit = new SpssStringVariable();
                hit.Name = $"Effectiveness";
                hit.Label = $"Whether the user hit the target or not";
                hit.ValueLabels.Add("Miss", "Miss");
                hit.ValueLabels.Add("Hit", "Hit");
                hit.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_NOM;
                doc.Variables.Add(hit);

                SpssNumericVariable accuracy = new SpssNumericVariable();
                accuracy.Name = $"Accuracy";
                accuracy.Label = $"Distance in pixels from target";
                accuracy.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_RAT;
                doc.Variables.Add(accuracy);

                SpssStringVariable gridSize = new SpssStringVariable();
                gridSize.Name = $"TargetSize";
                gridSize.Label = $"Target (grid) size for attempt";
                gridSize.ValueLabels.Add("Small", "Small");
                gridSize.ValueLabels.Add("Large", "Large");
                gridSize.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_NOM;
                doc.Variables.Add(gridSize);

                SpssStringVariable direction = new SpssStringVariable();
                direction.Name = $"Direction";
                direction.Label = $"Direction for attempt";
                direction.ValueLabels.Add("Push", "Push");
                direction.ValueLabels.Add("Pull", "Pull");
                direction.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_NOM;
                doc.Variables.Add(direction);

                SpssStringVariable technique = new SpssStringVariable();
                technique.Name = $"Technique";
                technique.Label = $"The technique used for the attempt";
                technique.ValueLabels.Add("Pinch", "Pinch");
                technique.ValueLabels.Add("Swipe", "Swipe");
                technique.ValueLabels.Add("Throw", "Throw");
                technique.ValueLabels.Add("Tilt", "Tilt");
                technique.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_NOM;
                doc.Variables.Add(technique);

                SpssStringVariable experiment = new SpssStringVariable();
                experiment.Name = $"Experiment";
                experiment.Label = $"The experiment in which the attempt was conducted in";
                // Target, Field, Old, Accuracy
                experiment.ValueLabels.Add("Target", "Target");
                experiment.ValueLabels.Add("Field", "Field");
                experiment.ValueLabels.Add("Old", "Old");
                experiment.ValueLabels.Add("Accuracy", "Accuracy");
                experiment.MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_NOM;
                doc.Variables.Add(experiment);

            }

            doc.CommitDictionary();
        }
Exemplo n.º 5
0
 private void CreateMetaData(List<Variable> list, SpssDataDocument doc)
 {
     foreach (Variable v in list)
     {
         SpssVariable var = CreateVariable(v);
         doc.Variables.Add(var);
     }
     doc.CommitDictionary();
 }