Troposphere DynamoDB TimeToLiveSpecification - amazon-dynamodb

I am trying to create a JSON Cloudformation template for a new DynamoDB table. I am trying to set the TimeToLiveSpecification but I get errors and the Troposphere documentation isn't clear.
I have
dynamoDB = t.add_resource(Table(
"myDynamoTable",
TableName=Join("-", [Ref(env), "dynamo-table"]),
AttributeDefinitions=[
AttributeDefinition(
AttributeName=Ref(hashkeyname),
AttributeType=Ref(hashkeytype)
),
AttributeDefinition(
AttributeName="sqsMessageId",
AttributeType="S"
),
AttributeDefinition(
AttributeName="system",
AttributeType="S"
),`enter code here`
AttributeDefinition(
AttributeName=Ref(sortkeyname),
AttributeType=Ref(sortkeytype)
),
AttributeDefinition(
AttributeName="text",
AttributeType="S"
),
AttributeDefinition(
AttributeName="ttl",
AttributeType="N"
)
],
KeySchema=[
KeySchema(
AttributeName=Ref(hashkeyname),
KeyType="HASH"
),
KeySchema(
AttributeName=Ref(sortkeyname),
KeyType="RANGE"
)
],
TimeToLiveSpecification="WHAT GOES HERE???"
))
I have tried even putting this in as ready formatted JSON, it won't work.
I have tried:
TimeToLiveSpecification=AWSProperty(AttributeName="ttl", Enabled=True)
TimeToLiveSpecification=AttributeDefinition(AttributeName="ttl", Enabled=True)
TimeToLiveSpecification=TimeToLiveSchema(AttributeName="ttl", Enabled=True) (grasping at straws with this one).

Try this (untested) with the TimeToLiveSpecification shown here:
TimeToLiveSpecification=TimeToLiveSpecification(
AttributeName="fill this in",
Enabled=True,
),

In the end I've gone for
ttlspec = t.add_resource(TimeToLiveSpecification(
"ttlspec",
AttributeName="ttl",
Enabled=True
))
then
dynamoDB = t.add_resource(Table(
"myDynamoTable",
TableName=Join("-", [Ref(env), "dynamo-table"]),
AttributeDefinitions=[
AttributeDefinition(
AttributeName=Ref(hashkeyname),
AttributeType=Ref(hashkeytype)
),
AttributeDefinition(
AttributeName="sqsMessageId",
AttributeType="S"
),
AttributeDefinition(
AttributeName="system",
AttributeType="S"
),`enter code here`
AttributeDefinition(
AttributeName=Ref(sortkeyname),
AttributeType=Ref(sortkeytype)
),
AttributeDefinition(
AttributeName="text",
AttributeType="S"
),
AttributeDefinition(
AttributeName="ttl",
AttributeType="N"
)
],
KeySchema=[
KeySchema(
AttributeName=Ref(hashkeyname),
KeyType="HASH"
),
KeySchema(
AttributeName=Ref(sortkeyname),
KeyType="RANGE"
)
],
TimeToLiveSpecification=Ref(ttlspec)
))
TimeToLiveSpecification is a Class and needs to be imported at the top. Docs here.

Related

Change CSS - Dash Datatable height as % of container

I’m unable to set the height of a table to match the constrained height of a container:
table = dbc.Container(
dash_table.DataTable(
id = 'tbl',
row_selectable = 'single',
selected_rows = [None],
selected_row_ids = [None],
data=df.to_dict('records'),
columns=[{'id': c, 'name': c , 'type': table_type(df[c]), 'format':table_format(df[c])} for c in df.columns
# omit the id column
if c != 'id'
],
page_action = 'none',
style_table = {
"max-height": "100%",
#"height": "80vh",
#"height" : "20vh",
#'overflowY':'auto',
#'overflowX':'auto',
},
sort_action = 'native',
# page_size=5,
fixed_rows = {"headers": True, "data": 0},
virtualization = True,
hidden_columns = [None],
style_cell = {
#'font-size':'10px',
# 'minWidth': '180px',
#'width': '85px',
#'maxWidth': '180px',
},
style_cell_conditional=[
{'if': {'column_id': chem_columns}, 'width': '100px'},
],
style_data_conditional = get_style_data_conditional()
# col_width_computated,
,
css=[{"selector": ".show-hide", "rule": "display: none"}],
fill_width=False,
),
style={"height": "100%", "border": "5px #8c2c5c solid"}
)
I’ve tried to delete all the options but none worked.
Is there any advice?
I've found that, by having a look with the DevTool of chrome, if I set the height:100% in the class dah-table-container it works!
Unfortunately, I’ve no idea how to do it in the python code…
[SOLVED]
Add a CSS file option in asset folder located in app parent directory.
.dash-table-container{
height: 100% !important;
}

Faunadb conditional statement can't run false condition expression

