Faceting a Layered Plot Vega-Lite Deneb - powerbi

wonder if you could help me out on the below.
I´m using Deneb to visualize small multiples in PBI and I´m not able to find out how to add text labels above/below the bar.
Does anyone know the workaround by chance?
Here´s the code that I´m using so far:
{
"data": {"values": [
{"Region":"A","Month":"1","Difference":"-0.01"},
{"Region":"A","Month":"2","Difference":"0"},
{"Region":"A","Month":"3","Difference":"-0.03"},
{"Region":"A","Month":"4","Difference":"-0.01"},
{"Region":"A","Month":"5","Difference":"-0.01"},
{"Region":"A","Month":"6","Difference":"0.05"},
{"Region":"A","Month":"7","Difference":"-0.05"},
{"Region":"A","Month":"8","Difference":"-0.03"},
{"Region":"A","Month":"9","Difference":"0.03"},
{"Region":"A","Month":"10","Difference":"-0.01"},
{"Region":"A","Month":"11","Difference":"-0.01"},
{"Region":"A","Month":"12","Difference":"0.03"},
{"Region":"B","Month":"1","Difference":"-0.02"},
{"Region":"B","Month":"2","Difference":"-0.02"},
{"Region":"B","Month":"3","Difference":"0.02"},
{"Region":"B","Month":"4","Difference":"0.03"},
{"Region":"B","Month":"5","Difference":"-0.05"},
{"Region":"B","Month":"6","Difference":"-0.02"},
{"Region":"B","Month":"7","Difference":"-0.01"},
{"Region":"B","Month":"8","Difference":"0.03"},
{"Region":"B","Month":"9","Difference":"-0.03"},
{"Region":"B","Month":"10","Difference":"-0.03"},
{"Region":"B","Month":"11","Difference":"0.01"},
{"Region":"B","Month":"12","Difference":"-0.02"},
{"Region":"C","Month":"1","Difference":"-0.05"},
{"Region":"C","Month":"2","Difference":"-0.04"},
{"Region":"C","Month":"3","Difference":"-0.03"},
{"Region":"C","Month":"4","Difference":"0"},
{"Region":"C","Month":"5","Difference":"0"},
{"Region":"C","Month":"6","Difference":"-0.02"},
{"Region":"C","Month":"7","Difference":"-0.05"},
{"Region":"C","Month":"8","Difference":"0.02"},
{"Region":"C","Month":"9","Difference":"0"},
{"Region":"C","Month":"10","Difference":"-0.03"},
{"Region":"C","Month":"11","Difference":"-0.03"},
{"Region":"C","Month":"12","Difference":"0.02"},
{"Region":"D","Month":"1","Difference":"0.05"},
{"Region":"D","Month":"2","Difference":"-0.02"},
{"Region":"D","Month":"3","Difference":"-0.05"},
{"Region":"D","Month":"4","Difference":"-0.05"},
{"Region":"D","Month":"5","Difference":"0"},
{"Region":"D","Month":"6","Difference":"-0.01"},
{"Region":"D","Month":"7","Difference":"0.02"},
{"Region":"D","Month":"8","Difference":"-0.01"},
{"Region":"D","Month":"9","Difference":"0"},
{"Region":"D","Month":"10","Difference":"-0.01"},
{"Region":"D","Month":"11","Difference":"0.01"},
{"Region":"D","Month":"12","Difference":"-0.03"}
]},
"mark": {
"type": "bar",
"stroke": "black",
"opacity": 1,
"cornerRadius": 2,
"tooltip":true
},
"width": 440,
"height": 75,
"cornerRadius": 2,
"encoding": {
"facet": {
"field": "Region",
"type": "ordinal",
"title": null,
"columns": 2
},
"x": {
"field": "Month",
"type": "ordinal",
"axis": {"labelAngle": 0}
},
"y": {
"field": "Difference",
"type": "quantitative",
"axis": {
"format": "0%",
"formatType": "pbiFormat"
}
},
"color": {
"condition": {
"test": "datum['Difference']<0",
"value": "#F78272"
},
"value": "#F2C80F"
},
"text": {
"field": "Difference",
"type": "quantitative"
}
}
}
Many thanks in advance!
*edit1: added desired output
*edit2: added dataset into the code
Desired outcome:

