Possible variable types in buildout cfg files - buildout

Is it possible to define a buildout variable of type dictionary?
I am trying to substitute a variable with a dictionary but buildout considers it a string.
E.g.
in buildout.cfg:
[MYPROG]
progr_args =
a : 1
b : 2
d :
d1: 1
d2: 2
in template:
my_params:
{% for key, val in parts.MYPROG.progr_args.items() %}\
${key}: ${val}\
{% end %}

Not with Buildout itself, no. Buildout configuration values are always strings; even the mr.scripty recipe, which lets you use Python code as part of your buildout configuration, stores the results of the Python code a strings.
Ever worse, initial whitespace from continuation lines is stripped, so your entry:
progr_args =
a : 1
b : 2
d :
d1: 1
d2: 2
is stored as \na : 1\nb : 2\nd :\nd1: 1\nd2: 2, having lost all indentation context.
You'll have to use Genshi itself to parse out your values. I suggest you use a separate section:
[MYPROG]
prog_params = section_name
[section_name]
a = 1
b = 2
and in your template:
my_params:
{% for key, val in parts[parts.MYPROG.progr_args].items() %}\
${key}: ${val}\
{% end %}

Related

How to print lists in a scific order in kotlin?

im working on a project and i have a list in kotlin like:
val list = listOf("banana", "1","apple","3","banana","2")
and i want to print it like
Output:
banana = 1
banana = 2
apple = 3
so like every work with the number should be like one val, and i need to print in scific order (the order is toooo random for any sort command), so im panning on just coppying the whole xinhua dictionary here (since all chinese words have a scific unicode), and make the code it replace like:
val list = listOf("banana丨", "1","apple丩","3","banana丨","2")
but how to print them in the order?
ps. even me as a chinese dont know most of the words in xinhua dictionary lol so there is more then enofe
Assuming that you have the following input list, as shown in your question, where the order of occurrence is always one word followed by the scific order:
val list = listOf("banana", "1","apple","3","banana","2")
You could do the following:
1. Create a data class that defines one entry in your raw input list
data class WordEntry(val word: String, val order: Int)
2. Map over your raw input list by using the windowed and map methods
val dictionary = list.windowed(2, 2).map { WordEntry(it.first(), it.last().toInt()) }
Here, the windowed(2, 2) method creates a window of size 2 and step 2, meaning that we iterate over the raw input list and always work with two entries at every second step. Assuming that the order in the raw input list is always the word followed by the scific order, this should work. Otherwise, this would not work, so the order is very important here!
3. Sort the transformed dictionary by the order property
val sortedDictionary = dictionary.sortedBy { it.order }
Edit: You can also sort by any other property. Just pass another property to the lambda expression of sortedBy (e.g. sortedBy { it.word } if you want to sort it by the word property)
4. Finally, you can print out your sorted dictionary
val outputStr = sortedDictionary.joinToString("\n") { "${it.word} = ${it.order}" }
print(outputStr)
Output:
banana = 1
banana = 2
apple = 3

How do I fix 'unparsable' sqlfluff lint error

I am receiving the error L: 3 | P: 1 | PRS | Found unparsable section:.
This is when I am calling the date_spine macro provide by dbt_utils. Has anyone come across this before and what expected value to set in the definition of the macro in sqlfluff?
See as follows for defining macro in sqlfluff file in dbt:
date_spine = {% macro date_spine(datepart, start_date, end_date) %}'HERE'{% endmacro %}
You don't need to set date_spine = portion, just define the macro as:
{% macro date_spine(datepart, start_date, end_date) %}'HERE'{% endmacro %}

Changing names of variables using the values of another variable