I tried to build fulltext search API using nextjs and faunadb.
I referenced the article "How to Get a Full-Text Search with FaunaDB"
My index setting is as below.
This API will receive two values artist and term(short for search term)
If there is two, it will combined by and statement.
Or it will run there own statement or each value.
Implemented code is as below.
const queryCase = req.body.artist && req.body.term ? 1 : req.body.term != undefined ? 2 : 3
const tokens = await serverClient.query(
Filter(
Paginate(Match(Index("all_token_by_artist_and_description"), true)),
Lambda(
[
"artist",
"description",
"image",
"seller",
"creator",
"category",
"refId"
],
If(
Equals(queryCase, 1),
And(
Or(
ContainsStr(
LowerCase(Var("artist")),
req.body.term
),
ContainsStr(
LowerCase(Var("description")),
req.body.term
)
),
Equals(
LowerCase(Var('artist')),
LowerCase(req.body.artist)
)
),
If(
Equals(queryCase, 2),
Or(
ContainsStr(
LowerCase(Var("artist")),
req.body.term
),
ContainsStr(
LowerCase(Var("description")),
req.body.term
)
),
Equals(
LowerCase(Var('artist')),
LowerCase(req.body.artist)
)
)
)
)
)
)
res.status(200).json(tokens.data)
It couldn't run false condition expression. The false expression works fine
when I switched truth expression and false expression.
I get it fixed by make 3 separate query.
if(queryCase == 1){
tokens = await serverClient.query(
.....
)
}else if(queryCase == 2){
tokens = await serverClient.query(
.....
)
}else{
tokens = await serverClient.query(
.....
)
}
But I really have no idea what's wrong with the original query.
Can anyone tell me the problem with the query?
It caused by missing value. So I assigned random string to the missing value after the case is determined.
eg) If I only get "artist" value from request, assign random string to the "term".

WooCommerce - Show Regular and Sale Price for The Product Variation which has Flat Price

The scenario is Simple product, Variable product are woocommerce's two different product types.
The simple product will show you the regular and sale price.
The variation would give you a price range.
What I am trying to achieve is, there are some products which have over 50+ variations which have a different sale and regular prices. A price range for that product is fare.
But there are also products which's variations have same regular and sale prices. No difference in prices. I want the price to be shown just as
I agree the question arises that why shouldn't I go with simple products? Because in simple products I am not allowed to add the colors that are available in drop downs. Any suggestions please?
I was finding the exact hook to fix the problem with codeNinja snippet! This is how it is fixed:
function wc_ninja_custom_variable_price( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'Starting From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( '', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
if ( $price !== $saleprice ) {
$price = ' <ins class="highlight"> '. $price.' </ins> <del class="strike"> '.$saleprice .' </del> ';
}
return $price;
}
add_filter( 'woocommerce_variable_sale_price_html', 'wc_ninja_custom_variable_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_ninja_custom_variable_price', 10, 2 );

How to get score of a registered-query

I'm trying to calculate a score for a complex match query.
For example:
if conditionA and conditionB and (conditionC or conditionD)
then score = 10
else score = 0
This is the solution I've come up:
let $idReq := cts:register(
cts:and-query((
cts:path-range-query("/person/name", "=", 'val1', ("score-function=linear", "collation=http://marklogic.com/collation//S1")),
cts:path-range-query("/person/country", "=", 'country', ("score-function=linear", "collation=http://marklogic.com/collation//S1")),
cts:or-query((
cts:path-range-query("/person/city", "=", 'city', ("score-function=linear", "collation=http://marklogic.com/collation//S1")),
cts:path-range-query("/person/school", "=", '', ("score-function=linear", "collation=http://marklogic.com/collation//S1"))
))
))
)
return
cts:score(cts:search(fn:doc(), cts:registered-query($idReq, ("unfiltered"), 10)))
All the indexes exists and the collation too.
When I execute this registered query, I always get 0 for the score.
EDITED
I've narrow down the problem , and it can reproduced by combining cts:register with cts:path-range-query.
let $query := cts:path-range-query("/person/name", "=", "val1", ("score-function=linear", "collation=http://marklogic.com/collation//S1"))
let $idReq := cts:register($query)
return
cts:score(
cts:search(fn:doc(),
cts:registered-query($idReq,("unfiltered"), 10)
(: $query :)
)
)
EDITED
Setup index config for testing:
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
let $dbid := xdmp:database("Documents")
let $config :=
admin:database-add-range-path-index(
admin:get-configuration(), $dbid,
admin:database-range-path-index(
$dbid, "string", "/person/name",
"http://marklogic.com/collation//S1",
fn:false(), "ignore"))
return admin:save-configuration($config)
Sample data:
xdmp:document-insert(
'/test/person1.xml',
<person>
<name>val1</name>
<city>city</city>
<country>country</country>
</person>
)

Passing jQuery slider values to GET

I'm trying to get the values from jQuery slider and pass them trought GET for meta search in Wordpress. Currently with my code below the input field passes this data via url: &price=Between+5000+and+25000+currency.
What is the best way for handling/getting this values so I can pass them to my php meta search function.
jQuery(function() {
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 100000,
values: [ 5000, 25000 ],
slide: function( event, ui ) {
$( "#amount" ).val( "Between " + ui.values[ 0 ] + " and " + ui.values[ 1 ] + " currency.");
}
});
$( "#amount" ).val( "Between " + $( "#slider-range" ).slider( "values", 0 ) + " and " + $( "#slider-range" ).slider( "values", 1 ) + " currency." );
});
I found a solution for myself. Still looking for better or more elegant handling of this. Here is my solution:
if( !empty($_GET['price']) ) { // Checked GET request
$pricesRange = $_GET['price'];
preg_match_all('!\d+!', $pricesRange, $matches); // Extract only the numbers
$rangeValue1 = $matches[0][0]; //preg_match_all returns multidimension array?
$rangeValue2 = $matches[0][1];
$meta_query[] = array(
'key' => 'price',
'value' => array($rangeValue1, $rangeValue2 ),
'type' => 'DECIMAL',
'compare' => 'BETWEEN',
);
}

Resources