qap

package module
v0.0.0-...-dd4fc37 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 7 Imported by: 0

README

go-qap

To solve the document naming convention problem.

Implementation of CERN's quality assurance plan (QAP) in pure Go.

This is a WIP.

Motivation

Startups in the business of mechanical engineering have limited choices when it comes to choosing cost effective PLM software.

In particular there is a real and immediate need to document deliverables and keep them organized in an electronic file repository.

This repository seeks to fully solve the problem regarding document naming conventions. This may seem like a trivial task but it is something that has been given a great deal of thought, not least by those in charge of the LHC project at CERN.

BoltQAP

BoltQAP

BoltQAP is a basic implementation of a document naming application which runs in a server. It is in the cmd/boltqap directory.

Get it by running

go install github.com/soypat/go-qap/cmd/boltqap@latest

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidNumber         = fmt.Errorf("QAP number out of range 0..%d", maxDocumentNumber)
	ErrEmptyProjectCode      = errors.New("zero length project code")
	ErrEmptyEquipmentCode    = errors.New("zero length equipment code")
	ErrEmptyDocumentTypeCode = errors.New("zero length document type code")
	ErrEmptyAttachmentNumber = errors.New("zero length attachment number")
	ErrBadProjectCode        = fmt.Errorf("project code must be %d upper case characters", lenP)
	ErrBadEquipmentCode      = fmt.Errorf("equipment code must be 1..%d digits or/and upper case characters", lenE)
	ErrBadDocumentTypeCode   = fmt.Errorf("document type code must be 1..%d upper case characters", lenDT)
	ErrBadAttachmentNumber   = fmt.Errorf("attachment number must be 2 digits in range 0..%d", maxAttachmentNumber)

	ErrZeroTime         = errors.New("creation/revision time is zero")
	ErrBadRevisionIndex = errors.New("revision index must be two digits or an upper case character followed by a digit")
)

Functions

func AreSequential

func AreSequential(a, b Revision) (minor, major bool)

AreSequential tests whether b follows a as a revision, indicating whether the increment between the two revisions is

  • A minor revision, which can be either
  • A draft to release increment (i.e. A.1-draft -> A.1)
  • A minor index increment (i.e. C.2 -> C.3 or C.2 -> C.3-draft)
  • A major revision (i.e. A.3 -> B.1 or A.3 -> B.1-draft)

It returns false for both minor and major if revisions are not in ascending order, they are not a single increment apart or if they are invalid revisions.

func HeaderCodesEqual

func HeaderCodesEqual(a, b Header) bool

HeaderCodesEqual tests project, equipment and document type codes of a and b are the same. If either a or b are invalid then HeaderCodesEqual returns false.

func HeadersEqual

func HeadersEqual(a, b Header) bool

HeadersEqual tests headers for complete equality. If either a or b are invalid then HeadersEqual returns false.

func ParseDocumentCodes

func ParseDocumentCodes(documentName string) (project, equipment, docType string)

ParseDocumentCodes is a helper function to extract document codes from human input.

func ParseDocumentName

func ParseDocumentName(docName string) (Header, Revision, error)

ParseDocumentName parses a full document name of the style "LHC-PM-QA-202.00 rev B.2" and returns the corresponding header.

If there is no " rev " text in the string the header is parsed and a new A.1 revision is returned.

Types

type DocInfo

type DocInfo struct {
	Header
	Revision Revision
	// Time document was created.
	Creation time.Time
	// Time revision index was last incremented.
	RevisionTime time.Time
}

DocInfo defines a document's type, naming and revision as specified by CERN's Quality Assurance Plan along with some helper data relating to time.

func (DocInfo) String

func (d DocInfo) String() string

String returns the document information as a string. If DocInfo is invalid it return a constant non-empty string. i.e "LHC-PM-QA-202.00 rev C.2"

func (DocInfo) Validate

func (d DocInfo) Validate() error

Validate tests DocInfo for malformed data.

type Family

type Family struct {
	Code        byte
	Types       []Type
	Name        string
	Description string
}

Family represents the second letter of the equipment code. It defines the family of the equipment within a given system.

func (*Family) AddType

func (f *Family) AddType(tp Type) error

func (Family) Letter

func (f Family) Letter() string

func (Family) String

func (f Family) String() string
type Header struct {
	// A user or system controlled number or a combination thereof.
	// Is 3 to 6 digits long. Referred to as EDMS number in QAP202.
	Number int32
	// Composed of 3 upper case characters
	ProjectCode [3]byte
	// Composed of 1 to 5 alphanumeric characters.
	EquipmentCode [5]byte
	// DocumentTypeCode identifies the purpose of the document.
	// Composed of 2 upper case characters.
	DocumentTypeCode [2]byte
	// For material attached to main document. The main document's attachment
	// number is 0.
	AttachmentNumber uint8
}

Header represents a unique document name according to LHC's Quality Assurance Plan (QAP). The API is designed so that the Header is immutable through method calls, thus only direct access by the user to its fields should mutate the underlying data.

func ParseHeader

func ParseHeader(header string, ignoreAttachment bool) (Header, error)

ParseHeader parses a complete unversioned QAP document string of the style "SPS-PEC-HP-0023.01". The attachment number parsing may be omitted by setting ignoreAttachment to true setting attachment result to 0.

This function is very careful of the input and will more readily return an error before forming a valid Header from ambiguous or unexpected input.