How's this?
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"Region": "A", "Month": "1", "Difference": "-0.01"},
{"Region": "A", "Month": "2", "Difference": "0"},
{"Region": "A", "Month": "3", "Difference": "-0.03"},
{"Region": "A", "Month": "4", "Difference": "-0.01"},
{"Region": "A", "Month": "5", "Difference": "-0.01"},
{"Region": "A", "Month": "6", "Difference": "0.05"},
{"Region": "A", "Month": "7", "Difference": "-0.05"},
{"Region": "A", "Month": "8", "Difference": "-0.03"},
{"Region": "A", "Month": "9", "Difference": "0.03"},
{"Region": "A", "Month": "10", "Difference": "-0.01"},
{"Region": "A", "Month": "11", "Difference": "-0.01"},
{"Region": "A", "Month": "12", "Difference": "0.03"},
{"Region": "B", "Month": "1", "Difference": "-0.02"},
{"Region": "B", "Month": "2", "Difference": "-0.02"},
{"Region": "B", "Month": "3", "Difference": "0.02"},
{"Region": "B", "Month": "4", "Difference": "0.03"},
{"Region": "B", "Month": "5", "Difference": "-0.05"},
{"Region": "B", "Month": "6", "Difference": "-0.02"},
{"Region": "B", "Month": "7", "Difference": "-0.01"},
{"Region": "B", "Month": "8", "Difference": "0.03"},
{"Region": "B", "Month": "9", "Difference": "-0.03"},
{"Region": "B", "Month": "10", "Difference": "-0.03"},
{"Region": "B", "Month": "11", "Difference": "0.01"},
{"Region": "B", "Month": "12", "Difference": "-0.02"},
{"Region": "C", "Month": "1", "Difference": "-0.05"},
{"Region": "C", "Month": "2", "Difference": "-0.04"},
{"Region": "C", "Month": "3", "Difference": "-0.03"},
{"Region": "C", "Month": "4", "Difference": "0"},
{"Region": "C", "Month": "5", "Difference": "0"},
{"Region": "C", "Month": "6", "Difference": "-0.02"},
{"Region": "C", "Month": "7", "Difference": "-0.05"},
{"Region": "C", "Month": "8", "Difference": "0.02"},
{"Region": "C", "Month": "9", "Difference": "0"},
{"Region": "C", "Month": "10", "Difference": "-0.03"},
{"Region": "C", "Month": "11", "Difference": "-0.03"},
{"Region": "C", "Month": "12", "Difference": "0.02"},
{"Region": "D", "Month": "1", "Difference": "0.05"},
{"Region": "D", "Month": "2", "Difference": "-0.02"},
{"Region": "D", "Month": "3", "Difference": "-0.05"},
{"Region": "D", "Month": "4", "Difference": "-0.05"},
{"Region": "D", "Month": "5", "Difference": "0"},
{"Region": "D", "Month": "6", "Difference": "-0.01"},
{"Region": "D", "Month": "7", "Difference": "0.02"},
{"Region": "D", "Month": "8", "Difference": "-0.01"},
{"Region": "D", "Month": "9", "Difference": "0"},
{"Region": "D", "Month": "10", "Difference": "-0.01"},
{"Region": "D", "Month": "11", "Difference": "0.01"},
{"Region": "D", "Month": "12", "Difference": "-0.03"}
]
},
"spec": {
"width": 440,
"height": 75,
"encoding": {
"x": {"field": "Month", "type": "ordinal", "axis": {"labelAngle": 0}},
"y": {
"field": "Difference",
"type": "quantitative",
"axis": {"format": "0%", "formatType": "pbiFormat"}
},
"color": {
"condition": {"test": "datum['Difference']<0", "value": "#F78272"},
"value": "#F2C80F"
}
},
"layer": [
{
"mark": {
"type": "bar",
"stroke": "black",
"opacity": 1,
"cornerRadius": 2,
"tooltip": true
}
},
{
"mark": {
"type": "text",
"dy": {"expr": "datum.Difference < 0 ? 10 : -10"}
},
"encoding": {"text": {"field": "Difference", "type": "quantitative"}}
}
]
},
"facet": {"field": "Region", "type": "ordinal", "title": null},
"columns": 2
}

Related

How do you change the font formatting of a single axis label value

