Thank you in advance to whoever can help me. I am trying to show data in expandable rows in tabular format. How can i groupby with multiple keys like height,type and rank.
I know stackoverflow is not for asking for code but being noob and beginner, stackoverflow is the only option i have. Please show your talent to help me out.
I need this for First semester 1 credit college project.
i have a object
const sensorData = [{
"id": 19,
"height": 3.0,
"orientation": null,
"rank": "Primary",
"relativeHeight": 4,
"stat": "min",
"type": "wdir",
},
{
"id": 19,
"height": 3.0,
"orientation": null,
"rank": "Primary",
"relativeHeight": 6,
"stat": "min",
"type": "wdir",
},
{
"id": 19,
"height": 1.0,
"orientation": null,
"rank": "Primary",
"relativeHeight": 6,
"stat": "min",
"type": "wdir",
}]
The output i want is:
[
{
"isExpandable":true,
"common":{
"height":3.0,
"rank":"Primary",
"type":"wdir"
},
"data":[
{
"id":19,
"orientation":null,
"relativeHeight":4,
"stat":"max"
},
{
"id":19,
"orientation":null,
"relativeHeight":6,
"stat":"min"
}
]
},
{
"isExpandable":false,
"id":19,
"height":1.0,
"orientation":null,
"rank":"Primary",
"relativeHeight":6,
"stat":"min",
"type":"wdir"
}
]
I found reduce and lodash (_groupBy) very difficult to achieve this.
Updated:
isExpandable is decided if any attribute are matched or object can be grouped.
Thanks
Related
i have made some charts for spreader beams in Amcharts (Worpress) and want to change the toolstips,
reverse the order of the 2 values.
append "tonnes" and "metres" after the respective values.
I can swap the order they appear in the code to change the order they appear, but how to append in plain text after the digit values so it shows "8 tonnes: 2 metres"?
Code for these is below in the tooltipText:
"series": [{
"type": "LineSeries",
"name": "30° Sling To Vertical Angle",
"xAxis": "id-1",
"yAxis": "id-2",
"baseAxis": "id-1",
"dataFields": {
"valueY": "value1",
"categoryX": "category"
},
"fillOpacity": 0.5,
"strokeWidth": 2,
"sequencedInterpolation": true,
"sequencedInterpolationDelay": 100,
"tooltipText": "{name}\n{categoryX}: {valueY}"
}, {
"type": "LineSeries",
"name": "45° Sling To Vertical Angle",
"xAxis": "id-1",
"yAxis": "id-2",
"dataFields": {
"valueY": "value2",
"categoryX": "category"
},
"simplifiedProcessing": true,
"calculatePercent": true,
"fillOpacity": 0.5,
"strokeWidth": 2,
"sequencedInterpolation": true,
"sequencedInterpolationDelay": 100,
"tooltipText": "{name}\n{categoryX}: {valueY}"
url is https://applifting.ga/modular-spreader-beams/sectionlift-6/
Thanks
Just swapped the order of the tool tip values and appended in plain text the denominator.
I would like to know how can I integrate some coding (python or javascript) in my dialog, in order to avoid the very limited bluemix interface for example for loops, or text mining.
EX : I am creating a pizza chatbot and I need to be able to process this kind of request :
I would like 2 margarita whose one with extra cheese and the other with pepperoni and a regina, with 3 diet cokes and two beers
It is just impossible to do it with bluemix.
If anyone has a solution I would be very grateful.
Thanks
So the first thing to understand is that Conversation has good and bad use cases.
If your user can enter in structured data, then it is better to use a form. Be that in the conversation window (like Watson Virtual Agent), or a form on your site/app.
So your example doesn't look like a good use case.
That said...
With your example it's possible if your main items are entities, and you haver #sys-number system entity enabled. You can then check the entities array to see distance from each other.
Example
Created the following entities.
#PizzaType
#PizzaTopping
#Drinks
When I ask your question, the entities object returns the following:
[
{
"entity": "Drinks",
"location": [
104,
114
],
"value": "diet coke",
"confidence": 1
},
{
"entity": "PizzaType",
"location": [
72,
81
],
"value": "Pepperoni",
"confidence": 1
},
{
"entity": "Drinks",
"location": [
123,
128
],
"value": "beer",
"confidence": 1
},
{
"entity": "PizzaType",
"location": [
88,
94
],
"value": "Regina",
"confidence": 1
},
{
"entity": "PizzaTopping",
"location": [
46,
52
],
"value": "cheese",
"confidence": 1
},
{
"entity": "PizzaType",
"location": [
15,
24
],
"value": "Margarita",
"confidence": 1
},
{
"entity": "sys-number",
"location": [
13,
14
],
"value": "2",
"confidence": 1,
"metadata": {
"numeric_value": 2
}
},
{
"entity": "sys-number",
"location": [
31,
34
],
"value": "1",
"confidence": 1,
"metadata": {
"numeric_value": 1
}
},
{
"entity": "sys-number",
"location": [
101,
102
],
"value": "3",
"confidence": 1,
"metadata": {
"numeric_value": 3
}
},
{
"entity": "sys-number",
"location": [
119,
122
],
"value": "2",
"confidence": 1,
"metadata": {
"numeric_value": 2
}
}
]
A summary of that is:
You can see straight away there are some issues there. If the user doesn't mention a number, you have to account for that. Also something like this question would break it as well (unless you cater for it).
I would like margarita pizzas (two).
But the important point is to build your system with representative questions. Your example question may never be asked by an end user, or you can even shape the conversation to prevent such an input.
Highcharts ng heatmap draw line instead of boxes
$scope.chartConfig = {
"chart": {
"type": "heatmap"
},
"credits": {
"enabled": false
},
"size": {
"height": 1000
},
"title": {
"text": ""
},
"xAxis": {
"categories": ["23-02-2005", "24-02-2005", "27-02-2005", "28-02-2005", "01-03-2005", "02-03-2005"]
},
"yAxis": {
"categories": ["Bond2Y", "Bond3Y"],
"title": null
},
"series": [{
"name": "Trades Data",
"borderWidth": 1,
"data": [
[0, 0, 0.7642386249005615],
[0, 1, 0.5010608923969173],
[1, 0, 0.5009742082142428],
[1, 1, 0.9114076033035807]
],
"dataLabels": {
"enabled": false,
"color": "#000000"
}
}]
}
Angular Highcharts
When i place these config with JQuery Its works fi
jQuery Highcharts
Is this is the highcharts-ng issue ?
When I checked your fiddle I had observed that you have not included the heatmap.js library.
Also, You need to move your chart and colorAxis inside the options block.
Check the below working fiddle link in which you can see the square blocks identical to your jQuery example.
Working Fiddle: http://jsfiddle.net/y9wjy0kz/10/
Hope this helps!
I am using an API that returns the following JSON:
I want to access the data in "value", but I have no idea how to do it. I don't want to mess around too often, because the API has a limited amount of credits and costs money.
EDIT: Sample JSON:
{
"method": [
["somename"]
],
"answer": [{
"name": [{
"domain": "somedomain",
"date": "somedate",
"value": "somenumber"
}]
}],
"credits": [{
"used": 1
}]
}
EDIT2: I honestly don't get why this is being downvoted.
The correct path is :
json.answer[0].name[0].value
You will get value by
jsonData.answer[0].name[0].value
Try this:
jsonData[1].answer[0][0].value
{
"method": [
["somename"]
],
"answer": [{
"name": [{
"domain": "somedomain",
"date": "somedate",
"value": "somenumber"
}]
}],
"credits": [{
"used": 1
}]
}
answer would be obj.answer[0].name[0].value
I have two rails models:
A Milestone has many Tasks
A Task belongs to a Milestone
In my controller I call the following:
#milestones = Milestone.all
render :json => #milestones.to_json(:include => :tasks)
Which gives me:
[ {
"id": 5,
"name": "This is milestone #1",
"tasks": [{
"complete": false,
"id": 60,
"name": "aaaaa",
"milestone_id": 5,
}, {
"complete": false,
"id": 62,
"name": "ccccc",
"milestone_id": 5,
}
]
}, {
"id": 6,
"name": "This is milestone #2",
"tasks": [{
"complete": false,
"id": 65,
"name": "ffffff",
"milestone_id": 5,
}, {
"complete": false,
"id": 66,
"name": "gggggg",
"milestone_id": 5,
}
]
}
]
But I need to be able to easily navigate through the JSON, so I'd like to be able to format it like this (notice each "sub array" is labeled with "milestone_ID" or "task_ID"):
[
"milestone_5": {
"id": 5,
"name": "This is milestone #1",
"tasks": [
"task_60":{
"complete": false,
"id": 60,
"name": "aaaaa",
"milestone_id": 5,
},
"task_62":{
"complete": false,
"id": 62,
"name": "ccccc",
"milestone_id": 5,
}
]
},
"milestone_6":{
"id": 6,
"name": "This is milestone #2",
"tasks": [
"task_65":{
"complete": false,
"id": 65,
"name": "ffffff",
"milestone_id": 5,
},
"task_66":{
"complete": false,
"id": 66,
"name": "gggggg",
"milestone_id": 5,
}
]
}
]
Does anybody have any idea how to get Rails to custom format JSON. Even if I have to lose the "milestone_" part and just spit out the ID, that would be very helpful.
Thanks!
Take a look at the json_builder gem.
What you're asking is certainly doable, but personally when you start doing anything remotely useful with json output from controllers, the default to_json method becomes unwieldy. It's best to explicitly output exactly what you want the json to look like.
Specifically in your json_builder file...
milestone.json.json_builder
#milestones.each do |milestone|
key "milestone_#{milestone.id}" do
id milestone.id
name milestone.name
end
end
etc etc. I believe that would do the trick.
Edit: I tend to only include the exact fields from the model that I need for whatever resource is consuming my json. This will improve performance and can make things easier to debug when something goes wrong. It's also very obvious which fields are going to show up where.