func (Header) DocumentType

func (h Header) DocumentType() string

DocumentType returns a valid QAP document type code string or an empty string.

func (Header) Equipment

func (h Header) Equipment() string

Equipment returns a valid QAP equipment code string or an empty string.

func (Header) Project

func (h Header) Project() string

Project returns a valid QAP project code string or an empty string.

func (Header) String

func (h Header) String() string

String returns the Header's document name representation i.e. "SPS-PEC-HP-023.00". This function is deterministic and different valid QAP document String() returned values will not collide.

func (Header) Validate

func (h Header) Validate() (err error)

Validate tests Header for malformed data.

type HeaderFilter

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

HeaderFilter is an in-memory header filtering structure optimized for common search patterns.

func NewHeaderFilter

func NewHeaderFilter(headers []Header) HeaderFilter

NewHeaderFilter initializes a HeaderFilter with headers data.

func (*HeaderFilter) AddHeader

func (hf *HeaderFilter) AddHeader(h Header) error

AddHeader adds a header to the filter.

func (*HeaderFilter) Do

func (hf *HeaderFilter) Do(f func(i int, h Header) error) error

func (*HeaderFilter) Has

func (hf *HeaderFilter) Has(h Header) bool

func (*HeaderFilter) HumanQuery

func (hf *HeaderFilter) HumanQuery(dst []Header, query string, page int) (n, totalFound int)

HumanQuery queries filter for n matches which are stored in dst. The total amount of matches found is totalFound.

func (*HeaderFilter) Len

func (hf *HeaderFilter) Len() int

Len returns the amount of headers contained in filter.

type Model

type Model struct {
	Code        byte
	Variants    []Variant
	Name        string
	Description string
}

Model represents the fourth letter within an equipment code.

func (Model) Letter

func (m Model) Letter() string

func (Model) String

func (m Model) String() string

type Project

type Project struct {
	Code        [3]byte // Project name (3 letters)
	Systems     []System
	Name        string
	Description string
}

Project represents the overlying project structure as outlined by LHC-PM-QA-202 and LHC-PM-QA-204.

func (*Project) AddEquipmentCode

func (p *Project) AddEquipmentCode(code, name, description string) error

func (*Project) AddFamily

func (p *Project) AddFamily(sys byte, family Family) error

func (*Project) AddSystem

func (p *Project) AddSystem(sys System) error

func (*Project) AddType

func (p *Project) AddType(sys, family byte, tp Type) error

func (Project) ContainsCode

func (p Project) ContainsCode(hd Header) bool

ContainsCode returns true if header equipment code and project code exist inside the project structure. Does not check for validity of entire Header.

func (Project) Project

func (p Project) Project() string

Project returns the project code string. i.e. "LHC"

func (Project) String

func (p Project) String() string

type Revision

type Revision struct {
	// Index is the document revision index and is
	// composed by two digits separated by a dot (or alphanumeric characters).
	Index [2]byte

	IsRelease bool
}

Revision holds version code information of a document.

When registered new documents should be given revision index A.1 and a non released status.

Prior to release, new revisions of draft documents are given the revision index A.1, A.2, A.3 and so on.

In the case of a minor change only the second digit/character of the revision index is incremented, for example from C.0 to C.1 or B.3 to B.4.

In the case of a major change the first digit of the revision index is incremented while the second is set to 0. (or A if using alphanumeric revision index) Example:

A.4 -> B.0

func NewRevision

func NewRevision() Revision

NewRevision returns the first version draft revision "A.1-draft".

func ParseRevision

func ParseRevision(revision string) (Revision, error)

ParseRevision creates a Revision from a formatted string i.e. "B.3-draft", "A.1"

func (Revision) IncrementMajor

func (d Revision) IncrementMajor(isRelease bool) (Revision, error)

IncrementMajor returns the DocInfo with it's major version incremented by one and IsReleased field set to isRelease argument.

func (Revision) IncrementMinor

func (d Revision) IncrementMinor(isRelease bool) (Revision, error)

IncrementMinor returns the DocInfo with it's minor version incremented by one and IsReleased field set to isRelease argument.

func (Revision) String

func (d Revision) String() string

String returns the revision index as a string. i.e. "A.1-draft" or "A.2" If the DocInfo's revision index is invalid it returns a constant string.

func (Revision) Validate

func (d Revision) Validate() error

Validate tests the Revision is valid and returns ErrBadRevisionIndex if it is not.

type System

type System struct {
	Code        byte
	Families    []Family
	Name        string
	Description string
}

System represents the first letter of the equipment code, which indicates the system to which the equipment belongs.

func (*System) AddFamily

func (s *System) AddFamily(family Family) error

func (*System) AddType

func (s *System) AddType(family byte, tp Type) error

func (System) Letter

func (s System) Letter() string

func (System) String

func (s System) String() string

type Type

type Type struct {
	Code        byte
	Models      []Model
	Name        string
	Description string
}

Type represents the third letter in an equipment code and defines the type within a family of an equipment.

func (Type) Letter

func (t Type) Letter() string

func (Type) String

func (t Type) String() string

type Variant

type Variant struct {
	Code        byte
	Name        string
	Description string
}

Variant represents the fifth letter within an equipment code.

func (Variant) Letter

func (v Variant) Letter() string

func (Variant) String

func (v Variant) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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