gospss

package module
v0.0.0-...-09dc903 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: MIT Imports: 10 Imported by: 0

README

GoSPSS

This package can read an IBM Statistics data file in to golang to handle it any which way you want.

Example 1:

Read data line by line.

package main

import (
	"fmt"
	"io"
	"log"
	"os"
	"github.com/hektorinho/gospss"
)

const TEST_FILE = "data/data7.sav"

func main() {
  	f, err := os.OpenFile(TEST_FILE, os.O_RDONLY, 0777)
	if err != nil {
		log.Panicf("failed to open %s ::: err >>> %s\n", TEST_FILE, err)
	}
	defer f.Close()
  
	r, err := NewReader(f)
	if err != nil {
		log.Panicf("failed to read %s ::: err >>> %s\n", TEST_FILE, err)
	}

	for i := 0; ; i++ {
		data, err := r.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Panicf("err >>> %s\n", err)
		}
		
		// Handle your data ...
		fmt.Println(i, data)
	}
}

Example 2:

Read all data and header information.

package main

import (
	"fmt"
	"io"
	"log"
	"os"
	"github.com/hektorinho/gospss"
)

const TEST_FILE = "data/data7.savz"

func main() {
  	f, err := os.OpenFile(TEST_FILE, os.O_RDONLY, 0777)
	if err != nil {
		log.Panicf("failed to open %s ::: err >>> %s\n", TEST_FILE, err)
	}
	defer f.Close()
  
	r, err := NewReader(f)
	if err != nil {
		log.Panicf("failed to read %s ::: err >>> %s\n", TEST_FILE, err)
	}

	// Exposes all header information
	header := r.Header()
	fmt.Println(header.Fileheader.ncases)

	// Reads the whole data file in to a list of gospss.Row.
	rows, err := r.ReadAll()
	if err != nil {
		log.Panicf("failed to read all records %s ::: err >>> %s", TEST_FILE, err)
	}
	for i, row := range rows[0:4] {
		fmt.Printf("row %d, data >>> %v\n", i, row)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotValidSPSSFile = errors.New("Not a valid IBM SPSS Statistics file.")
)

Functions

This section is empty.

Types

type Header struct {
	Fileheader              *fileHeader
	Variable                []*variabler
	ValueLabel              []*valueLabel
	Documents               *documents
	MachineIntegerInfo      *machineIntegerInfo
	MachineFloatingPoint    *machineFloatingPointInfo
	MultipleResponseSetsOld *multipleResponseSets
	ExtraProductInfo        *extraProductInfo
	VariableDisplay         *variableDisplay
	LongVariableNames       *longVariableNames
	VeryLongString          *veryLongString
	ExtendedNCasesInfo      *extendedNumberOfCases
	DataAttributes          *dataAttributes
	VariableAttributes      *dataAttributes
	MultipleResponseSetsNew *multipleResponseSets
	CharacterEncoding       *characterEncoding
	LongStringValueLabels   *longStringValueLabels
	LongStringMissingValues *longStringMissingValues
	DictionaryTermination   *dictionaryTermination
	ZLibDataHeader          *zLibDataHeader
	ZLibDataTrailer         *zLibDataTrailer
	// contains filtered or unexported fields
}

Header contains all the raw IBM SPSS Statistics metadata. It is fairly unstructured

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

A Reader reads data from an IBM SPSS Statistics encoded system file

As returned by NewReader blabla

func NewReader

func NewReader(r io.Reader) (*Reader, error)

NewReader returns a new Reader that reads from r

func (*Reader) ChangeEndianess

func (r *Reader) ChangeEndianess(endianess binary.ByteOrder)

Change endianess, can be binary.LittleEndian (most common) or binary.BigEndian

func (*Reader) Header

func (r *Reader) Header() *Header

HeaderData returns all raw header data from the IBM SPSS Statistics file.

func (*Reader) MetaData

func (r *Reader) MetaData() []*Variable

MetaData returns Human friendly meta data in form of a list of the Variable struct.

func (*Reader) Read

func (r *Reader) Read() (Row, error)

Read returns a pointer to an list of data and an error.

func (*Reader) ReadAll

func (r *Reader) ReadAll() ([]Row, error)

ReadAll returns a pointer to an Spss struct and an error.

type Row

type Row []interface{}

Data is the raw data type.

type ValueLabel

type ValueLabel struct {
	Key   interface{}
	Value string
}

ValueLabel ...

type Variable

type Variable struct {

	// Name is the variable name from the variable record or if long from the verylongstring.
	Name string

	// Label is the variable label.
	Label string

	// Decimal is the number of decimals in the variable.
	Decimal int

	// Width is the number of bytes used for the variable.
	Width int

	// Numeric is a bool if true the variable is a numeric variable.
	Numeric bool

	// Type is the variable type.
	Type int

	// List of missing value and long missing value strings.
	MissingValues []interface{}

	// List of value labels from variable record and LongValueLabels.
	ValueLabels []*ValueLabel

	// The measurement of the variable, (1) Nominal, (2) Ordinal or (3) Continuous.
	Measure int
	// contains filtered or unexported fields
}

Variable struct is a collection of useful information from the native spss structs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL