Orbeon forms - repeated sub-section - orbeon

I have repeated section (Minimum Number of Repetitions = 0; Maximum Number of Repetitions = 9). In this section it is nasted repeated sub-section (Minimum Number of Repetitions = 1; Maximum Number of Repetitions = 9). If I remove any repetition from section, then run Test and add first repetition to section, sub-section appears with no repetitions (although I have set Minimum Number of Repetitions to 1). Validator doesn't detect any error.
Is it possible to add repetition to sub-section, when I add repetition to section?
Probably I have to call sub-section template, when I add repetition to section:
<xf:insert context="path_TODO" origin="instance('sub-section-template')"/>
but I don't know how and where I should call this. Maybe somewhere here:
Example form: https://demo.orbeon.com/demo/fr/orbeon/builder/edit/81751a85c9206ee58ade5b1c16afeea6dc790327

In Form Builder:
Add a first outer section, make it repeated; I'll call this the outer repeat.
Inside the section, add the repeated grid; I'll call this the inner repeat.
In the Section/Grid Settings for the repeated grid, check the box for Initial number of iterations uses template:
Make sure you have 1 outer iteration, and 1 inner iteration:
Edit the source of the form and add the following, just inside the <xf:model>:
<fr:listener version="2018.2" modes="new" events="form-load-after-data"
actions="clear-outer-section"/>
<fr:action name="clear-outer-section" version="2018.2">
<fr:repeat-clear repeat="section-1"/>
</fr:action>
With step 1 to 4, when users create a new iteration of the outer repeat, the number of iterations in the inner repeat will be based on what you have in Form Builder in the first iteration of the outer repeat, instead of starting with 0 iteration. Your issue is that you want to have 0 outer iterations. But if you remove the last outer iteration, we don't have an example in the data for how many inner iterations to create. Hence we keep 1 in Form Builder, and remove it as soon as the form is loaded, which is what we do in step 5 with the action syntax.

Related

selecting range of values based upon first few characters in spss?

I know that through
select cases if char.substr(variable_name,1,3)="I22".
I can select values based on the first # of characters but this is not exactly my question. I need to select RANGE OF values that start with few characters, here is an example of what I want:
if I have the following cases:
I22A33
I22B33
I22C33
I22D33
So I want to select I22B33 and I22C33 out of the above 4 values, so it's like a range of cases between b and c.
One way to flag any cases that meet your criteria is using INDEX and a series of OR conditions. Not particularly modular, but if you just have a couple of conditions you're searching for it could get you on your way.
Edit: These searches are case-insensitive (due to UPCASE) and search for matches at the start of the string. To search for matches anywhere within the string set the condition to > 0 (instead of = 1).
COMPUTE f_I22 = (INDEX(UPCASE(var_name),'I22B33') = 1)
OR (INDEX(UPCASE(var_name),'I22C33') = 1) .
EXE .
Assuming in this range of values that you want to select, all the values will start with either "I22B" or "I22C", you can simply use:
select cases if char.substr(variable_name,1,4)="I22B" or
char.substr(variable_name,1,4)="I22C".

Using SPSS IF syntax to create a new variable from two categorical variables

