I have three images in my FLUID template and would like to show one of these three images at random. Is there any method to do this in the FLUID template or is this impossible and I must go a other way?
I tried the TYPO3 extension "VHS" to generate a random number:
{v:random.number(minimum: 1, maximum: 3, minimumDecimals: 0, maximumDecimals: 0)}
In the frontend I see the generated number. But how can I set the random number to a variable to use it in a if-else-condition?
This would also be possible with VHS
<v:iterator.sort subject="{images}" as="randomimages" order="RAND" />
On TYPO3v7 with VHS installed:
{v:random.number(...) -> v:variable.set(name: 'newvariablename')}
On TYPO3v8 and above, or on Fluid standalone:
{v:random.number(...) -> f:variable(name: 'newvariablename')}
Then use the new variable:
<f:if condition="{newvariablename}" then="random number greater than zero" />
I do not use vhs in TYPO3v9. I use seconds and simple math. I get the random value of the iterator from the array through:
<f:variable name="sec4random" value="{f:format.date(date:'0 seconds', format:'s')}"/>
<f:variable name="count4random" value="{f:count(subject: images)}"/>
Random index for iterator: {sec4random % count4random}
Related
I would like to understand how the data.pageParams array works in useInfiniteQuery.
In general we always set a default value to 1. I would like to set a default value as the pagenumber that I receive as props and calculate the next page based on that.
The pageParams array in data always has the value as [undefined, 1, 2, 3...]
If I need to pass the custom page number how should this be done. Can the pageNumber be updated in the pageParams array
Is the pageParam a factor for fetching data from cache?
if you implement getNextPageParam, the pageParam will always be computed from that function. pageParams are only stored in case you use the manual approach - by passing a pageParam directly to fetchNextPage.
I am currently using kfp.dsl.ParallelFor to train 300 models. It looks something like this:
...
models_to_train_op = get_models()
with dsl.ParallelFor(models_to_train_op.outputs["data"], parallelism=100) as item:
prepare_data_op = prepare_data(item)
train_model_op = train_model(prepare_data_op["train_data"]
...
Currently, the iterations in Vertex AI are labeled in a dropdown as something like for-loop-worker-0, for-loop-worker-1, and so on. For tasks (like prepare_data_op, there's a function called set_display_name. Is there a similar method that allows you to set the iteration name? It would be helpful to relate them to the training data so that it's easier to look through the dropdown UI that Vertex AI provides.
I reached out to a contact I have at Google. They recommended that you can pass the list that is passed to ParallelFor to set_display_name for each 'iteration' of the loop. When the pipeline is compiled, it'll know to set the corresponding iteration.
# Create component that returns a range list
model_list_op = model_list(n_models)
# Parallelize jobs
ParallelFor(model_list_op.outputs["model_list"], parallelism=100) as x:
x.set_display_name(str(model_list_op.outputs["model_list"]))
I need to generate random number in specific range for postman.
I wonder if there is possible to generate it and to use it in variable in postman, from what I saw at postman site is:
{{$randomint }}
will give random number between 1-1000
and I already tried to do something like this:
{{$randomint(1,5)}}
to get number between 1-5 but postman didn't get this kind of option, so how to specify range for the random in postman?
You can just use Lodash for this as it's a built-in module:
pm.environment.set("random_number", _.random(1, 5))
Or just add the number 5 to the _.random() function and this will be a number from 0 to 5.
This worked for me:
In your Pre-request script define your variable with:
pm.globals.set('randomNumber', Math.floor(Math.random() * 5));
Then in your URL call your variable in the URL like so:
{{randomNumber}}
Hope this works for you.
A little late.
But none of the above answers worked for me.
I solved it by setting a variable in pre-request tab.
Example:
pm.collectionVariables.set ("randomNum", _.random (20,100));
Then use the variable name in the body of my request (like any other variable)
{
"number": {{randomNum}}
}
Finally, this generates a new number between the desired values in each request
Just use the modulo operation:
const num = pm.variables.replaceIn('{{$randomInt}}') % 5 + 1;
pm.environment.set("random_number", num);
// test
console.log(pm.variables.get('random_number'));
Considering this code example and this post
...
<xf:action>
<xf:setvalue
iterate="instance('fr-send-submission-params')/#*"
ref="."
value="event(name(context()))"/>
</xf:action>
...
How can refer to current iterated position? Like value="position()"
Can i use this position as variable to xpath expressions? Like ref="/AnotherElement[position()]"
The following works:
<xf:action iterate="instance('fr-send-submission-params')/#*">
<xf:var name="p" value="position()"/>
<xf:setvalue ref="." value="$p"/>
</xf:action>
I don't think you can get away just with xf:setvalue, because ref changes the evaluation context of the expression to a single item which means that position() returns 1 within value.
A warning as I see that you iterate on attributes: I don't think that attribute position is guaranteed to be consistent.
Update:
The following works if you have elements, but then you need to have knowledge of the items iterated within the xf:setvalue:
<xf:setvalue
event="DOMActivate"
iterate="value"
ref="."
value="count(preceding-sibling::value) + 1"/>
So I think that the option with an enclosing action is much clearer.
I'm using YAML for a computer and human-editable and readable input format for a simulator. For human readability, some parts of the input are mostly amenable to block style, while flow style suits others better.
The default for PyYAML is to use block style wherever there are nested maps or sequences, and flow style everywhere else. *default_flow_style* allows one to choose all-flow-style or all-block-style.
But I'd like to output files more of the form
bonds:
- { strength: 2.0 }
- ...
tiles:
- { color: red, edges: [1, 0, 0, 1], stoic: 0.1}
- ...
args:
block: 2
Gse: 9.4
As can be seen, this doesn't follow a consistent pattern for styles throughout, and instead changes depending upon the part of the file. Essentially, I'd like to be able to specify that all values in some block style sequences be in flow style. Is there some way to get that sort of fine-level control over dumping? Being able to dump the top-level mapping in a particular order while not requiring that order (eg, omap) would be nice as well for readability.
It turns out this can be done by defining subclasses with representers for each item I want not to follow default_flow_style, and then converting everything necessary to those before dumping. In this case, that means I get something like:
class blockseq( dict ): pass
def blockseq_rep(dumper, data):
return dumper.represent_mapping( u'tag:yaml.org,2002:map', data, flow_style=False )
class flowmap( dict ): pass
def flowmap_rep(dumper, data):
return dumper.represent_mapping( u'tag:yaml.org,2002:map', data, flow_style=True )
yaml.add_representer(blockseq, blockseq_rep)
yaml.add_representer(flowmap, flowmap_rep)
def dump( st ):
st['tiles'] = [ flowmap(x) for x in st['tiles'] ]
st['bonds'] = [ flowmap(x) for x in st['bonds'] ]
if 'xgrowargs' in st.keys(): st['xgrowargs'] = blockseq(st['xgrowargs'])
return yaml.dump(st)
Annoyingly, the easier-to-use dumper.represent_list and dumper.represent_dict don't allow flow_style to be specified, so I have to specify the tag, but the system does work.