/
systemTestTypeImpacts.go
121 lines (98 loc) · 2.96 KB
/
systemTestTypeImpacts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package reports
import (
"encoding/csv"
"fmt"
"github.com/nsip/dev-nrt/records"
"github.com/tidwall/sjson"
)
type SystemTestTypeImpacts struct {
baseReport // embed common setup capability
}
//
// Reports tests for which the response contents are unexpected based on the test domain
//
func SystemTestTypeImpactsReport() *SystemTestTypeImpacts {
r := SystemTestTypeImpacts{}
r.initialise("./config/SystemTestTypeImpacts.toml")
r.printStatus()
return &r
}
//
// implement the EventPipe interface, core work of the
// report engine.
//
func (r *SystemTestTypeImpacts) ProcessEventRecords(in chan *records.EventOrientedRecord) chan *records.EventOrientedRecord {
out := make(chan *records.EventOrientedRecord)
go func() {
defer close(out)
// open the csv file writer, and set the header
w := csv.NewWriter(r.outF)
defer r.outF.Close()
w.Write(r.config.header)
defer w.Flush()
for eor := range in {
if !r.config.activated { // only process if activated
out <- eor
continue
}
tterr := validate(eor)
if tterr == nil { // only process events which fail validation
out <- eor
continue
}
//
// generate any calculated fields required
//
eor.CalculatedFields = r.calculateFields(eor, tterr)
//
// now loop through the ouput definitions to create a
// row of results
//
var result string
var row []string = make([]string, 0, len(r.config.queries))
for _, query := range r.config.queries {
result = eor.GetValueString(query)
row = append(row, result)
}
// write the row to the output file
if err := w.Write(row); err != nil {
fmt.Println("Warning: error writing record to csv:", r.config.name, err)
}
out <- eor
}
}()
return out
}
//
// generates a block of json that can be added to the
// record containing values that are not in the original data
//
//
func (r *SystemTestTypeImpacts) calculateFields(eor *records.EventOrientedRecord, err error) []byte {
json := eor.CalculatedFields
json, _ = sjson.SetBytes(json, "CalculatedFields.SystemTestTypeImpactError", err.Error())
return json
}
func validate(eor *records.EventOrientedRecord) error {
participationCode := eor.GetValueString("NAPEventStudentLink.ParticipationCode")
if participationCode != "S" && participationCode != "P" { // only evaluate valid tests
return nil
}
// writing response but adaptive pathway
if eor.IsWritingResponse() {
if eor.GetValueString("NAPStudentResponseSet.PathTakenForDomain") != "" ||
eor.GetValueString("NAPStudentResponseSet.ParallelTest") != "" {
return errWritingAdaptive
}
return nil
}
// not a writing response, but no adaptive pathway
if eor.GetValueString("NAPStudentResponseSet.PathTakenForDomain") == "" ||
eor.GetValueString("NAPStudentResponseSet.ParallelTest") == "" {
if eor.GetValueString("NAPStudentResponseSet.DomainScore.RawScore") != "0" &&
eor.GetValueString("NAPStudentResponseSet.DomainScore.RawScore") != "" {
return errNonAdaptive
}
}
return nil
}