I am trying to rename around 100 dummy variables with the values from a separate variable.
I have a variable products, which stores information on what products a company sells and have generated a dummy variable for each product using:
tab products, gen(productid)
However, the variables are named productid1, productid2 and so on. I would like these variables to take the values of the variable products instead.
Is there a way to do this in Stata without renaming each variable individually?
Edit:
Here is an example of the data that will be used. There will be duplications in the product column.
And then I have run the tab command to create a dummy variable for each product to produce the following table.
sort product
tab product, gen(productid)
I noticed it updates the labels to show what each variable represents.
What I would like to do is to assign the value to be the name of the variable such as commercial to replace productid1 and so on.
Using your example data:
clear
input companyid str10 product
1 "P2P"
2 "Retail"
3 "Commercial"
4 "CreditCard"
5 "CreditCard"
6 "EMFunds"
end
tabulate product, generate(productid)
list, abbreviate(10)
sort product
levelsof product, local(new) clean
tokenize `new'
ds productid*
local i 0
foreach var of varlist `r(varlist)' {
local ++i
rename `var' ``i''
}
Produces the desired output:
list, abbreviate(10)
+---------------------------------------------------------------------------+
| companyid product Commercial CreditCard EMFunds P2P Retail |
|---------------------------------------------------------------------------|
1. | 3 Commercial 1 0 0 0 0 |
2. | 5 CreditCard 0 1 0 0 0 |
3. | 4 CreditCard 0 1 0 0 0 |
4. | 6 EMFunds 0 0 1 0 0 |
5. | 1 P2P 0 0 0 1 0 |
6. | 2 Retail 0 0 0 0 1 |
+---------------------------------------------------------------------------+
Arbitrary strings might not be legal Stata variable names. This will happen if they (a) are too long; (b) start with any character other than a letter or an underscore; (c) contain characters other than letters, numeric digits and underscores; or (d) are identical to existing variable names. You might be better off making the strings into variable labels, where only an 80 character limit bites.
This code loops over the variables and does its best:
gen long obs = _n
foreach v of var productid? productid?? productid??? {
su obs if `v' == 1, meanonly
local tryit = product[r(min)]
capture rename `v' `=strtoname("`tryit'")'
}
Note: code not tested.
EDIT: Here is a test. I added code for variable labels. The data example and code show that repeated values and values that could not be variable names are accommodated.
clear
input str13 products
"one"
"two"
"one"
"three"
"four"
"five"
"six something"
end
tab products, gen(productsid)
gen long obs = _n
foreach v of var productsid*{
su obs if `v' == 1, meanonly
local value = products[r(min)]
local tryit = strtoname("`value'")
capture rename `v' `tryit'
if _rc == 0 capture label var `tryit' "`value'"
else label var `v' "`value'"
}
drop obs
describe
Contains data
obs: 7
vars: 7
size: 133
-------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------
products str13 %13s
five byte %8.0g five
four byte %8.0g four
one byte %8.0g one
six_something byte %8.0g six something
three byte %8.0g three
two byte %8.0g two
-------------------------------------------------------------------------------
Another solution is to use the extended macro function
local varlabel:variable label
The tested code is:
clear
input companyid str10 product
1 "P2P"
2 "Retail"
3 "Commercial"
4 "CreditCard"
5 "CreditCard"
6 "EMFunds"
end
tab product, gen(product_id)
* get the list of product id variables
ds product_id*
* loop through the product id variables and change the
variable name to its label
foreach var of varlist `r(varlist)' {
local varlabel: variable label `var'
display "`varlabel'"
local pos = strpos("`varlabel'","==")+2
local varlabel = substr("`varlabel'",`pos',.)
display "`varlabel'"
rename `var' `varlabel'
}

Selenium - Checking the first letter of a string in a variable

I'd like to know if it's possible, on Selenium IDE, to check the first letter of value inside a variable. For example, I have a variable called cartId, and this variable stores IDs inside it. Sometimes, the ID starts with "A", "E" or "P", examples:
A324FR
E289FS
P23U87
So i'd like to make something like this:
If starts with A, stores "A" in an auxiliary variable.
If starts with E, stores "E" in an auxiliary variable.
If starts with P, stores "P" in an auxiliary variable.
This is needed because depending on the first letter of the value, it will do a different method ... so I can use something like (command, target, value):
gotoIf | ${auxiliaryVariable} == 'A' | METHOD1
gotoIf | ${auxiliaryVariable} == 'E' | METHOD2
gotoIf | ${auxiliaryVariable} == 'P' | METHOD3
Thanks!
You could probably use storeEval to evaluate JavaScript to get your auxiliaryVariable
storeEval | document.getElementById("cartId").textContent[0] | auxiliaryVariable
This will get the element regardless of the text, then store the first letter A, E, or P inside of auxiliaryVariable for use later.
Thanks for all the help, I could do it using:
store | javascript{storedVars['cartId'].substring(0,1);} | auxiliary

How to extract keys from map?

How do I extract all keys from a map field?
I have a bag of tuples where one of the fields is a map that contains HTTP headers (and their values). I want to create a set of all possible keys (in my dataset) for a HTTP header and count how many times I've seen them.
Ideally, something like:
A = LOAD ...
B = FOREACH A GENERATE KEYS(http_headers)
C = GROUP FLATTEN(B) BY $0
D = FOREACH C GENERATE group, COUNT($0)
(didn't test it but it illustrates the idea..)
How do I do something like this? If I can extract a bag of keys from a map it would actually solve it. I just couldn't find any function like this in piglatin's documentation.
Yes there is a command in Pig to accomplish this.
Example:
/* data */
[a#1,b#2,c#3]
[green#sam,eggs#I,ham#am]
A = load 'data' as (M:[]);
B = foreach A generate KEYSET($0);
dump B
Output:
({(b),(c),(a)})
({(ham),(eggs),(green)})