How to format data to algolia - amazon-dynamodb

I'm learning How to use Algolia and I have a few questions.
I have the table FreightDriver, which has a relationship one to many with the table Truck
id: ID!
name: String!
email: String!
phoneNumber: String!
cities: [String!]!
state: String!
country: String!
picture: String
trucks: [Truck] #connection(keyName: "byFreightDriver", fields: ["id"])
Then, the table Truck, which has a relationship one to one with the table FreightDriver, and another table, which is Box one to one as well
id: ID!
freightDriverId: ID!
boxId: ID!
brand: String!
model: String!
yearModel: Int!
// and more fields
freightDriver: FreightDriver #connection(fields: ["freightDriverId"])
box: Box #connection(fields: ["boxId"])
and the table Box:
id: ID!
type: String!
width: Float!
height: Float!
depth: Float!
I want to find trucks based on the state and city of the FreightDrivers, and also (if the user needs it), find based on the type of box and brand or model of a truck (just as an example).
Example find by state and city of a FreightDriver:
{
"data": {
"freightDriversByState": {
"items": [
{
"name": "Andrés Montoya",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Ganadera",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 12,
"height": 12,
"depth": 12
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 12,
"height": 12,
"depth": 12
}
},
{
"brand": "chevrolet",
"model": "Semi",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Volcadora",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "hola",
"model": "12",
"yearModel": 12,
"box": {
"type": "Plataforma",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 1
}
},
{
"brand": "dasdas",
"model": "12",
"yearModel": 12231,
"box": {
"type": "Grúa",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "Tesla",
"model": "Semi",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 4,
"height": 4,
"depth": 2
}
}
]
}
},
{
"name": "Roberto mendez",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": []
}
},
{
"name": "Fletes Jalisco Sa de Cv ",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2018,
"box": {
"type": "Seca (cerrada)",
"width": 2.7,
"height": 2.5,
"depth": 4.5
}
},
{
"brand": "Hiundai",
"model": "H100",
"yearModel": 2009,
"box": {
"type": "Seca (abierta)",
"width": 2.3,
"height": 2,
"depth": 4
}
},
{
"brand": "Hiundai",
"model": "H100",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 2.35,
"height": 2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2018,
"box": {
"type": "Seca (cerrada)",
"width": 2.7,
"height": 2.2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2004,
"box": {
"type": "Seca (abierta)",
"width": 2.5,
"height": 2,
"depth": 3
}
}
]
}
},
{
"name": "Cotransport",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "Chevrolet",
"model": "CX-5",
"yearModel": 2019,
"box": {
"type": "Seca (cerrada)",
"width": 4,
"height": 3,
"depth": 4
}
}
]
}
},
{
"name": "Andrés",
"cities": [
"EL LIMÓN",
"MAGDALENA",
"SANTA MARÍA DEL ORO",
"GUADALAJARA",
"ETZATLÁN"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
}
]
}
}
]
}
}
}
But, if I want to find using the state and city of a freight driver, the type of box and the model or brand of a truck, that's where the problem comes, because I'm using Dynamodb and this one does not have relationships, so, it's a little bit tricky to get the exact data. That's why I'd like to use Algolia, but how do I format the data for Algolia in this case? What do I need to do? thanks!

If someone is interested, here's the answer https://discourse.algolia.com/t/how-to-format-data-to-algolia/10897

Related

HighCharts: align rotated multiline label

