From 495190fbc4975396573689c9e14d6ddf4c194a12 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Tue, 13 Dec 2016 12:05:40 +1100 Subject: [PATCH] Add numerical checker --- harness/nias.toml | 2 +- harness/public/index.html | 4 +- harness/validator_test.go | 4 +- lib/numericvalidservice.go | 77 ++++++++++++++++++++++++++++++++++++++ lib/serviceregister.go | 6 +++ 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 lib/numericvalidservice.go diff --git a/harness/nias.toml b/harness/nias.toml index f0b75a4..fc940ee 100755 --- a/harness/nias.toml +++ b/harness/nias.toml @@ -8,7 +8,7 @@ TestYear = "2017" # Validations to invoke # ValidationRoute = ["schema", "local", "id", "dob", "asl"] -ValidationRoute = ["schema", "schema2", "id", "dob", "asl", "psi"] +ValidationRoute = ["schema", "schema2", "id", "dob", "asl", "psi", "numericvalid"] SSFRoute = ["privacy"] SMSRoute = ["sif2graph"] diff --git a/harness/public/index.html b/harness/public/index.html index 33df0eb..f2c7296 100755 --- a/harness/public/index.html +++ b/harness/public/index.html @@ -72,11 +72,11 @@

NIAS - Naplan Validation

How to use the pre-validation tool
-

Select a csv file containing student registrations data with the file chooser on the left, you can drag files onto the highlighted area or browse for them.

+

Select a csv file containing student registrations data with the file chooser on the left, you can drag files onto the highlighted area or browse for them. If you have already processed a file, run stopnias, and close and reopen the browser window, to prevent any confusion between files.

The file will be uploaded and processed by all validation engines simultaneously. The Progress area on the right will show the progress of the validation activity.

Once all validations are complete the results will be displayed automatically in the graphs and tables below.

If there are a very large number of validation errors, only the first 10,000 will be returned to this web interface.

-

Click on the 'Download Validation Error Report' button to download the validation results as an excel/csv file. This will include all validation errors and is not capped at 10,000.

+

After the validator has finished processing all records, click on the 'Download Validation Error Report' button to download the validation results as an excel/csv file. This will include all validation errors and is not capped at 10,000.

diff --git a/harness/validator_test.go b/harness/validator_test.go index efc2f31..1bb80d3 100644 --- a/harness/validator_test.go +++ b/harness/validator_test.go @@ -283,11 +283,11 @@ func TestYearLevelTestLevelMismatch(t *testing.T) { } func TestMaximumFTE(t *testing.T) { - test_harness(t, "../unit_test_files/1MaximumFTE.csv", "FTE", "Year level supplied is UG, will result in SRM warning flag for test level") + test_harness(t, "../unit_test_files/1MaximumFTE.csv", "FTE", "FTE is greater than 1") } func TestMinimumFTE(t *testing.T) { - test_harness(t, "../unit_test_files/1MinimumFTE.csv", "FTE", "Year level supplied is UG, will result in SRM warning flag for test level") + test_harness(t, "../unit_test_files/1MinimumFTE.csv", "FTE", "FTE is less than 0") } func TestDupGivenLastNameDOBCARAId(t *testing.T) { diff --git a/lib/numericvalidservice.go b/lib/numericvalidservice.go new file mode 100644 index 0000000..1ef1548 --- /dev/null +++ b/lib/numericvalidservice.go @@ -0,0 +1,77 @@ +// numericvalidservice.go +package nias2 + +import ( + "fmt" + "log" + "strconv" +) + +// numeric value validator service + +// implementation of the id service +type NumericValidService struct { +} + +// create a new id service instance +func NewNumericValidService() (*NumericValidService, error) { + num := NumericValidService{} + + return &num, nil +} + +// implement the nias Service interface +func (num *NumericValidService) HandleMessage(req *NiasMessage) ([]NiasMessage, error) { + + responses := make([]NiasMessage, 0) + + rr, ok := req.Body.(RegistrationRecord) + if !ok { + log.Println("NumericValidService received a message that is not a RegistrationRecord, ignoring") + return responses, nil + } + + fte := rr.FTE + desc := "" + field := "FTE" + ok = true + + if len(fte) > 0 { + fte_f, err := strconv.ParseFloat(fte, 64) + if err != nil { + ok = false + desc = fmt.Sprintf("FTE %s is not a well formed float", fte) + } else { + if fte_f < 0 { + ok = false + desc = "FTE is less than 0" + } + if fte_f > 1 { + ok = false + desc = "FTE is greater than 1" + } + } + } + if !ok { + responses = add_error(responses, desc, field, req) + } + + return responses, nil + +} + +func add_error(responses []NiasMessage, desc string, field string, req *NiasMessage) []NiasMessage { + ve := ValidationError{ + Description: desc, + Field: field, + OriginalLine: req.SeqNo, + Vtype: "date", + } + r := NiasMessage{} + r.TxID = req.TxID + r.SeqNo = req.SeqNo + r.Target = VALIDATION_PREFIX + r.Body = ve + responses = append(responses, r) + return responses +} diff --git a/lib/serviceregister.go b/lib/serviceregister.go index 0ed7d6d..d9492ef 100644 --- a/lib/serviceregister.go +++ b/lib/serviceregister.go @@ -95,6 +95,11 @@ func createDefaultServiceRegister() *ServiceRegister { log.Fatal("Unable to create sif2graph service ", err) } + num, err := NewNumericValidService() + if err != nil { + log.Fatal("Unable to create numeric validation service ", err) + } + sr.AddService("schema", schema1) sr.AddService("schema2", schema11) sr.AddService("local", schema2) @@ -104,6 +109,7 @@ func createDefaultServiceRegister() *ServiceRegister { sr.AddService("psi", psi1) sr.AddService("privacy", priv1) sr.AddService("sif2graph", s2g1) + sr.AddService("numericvalid", num) log.Println("services created & installed in register")