change db types for better handling
This commit is contained in:
parent
5e8ccc6be1
commit
28c2c6a5d6
@ -13,7 +13,7 @@ type MeteoData struct {
|
|||||||
MaxTemp float32 `csv:"temperatura maxima"`
|
MaxTemp float32 `csv:"temperatura maxima"`
|
||||||
MinTemp float32 `csv:"temperatura minima"`
|
MinTemp float32 `csv:"temperatura minima"`
|
||||||
Rainfall float32 `csv:"precipitacion"`
|
Rainfall float32 `csv:"precipitacion"`
|
||||||
Cloudiness float32 `csv:"nubosidad"`
|
Cloudiness int `csv:"nubosidad"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RejectedMeteoData struct {
|
type RejectedMeteoData struct {
|
||||||
|
|||||||
@ -129,7 +129,7 @@ func normalize(record H) (*MeteoData, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
meteoData.Cloudiness, err = parseFloatField(record, "Nubosidad (%)", ErrMissingOrInvalidCloudiness)
|
meteoData.Cloudiness, err = parseIntField(record, "Nubosidad (%)", ErrMissingOrInvalidCloudiness)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -166,3 +166,15 @@ func parseFloatField(record H, key string, errMissing error) (float32, error) {
|
|||||||
}
|
}
|
||||||
return 0, errMissing
|
return 0, errMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseIntField(record H, key string, errMissing error) (int, error) {
|
||||||
|
if str, ok := record[key].(string); ok && str != "" {
|
||||||
|
str = strings.TrimSpace(str)
|
||||||
|
i, err := strconv.Atoi(str)
|
||||||
|
if err != nil {
|
||||||
|
return 0, errMissing
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
return 0, errMissing
|
||||||
|
}
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
|
create extension citext; -- noqa
|
||||||
|
|
||||||
create table public.meteo_data
|
create table public.meteo_data
|
||||||
(
|
(
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
|
|
||||||
location_name citext not null,
|
location_name citext not null,
|
||||||
max_temp float not null,
|
max_temp numeric(5,2) not null,
|
||||||
min_temp float not null,
|
min_temp numeric(5,2) not null,
|
||||||
rainfall float not null,
|
rainfall numeric(5,2) not null,
|
||||||
cloudiness float not null,
|
cloudiness int not null,
|
||||||
|
|
||||||
created_at timestamp not null default now()
|
created_at date not null default now()
|
||||||
);
|
);
|
||||||
|
|
||||||
create index idx_meteo_data_location_name on public.meteo_data (location_name);
|
create index idx_meteo_data_location_name on public.meteo_data (location_name);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user