I want to create a new variable from two other variables.
The first is SEX (0=male, 1=female; there were no other genders selected by respondents though we had planned for that possibility) whereas the second is RACE9 (0=white, 1=racialized). The new variable is named SEXRACE9.
While the following code produces counts for white males, racialized males, white females and racialized females, the code fails to produce a count for total male or total female.
* Create combined sex and race categorical variable.
IF (sex=0 AND (race9=0 OR race9=1)) sexrace9=1. /*Total males - glitchy.
IF sex=0 AND race9=1 sexrace9=2. /*White males.
IF sex=0 AND race9=0 sexrace9=3. /*Racialized males.
IF (sex=1 AND (race9=0 OR race9=1)) sexrace9=4. /*Total females - glitchy.
IF sex=1 AND race9=1 sexrace9=5. /*White females.
IF sex=1 AND race9=0 sexrace9=6. /*Racialized females.
EXECUTE.
Am I missing something? Alternately, does anyone have a solution for how to insert a count for total males and total females using COMPUTE? Any help is greatly appreciated.
You are missing two key aspects:
Your sexracevariable is intended to define mutually exclusive groups (i.e. - each case will belong to one group, and no case could qualify for more than one group)
SPSS syntax is being run sequentially, line by line, so a syntax line can overwrite previous lines.
More to the point:
IF (sex=0 AND (race9=0 OR race9=1)) sexrace9=1.
is being partially overwritten by
IF sex=0 AND race9=1 sexrace9=2. /*White males.
because white males would qualify for both sexrace=1 and sexrace=2.
, and then by the line
IF sex=0 AND race9=0 sexrace9=3. /*Racialized males.
, because Racialized males qualify for both sexrace=1 and sexrace =3.
So I am guessing that no cases ghave sexrace=1 after running your syntax :)
Exactly the same logic goes for Females.
I am not sure what you want to achieve by your Total Males and Total Femalessyntax lines. You already have the sexvariable to differentiate between males and females.

stack data and restructure without using var to cases or casestovar in SPSS

I have the following situation: a loop (stack data) with only 1 index variable and with multiple items corresponding to the statements, as in the picture below (sorry it is Excel, but is the same as in SPSS):
stack data - cases on multiple lines, but never filling for 1 respondent all the columns
I want to reach to the following situation but without using casestovars to restructure, because that creates a lot of empty variables. I remember for older versions it was a command like Update, which was moving up the cases, to reach the following result:
reducing the cases per respondent
Like starting from this:
ID Index Q1_1 Q1_2 Q1_3 Q1_4 Q1_5 Q1_6
1 1 1 1
1 2 1 1
1 3 1 1
To reach to this:
ID Q1_1 Q1_2 Q1_3 Q1_4 Q1_5 Q1_6
1 1 1 1 1 1 1
But without using casestovars. Is there any command in SPSS syntax for this?
Thank you very much, have a nice day!
Not entirely sure how variable your data structure is likely to be in reality but if as demo'ed where you have only a single response for each q1_1 to q1_6 per respondent ID, then the below would be sufficient:
dataset declare dsAgg.
aggregate outfile="dsAgg" /break=respid /q1_1 to q1_6=max(q1_1 to q1_6).
Also not sure of the significance of duplicate index values within the same respondent IDs, if this was intended or not.
The following syntax could do the job -
* first we'll recreate your example data.
data list list/respid index q1_1 to q1_6.
begin data
1,1,1,,,,,
1,2,,2,,,,
1,3,,,1,,,
1,4,,,,2,,
1,5,,,,,1,
1,6,,,,,,2
2,1,3,,,,,
2,1,,4,,,,
2,2,,,5,,,
2,2,,,,4,,
2,3,,,,,3,
2,3,,,,,,2
end data.
* now to work: first thing is to make sure the data from each ID are together.
sort cases by respid index.
* the loop will fill down the data to the last line of each ID.
do repeat qq=q1_1 to q1_6.
if respid=lag(respid) and missing(qq) qq=lag(qq).
end repeat.
* the following lines will help recognize the last line for each ID and select it.
compute lineNR=$casenum.
aggregate /outfile=* mode=ADDVARIABLES/break=respid/MXlineNR=max(lineNR).
select if lineNR=MXlineNR.
exe.

SUM(LAST()) on GROUP BY

I have a series, disk, that contains a path (/mnt/disk1, /mnt/disk2, etc) and total space of a disk. It also includes free and used values. These values are updated at a specified interval. What I would like to do, is query to get the sum of the total of the last() of each path. I would also like to do the same for free and for used, to get a aggregate of the total size, free space, and used space of all of my disks on my server.
I have a query here that will get me the last(total) of all the disks, grouped by its path (for distinction):
select last(total) as total from disk where path =~ /(mnt\/disk).*/ group by path
Currently, this returns 5 series, each containing 1 row (the latest) and the value of its total. I then want to take the sum of those series, but I cannot just wrap the last(total) into a sum() function call. Is there a way to do this that I am missing?
Carrying on from my comment above about nested functions.
Building a toy example:
CREATE DATABASE FOO
USE FOO
Assuming your data is updated at intervals greater than[1] every minute:
CREATE CONTINUOUS QUERY disk_sum_total ON FOO
BEGIN
SELECT sum("total") AS "total_1m" INTO disk_1m_total FROM "disk"
GROUP BY time(1m)
END
Then push some values in:
INSERT disk,path="/mnt/disk1" total=30
INSERT disk,path="/mnt/disk2" total=32
INSERT disk,path="/mnt/disk3" total=33
And wait more than a minute. Then:
INSERT disk,path="/mnt/disk1" total=41
INSERT disk,path="/mnt/disk2" total=42
INSERT disk,path="/mnt/disk3" total=43
And wait a minute+ again. Then:
SELECT * FROM disk_1m_total
name: disk_1m_total
-------------------
time total_1m
1476015300000000000 95
1476015420000000000 126
The two values are 30+32+33=95 and 41+42+43=126.
From there, it's trivial to query:
SELECT last(total_1m) FROM disk_1m_total
name: disk_1m_total
-------------------
time last
1476015420000000000 126
Hope that helps.
[1] Picking intervals smaller than the update frequency prevents minor timing jitters from making all the data being accidentally summed twice for a given group. There might be some "zero update" intervals, but no "double counting" intervals. I typically run the query twice as fast as the updates. If the CQ sees no data for a window, there will be no CQ performed for that window, so last() will still give the correct answer. For example, I left the CQ running overnight and pushed no new data in: last(total_1m) gives the same answer, not zero for "no new data".