I have a text field ['Region'] with four values {Global, AMER, APAC, EMEA}. I have a simple bar chart and want the label to be bold only for 'Global' but have been unable to do so.
I tried:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": { "values": [
{"Region": "Global", "Months": 1, "RegionRank":1},
{"Region": "AMER", "Months": -1, "RegionRank":2},
{"Region": "APAC", "Months": 3, "RegionRank":3}, {"Region": "EMEA", "Months": 2, "RegionRank":4}
]},
"layer": [
{
"mark": {
"type": "bar",
"filled": false,
"stroke": "gray",
"strokeDash": [3.6],
"strokeWidth": 3
}
},
{
"mark": {
"type": "text",
"fontSize": 14,
"xOffset": {
"expr": "datum['Months']<0 ? -15:15"
}
},
"encoding": {
"text": {
"field": "Months",
"format": "+.0f"
}
}
}
],
"encoding": {
"y": {
"field": "Region",
"type": "nominal",
"axis": {
"offset": 10,
"title": null,
// problem section
"labelFontWeight": {
"condition": {"test": "datum['Region'] == 'Global'","value":"bold"},
"value":"normal"
}
},
"sort": {
"op": "min",
"field": "RegionRank",
"order": "ascending"
}
},
"x": {
"field": "Months",
"type": "quantitative",
"axis": {"title": null}
}
}
}
but there is no change to the label font weight.
What is interesting is that I switched the result conditions, making the '==Global' result "normal" and the else "bold" and it changed font weight on all the labels to bold. That leads me to believe that my condition is never being evaluated as true. Any ideas why? Is what I want to do - changing a signal value in an axis label - possible?
You mean like this?
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"Region": "Global", "Months": 1, "RegionRank": 1},
{"Region": "AMER", "Months": -1, "RegionRank": 2},
{"Region": "APAC", "Months": 3, "RegionRank": 3},
{"Region": "EMEA", "Months": 2, "RegionRank": 4}
]
},
"layer": [
{
"mark": {
"type": "bar",
"filled": false,
"stroke": "gray",
"strokeDash": [3.6],
"strokeWidth": 3
}
},
{
"mark": {
"type": "text",
"fontSize": 14,
"xOffset": {"expr": "datum['Months']<0 ? -15:15"}
},
"encoding": {"text": {"field": "Months", "format": "+.0f"}}
}
],
"encoding": {
"y": {
"field": "Region",
"type": "nominal",
"axis": {
"offset": 10,
"title": null,
"labelFontWeight": {
"condition": {"test": "datum.label == 'Global'", "value": "bold"},
"value": "normal"
}
},
"sort": {"op": "min", "field": "RegionRank", "order": "ascending"}
},
"x": {"field": "Months", "type": "quantitative", "axis": {"title": null}}
}
}

Passing varibles from API to template in Django

