CARBONE.IO Conditional display (ifEQ) - if-statement

I'm using Carbone to generate PDF with variables.
I need to make a conditional display. If a product have a specific category I need to display an information.
I tried to make the condition with ifEQ, show and showBeggin // showEnd but it does'nt work.
// My JSON
const json = {
shopping : {
sales :[
{
product_name: "Apple",
product_price: 2,
product_category: "fruits",
comment: "",
},
{
product_name: "Coke",
product_price: 3,
product_category: "soda",
comment: "",
},
{
product_name: "Cucumber",
product_price: 1.5,
product_category: "vegetable",
comment: "",
},
{
product_name: "Vodka",
product_price: 15,
product_category: "Alcohol",
comment: "Dangerous for health, prohibited at least 18 years old",
},
]
}
}
What I made on my document :
State
{d.shopping.sales[i].product_name} {d.shopping.sales[i].product_category(“Alcohol”):showBeggin} Information {d.shopping.sales[i].comment}, {d.shopping.sales[i].product_price}, {d.shopping.sales[i].produt_name}{d.shopping.sales[i].product_category::showEnd}
{d.shopping.sales[i+1].product_name}
Thank's for help !

Your example got a couple of errors, some fixes to do:
it is missing the ifEQ just before the showBegin
if the ifEQ argument is a string, it must be wrap with single quotes
showBeggin should be written showBegin
the last showEnd should be preceded by only one colon.
Here is your template with all corrections:
State
{d.shopping.sales[i].product_name} {d.shopping.sales[i].product_category:ifEQ('Alcohol'):showBegin}
Information {d.shopping.sales[i].comment}, {d.shopping.sales[i].product_price}, {d.shopping.sales[i].produt_name}{d.shopping.sales[i].product_category:showEnd}
{d.shopping.sales[i+1].product_name}
The conditional block documentation has been improved a lot, to get more examples: https://carbone.io/documentation.html#conditioned-output
Have a great day!

Related

How to use match as with Regular Expression in Mongodb with in Aggregate switch case?

Here what i did.
Inside $AddFields
{
ClientStatus:{
$switch: {
branches: [
{ case: {
$eq:
[
"$CaseClientStatus",
/In Progress/i
]},
then:'In Progress'
},
{ case: {
$eq:
[
"$CaseClientStatus",
{regex:/Cancelled/i}
],
},then:'Cancelled'},
{ case: {$eq:['$CaseClientStatus','Complete - All Results Clear']}, then:'Complete'},
{ case: {$eq:['$CaseClientStatus','Case on Hold']}, then:'Case on Hold'}
],
default: 'Other'
}}
}
but with this my ClientStatus is showing only Complete,Other,Case On Hold not the one with specified with regex. alghough field contains those words.
here is the one of the doc
{
"CandidateName": "Bruce Consumer",
"_id": "61b30daeaa237672bb7a17cc",
"CaseClientStatus": "Background Check Case In Progress",
"TAT": "N/A",
"CaseCloseDate": null,
"FormationAutomationStatus": "Automated",
"MethodOfDataSupply": "Automated",
"Status": "Background Case In Progress",
"CreatedDate": "2021-12-10T08:19:58.389Z",
"OrderId": "Ord3954",
"PONumber": "",
"Position": "",
"FacilityCode": "",
"IsCaseClose": false,
"Requester": "Shah Shah",
"ReportErrorList": 0
}
Assuming you are on version 4.2 or higher (and you should be because 4.2 came out almost 2 years ago) then the $regexFind function gives you what you need. Prior to 4.2, regex was only available in a $match operator, not in complex agg expressions. Your attempt above is admirable but the // regex syntax is not doing what you think it should be doing. Notably, {regex:/Cancelled/i} is simply creating a new object with key regex and string value /Cancelled/i (including the slashes) which clearly will not equal anything in $CaseClientStatus. Here is a solution:
ClientStatus:{
$switch: {
branches: [
{ case: {
$ne: [null, {$regexFind: {input: "$CaseClientStatus", regex: /In Progress/i}}]
}, then:'In Progress'},
{ case: {
$ne: [null, {$regexFind: {input: "$CaseClientStatus", regex: /Cancelled/i}}]
},then:'Cancelled'},
{ case: {$eq:['$CaseClientStatus','Complete - All Results Clear']}, then:'Complete'},
{ case: {$eq:['$CaseClientStatus','Case on Hold']}, then:'Case on Hold'}
],
default: 'Other'
}}
It looks like you are trying to take a somewhat free-form status "description" field and create a strong enumerated status from it. I would recommend that your $ClientStatus output be more code-ish e.g. IN_PROGRESS, COMPLETE, CXL etc. Eliminate case and certainly whitespace.

