added unique filter type
This commit is contained in:
parent
0d3c32cb53
commit
25cf91966e
6 changed files with 118 additions and 1 deletions
15
scraping.go
15
scraping.go
|
@ -807,6 +807,21 @@ func getFilterResultConditionHigherThan(filter *Filter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFilterResultUnique(filter *Filter) {
|
||||||
|
var valueMap map[string]bool
|
||||||
|
valueMap = make(map[string]bool)
|
||||||
|
|
||||||
|
for _, parent := range filter.Parents {
|
||||||
|
for _, result := range parent.Results {
|
||||||
|
valueMap[result] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for value, _ := range valueMap {
|
||||||
|
filter.Results = append(filter.Results, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func notifyFilter(filters []Filter, filter *Filter, watch *Watch, web *Web, debug bool) {
|
func notifyFilter(filters []Filter, filter *Filter, watch *Watch, web *Web, debug bool) {
|
||||||
haveResults := false
|
haveResults := false
|
||||||
for _, parent := range filter.Parents {
|
for _, parent := range filter.Parents {
|
||||||
|
|
|
@ -1126,6 +1126,48 @@ func TestFilterHigherThan(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFilterUnique(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
Input []string
|
||||||
|
Want []string
|
||||||
|
}{
|
||||||
|
{[]string{"1"}, []string{"1"}},
|
||||||
|
{[]string{"1", "2"}, []string{"1", "2"}},
|
||||||
|
{[]string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "1"}, []string{"1", "2", "3", "4", "5", "6", "7", "8", "9"}},
|
||||||
|
{[]string{"1", "1"}, []string{"1"}},
|
||||||
|
{[]string{}, []string{}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
testname := fmt.Sprintf("%s", test.Input)
|
||||||
|
t.Run(testname, func(t *testing.T) {
|
||||||
|
filter := Filter{
|
||||||
|
Parents: []*Filter{
|
||||||
|
{
|
||||||
|
Results: test.Input,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
getFilterResultUnique(
|
||||||
|
&filter,
|
||||||
|
)
|
||||||
|
var wantMap map[string]bool
|
||||||
|
wantMap = make(map[string]bool)
|
||||||
|
for _, want := range test.Want {
|
||||||
|
wantMap[want] = true
|
||||||
|
}
|
||||||
|
var resultMap map[string]bool
|
||||||
|
resultMap = make(map[string]bool)
|
||||||
|
for _, result := range filter.Results {
|
||||||
|
resultMap[result] = true
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(wantMap, resultMap) {
|
||||||
|
t.Errorf("Got %s, want %s", filter.Results, test.Want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFilterLua(t *testing.T) {
|
func TestFilterLua(t *testing.T) {
|
||||||
passAll := `
|
passAll := `
|
||||||
for i,input in pairs(inputs) do
|
for i,input in pairs(inputs) do
|
||||||
|
|
|
@ -409,6 +409,35 @@ function onTypeChange(node) {
|
||||||
var3Div.appendChild(var3Input);
|
var3Div.appendChild(var3Input);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "unique": {
|
||||||
|
console.log("TEST");
|
||||||
|
var var1Input = document.createElement("input");
|
||||||
|
var1Input.name = "var1";
|
||||||
|
var1Input.id = "var1Input";
|
||||||
|
var1Input.value = var1Value;
|
||||||
|
var1Input.classList.add("form-control");
|
||||||
|
var1Input.disabled = true;
|
||||||
|
var1Label.innerHTML = "-";
|
||||||
|
var1Input.placeholder = "";
|
||||||
|
var1Div.appendChild(var1Input);
|
||||||
|
var var2Input = document.createElement("input");
|
||||||
|
var2Input.name = "var2";
|
||||||
|
var2Input.id = "var2Input";
|
||||||
|
var2Input.value = var2Value;
|
||||||
|
var2Input.classList.add("form-control");
|
||||||
|
var2Input.disabled = true;
|
||||||
|
var2Label.innerHTML = "-";
|
||||||
|
var2Div.appendChild(var2Input);
|
||||||
|
var var3Input = document.createElement("input");
|
||||||
|
var3Input.name = "var3";
|
||||||
|
var3Input.id = "var3Input";
|
||||||
|
var3Input.value = var3Value;
|
||||||
|
var3Input.classList.add("form-control");
|
||||||
|
var3Input.disabled = true;
|
||||||
|
var3Label.innerHTML = "-";
|
||||||
|
var3Div.appendChild(var3Input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "condition": {
|
case "condition": {
|
||||||
var conditionSelect = document.createElement("select");
|
var conditionSelect = document.createElement("select");
|
||||||
conditionSelect.name = "var1";
|
conditionSelect.name = "var1";
|
||||||
|
|
|
@ -400,6 +400,37 @@ function onTypeChange(node: DiagramNode | null = null){
|
||||||
var3Div.appendChild(var3Input);
|
var3Div.appendChild(var3Input);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "unique": {
|
||||||
|
console.log("TEST");
|
||||||
|
let var1Input = document.createElement("input");
|
||||||
|
var1Input.name = "var1";
|
||||||
|
var1Input.id = "var1Input";
|
||||||
|
var1Input.value = var1Value;
|
||||||
|
var1Input.classList.add("form-control")
|
||||||
|
var1Input.disabled = true;
|
||||||
|
var1Label.innerHTML = "-";
|
||||||
|
var1Input.placeholder = "";
|
||||||
|
var1Div.appendChild(var1Input);
|
||||||
|
|
||||||
|
let var2Input = document.createElement("input");
|
||||||
|
var2Input.name = "var2";
|
||||||
|
var2Input.id = "var2Input";
|
||||||
|
var2Input.value = var2Value;
|
||||||
|
var2Input.classList.add("form-control")
|
||||||
|
var2Input.disabled = true;
|
||||||
|
var2Label.innerHTML = "-";
|
||||||
|
var2Div.appendChild(var2Input);
|
||||||
|
|
||||||
|
let var3Input = document.createElement("input");
|
||||||
|
var3Input.name = "var3";
|
||||||
|
var3Input.id = "var3Input";
|
||||||
|
var3Input.value = var3Value;
|
||||||
|
var3Input.classList.add("form-control");
|
||||||
|
var3Input.disabled = true;
|
||||||
|
var3Label.innerHTML = "-";
|
||||||
|
var3Div.appendChild(var3Input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "condition":{
|
case "condition":{
|
||||||
let conditionSelect = document.createElement("select");
|
let conditionSelect = document.createElement("select");
|
||||||
conditionSelect.name = "var1";
|
conditionSelect.name = "var1";
|
||||||
|
|
|
@ -79,6 +79,7 @@ GoWatch Edit {{ .Watch.Name }}
|
||||||
<option value="match">Match</option>
|
<option value="match">Match</option>
|
||||||
<option value="substring">Substring</option>
|
<option value="substring">Substring</option>
|
||||||
<option value="contains">Contains</option>
|
<option value="contains">Contains</option>
|
||||||
|
<option value="unique">Unique</option>
|
||||||
<option value="math">Math</option>
|
<option value="math">Math</option>
|
||||||
<option value="store">Store</option>
|
<option value="store">Store</option>
|
||||||
<option value="condition">Condition</option>
|
<option value="condition">Condition</option>
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -10,7 +10,6 @@
|
||||||
- trusted proxies in conf?
|
- trusted proxies in conf?
|
||||||
- log things to db for cron runs
|
- log things to db for cron runs
|
||||||
- comments
|
- comments
|
||||||
- add unique filter
|
|
||||||
- provide template/example watches?
|
- provide template/example watches?
|
||||||
- Amazon
|
- Amazon
|
||||||
- NewEgg
|
- NewEgg
|
||||||
|
|
Loading…
Add table
Reference in a new issue