I'm trying to align axis labels in HighCharts
Labels should not be trimed, so ellipsis is not allowed
How it looks now:
How I want it to be:
Code: https://jsfiddle.net/9xw6dL3f/25/
{
"chart": {
"width": 500,
"height": 300,
"type": "column"
},
"title": {
"text": null
},
"xAxis": {
"type": "category",
"labels": {
"rotation": -90,
"style": {
"textOverflow": "none"
}
}
},
"series": [
{
"name": "",
"data": [
{ "name": "Follow me into my theatre of lunacy", "y": -10, "color": "#ABC" },
{ "name": "1", "y": 1, "color": "#000" },
{ "name": "2", "y": 2, "color": "#000" },
{ "name": "3", "y": 3, "color": "#000" },
{ "name": "4", "y": 4, "color": "#000" },
{ "name": "5", "y": 5, "color": "#000" },
]
}
]
}
It is possible to move label depending on it's rows count
Add render function to the chart object
{
"chart": {
...
events: {
render() {
for (let i = 0; i < this.xAxis[0].names.length; i++) {
const label = this.xAxis[0].ticks[i].label;
const rows = (label.element.innerHTML.match(/<\/tspan>/g) || []).length;
label.translate(-8 * rows, 0);
}
}
}
where 8 is half of row size in px
https://jsfiddle.net/kLz1uoga/5/

Turn-by-turn latitude and longitude on HERE Routing API

I want to get the latitude and longitude per instruction on the actions I get from HERE Routing API v8. I get the maneuvers from HERE Routing v7 but not on v8. I tried all the return values.
https://router.hereapi.com/v8/routes?apikey=APIKEY&origin=14.57755,121.04239&destination=14.57735,121.04274&return=polyline,summary,actions,instructions&spans=segmentId&transportMode=car
{
"routes": [{
"id": "bae447cc-a31f-48f7-83a7-2c73c34d492d",
"sections": [{
"id": "152087e3-7f61-451e-b764-e88583586f10",
"type": "vehicle",
"actions": [{
"action": "depart",
"duration": 10,
"length": 76,
"instruction": "Head toward Camiguin on Barangka Dr. Go for 76 m.",
"offset": 0
},
{
"action": "continue",
"duration": 22,
"length": 102,
"instruction": "Continue on 9 de Febrero toward Ortigas Ave/Shaw Blvd. Go for 102 m.",
"offset": 3
},
{
"action": "turn",
"duration": 12,
"length": 53,
"instruction": "Turn right onto Talumpong. Go for 53 m.",
"offset": 7,
"direction": "right",
"severity": "quite"
},
{
"action": "turn",
"duration": 29,
"length": 149,
"instruction": "Turn right onto Tabayog. Go for 149 m.",
"offset": 8,
"direction": "right",
"severity": "quite"
},
{
"action": "arrive",
"duration": 0,
"length": 0,
"instruction": "Arrive at Tabayog. Your destination is on the left.",
"offset": 13
}
],
"departure": {
"time": "2022-02-03T18:59:50+08:00",
"place": {
"type": "place",
"location": {
"lat": 14.5775706,
"lng": 121.0423584
},
"originalLocation": {
"lat": 14.5775499,
"lng": 121.04239
}
}
},
"arrival": {
"time": "2022-02-03T19:01:03+08:00",
"place": {
"type": "place",
"location": {
"lat": 14.5773811,
"lng": 121.0426889
},
"originalLocation": {
"lat": 14.5773499,
"lng": 121.04274
}
}
},
"summary": {
"duration": 73,
"length": 380,
"baseDuration": 65
},
"polyline": "BGm635bs767mHiS0MsEkD8L0KgF0FsEoGgF4IoQsdvb8L3IvRnQze3IvHzK3I9ElD",
"spans": [{
"offset": 0,
"topologySegmentId": "+here:cm:segment:46864687"
},
{
"offset": 3,
"topologySegmentId": "+here:cm:segment:47392105"
},
{
"offset": 7,
"topologySegmentId": "-here:cm:segment:26196228"
},
{
"offset": 8,
"topologySegmentId": "-here:cm:segment:23767715"
},
{
"offset": 10,
"topologySegmentId": "-here:cm:segment:21101714"
}
],
"language": "en-us",
"transport": {
"mode": "car"
}
}],
}],
}
As of 2nd day of February 2022, the position paremeter that outputs latitude and longitude in v7 is not supported in v8 under maneuverAttributes. Source
That is correct in routing V8, there is an offset into polyline in maneuver. Offset is the index into the polyline and all coordinates in V8 work this way. spans, actions, they have offset into the route shape which is an array of coordinates. Example: https://demo.routing.ext.here.com/#url=https://router.hereapi.com/v8/routes?apikey=DEFAULT_API_KEY&origin=52.551325,13.351349&destination=52.514255,13.34929&return=polyline,summary,actions,instructions&transportMode=car

Vega-Lite - Is it possible to have the same selector for two different plots?

I've created a plot using Vega-Lite that allows me to use a binder to alter the parameters of a functions that I'm visualizing. It's similar to this sample code:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Plots two functions using a generated sequence.",
"width": 300,
"height": 150,
"data": {"sequence": {"start": 0, "stop": 12.7, "step": 0.1, "as": "x"}},
"transform": [
{"calculate": "amp.sin * sin(datum.x)", "as": "sin(x)"},
{"calculate": "amp.cos * cos(datum.x)", "as": "cos(x)"},
{"fold": ["sin(x)", "cos(x)"]}
],
"mark": "line",
"encoding": {
"x": {"type": "quantitative", "field": "x"},
"y": {"field": "value", "type": "quantitative"},
"color": {"field": "key", "type": "nominal", "title": null}
},
"selection": {
"amp": {
"type": "single",
"fields": ["sin", "cos"],
"init": {"sin": 1, "cos": 1},
"bind": {
"sin": {"input": "range", "min": 0, "max": 10, "step": 0.1},
"cos": {"input": "range", "min": 0, "max": 10, "step": 0.1}
}
}
}
}
Here is the code above in the Vega editor.
Now, what I'd like to do is to create another visualization parallel to this one, but with another function, but that would also vary with the same binder.
Is this possible? Note that in my code, each plot uses a different dataset, but share the variable of the binder in common.
Yes, for example you can do this using a "concat". Here is an example based on your chart (open in editor):
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Plots two functions using a generated sequence.",
"data": {"sequence": {"start": 0, "stop": 12.7, "step": 0.1, "as": "x"}},
"concat": [
{
"width": 300,
"height": 150,
"transform": [
{"calculate": "amp.sin * sin(datum.x)", "as": "sin(x)"},
{"calculate": "amp.cos * cos(datum.x)", "as": "cos(x)"},
{"fold": ["sin(x)", "cos(x)"]}
],
"mark": "line",
"encoding": {
"x": {"type": "quantitative", "field": "x"},
"y": {"field": "value", "type": "quantitative"},
"color": {"field": "key", "type": "nominal", "title": null}
},
"selection": {
"amp": {
"type": "single",
"fields": ["sin", "cos"],
"init": {"sin": 1, "cos": 1},
"bind": {
"sin": {"input": "range", "min": 0, "max": 10, "step": 0.1},
"cos": {"input": "range", "min": 0, "max": 10, "step": 0.1}
}
}
}
},
{
"width": 300,
"height": 150,
"transform": [
{
"calculate": "amp.cos * cos(datum.x) - amp.sin * sin(datum.x)",
"as": "cos(x) - sin(x)"
}
],
"mark": "line",
"encoding": {
"x": {"type": "quantitative", "field": "x"},
"y": {"field": "cos(x) - sin(x)", "type": "quantitative"}
}
}
],
"resolve": {"scale": {"y": "shared", "color": "independent"}}
}

