Formatting a Semantic MediaWiki query resulttable template with cell newlines - templates

I need a semantic query result table template where I can have both newline-delimited cell results for some columns and comma-delimited columns in the same table.
If I use the standard format=broadtable, for example, the result is separated by newlines inside the table cells for all columns:
{{#ask:[[Category:Items]]
|?Description
|?Models
|?Addons
|format=broadtable
}}
If I create a template, all I am able to accomplish is a comma-separated result:
<includeonly>
{| class="wikitable sortable"
! style="width: 30%;" | Page
!! style="width: 30%;" | Description
!! style="width: 20%;" | Models
!! style="width: 20%;" | Addons
|-
</includeonly>
{{#ask:[[Category:Items]]
|?Description
|?Models
|?Addons
|format=template
|template=QResTemplate
}}
<includeonly>
|}
</includeonly>
Here is the QResTemplate:
<includeonly>
| {{{1}}} || {{{2}}} || {{{3}}} || {{{4}}}
|-
</includeonly>
Every Item has multiple Models and Addons, so it is column 3 and 4 in the table that I need one of them to be comma-separated while the other is newline-separated.
If I add something after {{{3}}}, like a newline, it is added after the last Model on the table row, not after each Model as I want it to.

Use Extension:Arrays to format your comma separated outputs as you want:
<includeonly><!--
store arrays
-->{{#arraydefine:models|{{{3}}}}}<!--
-->{{#arraydefine:addons|{{{4}}}}}<!--
print row
-->
| {{{1}}} || {{{2}}} || {{#arrayprint:models|<br/>}} || {{#arrayprint:addons|, }}
|-
</includeonly>
First you store both lists as arrays. arraydefine assumes that your list is comma separated, unless you specify somthing else. Then you print your arrays again with #arrayprint, but this time you can decide how you want those values to be separated.
If you can't use commas (e.g. because some value contains a comma, you can add e.g. sep=¤ to your ask query, and then do {{#arraydefine:models|{{{3}}}|¤}} to tell arraydefine that you are using a different separator.

Related

django getlist() function

I have a tags generator for my blog site and every time I enter tags it generates a hidden html input, and it appends whenever I insert a tag like this example below.
<input type="hiiden" name="tags" value="<value of inserted tags>">
<input type="hiiden" name="tags" value="<value of inserted tags>">
<input type="hiiden" name="tags" value="<value of inserted tags>">
In my Django view I get all the tags from the form through request.POST.getlist("tags") and save it on database so the inserted tags is like this on database ['value1','value2','value3'] When I fetch the tags in the Django template through for loop to extract the strings from the arrayfield the output shows like this:
[ ' v a l u e 1 ' , ' v a l u e 2 ' , ' v a l u e 3 ' ] // one by one character output
the code works fine but the problem is it outputs character by character in the array including the brackets and the apostrophe and the commas. What i want to achieve is only the strings which are present in the array field
anyone knows what can be the solution for this? any suggestion and help is appreciated.

pandas filter text in column according to data in other column

I'm making prep of social media text data. The two columns look like this:
name text
#dnsTV2 #raisa Bullshit!
Sebastian #dnsTV2, are you kidding?
#raisa #dnsTV2 thanks to corona...
imax468 #oksana what do you mean by that???
oksana raisa! It is so true!
In 'text' the first one or two words are the nicknames of people the person is answering to in his comment (sometimes beginning with #, but not always). All nicknames persons are answering to are at some place in 'name' column because people are talking to each other.
My task is to delete this names and '#' from 'text' column while keeping the rest of the text.
Is there a way I could filter the text in the second column using the content of the first?
Thank you in advance!
Here is a solution that uses regex. It takes all the names from the names column and removes the #. It then adds #? in front of them, which means optional #in regex. It then joins them all with |, which lets you pass them all to Series.str.replace function, replacing them with empty strings.
This assumes there is no consistency between the names that have # in the text column and in the name column. If there is, there is an even simpler solution.
import re
df = pd.DataFrame({
'name': ['#dnsTV2', 'Sebastian', '#raisa', 'imax468', 'oksana', 'extra'],
'text': ['#raisa Bullshit!',
'#dnsTV2, are you kidding?',
'#dnsTV2 thanks to corona...',
'#oksana what do you mean by that???',
'raisa! It is so true!',
'this row has now nicknames']
})
regexes = '|'.join(['#?' + re.escape(name) for name in df.name.str.replace('#', '')])
df['text2'] = df['text'].str.replace(regexes, '')
df
name text \
0 #dnsTV2 #raisa Bullshit!
1 Sebastian #dnsTV2, are you kidding?
2 #raisa #dnsTV2 thanks to corona...
3 imax468 #oksana what do you mean by that???
4 oksana raisa! It is so true!
5 extra this row has no nicknames
text2
0 Bullshit!
1 , are you kidding?
2 thanks to corona...
3 what do you mean by that???
4 ! It is so true!
5 this row has no nicknames

How to conditionally transform text in a column in power query?

I am building a workbook in PowerBI and I have the need for doing a conditional appending of text to column A if it meets a certain criteria. Specifically, if column A does not end with ".html" then I want to append the text ".html" to the column.
A sample of the data would look like this:
URL | Visits
site.com/page1.html | 5
site.com/page2.html | 12
site.com/page3 | 15
site.com/page4.html | 8
where the desired output would look like this:
URL | Visits
site.com/page1.html | 5
site.com/page2.html | 12
site.com/page3.html | 15
site.com/page4.html | 8
I have tried using the code:
#"CurrentLine" = Table.TransformColumns(#"PreviousLine", {{"URL", each if Text.EndsWith([URL],".html") = false then _ & ".html" else "URL", type text}})
But that returns an error "cannot apply field access to the type Text".
I can achieve the desired output in a very roundabout way if I use an AddColumn to store the criteria value, and then another AddColumn to store the new appended value, but this seems like an extremely overkill way to approach doing a single transformation to a column. (I am specifically looking to avoid this as I have about 10 or so transformations and don't want to have so many columns to add and cleanup if there is a more succinct way of coding)
You don't want [URL] inside Text.EndWith. Try this:
= Table.TransformColumns(#"PreviousLine",
{{"URL", each if Text.EndsWith(_, ".html") then _ else _ & ".html", type text}}
)

Output nested list to xlsx using Django

I have a complex nested list of models that looks like this:
hierarchy_tree = ['0000', 'hierarchy' [['0000-22', 'hierarchy2', [['0000-33', 'hiearchy3', [['0000-44-4444', 'hiearchy4', [['0000-55-5555-55', 'hiearchy5', []]]]]]]]]]
I am able to easily display this in a template using dot notation - example:
{% for hierarchy in hierarchy_tree %}
<tr class="item" data-id="{{system.0}}" data-parent="">
<td>
{{hierarchy.0}}
</td>
<td>
{{hierarchy.1.genericname}}
</td>
Now I am trying to output this to an .xlsx file but I cannot figure out how to pass all of the levels of this list? How can I do the same thing that I did in the template to pass this list to excel?
I have tried the following which will return the 1st list but throws an error (ValueError at /post/1/export/hierarchy/ - cannot covert(my passed in list)to excel) for the sublists because of the way that they are nested I believe.
for r in hierarchy_tree:
ws.append(r)
I have also tried and failed repeatedly to access the sublists using other methods.
So bottom line I need to figure out how to access and pass the values for the sublists - any ideas or help will be greatly appreciated?
Thank you
Comment: ... is just 1 row in the list ...
Python print a instance of Type list in one line, surounding with [ ... ].
Your hierarchy_tree is of Type list of n lists.
Every n't list in hierarchy_tree starts with [ and ends with ].
You have to break your hierarchy_tree into row Data.
For instance:
def treeWalk(tree, level=0):
rData = [ '' for i in range(level)]
for item in tree:
if isinstance(item, list):
if len(rData) > level:
ws.append(rData)
level += 1
treeWalk(item, level)
return
rData.append(item)
treeWalk(hierarchy_tree)
Tested with Python:3.4.2 - openpyxl:2.4.1 - LibreOffice: 4.3.3.2

BIRT: Align rows in list element

I'm using the Birt list element to display my data from left to right. (see this question as reference). Eg. List element with a Grid in details and the grid set to inline.
The issue I'm facing now is, that the different rows in the grid are not aligned left to right (probably due to some rows having empty values in some fields). How can I force BIRT to align properly?
EDIT:
This is especially also a problem with longer text that wraps to more than 1 line. The wrapping /multiple lines should be reflected by all list elements in that "row of the output".
Unfortunately, I don't see any chance to accomplish this easily in the generic case - that is, if the number of records is unknown in advance, so you'd need more than one line:
student1 student2 student3
student4 student5
Let's call those line "main lines". One main line can contain up to 3 records. The number 3 may be different in your case, but we can assume it is a constant, since (at least for PDF reports) the paper width is restricted.
A possible solution could work like this:
In your data set, add two columns for each row: MAIN_LINE_NUM and COLUMN_NUM, where the meaning is obvious. For example, this could be done with pure SQL using analytic functions (untested):
select ...,
trunc((row_number() over (order by ...whatever...) - 1) / 3) + 1 as MAIN_LINE_NUM,
mod(row_number() over (order by ...whatever...) - 1), 3) +1 as COLUMN_NUM
from ...
order by ...whatever... -- The order must be the same as above.
Now you know where each record should go.
The next task is to transform the result set into a form where each record looks like this (for the example, think that you have 3 properties STUDENT_ID, NAME, ADDRESS for each student):
MAIN_LINE
STUDENT_ID_1
NAME_1
ADDRESS_1
STUDENT_ID_2
NAME_2
ADDRESS_2
STUDENT_ID_3
NAME_3
ADDRESS_3
You get the picture...
The SQL trick to achieve this is one that one should know.
I'll show this for the STUDENT_ID_1, STUDENT_ID_2 and NAME_1 column as an example:
with my_data as
( ... the query shown above including MAIN_LINE_NUM and COLUMN_NUM ...
)
select MAIN_LINE_NUM,
max(case when COLUMN_NUM=1 then STUDENT_ID else null end) as STUDENT_ID_1,
max(case when COLUMN_NUM=2 then STUDENT_ID else null end) as STUDENT_ID_2,
...
max(case when COLUMN_NUM=1 then NAME else null end) as NAME_1,
...
from my_data
group by MAIN_LINE_NUM
order by MAIN_LINE_NUM
As you see, this is quite clumsy if you need a lot of different columns.
On the other hand, this makes the output a lot easier.
Create a table item for your dat set, with 3 columns (for 1, 2, 3). It's best to not drag the dataset into the layout. Instead, use the "Insert element" context menu.
You need a detail row for each of the columns (STUDENT_ID, NAME, ADDRESS). So, add two more details rows (the default is one detail row).
Add header labels manually, if you like, or remove the header row if you don't need it (which is what I assume).
Remove the footer row, as you probably don't need it.
Drag the columns to the corresponding position in your table.
The table item should look like this now (data items):
+--------------+--------------+-------------+
+ STUDENT_ID_1 | STUDENT_ID_2 | STUDENT_ID3 |
+--------------+--------------+-------------+
+ NAME_1 | NAME_2 | NAME_3 |
+--------------+--------------+-------------+
+ ADDRESS_1 | ADDRESS_2 | ADDRESS_3 |
+--------------+--------------+-------------+
That's it!
This is one of the few examples where BIRT sucks IMHO in comparison to other tools like e.g. Oracle Reports - excuse my Klatchian.