예제 #1
0
        public override SpssVariable Clone()
        {
            SpssStringVariable other = new SpssStringVariable();

            this.CloneTo(other);
            return(other);
        }
예제 #2
0
        internal static SpssVariable LoadVariable(SpssVariablesCollection parent, string varName, int varType)
        {
            FormatTypeCode writeFormat, printFormat;
            int            writeDecimal, writeWidth, printDecimal, printWidth;

            SpssException.ThrowOnFailure(SpssSafeWrapper.spssGetVarWriteFormat(parent.Document.Handle, varName, out writeFormat, out writeDecimal, out writeWidth), "spssGetVarWriteFormat");
            SpssException.ThrowOnFailure(SpssSafeWrapper.spssGetVarPrintFormat(parent.Document.Handle, varName, out printFormat, out printDecimal, out printWidth), "spssGetVarPrintFormat");

            SpssVariable variable;

            switch (varType)
            {
            case 0:
                // This may be a date or a numeric
                if (SpssDateVariable.IsDateVariable(writeFormat))
                {
                    variable = new SpssDateVariable(parent, varName, writeFormat, writeWidth, printFormat, printWidth);
                }
                else
                {
                    variable = new SpssNumericVariable(parent, varName, writeFormat, writeDecimal, writeWidth, printFormat, printDecimal, printWidth);
                }

                break;

            default:
                Debug.Assert(varType == printWidth);
                variable = new SpssStringVariable(parent, varName, varType);
                break;
            }

            return(variable);
        }
예제 #3
0
        internal static SpssVariable LoadVariable(SpssVariablesCollection parent, string varName, int varType)
        {
            FormatTypeCode writeFormat, printFormat;
            int writeDecimal, writeWidth, printDecimal, printWidth;
            SpssException.ThrowOnFailure(SpssSafeWrapper.spssGetVarWriteFormat(parent.Document.Handle, varName, out writeFormat, out writeDecimal, out writeWidth), "spssGetVarWriteFormat");
            SpssException.ThrowOnFailure(SpssSafeWrapper.spssGetVarPrintFormat(parent.Document.Handle, varName, out printFormat, out printDecimal, out printWidth), "spssGetVarPrintFormat");

            SpssVariable variable;
            switch (varType)
            {
                case 0:
                    // This may be a date or a numeric
                    if (SpssDateVariable.IsDateVariable(writeFormat))
                        variable = new SpssDateVariable(parent, varName, writeFormat, writeWidth, printFormat, printWidth);
                    else
                        variable = new SpssNumericVariable(parent, varName, writeFormat, writeDecimal, writeWidth, printFormat, printDecimal, printWidth);
                    break;
                default:
                    Debug.Assert(varType == printWidth);
                    variable = new SpssStringVariable(parent, varName, varType);
                    break;
            }

            return variable;
        }
예제 #4
0
        protected override void CloneTo(SpssVariable spssVar)
        {
            base.CloneTo(spssVar);
            SpssStringVariable other = spssVar as SpssStringVariable;

            if (other == null)
            {
                throw new ArgumentException("Must be of type " + GetType().Name + ".", "other");
            }
            other.Length = Length;
            this.valueLabels.CopyTo(other.valueLabels);
        }
예제 #5
0
        /// <summary>
        /// Defines the variables in the SPSS data file so that they mirror
        /// those defined in a <see cref="DataTable"/>.
        /// </summary>
        /// <param name="table">
        /// The DataTable whose list of columns are the ones we want to copy.
        /// </param>
        /// <param name="fillInMetadataCallback">
        /// The callback method to use to retrieve the additional metadata
        /// to put into the SPSS data document, that is not included in a DataTable.
        /// Optional.
        /// </param>
        public void ImportSchema(DataTable table, Action <SpssVariable> fillInMetadataCallback)
        {
            foreach (DataColumn column in table.Columns)
            {
                try
                {
                    SpssVariable var;
                    if (column.DataType == typeof(string))
                    {
                        var = new SpssStringVariable();
                        ((SpssStringVariable)var).Length = (column.MaxLength <0 || column.MaxLength> SpssSafeWrapper.SPSS_MAX_LONGSTRING) ? SpssSafeWrapper.SPSS_MAX_LONGSTRING : column.MaxLength;
                    }
                    else if (column.DataType == typeof(DateTime))
                    {
                        var = new SpssDateVariable();
                    }
                    else
                    {
                        var = new SpssNumericVariable();
                        if (column.DataType == typeof(float) || column.DataType == typeof(double))
                        {
                            ((SpssNumericVariable)var).PrintDecimal = 2;
                            ((SpssNumericVariable)var).WriteDecimal = 2;
                        }
                    }

                    var.Name = this.GenerateColumnName(column.ColumnName);
                    this.Add(var);

                    // Provide opportunity for callback function to fill in variable-specific metadata
                    if (fillInMetadataCallback != null)
                    {
                        try
                        {
                            fillInMetadataCallback(var);
                        }
                        catch (Exception ex)
                        {
                            throw new ApplicationException("Exception in metadata filler callback function on column " + column.ColumnName + ".", ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Error adding column " + column.ColumnName + " schema information to the SPSS .SAV data file.", ex);
                }
            }
        }
예제 #6
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();
        }
예제 #7
0
 public override SpssVariable Clone()
 {
     SpssStringVariable other = new SpssStringVariable();
     CloneTo(other);
     return other;
 }
예제 #8
0
 private SpssVariable CreateStringVariable(Variable v)
 {
     SpssStringVariable var1 = new SpssStringVariable();
     foreach (var item in v.ValueLabels)
         if (var1.ValueLabels.ContainsKey(item.Key) == false)
             var1.ValueLabels.Add(item.Key, item.Value);
     var1.Length = v.Size;
     return var1;
 }