Skip to content

Commit

Permalink
Add numerical checker
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Dec 13, 2016
1 parent 2b951d3 commit 495190f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 5 deletions.
2 changes: 1 addition & 1 deletion harness/nias.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 2 additions & 2 deletions harness/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ <h4>NIAS - Naplan Validation</h4>
<div class="row">
<div class="twelve columns">
<h6 class="docs-header">How to use the pre-validation tool</h6>
<p>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.</p>
<p>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 <i>stopnias</i>, and close and reopen the browser window, to prevent any confusion between files.</p>
<p>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. </p>
<p>Once all validations are complete the results will be displayed automatically in the graphs and tables below. </p>
<p>If there are a very large number of validation errors, only the first 10,000 will be returned to this web interface. </p>
<p>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.</p>
<p>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.</p>
</div>
</div>
<div class="row">
Expand Down
4 changes: 2 additions & 2 deletions harness/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
77 changes: 77 additions & 0 deletions lib/numericvalidservice.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions lib/serviceregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")

Expand Down

0 comments on commit 495190f

Please sign in to comment.