88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
package meteo
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
type MeteoData struct {
|
|
Timestamp time.Time `csv:"fecha"`
|
|
Location string `csv:"ciudad"`
|
|
MaxTemp float32 `csv:"temperatura maxima"`
|
|
MinTemp float32 `csv:"temperatura minima"`
|
|
Rainfall float32 `csv:"precipitacion"`
|
|
Cloudiness int `csv:"nubosidad"`
|
|
}
|
|
|
|
type RejectedMeteoData struct {
|
|
RowValue string
|
|
Reason string
|
|
}
|
|
|
|
type FileStats struct {
|
|
BatchID int `json:"batch_id"`
|
|
RowsInserted int `json:"rows_inserted"`
|
|
RowsRejected int `json:"rows_rejected"`
|
|
ElapsedMS int `json:"elapsed_ms"`
|
|
FileChecksum string `json:"file_checksum"`
|
|
}
|
|
|
|
type GetMeteoData struct {
|
|
Location string
|
|
From string
|
|
To string
|
|
Page int
|
|
Limit int
|
|
Offset int
|
|
}
|
|
|
|
func (mt *GetMeteoData) Validate() error {
|
|
if mt.Location == "" {
|
|
return ErrMissingOrInvalidLocation
|
|
}
|
|
|
|
if mt.From == "" {
|
|
return ErrMissingOrInvalidFromDate
|
|
}
|
|
|
|
if mt.To == "" {
|
|
return ErrMissingOrInvalidToDate
|
|
}
|
|
|
|
if _, err := time.Parse("2006-01-02", mt.From); err != nil {
|
|
return ErrMissingOrInvalidFromDate
|
|
}
|
|
|
|
if _, err := time.Parse("2006-01-02", mt.To); err != nil {
|
|
return ErrMissingOrInvalidToDate
|
|
}
|
|
|
|
mt.Offset = (mt.Page - 1) * mt.Limit
|
|
|
|
return nil
|
|
}
|
|
|
|
var (
|
|
ErrCannotParseFile = errors.New("cannot parse file")
|
|
ErrValidateRecord = errors.New("error validating record")
|
|
ErrRecordNotValid = errors.New("record not valid")
|
|
ErrReadingCSVHeader = errors.New("error reading CSV header")
|
|
ErrReadingCSVRow = errors.New("error reading CSV row")
|
|
ErrMissingOrInvalidDate = errors.New("missing or invalid date")
|
|
ErrMissingOrInvalidFromDate = errors.New("missing or invalid from date")
|
|
ErrMissingOrInvalidToDate = errors.New("missing or invalid to date")
|
|
ErrMissingOrInvalidLocation = errors.New("missing or invalid location")
|
|
ErrMissingOrInvalidMaxTemp = errors.New("missing or invalid max temp")
|
|
ErrMissingOrInvalidMinTemp = errors.New("missing or invalid min temp")
|
|
ErrMissingOrInvalidRainfall = errors.New("missing or invalid rainfall")
|
|
ErrMissingOrInvalidCloudiness = errors.New("missing or invalid cloudiness")
|
|
ErrMaxTempOutOfRange = errors.New("max temp out of range (must be <= 60°C)")
|
|
ErrMinTempOutOfRange = errors.New("min temp out of range (must be >= -20°C)")
|
|
ErrRainfallOutOfRange = errors.New("rainfall out of range (must be 0-500 mm)")
|
|
ErrCloudinessOutOfRange = errors.New("cloudiness out of range (must be 0-100%)")
|
|
ErrParsingForm = errors.New("error parsing form")
|
|
ErrRetrievingFile = errors.New("error retrieving file")
|
|
ErrReadingFile = errors.New("error reading file")
|
|
ErrReadingData = errors.New("error reading data")
|
|
)
|