-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notes): add a environment notes table
- Loading branch information
Showing
9 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Code,Network,Entry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package meta | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
) | ||
|
||
const ( | ||
noteCode = iota | ||
noteNetwork | ||
noteEntry | ||
noteLast | ||
) | ||
|
||
var noteHeaders Header = map[string]int{ | ||
"Code": noteCode, | ||
"Network": noteNetwork, | ||
"Entry": noteEntry, | ||
} | ||
|
||
type Note struct { | ||
Code string | ||
Network string | ||
Entry string | ||
} | ||
|
||
type NoteList []Note | ||
|
||
func (n NoteList) Len() int { return len(n) } | ||
func (n NoteList) Swap(i, j int) { n[i], n[j] = n[j], n[i] } | ||
func (n NoteList) Less(i, j int) bool { | ||
switch { | ||
case n[i].Code < n[j].Code: | ||
return true | ||
case n[i].Code > n[j].Code: | ||
return false | ||
case n[i].Network < n[j].Network: | ||
return true | ||
case n[i].Network > n[j].Network: | ||
return false | ||
case n[i].Entry < n[j].Entry: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func (n NoteList) encode() [][]string { | ||
var data [][]string | ||
|
||
data = append(data, noteHeaders.Columns()) | ||
|
||
for _, l := range n { | ||
data = append(data, []string{ | ||
strings.TrimSpace(l.Code), | ||
strings.TrimSpace(l.Network), | ||
strings.TrimSpace(l.Entry), | ||
}) | ||
} | ||
return data | ||
} | ||
|
||
func (n *NoteList) decode(data [][]string) error { | ||
if !(len(data) > 1) { | ||
return nil | ||
} | ||
|
||
var notes []Note | ||
|
||
fields := noteHeaders.Fields(data[0]) | ||
for _, v := range data[1:] { | ||
d := fields.Remap(v) | ||
|
||
notes = append(notes, Note{ | ||
Code: strings.TrimSpace(d[noteCode]), | ||
Network: strings.TrimSpace(d[noteNetwork]), | ||
Entry: strings.TrimSpace(d[noteEntry]), | ||
}) | ||
} | ||
|
||
*n = NoteList(notes) | ||
|
||
return nil | ||
} | ||
|
||
func LoadNotes(path string) ([]Note, error) { | ||
var v []Note | ||
|
||
if err := LoadList(path, (*NoteList)(&v)); err != nil { | ||
return nil, err | ||
} | ||
|
||
sort.Sort(NoteList(v)) | ||
|
||
return v, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package meta | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestNoteList(t *testing.T) { | ||
t.Run("check notes", testListFunc("testdata/notes.csv", &NoteList{ | ||
Note{ | ||
Code: "ARTA", | ||
Network: "CG", | ||
Entry: "Concrete pillar with 3 stainless rods drilled to 0.5m into concrete butress.Note that between 2006-10-12 and 2006-11-08 the existing pillar adjacent to this one was occupied using the code ATIA as a test.", | ||
}, | ||
Note{ | ||
Code: "ATIA", | ||
Network: "XX", | ||
Entry: "Test deployment for site ARTA", | ||
}, | ||
Note{ | ||
Code: "AUCK", | ||
Network: "LI", | ||
Entry: "Site upgraded to Trimble NETRS/Trimble Zephyr combination on 3rd November 2005", | ||
}, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Code,Network,Entry | ||
ARTA,CG,Concrete pillar with 3 stainless rods drilled to 0.5m into concrete butress.Note that between 2006-10-12 and 2006-11-08 the existing pillar adjacent to this one was occupied using the code ATIA as a test. | ||
ATIA,XX,Test deployment for site ARTA | ||
AUCK,LI,Site upgraded to Trimble NETRS/Trimble Zephyr combination on 3rd November 2005 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package delta_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/GeoNet/delta" | ||
"github.com/GeoNet/delta/meta" | ||
) | ||
|
||
var noteChecks = map[string]func(*meta.Set) func(t *testing.T){ | ||
|
||
"check for duplicated notes": func(set *meta.Set) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
notes := set.Notes() | ||
for i := 0; i < len(notes); i++ { | ||
for j := i + 1; j < len(notes); j++ { | ||
if notes[i].Code != notes[j].Code { | ||
continue | ||
} | ||
if notes[i].Network != notes[j].Network { | ||
continue | ||
} | ||
if notes[i].Entry != notes[j].Entry { | ||
continue | ||
} | ||
t.Errorf("note duplication: %s/%s", notes[i].Code, notes[i].Network) | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func TestNotes(t *testing.T) { | ||
|
||
set, err := delta.New() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
for k, v := range noteChecks { | ||
t.Run(k, v(set)) | ||
} | ||
} |