marshal

package
v0.0.0-...-5b7235d Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxParsingErrors = 200

MaxParsingErrors is the number of parsing errors to report per file.

Functions

func CreateTempFileWithContent

func CreateTempFileWithContent(t *testing.T, content []byte) *os.File

CreateTempFileWithContent créée un fichier temporaire et le supprime après le passage (ou échec) du test.

func GetJSON

func GetJSON(tuple Tuple) ([]byte, error)

GetJSON sérialise un tuple au format JSON.

func GetSiret

func GetSiret(compte string, date *time.Time, cache Cache, batch *base.AdminBatch) (string, error)

GetSiret gets the siret related to a specific compte at a given point in time

func GetSiretFromComptesMapping

func GetSiretFromComptesMapping(compte string, date *time.Time, comptes Comptes) (string, error)

GetSiretFromComptesMapping gets the siret related to a specific compte at a given point in time

func LogProgress

func LogProgress(lineNumber *int) (stop context.CancelFunc)

LogProgress affiche le numéro de ligne en cours de parsing, toutes les 2s.

func ParseFilesFromBatch

func ParseFilesFromBatch(cache Cache, batch *base.AdminBatch, parser Parser) (chan Tuple, chan Event)

ParseFilesFromBatch parse tous les fichiers spécifiés dans batch pour un parseur donné.

func RunParser

func RunParser(
	parser Parser,
	cache Cache,
	inputFile string,
) (output tuplesAndEvents)

RunParser returns Tuples and Events resulting from the execution of a Parser on a given input file.

func TestParserOutput

func TestParserOutput(
	t *testing.T,
	parser Parser,
	cache Cache,
	inputFile string,
	goldenFile string,
	update bool,
)

TestParserOutput compares output Tuples and output Events with JSON stored in a golden file. If update = true, the the golden file is updated.

func UrssafToDate

func UrssafToDate(urssaf string) (time.Time, error)

UrssafToDate convertit le format de date urssaf en type Date. Les dates urssaf sont au format YYYMMJJ tels que YYY = YYYY - 1900 (e.g: 118 signifie 2018)

func UrssafToPeriod

func UrssafToPeriod(urssaf string) (misc.Periode, error)

UrssafToPeriod convertit le format de période urssaf en type Periode. On trouve ces périodes formatées en 4 ou 6 caractère (YYQM ou YYYYQM). si YY < 50 alors YYYY = 20YY sinon YYYY = 19YY. si QM == 62 alors période annuelle sur YYYY. si M == 0 alors période trimestrielle sur le trimestre Q de YYYY. si 0 < M < 4 alors mois M du trimestre Q.

Types

type Cache

type Cache map[string]interface{}

Cache saves values in memory

func NewCache

func NewCache() Cache

NewCache returns a new cache object

func (Cache) Get

func (ca Cache) Get(name string) (interface{}, error)

Get gets a value from the cache

func (Cache) Set

func (ca Cache) Set(name string, value interface{})

Set writes a value to the Cache

type Code

type Code string

Code test

type Comptes

type Comptes map[string][]SiretDate

Comptes associates a SiretDate to an urssaf account number

func GetCompteSiretMapping

func GetCompteSiretMapping(cache Cache, batch *base.AdminBatch, mr mappingReader) (Comptes, error)

GetCompteSiretMapping returns the siret mapping in cache if available, else reads the file and save it in cache. Lazy loaded.

func MockComptesMapping

func MockComptesMapping(mapping map[string]string) Comptes

MockComptesMapping ...

func OpenAndReadSiretMapping

func OpenAndReadSiretMapping(
	basePath string,
	endPath string,
	compteSiretMapping Comptes,
	cache Cache,
	batch *base.AdminBatch,
) (Comptes, error)

OpenAndReadSiretMapping opens files and reads their content

func (*Comptes) GetSortedKeys

func (comptes *Comptes) GetSortedKeys() []string

GetSortedKeys retourne la liste classée des numéros de Comptes.

type Event