I am working on building a flight price search website as part of a project and have managed to get most of the functionality I require working.
Here's what the front-end looks like so far:
When users enter in the details, a POST request is sent to an API.
API: https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-search
API Python SDK: https://github.com/amadeus4dev/amadeus-python
I'm receiving a response from the API; however, am struggling to understand what I should then do with the information received. The next step is to pass the information from the API into a search results template and split out all of the received flight information, similar to how it is displayed on Sky Scanner:
Below is what I have in my views.py so far (currently passing in the whole response, in what I believe is JSON format?)
Views.py:
def flight_search(request):
kwargs = {'originLocationCode': request.POST.get('Origincity'),
'destinationLocationCode': request.POST.get('Destinationcity'),
'departureDate': request.POST.get('Departuredate'),
'returnDate': request.POST.get('Returndate'),
'adults': '1'}
try:
response = amadeus.shopping.flight_offers_search.get(
**kwargs)
print(response.data)
return render(request, "flightfinder/flight_search.html", {
"response": response
})
except ResponseError as error:
raise error
Here is an example response from the API:
{
"meta": {
"count": 2
},
"data": [
{
"type": "flight-offer",
"id": "1",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"oneWay": false,
"lastTicketingDate": "2020-11-20",
"numberOfBookableSeats": 2,
"itineraries": [
{
"duration": "PT22H40M",
"segments": [
{
"departure": {
"iataCode": "GIG",
"terminal": "2",
"at": "2020-12-01T16:30:00"
},
"arrival": {
"iataCode": "CDG",
"terminal": "2E",
"at": "2020-12-02T07:45:00"
},
"carrierCode": "AF",
"number": "443",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT11H15M",
"id": "3",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "ORY",
"terminal": "2",
"at": "2020-12-02T17:10:00"
},
"arrival": {
"iataCode": "MAD",
"terminal": "2",
"at": "2020-12-02T19:10:00"
},
"carrierCode": "AF",
"number": "4792",
"aircraft": {
"code": "73H"
},
"operating": {
"carrierCode": "UX"
},
"duration": "PT2H",
"id": "4",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
},
{
"duration": "PT15H5M",
"segments": [
{
"departure": {
"iataCode": "MAD",
"terminal": "2",
"at": "2020-12-12T20:05:00"
},
"arrival": {
"iataCode": "CDG",
"terminal": "2F",
"at": "2020-12-12T22:20:00"
},
"carrierCode": "AF",
"number": "1101",
"aircraft": {
"code": "319"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT2H15M",
"id": "5",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "CDG",
"terminal": "2E",
"at": "2020-12-12T23:35:00"
},
"arrival": {
"iataCode": "GIG",
"terminal": "2",
"at": "2020-12-13T07:10:00"
},
"carrierCode": "AF",
"number": "442",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT11H35M",
"id": "6",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
}
],
"price": {
"currency": "USD",
"total": "2324.04",
"base": "2089.00",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
}
],
"grandTotal": "2324.04"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": false
},
"validatingAirlineCodes": [
"AF"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "USD",
"total": "1311.52",
"base": "1194.00"
},
"fareDetailsBySegment": [
{
"segmentId": "3",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "O",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "4",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "J",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "5",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "L",
"includedCheckedBags": {
"quantity": 0
}
},
{
"segmentId": "6",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "R",
"includedCheckedBags": {
"quantity": 0
}
}
]
},
{
"travelerId": "2",
"fareOption": "STANDARD",
"travelerType": "CHILD",
"price": {
"currency": "USD",
"total": "1012.52",
"base": "895.00"
},
"fareDetailsBySegment": [
{
"segmentId": "3",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "O"
},
{
"segmentId": "4",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "J"
},
{
"segmentId": "5",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "L"
},
{
"segmentId": "6",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "R"
}
]
}
]
},
{
"type": "flight-offer",
"id": "2",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"oneWay": false,
"lastTicketingDate": "2020-11-20",
"numberOfBookableSeats": 2,
"itineraries": [
{
"duration": "PT15H10M",
"segments": [
{
"departure": {
"iataCode": "GIG",
"terminal": "2",
"at": "2020-12-01T16:30:00"
},
"arrival": {
"iataCode": "CDG",
"terminal": "2E",
"at": "2020-12-02T07:45:00"
},
"carrierCode": "AF",
"number": "443",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT11H15M",
"id": "1",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "CDG",
"terminal": "2F",
"at": "2020-12-02T09:35:00"
},
"arrival": {
"iataCode": "MAD",
"terminal": "2",
"at": "2020-12-02T11:40:00"
},
"carrierCode": "AF",
"number": "1300",
"aircraft": {
"code": "319"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT2H5M",
"id": "2",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
},
{
"duration": "PT15H5M",
"segments": [
{
"departure": {
"iataCode": "MAD",
"terminal": "2",
"at": "2020-12-12T20:05:00"
},
"arrival": {
"iataCode": "CDG",
"terminal": "2F",
"at": "2020-12-12T22:20:00"
},
"carrierCode": "AF",
"number": "1101",
"aircraft": {
"code": "319"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT2H15M",
"id": "5",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "CDG",
"terminal": "2E",
"at": "2020-12-12T23:35:00"
},
"arrival": {
"iataCode": "GIG",
"terminal": "2",
"at": "2020-12-13T07:10:00"
},
"carrierCode": "AF",
"number": "442",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT11H35M",
"id": "6",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
}
],
"price": {
"currency": "USD",
"total": "2334.44",
"base": "2089.00",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
}
],
"grandTotal": "2334.44"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": false
},
"validatingAirlineCodes": [
"AF"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "USD",
"total": "1316.72",
"base": "1194.00"
},
"fareDetailsBySegment": [
{
"segmentId": "1",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "O",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "2",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "J",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "5",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "L",
"includedCheckedBags": {
"quantity": 0
}
},
{
"segmentId": "6",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "R",
"includedCheckedBags": {
"quantity": 0
}
}
]
},
{
"travelerId": "2",
"fareOption": "STANDARD",
"travelerType": "CHILD",
"price": {
"currency": "USD",
"total": "1017.72",
"base": "895.00"
},
"fareDetailsBySegment": [
{
"segmentId": "1",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "O"
},
{
"segmentId": "2",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "J"
},
{
"segmentId": "5",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "L"
},
{
"segmentId": "6",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "R"
}
]
}
]
}
],
"dictionaries": {
"locations": {
"MAD": {
"cityCode": "MAD",
"countryCode": "ES"
},
"GIG": {
"cityCode": "RIO",
"countryCode": "BR"
},
"CDG": {
"cityCode": "PAR",
"countryCode": "FR"
},
"ORY": {
"cityCode": "PAR",
"countryCode": "FR"
}
},
"aircraft": {
"77W": "BOEING 777-300ER",
"319": "AIRBUS A319",
"73H": "BOEING 737-800 (WINGLETS)"
},
"currencies": {
"USD": "US DOLLAR"
},
"carriers": {
"UX": "AIR EUROPA",
"AF": "AIR FRANCE"
}
}
}
My question is: how should I pass this information to the search results template so that I can populate the page with all of the flight information?
Should I pull out the information I need into lists and then pass these through to the template which displays the flight search results? (I'm not sure how I would then ensure the information pertained to a particular flight on the search results template)
Or should I simply pass the response and then extract the information from it on the template?
My apologies for the vague question here, please let me know if you require any additional information - I'm essentially stuck on how to handle this response and would really appreciate any guidance that anybody has.
Thank you!

ChartJS How to provide an array of objects as a dataset?

I've got a dataset that looks like so;
[
"transactions": [
{
"month": "Dec",
"data": [
{
"id": "333a32c6-eaf0-3f11-8a2b-963282fb700c",
"amount": "776",
"created_at": "2019-12-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
},
{
"id": "36688452-92f2-3ae7-911a-9543fe29cae6",
"amount": "1798",
"created_at": "2019-12-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
},
{
"id": "67856ceb-1eb5-369b-b3c1-7bd92c037c70",
"amount": "9507",
"created_at": "2019-12-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
},
{
"id": "7e9465be-0151-3828-b429-2b7c4db2aa5e",
"amount": "944",
"created_at": "2019-12-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
},
{
"id": "dd5019b5-690b-33e0-a633-de6162cd687a",
"amount": "5327",
"created_at": "2019-12-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
},
{
"id": "eb5f1473-e871-357d-be3c-af2dc00ff22d",
"amount": "4638",
"created_at": "2019-12-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
}
]
},
{
"month": "Mar",
"data": [
{
"id": "5929f7ad-7ad5-35dc-9935-c06bc0283f20",
"amount": "5251",
"created_at": "2019-03-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
}
]
},
{
"month": "Nov",
"data": [
{
"id": "8c36b5dd-2b15-3024-83f4-551df33d9fcc",
"amount": "3643",
"created_at": "2019-11-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
},
{
"id": "abcd4af5-7a7e-3a9b-8c02-f251f6724062",
"amount": "2622",
"created_at": "2019-11-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
}
]
},
{
"month": "Oct",
"data": [
{
"id": "925b5efb-7933-396e-96ab-9473a93009ff",
"amount": "8674",
"created_at": "2019-10-04 10:57:50",
"updated_at": "2019-12-04 10:57:50"
}
]
}
]
]
Basically I want to show a chart with all the months of the year, and if they aren't present in the transactions array, it returns just 0 for that month on the chart.
How would I go about parsing this object and making sure it all matches up with my labels on my chart? All examples in the documentation use really basic integer's as the dataset and there are no examples I could find of using an object!

Test script inside to postman on by get data for keep in variable?

I need to store values from response data (below) in variable.
Response Body:
{
"data": {
"packages": [
{
"object": "AAA",
"id": "BBB",
"code": "123",
"name": "Test8",
"description": "Test111",
"fee": "130.00 bath",
"productSeq": "3"
}, {
"object": "AAA",
"id": "CCC",
"code": "456",
"name": "Test9",
"description": "Test222",
"fee": "80.00 bath",
"productSeq": "2"
}, {
"object": "AAA",
"id": "CCC",
"code": "789",
"name": "Test10",
"description":"Test111",
"fee": "70.00 bath",
"productSeq": "1"
}
]
},
"resultCode": "20000",
"resultDesc": "Success",
"developerMessage": "Success"
}
If the id value of an object in the response is "CCC", I need to store that data like this, in a variable:
{
"object": "AAA",
"id": "CCC",
"code": "456",
"name": "Test9",
"description": "Test222",
"fee": "80.00 bath",
"productSeq": "2"
}, {
"object": "AAA",
"id": "CCC",
"code": "789",
"name": "Test10",
"description":"Test111",
"fee": "70.00 bath",
"productSeq": "1"
}
Can you help me create the script that would do that?
You can do it like this: -
var body = JSON.parse(responseBody)
var objArray = [];
for (i=0; i<body.data.packages.length;i++){
if (body.data.packages[i].id === "CCC"){
objArray.push(body.data.packages[i]);
}
}
postman.setEnvironmentVariable("varName", objArray)

Issue with variable values in selenium grid execution

We are using selenium grid to all UI testcases.
We are facing issue when any variable having value 1 which is getting entered into any text field.
e.g.
set test variable ${data} 1
input text ${data}
if a variable has value set to 1 but below value is getting set:
/tmp/21fe989d-6c5d-413b-8365-cf6da42e92b9/upload957182740231871694file/1
Due to this testcases are failing as text field expectes int but it gets above value.
I am not sure from where "/tmp/21fe989d-6c5d-413b-8365-cf6da42e92b9/upload957182740231871694file/" this part is getting appended to the variable value.
This is strage as it happens only when value is 1.
Below is the detail log from test exection:
16:56:00.882 INFO Typing text '1' into text field 'xpath=//input[#name='floorValue']'
16:56:00.883 DEBUG POST http://192.168.1.201:4444/wd/hub/session/e8d83ee3-7a75-40cd-a079-bb2c83d6fb2e/elements {"using": "xpath", "sessionId": "e8d83ee3-7a75-40cd-a079-bb2c83d6fb2e", "value": "//input[#name='floorValue']"}
16:56:00.905 DEBUG Finished Request
16:56:00.905 DEBUG POST http://192.168.1.201:4444/wd/hub/session/e8d83ee3-7a75-40cd-a079-bb2c83d6fb2e/element/26/clear {"sessionId": "e8d83ee3-7a75-40cd-a079-bb2c83d6fb2e", "id": "26"}
16:56:00.931 DEBUG Finished Request
16:56:00.933 DEBUG POST http://192.168.1.201:4444/wd/hub/session/e8d83ee3-7a75-40cd-a079-bb2c83d6fb2e/file {"sessionId": "e8d83ee3-7a75-40cd-a079-bb2c83d6fb2e", "id": "26", "file": "UEsDBBQAAAAIAGJU9Uhr90YTkgoAAF5CAAABAAAAMe1bbW/bOBL+HP8Kwf5g+dZRGvd6iwtOi3Ob\n9tBDui2SvuCQBAQtMTa7suQVqdTeX398lUhJfpHk7uWA+kMiUjMPh8OZ4QwlDR7SZOkEyXKZxCCj\nOMIUI+JdYUIvIYUOXq6SlDq63asnX6BohVJNnCIY0iTEAZXkaTJLqBfhWQpTTv0ywxF9G2ty1ezl\n3PqK0BTH87wfxmGy1C2KlzldQnKOTX4ZQooEkRBBt5yD747FECGK9KTlLOAKa6oomc9RKm/eoAjF\nOFtOrsQsN5qm3F9P/XpNUUxwEpNtfAVFj/0GDvHLFO6oNyBoUukvODmFk6WR4zv9BaWri7Oz858n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RdTxHUmbZrGbZJQpwD+GYHeU\nyeStlxGTprdNZddChC8pG5+py2wdRTmGDN43DgvknInLjS2l/vBogyzoMhqOo2R+HEwGJCFH0hr/\nC1BLAQIUAxQAAAAIAGJU9Uhr90YTkgoAAF5CAAABAAAAAAAAAAAAAACkgQAAAAAxUEsFBgAAAAAB\nAAEALwAAALEKAAAAAA==\n"}
16:56:00.943 DEBUG Finished Request
16:56:00.944 DEBUG POST http://192.168.1.201:4444/wd/hub/session/e8d83ee3-7a75-40cd-a079-bb2c83d6fb2e/element/26/value {"sessionId": "e8d83ee3-7a75-40cd-a079-bb2c83d6fb2e", "id": "26", "value": ["/", "t", "m", "p", "/", "e", "8", "d", "8", "3", "e", "e", "3", "-", "7", "a", "7", "5", "-", "4", "0", "c", "d", "-", "a", "0", "7", "9", "-", "b", "b", "2", "c", "8", "3", "d", "6", "f", "b", "2", "e", "/", "u", "p", "l", "o", "a", "d", "6", "0", "5", "4", "3", "8", "4", "5", "8", "0", "2", "8", "1", "8", "0", "7", "9", "3", "f", "i", "l", "e", "/", "1"]}"