ags-upload

Insert AGS files to a database
git clone git://src.adamsgaard.dk/ags-upload # fast
git clone https://src.adamsgaard.dk/ags-upload.git # slow
Log | Files | Refs Back to index

commit b08da215c078c301b68291b5c298ad34c50ca130
parent 52ae372551aa77ef8cff17830e9ad996f6876516
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed,  8 Oct 2025 11:51:26 +0200

main.go: set empty fields as NULL

Diffstat:
Mcmd/main.go | 39+++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go @@ -33,13 +33,13 @@ type Cpt struct { // group SCPG - data InfoId uint //foreign key from CptInfo LocationId string // LOCA_ID TestReference string // SCPG_TESN - Depth float64 // SCPT_DPTH - ConeRes float64 // SCPT_RES - SideFric float64 // SCPT_FRES - Pore1 float64 // SCPT_PWP1 - Pore2 float64 // SCPT_PWP2 - Pore3 float64 // SCPT_PWP3 - FrictionRatio float64 // SCPT_FRR + Depth *float64 // SCPT_DPTH + ConeRes *float64 // SCPT_RES + SideFric *float64 // SCPT_FRES + Pore1 *float64 // SCPT_PWP1 + Pore2 *float64 // SCPT_PWP2 + Pore3 *float64 // SCPT_PWP3 + FrictionRatio *float64 // SCPT_FRR } func ParseAGSProjectAndSCPT(r io.Reader) (*CptInfo, []Cpt, error) { @@ -69,14 +69,17 @@ func ParseAGSProjectAndSCPT(r io.Reader) (*CptInfo, []Cpt, error) { } return "" } - parseF64 := func(s string) float64 { + parseF64Ptr := func(s string) *float64 { if s == "" { - return 0 + return nil } // Optional: handle decimal commas s = strings.ReplaceAll(s, ",", ".") - f, _ := strconv.ParseFloat(s, 64) - return f + f, err := strconv.ParseFloat(s, 64) + if err != nil { + return nil + } + return &f } for { @@ -138,13 +141,13 @@ func ParseAGSProjectAndSCPT(r io.Reader) (*CptInfo, []Cpt, error) { cpts = append(cpts, Cpt{ LocationId: get("SCPT", data, "LOCA_ID"), TestReference: get("SCPT", data, "SCPG_TESN"), - Depth: parseF64(get("SCPT", data, "SCPT_DPTH")), - ConeRes: parseF64(get("SCPT", data, "SCPT_RES")), - SideFric: parseF64(get("SCPT", data, "SCPT_FRES")), - Pore1: parseF64(get("SCPT", data, "SCPT_PWP1")), - Pore2: parseF64(get("SCPT", data, "SCPT_PWP2")), - Pore3: parseF64(get("SCPT", data, "SCPT_PWP3")), - FrictionRatio: parseF64(get("SCPT", data, "SCPT_FRR")), + Depth: parseF64Ptr(get("SCPT", data, "SCPT_DPTH")), + ConeRes: parseF64Ptr(get("SCPT", data, "SCPT_RES")), + SideFric: parseF64Ptr(get("SCPT", data, "SCPT_FRES")), + Pore1: parseF64Ptr(get("SCPT", data, "SCPT_PWP1")), + Pore2: parseF64Ptr(get("SCPT", data, "SCPT_PWP2")), + Pore3: parseF64Ptr(get("SCPT", data, "SCPT_PWP3")), + FrictionRatio: parseF64Ptr(get("SCPT", data, "SCPT_FRR")), }) default: // ignore other groups for now