type Event struct {
	ID         bson.ObjectId `json:"-" bson:"_id"`
	Date       time.Time     `json:"date" bson:"date"`
	StartDate  time.Time     `json:"startDate" bson:"startDate"`
	Comment    interface{}   `json:"event" bson:"event"`
	Priority   Priority      `json:"priority" bson:"priority"`
	Code       Code          `json:"parserCode" bson:"parserCode"`
	ReportType string        `json:"report_type" bson:"record_type"`
	Channel    chan Event    `json:"-"`
}

Event est un objet de journal swagger:ignore

func CreateEvent

func CreateEvent() (event Event)

CreateEvent initialise un évènement avec les valeurs par défaut.

func (Event) GetBSON

func (event Event) GetBSON() (interface{}, error)

GetBSON retourne l'objet Event sous une forme sérialisable

func (Event) Info

func (event Event) Info(comment interface{})

Info produit un évènement de niveau Info

func (Event) ParseReport

func (event Event) ParseReport() (map[string]interface{}, error)

ParseReport permet d'accéder aux propriétés d'un rapport de parsing.

type ParsedLineResult

type ParsedLineResult struct {
	Tuples      []Tuple
	Errors      []error
	FilterError error
}

ParsedLineResult est le résultat du parsing d'une ligne.

func (*ParsedLineResult) AddRegularError

func (res *ParsedLineResult) AddRegularError(err error)

AddRegularError permet au parseur de rapporter une erreur d'extraction.

func (*ParsedLineResult) AddTuple

func (res *ParsedLineResult) AddTuple(tuple Tuple)

AddTuple permet au parseur d'ajouter un tuple extrait depuis la ligne en cours.

func (*ParsedLineResult) SetFilterError

func (res *ParsedLineResult) SetFilterError(err error)

SetFilterError permet au parseur de rapporter que la ligne doit été filtrée.

type Parser

type Parser interface {
	GetFileType() string
	Init(cache *Cache, batch *base.AdminBatch) error
	Open(filePath string) error
	ParseLines(parsedLineChan chan ParsedLineResult)
	Close() error
}

Parser fournit les fonctions de parsing d'un type de fichier donné.

type ParsingTracker

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

ParsingTracker permet de collecter puis rapporter des erreurs de parsing.

func NewParsingTracker

func NewParsingTracker() ParsingTracker

NewParsingTracker retourne une instance pour rapporter les erreurs de parsing.

func (*ParsingTracker) AddFatalError

func (tracker *ParsingTracker) AddFatalError(err error)

AddFatalError rapporte une erreur fatale liée au parsing d'un fichier

func (*ParsingTracker) AddFilterError

func (tracker *ParsingTracker) AddFilterError(err error)

AddFilterError rapporte le fait que la ligne en cours de parsing est ignorée à cause du filtre/périmètre

func (*ParsingTracker) AddParseError

func (tracker *ParsingTracker) AddParseError(err error)

AddParseError rapporte une erreur rencontrée sur la ligne en cours de parsing

func (*ParsingTracker) Next

func (tracker *ParsingTracker) Next()

Next informe le Tracker qu'on va parser la ligne suivante.

func (*ParsingTracker) Report

func (tracker *ParsingTracker) Report(batchKey string, filePath string) bson.M

Report génère un rapport de parsing à partir des erreurs rapportées.

type Priority

type Priority string

Priority test

type SirenFilter

type SirenFilter map[string]bool

SirenFilter liste les numéros SIREN d'entreprise et établissements à exclure des traitements.

func GetSirenFilter

func GetSirenFilter(cache Cache, batch *base.AdminBatch) (SirenFilter, error)

GetSirenFilter reads the filter from cache if it cans, or else it reads it from input files and stores it in cache

func GetSirenFilterFromCache

func GetSirenFilterFromCache(cache Cache) SirenFilter

GetSirenFilterFromCache reads the filter from cache.

func (SirenFilter) Skips

func (filter SirenFilter) Skips(siretOrSiren string) bool

Skips retourne `false` si le numéro SIREN/SIRET peut être traité, car il est inclus dans le Filtre, ou car il n'y a pas de filtre.

type SiretDate

type SiretDate struct {
	Siret string
	Date  time.Time
}

SiretDate holds a pair of a siret and a date

type Tuple

type Tuple interface {
	Key() string
	Scope() string
	Type() string
}

Tuple unité de donnée à insérer dans un type

Jump to

Keyboard shortcuts

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