Gatling : regex to get a specific value from a JSON

I have this JSON Object coming from an HTML.
{
"isCompany": false,
"accommodations": [
{
"id": "00000000031000006435",
"isChecked": false,
"name": "Théo",
"addressLine1": "Rue des patriotes 40 Y",
"addressLine2": "1050 Ixelles",
"nightsDeclared": 5,
"schoolNightsDeclared": 3,
"schoolNightsAttached": 0,
"taxableNights": 2.0,
"totalPayment": 0.0,
"isInProgress": true,
"isLate": false,
"isPayed": "false",
"deadline": "2021-12-31",
"initialAmount": 0.0,
"remainingAmount": 0.0
},
{
"id": "00000000031000006438",
"isChecked": false,
"name": "Théo",
"addressLine1": "Rue des Gens 45 B",
"addressLine2": "1040 Etterbeek",
"nightsDeclared": 5,
"schoolNightsDeclared": 3,
"schoolNightsAttached": 0,
"taxableNights": 2.0,
"totalPayment": 0.0,
"isInProgress": true,
"isLate": false,
"isPayed": "false",
"deadline": "2021-12-31",
"initialAmount": 0.0,
"remainingAmount": 0.0
}
]
}
I know that in Gatling, it is possible to get the accommodation id by writing this regex :
check(regex(""""accommodations":\[\{"id":"(.*?)"""").saveAs("accommodationId"))
Now my question is, what is the regex that gets the "isInProgress"?
Don't!
Using regex in this specific case could result in your code breaking on slight input changes and will result in unreadable code.
Instead deserialize and access as a dictionary?
[a['id'] for a in json.loads(json_string)['accommodations']]
Also, have you tried to simply replace id with the name of the field you want?
If you insist on using regex for this, check out online regex sites like regex101.com, regexr.com, regextester.com etc. (search for "online regex test") and try to solve this yourself. If your code does not work, ask a question again.
Ok, you have this in your regex
"id":"(.*?)"
You need just change to expected key name as isInProgress or any another. Also pay attention on " around (.*?) - since the value for id a string, they are needed, but value in isInProgress with another type.

Plotting multiple lines on a Cube.js line graph

Imagine a simple line graph plotting a person count (y-axis) against a custom time value (x-axis), as such:
Suppose you have another dimension, say specific groupings of people, how do you draw a separate line on this graph for each group?
You have to use the PivotConfig here an example I used in Angular
(EDIT) Here is the Query
Query = {
measures: ['Admissions.count'],
timeDimensions: [
{
dimension: 'Admissions.createdDate',
granularity: 'week',
dateRange: 'This quarter',
},
],
dimensions: ['Admissions.status'],
order: {
'Admissions.createdDate': 'asc',
},
}
(END EDIT)
PivotConfig = {
x: ['Admissions.createdDate.day'],
y: ['Admissions.status', 'measures'],
fillMissingDates: true,
joinDateRange: false,
}
Code to extract data from resultset :
let chartData = resultSet.series(this.PivotConfig).map(item => {
return {
label: item.title.split(',')[0], //title contains "ADMIS, COUNT"
data: item.series.map(({ value }) => value),
}
})
Result Object (not the one in the chart):
[{
"label": "ADMIS",
"data": [2,1,0,0,0,0,0]
},{
"label": "SORTIE",
"data": [2,1,0,0,0,0,0]
}]
Here is what the output looks like!
The chart renderer in the Developer Playground is meant to be quite simplistic; I'd recommend creating a dashboard app or using one of our frontend integrations in an existing project to gain complete control over chart rendering.

autofilling a dict python 2.x

I'm quite new to Python and programming in general, so apologies if this is quite basic or has been asked and answered before. Here is a sample of the data I'm working with:
{
"homeTeam": {
"formation": [
"4",
"4",
"2"
],
"lineupsSorted": [
{
"player": {
"name": "Scott P. Brown",
"slug": "scott-p-brown",
"shortName": "S. P. Brown",
"id": 19889,
"hasImage": true
},
"position": 1,
"shirtNumber": 1,
"substitute": false,
"positionName": "Goalkeeper",
"positionNameshort": "G",
"captain": false
},
{
"player": {
"name": "Carl Winchester",
"slug": "carl-winchester",
"shortName": "C. Winchester",
"id": 110785,
"hasImage": true
},
"position": 2,
"shirtNumber": 27,
"substitute": false,
"positionName": "Midfielder",
"positionNameshort": "M",
"captain": false
},
I am looking to automate populating defined names as I have done manually here:
hometeamPositions =['Goalkeeper','Midfielder','Defender','Defender','Defender','Midfielder','Midfielder','Midfielder','Midfielder','Forward','Forward','Goalkeeper','Defender','Defender','Midfielder','Midfielder','Forward','Forward']
hometeamPlayers = ['S. P. Brown','C. Winchester','M. Onariase','W.
Boyle','J. Cranston','H. Pell','J. Rowe','K. Storer','B. Waters','D.
Wright','D. Holman','R. Lovett','J. Barthram','T. Plavotic','J.
Munns','L. Davis','K. Wootton','J. Dayton']
As I will be repeating this process many hundreds of times with different data (same structure) I was wondering if anyone could give me some tips on automatically building these ranges?
Thanks,
Peter
I'm not sure I understood what is the problem you are trying to solve but I'll try to help.
Assuming you have a dictionary team_dict and you want to create 2 list: hometeamPositions and hometeamPlayers you can use the following code:
hometeamPlayers = []
hometeamPositions = []
for player_dict in teams_dict['homeTeam']['lineupsSorted']:
hometeamPlayers.append(player_dict['player']['shortName'])
hometeamPositions.append(player_dict['positionName'])
The output on your example will be:
hometeamPlayers = ['S. P. Brown', 'C. Winchester']
hometeamPositions = ['Goalkeeper', 'Midfielder']

Rails, Highchart maps - adding custom data

I need some basic assistance with a Highmap (via Highcharts) I am trying to put in my Rails 4 app. I suspect I have some fundamental misunderstanding of it but can't find any clear guidance.
See a simple fiddle taken from the documentation, here
http://jsfiddle.net/SimonWalsh/zpdc1btu/
What I ultimately need to do is provide membership numbers for each country so that it will be displayed much the same as the population density is in this map.
I know I need to provide my data and the means to join it to the map data in
series : [{
data : data,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'code'],
name: 'Population density',
states: {
hover: {
color: '#BADA55'
}
}
}]
In this example, I am guessing that the data is being pulled from an external source and that the map data is the 'iso-a2' part of the array.
If this is the case, then why can't I supply this with my data....as an example see the added array with my data.....(just one example given for Denmark)
var mydata = [
{
"iso-a2": "dk",
"value": 30
},
]
and then do
series : [{
data : mydata,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'value'],
name: 'Population density',
states: {
hover: {
color: '#BADA55'
}
}
}]
This does not work.....any guidance at all (other than simply pointing me to docs would be greatly appreciated)
The joinBy specifies on which value you map a country with your data. With
joinBy: ['iso-a2', 'code']
you say that the 'iso-a2' value of the mapData should be equal to the 'code' value of your data. Therefore, your data must have this format:
var mydata = [
{
"code": "dk",
"value": 30
},
/* ... */
]