So we have this template:
{| class="wikitable"
|-
| [[Saplings]] || ''{{{saplings|Lower}}}'' || [[Sappiness]] || ''{{{sappiness|Lowest}}}''
|-
| [[Matures]] || ''{{{matures|Average}}}'' || [[Effect (Tree)|Effect]] || ''{{{effect|None}}}''
|-
| [[Height]] || ''{{{height|Small}}}'' || [[Growth (Forestry)|Growth]] || ''{{{growth|Light}}}''
|-
| [[Girth]] || ''{{{girth|1}}}x{{{girth|1}}}'' || [[Tolerates]] || ''{{{tolerates| }}}''
|-
| [[Yield]] || ''{{{yield|Lowest}}}'' || [[Fruits]] || ''{{{fruits|None}}}''
|}<noinclude>{{Documentation}}</noinclude>
As you can see, all the fields have defaults. Now, in the actual pages, some leave off the default altogether (notice, no 'saplings'):
{{Tree-Attributes
| sappiness = Average
| fruits = Crabapple
}}
While others include the default explicitly:
{{Tree-Attributes
| saplings = Lower
| height = Large
| yield = Lowest
| sappiness = Lower
| fruits = none
| girth = 2
}}
Using the following DPL command, I can see all the ones with an explicit 'Lower' value. How do I get that and the ones left to default?
{{#dpl:
|category = Trees
|uses = Template:Tree
|includematch = ,/saplings\s*=\s*Lower\s*/i
|include = {Tree}:name, {Tree-Attributes}:speed
|table = class="wikitable",-,Lower
|tablerow = ²{P{{!}}%% Sapling{{!}}F}² [[%%]]<span style="display:none;">«nowiki»,«/nowiki»</span>
|allowcachedresults = true
}}
[Incidentally, I have no idea why there's a reference to attribute 'speed', when none is defined…]
Self-answer: I won't select this answer for a while, to see if anybody else comes up with something better.
I got the results I wanted by changing
includematch = ,/saplings\s*=\s*Lower\s*/i
to
includematch = ,/(saplings\s*=\s*Lower\s*){{!}}(^((?!saplings)(.{{!}}\n))+$)/i
Related
I need to storetext all lines from a table where CODICE CATASTALE have a value
I add an image to show, I need to save all line in variable with storetext with this characteristic CODICE CATASTALE have a value, in the image I add 1 - 2 - 3 - 4 to explain line to store.
This is a relative storetext when CODICE CATASTALE have a value stored the line.
Here the page
nonsolocap.it/cap?k=56040
Image
After the execution such script in Selenium IDE table variable will contain data from the table. xpath_to_all_rows_with_CODICE_CATASTALE should be replaced with corresponding xpath.
store xpath count | xpath = xpath_to_all_rows_with_CODICE_CATASTALE | n
store | 0 | j
while | ${j} < ${n} |
store | | rowElement
store | 0 | i
while | ${i} < 7 |
store text | xpath = xpath_to_all_rows_with_CODICE_CATASTALE[${j}]/td[${i}] | element
execute script | if (${i} != 0) var arr = ${rowElement}; else var arr = []; var element = ${element}; arr.push(element); return arr; | rowElement
execute script | return Number(${i}) + 1; | i
end| |
execute script | if (${j} != 0) var arr = ${table}; else var arr = []; var rowElement = ${rowElement}; arr.push(rowElement); return arr; | table
execute script | return Number(${j}) + 1; | j
end| |
use scvSave command and give a name for the target for divide raws
I have this table that I use (but not only) for storing friends in a database :
user_1 | user_2 | status
where 'status' can be -1,0 or 1. Here, we will consider only cases where status are '0' (pending for user_1) or '1' (approved by user_2). I have the following query to look for pending/approved friends for a given $user :
SELECT user_1,user_2,status
FROM Friends
WHERE (user_2 = '$user' OR user_1 = '$user') AND status >= 0;
The goal here is to modify the query to also tell if a given $user2 is a common (approved) friend of $user1 and each (approved) friend of $user1.
After some researches, I figured out that the left join would do the trick, by setting another field to either NULL (if no mutual) or $user2. I would want to do it efficiently. I tried several shots, but no success around it.
Thanks by advance for your help
EDIT : For example, let's say we have the following entries :
a | b | 1
c | a | 1
c | b | 1
a | d | 1
I want to list the friends of 'a' and for each friend f of 'a', verify if 'b' is a common friend of f and 'a'. Also, f =/= b for the mutual test. The result of such a query would be :
a | b | 1 | NULL
c | a | 1 | b
a | d | 1 | NULL
Let me know if you need more clarification
As in MySQL query would be so complicated and slow, that I wouldn't use it myself, here's a solution in PHP, with only one query:
<?php
// $db = mysqli_connect(...);
function findMutualFriends($of,$mutual_with){
global $db;
$user_friends = array();
$mutual_friends = array();
$results = array();
$res = mysqli_query($db,"SELECT user_1,user_2,status FROM Friends WHERE ((user_2 = '$of' OR user_1 = '$of') OR (user_2 = '$mutual_with' OR user_1 = '$mutual_with')) AND status >= 0;";
while($row = mysqli_fetch_assoc($res)){
if($row['user_1'] == $of || $row['user_2'] == $of){
$user_friends[] = (($row['user_1'] == $of) ? $row['user_2'] : $row['user_1']);
}
if($row['user_1'] == $mutual_with || $row['user_2'] == $mutual_with){
$mutual_friends[(($row['user_1'] == $mutual_with) ? $row['user_2'] : $row['user_1'])] = 1;
}
}
foreach($user_friends as $friend){
if($mutual_firends[$friend]){
$results[] = $friend;
}
}
return $results;
}
?>
Please notice that it haven't been tested. May contain some minor syntax error, but should return an array of mutual friends.
I modified a bit the Flash Thunder's function post. Just tested with some modifications and it works ! Thanks again.
function findMutualFriends($pdo, $of,$mutual_with){
$user_friends = array();
$mutual_friends = array();
$results = array();
$query = "SELECT user_1,user_2,status FROM Friends WHERE ((user_2 = '$of' OR user_1 = '$of') OR (user_2 = '$mutual_with' OR user_1 = '$mutual_with')) AND status = 1;";
$prep = $pdo->prepare($query);
$res = $prep->execute();
$rows = $prep->fetchAll();
foreach ($rows as $row) {
if($row['user_1'] == $of || $row['user_2'] == $of) {
$user_friends[] = ($row['user_1'] == $of ? $row['user_2'] :$row['user_1']);
}
if($row['user_1'] == $mutual_with || $row['user_2'] == $mutual_with) {
$mutual_friends[($row['user_1'] == $mutual_with ? $row['user_2'] :$row['user_1'])] = true;
}
}
foreach($user_friends as $friend) {
$results[$friend] = $mutual_friends[$friend] == true ? true : false;
}
return $results;
}
I have the following situation:
Column G Column H
|Black, Brown, Grey| | dog |
|Calico | | cat |
|Green, Blue | | bird|
| ... | | ... |
I would like to split and fill down to this:
Column G Column H
|Black | |dog |
|Brown | |dog |
|Grey | |dog |
|Calico| |cat |
|Green | |bird|
|Blue | |bird|
|... | | ...|
Looking at the script to split a comma delineated cell (Function to split text in cell and create column) I can follow the split but it's the filling down portion that I am having trouble with. I understand I should set up a while loop with the first cell as var = i and the second cell as var = j. Dump the split contents of i to an array and then fill down the array.length. However, I can't seem to get the syntax correct.
I'm pretty new to JS and GAS so any help would be appreciated.
Thanks for the help.
-JH
Here's a custom function that should work for you:
/**
* Splits the array by commas in the column with given index, by given delimiter
* #param {A2:B20} range Range reference
* #param {2} colToSplit Column index
* #param {","} delimiter Character by which to split
* #customfunction
*/
function advancedSplit(range, colToSplit, delimiter) {
var resArr = [], row;
range.forEach(function (r) {
r[colToSplit-1].replace(/(?:\r\n|\r|\n)(\d|\w)/g,", ").split(delimiter)
.forEach(function (s) {
row = [];
r.forEach(function (c, k) {
row.push( (k === colToSplit-1) ? s.trim() : c);
})
resArr.push(row);
})
})
return resArr.filter(function (r) {
return r.toString()
.replace(/,/g, "")
})
}
This function can be used like this:
I have an issue and i'm looping on it! :| I hope someone can help me..
So i have an input file (.xls), that is simple but there are a row (lets say its "ROW1") that is like this:
ROW1 | ROW2 | ROW3 | ROW_N
765 | 1 | AAAA-MM-DD | ...
null | 1 | AAAA-MM-DD | ...
null | 1 | AAAA-MM-DD | ...
944 | 2 | AAAA-MM-DD | ...
null | 2 | AAAA-MM-DD | ...
088 | 7 | AAAA-MM-DD | ...
555 | 2 | AAAA-MM-DD | ...
null | 2 | AAAA-MM-DD | ...
There are no stardard here, like you can see.. There are some lines null (ROW1) and in ROW2, there are equal numbers, with different association to ROW1 (like in line 5 and 6, then in line 8 and 9).
My objective is to copy and paste the values from ROW1, in the ROW1 after when is null, till isn't null. Basically is to copy form previous step, when is null...
I'm trying to use the "Formula" step, by using something like:
=IF(AND(ISBLANK([ROW1]);NOT(ISBLANK([ROW2]));ROW_n=ROW1;IF(AND(NOT(ISBLANK([ROW1]));NOT(ISBLANK([ROW2]));ROW_n=ROW1;ROW_n=""));
But nothing yet..
I've tried "Analytic Query" but nothing too..
I'm using just stream a xls file input..
Tks very much, any help is very much appreciiated!!
Best Regardsd!
Well i discover a solution, adding a "User Defined Java Class" with the code below:
import java.util.HashMap;
private FieldHelper output_field, card_field;
private RowSet out, log;
private String previou_card =null;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
if (first)
{
first = false;
out = findTargetRowSet("out");
output_field = get(Fields.Out, "previous_card");
} else {
Object[] r = getRow();
if (r == null) {
setOutputDone();
return false;
}
r = createOutputRow(r, data.outputRowMeta.size());
if (previous_card != null) {
output_field.setValue(r, previous_card);
}
if (card_field == null) {
card_field = get(Fields.In, "Grupo de Cartões");
}
String card = card_field.getString(r);
if (card != null && !card.isEmpty()) {
previous_card = card;
}
// Send the row on to the next step.
putRowTo(data.outputRowMeta, r, out);
}
return true;
After this i have to put a few steps but this help very much.
Thank you mates!!
Finally i got result. Please follow below steps
Below image is full transformation screen.
Data Grid Data will be like these. Sorry for that in my local i don't have Microsoft because of that i took Data Grid. Instead of Data Grid you can drag and drop Microsoft Excel Input step.
Drag and Drop one java script step and write below code.
Last step of transformation, drag and drop Select values step and select the columns.( These step is no necessary)
Final result will be like these.
Hope this helps.
I have two tables like this
Table1: manager
=======================================
|| Id || MgrName || department ||
=========================================
|| 1 || mgr1 ||human resource ||
|| 2 || mgr2 ||marketing ||
|| 3 || mgr3 ||customer management ||
=========================================
Table2: employee
====================================
|| empid || empname || empmanager||
====================================
|| 1 || abc || mgr1 ||
|| 2 || xyz || mgr1 ||
|| 3 || def || mgr3 ||
=====================================
The thing is when I delete mgr1 in table1:manager. I also want to update employee table where empmanager is mgr1 by null. I don't want to use any trigger.
Please tell me proper way to design database and also to avoid this problem.
You should follow normalization rules to avoid anomalies while performing CRUD operations,
First Normal Form
Second Normal Form
Third Normal Form
please refer these links to apply normalization to you tables link 1 link 2