Highchart Pie Chart not working properly with series

Sample Code
JsFiddle Example for below code.
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares in January, 2018'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [
{
"name": "Display",
"y": 0.1,
"value": 5
},
{
"name": "Paid Social",
"y": 0,
"value": 0,
sliced: true,
selected: true
},
{
"name": "Direct",
"y": 14.5,
"value": 559
},
{
"name": "Referral",
"y": 2,
"value": 77
},
{
"name": "Email",
"y": 4,
"value": 152
},
{
"name": "Other",
"y": 0,
"value": 1
},
{
"name": "Organic Search",
"y": 23.4,
"value": 901
},
{
"name": "Meta Search",
"y": 0.2,
"value": 5
},
{
"name": "Organic Social",
"y": 2.4,
"value": 93
},
{
"name": "Directory",
"y": 0.2,
"value": 9
},
{
"name": "Other Advertising",
"y": 0.1,
"value": 3
},
{
"name": "OTA Referral Traffic",
"y": 0.7,
"value": 26
},
{
"name": "Paid Search",
"y": 27.8,
"value": 1068
},
{
"name": "Local",
"y": 24.5,
"value": 941
}]
}]
});
Scenario
I want to display dataLabels for all even y value is zero.
In Above code We have "name": "Display" y=0.1 but still it is not displaying in Pie Chart don't know why. If any one have idea about this problem please let me know.
The dataLabels are hidden due to lack of space and overlapping. As a solution you can set: padding: 0
plotOptions: {
pie: {
...,
dataLabels: {
padding: 0,
...
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/g5s27tyb/
API Reference: https://api.highcharts.com/highcharts/plotOptions.pie.dataLabels.padding

Not getting company names from LinkedIn people API

I recently noticed that, when I access some users via the peopla API, I do not get the company names in their positions.
E.g.
I ask: /v1/people/~:(id,first-name,last-name,positions:(title,summary,start-date,end-date,company:(id,name)))
I get:
{
"firstName": "xxxxx",
"id": "WzdY2z96Tw",
"lastName": "xxxx",
"positions": {
"_total": 12,
"values": [
{
"company": {},
"startDate": {
"month": 4,
"year": 2015
}
},
{
"company": {"id": 1970},
"endDate": {
"month": 11,
"year": 2014
},
"startDate": {
"month": 7,
"year": 2008
}
},
{
"company": {},
"endDate": {
"month": 7,
"year": 2008
},
"startDate": {
"month": 4,
"year": 2006
}
},
{
"company": {"id": 1159270},
"endDate": {
"month": 1,
"year": 2006
},
"startDate": {
"month": 5,
"year": 2004
}
},
{
"company": {"id": 106859},
"endDate": {
"month": 5,
"year": 2004
},
"startDate": {
"month": 1,
"year": 2003
}
},
{
"company": {"id": 106859},
"endDate": {
"month": 1,
"year": 2003
},
"startDate": {
"month": 5,
"year": 2001
}
},
{
"company": {},
"endDate": {
"month": 5,
"year": 2001
},
"startDate": {
"month": 1,
"year": 1999
}
},
{
"company": {},
"endDate": {"year": 1998},
"startDate": {"year": 1995}
},
{
"company": {},
"endDate": {"year": 1995},
"startDate": {"year": 1994}
},
{
"company": {},
"endDate": {"year": 1994},
"startDate": {"year": 1993}
},
{
"company": {},
"endDate": {"year": 1993},
"startDate": {"year": 1991}
},
{
"company": {},
"endDate": {"year": 1991},
"startDate": {"year": 1988}
}
]
}
}
(I changed the name to x'es for privacy reasons)
So, as you can see, I don't get the company names back.
I do get the company names back for other users.
What can I do?
/v1/people/~:(id,first-name,last-name,positions) enough for retrieving company names.

Resources