Auto-assigning objects to users based on priority in Postgres/Ruby on Rails

I'm building a rails app for managing a queue of work items. I have several types of users ("access levels") to whom I want to auto-assign these work items.
The end goal is an "Auto-assign" button on one of my views that will automatically grab the next work item based on a priority, which is defined by the users's access level.
I'm trying to set up a class method in my work_item model to automatically sort work items by type based on the user's access level. I am looking at something like this:
def self.auto_assign_next(access_level)
case
when access_level = 2
where("completed = 'f'").order("requested_time ASC").limit(1)
when access_level > 2
where("completed = 'f'").order("CASE WHEN form='supervisor' THEN 1 WHEN form='installer' THEN 2 WHEN form='repair' THEN 3 WHEN form='mail' THEN 4 WHEN form='hp' THEN 5 ELSE 6 END").limit(1)
end
This isn't very DRY, though. Ideally I'd like the sort order to be configurable by administrators, so maybe setting up a separate table on which the sort order is kept would be best. The problem with that idea is that I have no idea how to pass the priority order on that table to the [postgre]SQL query. I'm new to SQL in general and somewhat lost with this one. Does anybody have any suggestions as to how this should be handled?
One fairly simple approach starts with turning your case statement into a new table, listing form values versus what precedence value they should be sorted by:
id | form | precedence
-----------------------------------
1 | supervisor | 1
2 | installer | 2
(etc)
Create a model for this, say, FormPrecedences (not a great name, but I don't totally grok your data model so pick one that better describes it). Then, your query can look like this (note: I'm assuming your current model is called WorkItems):
when access_level > 2
joins("LEFT JOIN form_precedences ON form_precedences.form = work_items.form")
.where("completed = 'f'")
.order("COALESCE(form_precedences.precedence, 6)")
.limit(1)
The way this works isn't as complicated as it looks. A "left join" in SQL simply takes all the rows of the table on the left (in this case, work_items) and, for each row, finds all the matching rows from the table on the right (form_precedences, where "matching" is defined by the bit after the "ON" keyword: form_precedences.form = work_items.form), and emits one combined row. If no match is found, a LEFT JOIN will still emit a row, but with all the right-hand values being NULL. A normal join would skip any rows with no right-hand match found.
Anyway, with the precedence data joined on to our work items, we can just sort by the precedence value. But, in case no match was found during the join above, that value will be NULL -- so, I use COALESCE (which returns the first of its arguments that's not NULL) to default to a precedence of 6.
Hope that helps!

Resources