#integration #no-database-cleaner #javascript
Scenario: Create New Mortality Table for ShipCase 2.2.2.5
Given shipcase user logs into test environment with password: "*******"
Given the user chooses to add a new mortality base table
And the user specifies "TestScriptMortalityTable" as name for base mortality table
And the user chooses "Male" as Gender , "qx" as type, "United States" as region and "2011" as base year for the mortality table
And I specify the following mortality rates:
| age | mortality_risk |
| 0 | 0.1 |
| 1 | 0.2 |
| 2 | 0.000200332 |
| 3 | 0.000200332 |
| 4 | 0.000200332 |
| 5 | 0.000200332 |
| 6 | 0.000200332 |
| 7 | 0.000200332 |
| 8 | 0.000200332 |
| 9 | 0.000200332 |
| 10 | 0.000200332 |
| 11 | 0.000200332 |
| 12 | 0.000200332 |
| 13 | 0.000200332 |
| 14 | 0.000200332 |
| 15 | 0.000200332 |
| 16 | 0.000200332 |
| 17 | 0.000200332 |
| 18 | 0.000200332 |
| 19 | 0.000200332 |
| 20 | 0.000200332 |
#And I save the profile
I am able to get the value in the value variable, but cannot set it. I still get a 0 when I explicitly set the value. Can anyone suggest why? I just figured out that the table is rendered using JavaScript and it uses HandsOnTable control. The control has a text area with specific CSS. I am using code above to set it. ITs a text area. But still capybara says the element is not found.
I see the click happening on the <td>. but I cannot set text , capybara complains that it cannot find the text area.
Steps file is below
Given /^I specify the following mortality rates:$/ do |mortality_table|
#mortality_data = mortality_table.hashes
#mortality_data.each_with_index do |data, i|
row = first(:xpath, "//div[#id='mortality-table-data']//table/tbody/tr/td[contains(.,'#{data["age"]}')]/..")
row.find(:xpath,"td[2]").click
sleep 3
elem = page.driver.find_element(:css, 'handsontableInput')
puts elem.object_id
end
end
When I do the page source I see the element
<div class="handsontableInputHolder htHidden" style="top: 91px; left: 58px; overflow: hidden;"><textarea class="handsontableInput" style="height: 0px; width: 0px;"></textarea></div>
Related
I'm trying to make a "friendly" view of a more complicated sheet by filtering out unnecessary data. I want one of the filter conditions to be to return a value only if that value is different than the previous row's value.
I've tried doing a filter, such as =filter(B:B, B2 <> B1) which obviously doesn't resolve. How do I do an offset reference so that the results are similar to as follows:
Sample Data
| Row | Category | Subcategory |
| --- | -------- | ----------- |
| 1 | Accounts | Ac1 |
| 2 | Accounts | Ac2 |
| 3 | Accounts | Ac3 |
| 4 | Accounts | Ac4 |
| 5 | Feedback | FbA |
| 6 | Feedback | FbB |
| 7 | Feedback | FbC |
| 8 | Feedback | FbD |
| 9 | Profile | PfOne |
| 10 | Profile | PfTwo |
| 11 | Profile | PfThree |
Desired Result
| Row | Category | Subcategory |
| --- | -------- | ----------- |
| 1 | Accounts | Ac1 |
| 5 | Feedback | FbA |
| 9 | Profile | PfOne |
Here is another approach (assuming that your posted "Row" column is not actually part of your data, but that your "Category" header is, in fact, in A1):
=ArrayFormula({A1:B1;FILTER(A2:B,A2:A<>INDIRECT("A1:A"&ROWS(A:A)-1))})
Try:
={A1:C1;FILTER(A2:C,B1:INDEX(B:B,COUNTA(B:B),1)<>B2:B)}
go for:
=SORTN(A1:C, 9^9, 2, 2, 1)
I am trying to conditional format a dynamically resizing Total row of multiple tables stacked one above the other. The number of cells in the Total row may change depending upon the selection in a Year dropdown.
A | B | C | D | E | F | G | H | I | J | K | L | M |
<Year dropdown>
|Issues|2020-Jan|2020-Feb|2020-Mar|2020-Apr|2020-May|2020-Jun| | | | | | |
--------------------------------------------------------------------------------
| abc | 9 | 2 | 2 | 1 | 3 | 8 | | | | | | |
| def | 1 | 3 | 7 | 1 | 5 | 3 | | | | | | |
| ghi | 2 | 1 | 3 | 1 | 1 | 2 | | | | | | |
--------------------------------------------------------------------------------
|Total | 12 | 6 | 12 | 3 | 9 | 13 | | | | | | |
--------------------------------------------------------------------------------
I am using this formula to highlight the Total row. However, it is highlighting the entire row depending upon what range is set in the Conditional Formatting > Apply to Range box. I want to highlight only the numeric cells i.e. exclude blank cells.
=ISNUMBER(SEARCH("total",$B1))
This highlights the entire Total row including any blank cells. I modified it to exclude any blank cells in row, but no joy!
=AND(ISNUMBER(SEARCH("total",$B1)), SEARCH("total",$B1)<>""))
You can also do it like this, relying on relative addressing to modify the formula as it's effectively dragged across the formatted area:
=and(isnumber(search("Total",$B3)),B3<>"")
Use formula:
=(ISNUMBER(SEARCH("total",$B1))+(($B1:$Z1<>"")))>1
I would like to create a formula in the below column Assigned so that a random name matching the same group as the current name is automatically inserted.
Names in the Assigned column must match the group of the current name and must not repeat throughout the list. I can't assign the current name with it's own name either. Any suggestions on how to do this?
I guess it is worth posting this. Although it might not be practical for large groups, it is a formula solution that works in Excel and Google sheets:
=INDEX($A$2:$A$8,SMALL(IF(($B$2:$B$8=B2)*($A$2:$A$8<>A2)*(COUNTIF(C$1:C1,$A$2:$A$8)=0),ROW($A$2:$A$8)-1),
RANDBETWEEN(1,SUM(($B$2:$B$8=B2)*($A$2:$A$8<>A2)*(COUNTIF(C$1:C1,$A$2:$A$8)=0)))))
entered as an array formula using CtrlShiftEnter
Here is an example of a successful match:
and an unsuccessful one:
As you can see, Mike, Jack and Fred have paired up together leaving Dave on his own, likewise with Lucy and Harry.
In Excel you may have to press F9 a few times to get a successful result - in Google sheets you just have to keep changing something, or set it to update every minute while you make a cup of tea.
It was my first time to work on something related to unique values, it took time but I learned lot from this question.
Answer of #Tom-Sharpe gave me an inspiration that it can be done, thanks to Tom for that. I tried and here it is.
I have checked it on some random data
+------------+-------+-------------+------------+
| Name | Group | RAND | Assigned |
| Malynda | 1 | 0.644382728 | Boonie |
| Boonie | 1 | 0.167369621 | Venus |
| Venus | 1 | 0.547165865 | Malynda |
| Jamal | 2 | 0.193081046 | Cora |
| Cora | 2 | 0.399459181 | Jamal |
| Alaster | 2 | 0.910498559 | Enrika |
| Enrika | 2 | 0.45819549 | Melisandra |
| Melisandra | 2 | 0.612592303 | Alaster |
| Petunia | 3 | 0.957104883 | Lawton |
| Mariam | 3 | 0.602293619 | Grenville |
| Caterina | 3 | 0.695342797 | Mariam |
| Stace | 3 | 0.942926886 | Caterina |
| Perle1 | 3 | 0.787227158 | Stace |
| Lawton | 3 | 0.315403693 | Perle1 |
| Grenville | 3 | 0.515276361 | Petunia |
| Elia | 4 | 0.655404975 | Catarina |
| Agosto | 4 | 0.322045058 | Fidela |
| Fidela | 4 | 0.490635045 | Agosto |
| Catarina | 4 | 0.121053081 | Elia |
| Elliot | 5 | 0.994137138 | Eddie |
| Mae | 5 | 0.349103119 | Wadsworth |
| Farleigh | 5 | 0.645375865 | Mae |
| Trudey | 5 | 0.473849475 | Farleigh |
| Gwenneth | 5 | 0.678186154 | Trudey |
| Wadsworth | 5 | 0.254168853 | Gwenneth |
| Eddie | 5 | 0.02103249 | Elliot |
| Denyse | 6 | 0.294801945 | Fayina |
| Tracie | 6 | 0.113670327 | Denyse |
| Aili | 6 | 0.901562575 | Tracie |
| Fayina | 6 | 0.029515522 | Alain |
| Mort | 6 | 0.938536467 | Perle |
| Alain | 6 | 0.389741125 | Aili |
| Perle | 6 | 0.513800791 | Mort |
| Mathew | 6 | 0.972656521 | #N/A |
| Benton | 7 | 0.423710316 | Bret |
| Bret | 7 | 0.127478128 | Benton |
| Mayne | 7 | 0.701027869 | Kirbee |
| Derry | 7 | 0.564710572 | Marje |
| Kirbee | 7 | 0.510258205 | Derry |
| Marje | 7 | 0.600908601 | Mayne |
| Devin | 7 | 0.718740939 | #N/A |
| Wilbert | 8 | 0.763761013 | Griswold |
| Brandice | 8 | 0.482092682 | Marty |
| Griswold | 8 | 0.111418464 | Brandice |
| Brandais | 8 | 0.594020577 | Fair |
| Kim | 8 | 0.727863883 | Brandais |
| Cam | 8 | 0.858246187 | Kim |
| Fair | 8 | 0.640979168 | Wilbert |
| Ardath | 8 | 0.883008322 | Cam |
| Marty | 8 | 0.339506717 | Ardath |
+------------+-------+-------------+------------+
D2 contains the below formula
=INDEX(
$A$2:$A$51,
MATCH(
MIN(IF(
(COUNTIF($D$1:D1,$A$2:$A$51)=0)*
($B$2:$B$51=B2)*
($A$2:$A$51<>A2),
$C$2:$C$51)
),
$C$2:$C$51,0)
)
C2 contains just the RAND() function but it is pasted as values so that it doesn't update on every calculation, but if you want you can keep it as a function
There are some #N/A values returned by the formula, it arrives when there is no other person left that can be assigned.
Check it on your data and let me know if it working correctly.
Note that the formula is assuming that names are unique and are sorted based on the groups.
If you're fluent with javascript you could attempt to use Google Apps Script to handle this by going to the toolbar Tools > Script Editor. Another way would be to record a macro via Tools > Macros > Record Macro. The script I generated via this method is below, however I couldn't figure out how to prevent assigning the current name with it's own name. My workaround for that is to select the range of assigned names in the same group and applying Data > Randomize Range until the assignment is satisfactory.
function AppendRandomNameByGroup() {
//Sort based on integer in group column
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet();
sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).activate();
spreadsheet.getActiveRange().offset(1, 0, spreadsheet.getActiveRange().getNumRows() - 1).sort({column: spreadsheet.getActiveRange().getColumn() + 1, ascending: true});
spreadsheet.getRange('C2').activate();
//Duplicate names to assigned names column
spreadsheet.getRange('A2:A1000').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
var sheet = spreadsheet.getActiveSheet();
sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).activate();
//Filter for each group and randomize items in 'assigned' column
sheet = spreadsheet.getActiveSheet();
sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).createFilter();
spreadsheet.getRange('B1').activate();
var criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues(['', '2', '3'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(2, criteria);
spreadsheet.getRange('C2:C1000').activate();
spreadsheet.setCurrentCell(spreadsheet.getRange('C4'));
spreadsheet.getActiveRange().randomize();
spreadsheet.getRange('B1').activate();
criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues(['1', '', '3'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(2, criteria);
spreadsheet.getRange('C2:C1000').activate()
.randomize();
spreadsheet.getRange('B1').activate();
criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues(['2', '', '1'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(2, criteria);
spreadsheet.getRange('C2:C1000').activate();
spreadsheet.setCurrentCell(spreadsheet.getRange('C8'));
spreadsheet.getActiveRange().randomize();
spreadsheet.getActiveSheet().getFilter().remove();
};
If you're trying to set-up a secret santa of some kind, another possible alternative to using scripts would be this Google Sheets Add-On that does something similar including the group functionality that you desire. However instead of assigning a recipient name in-sheet, it requires you to input corresponding e-mail addresses for each name and proceeds to email each participant with their assigned name.
Secret Santa
Sorry that this doesn't fit all your criteria.
I'm a new with Rails and I'm having trouble with some types of associations that seem a bit more complex than the ones I've been exposed to so far.
Zombie_users Body_parts_status Body_parts
| id | name | | id | user_id | body_part_id | recovery | | id | name |
|-----------| --> |----------------------------------------| --> |---------------|
| 1 | Joe | | 1 | 1 | 2 | 10% | | 1 | left leg |
| 2 | Max | | 2 | 1 | 3 | 43% | | 2 | brain |
| 3 | hair |
| 4 | blue eye |
Zobmie_users Recovery_tools Body_parts_impacts
| id | name | | id |user_id| name | | id|recovery_tool_id| body_part_id | impact |
|-----------|-->|-------------------|-->|--------------------------------------------|
| 1 | Joe | | 1 | 1 |hammer| | 1 | 1 | 2 | 10% |
| 2 | Max | | 2 | 1 |magic | | 2 | 2 | 3 | 43% |
graphic illustration of the needed functionality
We have users and a list of body parts.
I need that the users will be able to create recovery tools with which they can through Body Parts impact recover their body parts status :)
and be able to check what part of the body still need to be fixed(compared to the list) and what body parts they have already corrected.
My problem is that I do not know how to implement such connections.
because I need to have some kind of clone of the body parts to body parts status for each user.
But how I reference it so it also works with Body Parts impacts
I do not have even a concept of where to start :)
body parts table is just a long listing of all the parts of the human body
and each user should have their own "copy" of all these parts.
I am using this gem https://github.com/stefankroes/ancestry for my People modle. The table looks like this:
+----+----------+
| id | ancestry |
+----+----------+
| 1 | NULL |
| 2 | 1 |
| 3 | 1 |
| 4 | 1/2 |
| 5 | 1/3 |
| 6 | NULL |
| 7 | 1/2 |
| 8 | 1/2 |
| 9 | 1/3 |
| 10 | NULL |
| 11 | 10 |
| 12 | 10 |
| 13 | NULL |
| 14 | NULL |
| 15 | 6 |
| 16 | 6 |
| 17 | 6/16 |
| 18 | 6 |
| 19 | 6/18 |
| 20 | 14 |
+----+----------+
What I want to query is:
given two people with id 1 and 6
get all descendants of these two people
in one query instead of querying one by one since I need to put this into an Arel.or method.
I knew that using:
People.select("id").where(People.arel_table[:ancestry].matches("6/%"))
generates LIKE sql statement and returns all grandchildren of the people with id 6. I also knew:
People.select("id").where(People.arel_table[:ancestry].matches(["1/%","6/%"]))
doesn't work because it generates invalid LIKE statement:
SELECT id FROM `people` WHERE (`people`.`ancestry` LIKE '1/%', '6/%')
On the other hand, I knew:
People.select("id").where(People.arel_table[:ancestry].in(["1", "6"]))
generates IN sql statement and returns all children (but not grandchildren) of both 1 and 6. I also knew:
People.select("id").where(People.arel_table[:ancestry].in(["1/%", "6/%"]))
returns nothing because IN statement works as precisely matching.
My question then is: how can I put them all into a (probably chaining) query to get all descendants of both 1 and 6? In this example, I would expect the result is: [ 2, 3, 4, 5, 7, 9, 15, 16, 17, 18, 19 ].
Thank you very much for the suggestions
People.select("id").where(People.arel_table[:ancestry].matches("1/%").or(People.arel_table[:ancestry].matches("6/%"))