for a small local business I am trying to fix their spam orders.
they have multiple select option in their order form and I would like to filter that atleast 1 is selected.
[select gerookte-zalm "0" "1" "2" "3" "4"] Meal 1
[select gerookte-zalm "0" "1" "2" "3" "4"] Meal 2
etc.
If nothing is ordered: (so all selects are 0 which is default) it should not be able to send.
Is this possible?
Related
I'm trying to implement query functionality for my AWS redis cluster. I have stored all my data as hash maps and also created SortedSet for each of the indexed fields.
Whenever a query is received we query SortedSet to find ids. The querying may involve multiple indexes as well which gets merged based on AND/OR conditions. Once we have the final set of ids we need to sort the data based on some fields. So basically im fetching list of hashmaps which matches the ids. The hashmap looks like below
HSET employees::1 name Arivu salary 100000 age 30
HSET employees::2 name Uma salary 300000 age 31
HSET employees::3 name Jane salary 100000 age 25
HSET employees::4 name Zakir salary 150000 age 28
Now I'm adding all the hashes to a set so that I can use a sort function
SADD collection employees::1 employees::2 employees::3 employees::4
Now when i try to sort based on string field the sort doesn't seems to work
127.0.0.1:6379> SORT collection by name
1) "employees::2"
2) "employees::4"
3) "employees::3"
4) "employees::1"
127.0.0.1:6379> SORT collection by name desc
1) "employees::2"
2) "employees::4"
3) "employees::3"
4) "employees::1"
I assume this is because the hasmaps are stored as byte data but is there anyway i can sort these alphabetically?
I have also tried using alpha param which sort function provides but it doesnt seems to work
SORT collection by name desc ALPHA
Your usage seems to be incorrect.
Set your hash like this (like you are doing)
HSET employees::1 name Arivu salary 100000 age 30
HSET employees::2 name Uma salary 300000 age 31
HSET employees::3 name Jane salary 100000 age 25
HSET employees::4 name Zakir salary 150000 age 28
Store your ids in the set like this:
SADD collection 1 2 3 4
Please note in the set I just store the ids of the employee (1,2,3,4).
Now time to sort
SORT collection by employees::*->name ALPHA
It will sort like this as you expected
1) "1"
2) "3"
3) "2"
4) "4"
In case you need fields do like this:
SORT collection by employees::*->name ALPHA GET employees::*->name
1) "Arivu"
2) "Jane"
3) "Uma"
4) "Zakir"
In case you need age also along with name:
SORT collection by employees::*->name ALPHA GET employees::*->name GET employees::*->age
1) "Arivu"
2) "30"
3) "Jane"
4) "25"
5) "Uma"
6) "31"
7) "Zakir"
8) "28"
Sample file
The column c of a table T can have the values 1, 2 or 3. I want to filter the table such as when the user selects value 1 nothing is filtered. When the selected value is 2 then show only the rows with the c column containing the value 2 or the value 3 not the value 1 and finally if the selected value is 3 then show only those rows containing 3 in the c column. The slider or a plain filter must be single selection not multi because otherwise it would violate one of the user's business rule.
Selected Show
1 all rows
2 rows with 2 or 3
3 only rows with 3
I tried to create columns and to create measures but I can't get anywhere. Any directions?
I agree that the disconnected table might be the best workaround here. I hope this solution will work with your actual file.
Step 1 - create a new disconnected table
FilterC = DISTINCT(T[c])
Step 2 - make sure that your slicer is sourced from the new table (FilterC)
Step 3 - create a measure that will return 1 for rows that we want to see, and 0 for rows that we want to hide:
mFilter =
var Filter_C = SELECTEDVALUE(FilterC[c])
var Row_C = SELECTEDVALUE(T[c])
return
SWITCH(
Filter_C,
"1", 1,
"2", IF(OR(Row_C = "2", Row_C = "3"), 1, 0),
"3", IF(Row_C = "3", 1, 0)
)
Step 4 - add this measure to the table, or even table filters will suffice.
Step 5 - start switching the values!
First you need to set it to a number column.
Second, you could write complex measures and use a disconnected table, but the best option is to use the correct slicer. There is a Greater than or Equal To option.
I have a unbelanced panel data and have hard time to analyze it
I would like to remove all rows that I have for each person before an event happens because I'm interested in the effect of the event on other variables
One problem are the many missing values, mostly every other year, the second problem are persons where the "event" occurs more than once, in this care I'm only interessted in the last event as you can see for person 3 in my picture
If all you are interested in is identifying the last non-missing event, this should do the trick:
clear
* Input data
input float id str7 event
1 "1"
1 "missing"
1 "1"
1 "missing"
1 "0"
1 "missing"
2 "missing"
2 "0"
2 "missing"
2 "missing"
2 "1"
2 "missing"
2 "0"
3 "missing"
3 "0"
3 "1"
3 "0"
3 "missing"
3 "1"
3 "0"
end
* Re-structure event variable to byte and preserve sort order
replace event = "." if event == "missing"
destring event, replace
gen sortorder = _n
* Identify last event iff event == 1
bysort id event (sortorder): gen lastevent = _n == _N if event == 1
I assume you have a time variable to preserve sort order better, but this should serve in the example. Once you have them identified, you can do with them what you wish. Use keep if lastevent == 1 to drop all necessary observations, or keep them around as missing (for event == missing | 0).
I have a set of household data with more than 20,000 records of 4200 households. In my data set there is no any column for household ID & all the records are per household member. There is a column for person's serial no & with each & every "1", the household should be changed.( i.e: if we start to number households, with the very 1st person's serial no when it's equal to 1, the corresponding HH_ID should be "1". Once the next record when person's serial no=1 meets, then the HH_ID should be 2.) So I want to add a column named HH_ID & number it from 1-4200. How could I write a program using STATA?
What you want is (assuming a variable personid for person identifier)
. gen hhid = sum(personid == 1)
That's it. The explanation is longer than the code. The expression personid == 1 evaluates as 1 when true and 0 when false. For the first household, first person, this will be 1, and for the other persons in the same household 0. For the second household, first person, this will be 1, and so on. The function sum() gives the cumulative or running sum, so that you should end with something that goes 1,1,1,2,2,2,2,3,3,3,... Clearly the actual numbers of 1s, 2s, 3s etc. will depend on the numbers of persons in the households.
On true and false in Stata see
http://www.stata.com/support/faqs/data-management/true-and-false/index.html
I have a view with two columns: a person's ID (a number) and the sector that they below to (given as numbers 1-5).
I want to create a view to show whether people belong to the same sector. I think this would have three columns: ID1, ID2, and SameSector. The first column would list IDs, and for each ID in column 1 the second column would list ALL of the IDs. The third column would be an if statement, 1 if the sector was the same for both IDs, 0 if it wasn't. This is made slightly more complicated because a person can belong to more than one sector.
For example:
I have:
ID Sector
1 1
2 1
2 5
3 1
I want:
ID1 ID2 SameSector
1 1 1
1 2 1
1 2 0
1 3 0
2 1 1
2 1 0
etc.
I'm guessing this involves some sort of self join and if statement but I can't figure out how to get all of the ID fields to be listed in ID1 column and matched to all of the ID fields in ID2 any ideas?
This should be what you want:
SELECT a.ID AS ID1, b.ID AS ID2, IF(a.Sector=b.Sector,1,0) AS SameSector
FROM theTable AS a, theTable AS b
http://sqlfiddle.com/#!2/f2cbc/4
I initially had a much more complicated query, but then realized you wanted a complete cross-join, including the same ID comparing to itself.