Parsing and then reading specific values of JSON / HTTParty::Response - ruby-on-rails

I want to be able to retrieve the tier and division from this code, however when using the response object from HTTParty and doing res[0]["#{id}"]["tier"] it comes up with "cannot implicitly convert string to integer", which means it expects an integer, but I don't know where
This is the response I get (I'm doing it in a loop which is why I'm putting in the ID with "#{id}")
{"37714607": [
{
"queue": "RANKED_SOLO_5x5",
"name": "Diana's Patriots",
"entries": [{
"leaguePoints": 32,
"isFreshBlood": false,
"isHotStreak": false,
"division": "IV",
"isInactive": false,
"isVeteran": false,
"losses": 65,
"playerOrTeamName": "Wicked7000",
"playerOrTeamId": "37714607",
"wins": 59
}],
"tier": "GOLD"
},
{
"queue": "RANKED_TEAM_5x5",
"name": "Nasus's Justicars",
"entries": [{
"leaguePoints": 81,
"isFreshBlood": false,
"isHotStreak": false,
"division": "V",
"isInactive": false,
"isVeteran": false,
"losses": 73,
"playerOrTeamName": "Pink Fedoras",
"playerOrTeamId": "TEAM-5ffedf90-45ba-11e4-9e4b-c81f66db8bc5",
"wins": 73
}],
"tier": "SILVER"
},
{
"queue": "RANKED_TEAM_3x3",
"name": "Cassiopeia's Marksmen",
"entries": [{
"leaguePoints": 0,
"isFreshBlood": false,
"isHotStreak": true,
"division": "I",
"isInactive": false,
"isVeteran": false,
"losses": 3,
"playerOrTeamName": "The Booty Brothers",
"playerOrTeamId": "TEAM-53a65b60-ff2d-11e4-9e51-c81f66dba0e7",
"wins": 7
}],
"tier": "BRONZE"
}
]}

As your json something like below
{"37714607": [
{
"queue": "RANKED_SOLO_5x5",
"name": "Diana's Patriots",
"entries": [{
"leaguePoints": 32,
"isFreshBlood": false,
"isHotStreak": false,
"division": "IV",
"isInactive": false,
"isVeteran": false,
"losses": 65,
"playerOrTeamName": "Wicked7000",
"playerOrTeamId": "37714607",
"wins": 59
}],
"tier": "GOLD"
},
so it will first id = "37714607" then an array start([) the array contains hashes so first hash has "tier" key
so it should be
tiers = []
res["#{id}"].each do |result| #id = 37714607
tiers << result["tier"]
end

Seems like you need to do res[id.to_s][0]["tier"] instead – first take the root key, then first element (you did it vice versa).

Related

Highcharts xAxis has extra gap when multiple yAxis

We have a chart that plots multiple series at once.
There are the main y-series (line type) that will have the main data readings.
There is the option to set two different 'levels' (line types) on the y-axis as well.
There are also options to have multiple additional y-axis bars (bar types).
With the x-axis being the datetime
Here is what a typical example of a chart looks like with valid date for the given range
This is working as expected.
We have the main y-series as the average air temp (left y-axis)
Then we have two bars, one for rainfall and one for irrigation (right y-axis)
And then the two 'levels', one red and one blue.
This is all great.
However, when we go to a date range in the future, where there is no air temp data, we get the following
Note that the start date is 2 days before the date range, and the end date looks equal distance from the end of the 'levels'
Interestingly if we remove the bars we get the following
This now shows the 'levels' to span the full width of the chart
If we remove the lines and just have the bars then we get the following (which is how it should look, but with the 'levels')
There seems to be something in here that is causing the conflict when there are multiple y-series without the main y-series.
I am setting the xAxis.setExtremes to the start and end dates of the date range we are looking at, but that seems to be doing nothing.
Here is the config;
{
"chart": {
"type":"line",
"animation": {
"duration":150
},
"events":{}
},
"credits":{
"enabled":false
},
"title":{
"text":""
},
"subtitle":{
"text":""
},
"tooltip":{
"shared":true,
"crosshairs":true,
"borderWidth":0,
"followPointer":true,
"useHTML":true,
"headerFormat":"<span style=\"font-size: 10px;\">{point.key}</span><br><br>"
},
"xAxis":[
{
"id":"x-axis",
"type":"datetime",
"crosshair":{
"snap":false
},
"title":{
"text":"25th Sep 2019 - 1st Oct 2019",
"margin":15
}
}
],
"yAxis":[
{
"id":"y-axis-sensors",
"title":{
"text":"ºC"
},
"reversed":false,
"visible":true,
"endOnTick":false,
"startOnTick":false,
"alignTicks":false
},
{
"id":"y-axis-moisture",
"title":{
"text":"mm"
},
"opposite":true,
"min":0,
"endOnTick":false,
"startOnTick":false,
"alignTicks":false,
"tickWidth":0,
"gridLineWidth":0
}
],
"series":[
{
"type":"line",
"yAxis":"y-axis-sensors",
"marker":{
"enabled":false
},
"lineWidth":1,
"animation":false,
"name":"Full",
"seriesGroup":"levelSeries",
"id":"series-level-range-full",
"color":"#31B5E0",
"showInLegend":false,
"states":{
"hover":{
"enabled":false
}
},
"enableMouseTracking":false,
"zIndex":5,
"step":true,
"data":[
[1569369600000,5],
[1569974400000,5]
]
},
{
"type":"line",
"yAxis":"y-axis-sensors",
"marker":{
"enabled":false
},
"lineWidth":1,
"animation":false,
"name":"Refill",
"seriesGroup":"levelSeries",
"id":"series-level-range-refill",
"color":"#D23333",
"showInLegend":false,
"states":{
"hover":{
"enabled":false
}
},
"enableMouseTracking":false,
"zIndex":5,
"step":true,
"data":[
[1569369600000,17],
[1569974400000,17]
]
},
{
"type":"column",
"yAxis":"y-axis-moisture",
"marker":{
"enabled":false
},
"name":"Rainfall",
"seriesGroup":"rainfallSeries",
"states":{
"hover":{
"enabled":false
}
},
"id":"series-rainfall",
"pointWidth":6,
"borderWidth":0,
"color":"rgba(41, 182, 246, 0.3)",
"data":[
[1569488400000,5]
],
"zIndex":10,
"stacking":"normal",
"stack":"moisture"
},
{
"type":"column",
"yAxis":"y-axis-moisture",
"marker":{
"enabled":false
},
"states":{
"hover":{
"enabled":false
}
},
"name":"Irrigation",
"seriesGroup":"irrigationSeries",
"id":"series-irrigation",
"pointWidth":6,
"borderWidth":0,
"color":"rgba(205,220,57, 0.3)",
"data":[[1569574800000,3]],
"zIndex":10,
"stacking":"normal",
"stack":"moisture"
}
]
}
I am at a bit of a loss here as to why this is happening.
Can anyone shed some light on this?
One of the solutions can be to add additional x-axis and bind line series to it. Then it looks like your expected result. Check demo and code posted below.
Code:
Highcharts.chart('container', {
"chart": {
"type": "line",
"animation": {
"duration": 150
},
"events": {}
},
"credits": {
"enabled": false
},
"title": {
"text": ""
},
"subtitle": {
"text": ""
},
"tooltip": {
"shared": true,
"crosshairs": true,
"borderWidth": 0,
"followPointer": true,
"useHTML": true,
"headerFormat": "<span style=\"font-size: 10px;\">{point.key}</span><br><br>"
},
"xAxis": [{
"id": "x-axis1",
"type": "datetime",
"crosshair": {
"snap": false
},
"title": {
"text": "25th Sep 2019 - 1st Oct 2019",
"margin": 15
}
}, {
"id": "x-axis2",
visible: false,
"type": "datetime"
}],
"yAxis": [{
"id": "y-axis-sensors",
"title": {
"text": "ºC"
},
"reversed": false,
"visible": true,
"endOnTick": false,
"startOnTick": false,
"alignTicks": false
},
{
"id": "y-axis-moisture",
"title": {
"text": "mm"
},
"opposite": true,
"min": 0,
"endOnTick": false,
"startOnTick": false,
"alignTicks": false,
"tickWidth": 0,
"gridLineWidth": 0
}
],
"series": [
{
"type": "line",
xAxis: 'x-axis2',
"yAxis": "y-axis-sensors",
"marker": {
"enabled": false
},
"lineWidth": 1,
"animation": false,
"name": "Full",
"seriesGroup": "levelSeries",
"id": "series-level-range-full",
"color": "#31B5E0",
"showInLegend": false,
"states": {
"hover": {
"enabled": false
}
},
"enableMouseTracking": false,
"zIndex": 5,
"step": true,
"data": [
[1569369600000, 5],
[1569974400000, 5]
]
},
{
"type": "line",
xAxis: 'x-axis2',
"yAxis": "y-axis-sensors",
"marker": {
"enabled": false
},
"lineWidth": 1,
"animation": false,
"name": "Refill",
"seriesGroup": "levelSeries",
"id": "series-level-range-refill",
"color": "#D23333",
"showInLegend": false,
"states": {
"hover": {
"enabled": false
}
},
"enableMouseTracking": false,
"zIndex": 5,
"step": true,
"data": [
[1569369600000, 17],
[1569974400000, 17]
]
},
{
"type": "column",
xAxis: 'x-axis1',
"yAxis": "y-axis-moisture",
"marker": {
"enabled": false
},
"name": "Rainfall",
"seriesGroup": "rainfallSeries",
"states": {
"hover": {
"enabled": false
}
},
"id": "series-rainfall",
"pointWidth": 6,
"borderWidth": 0,
"color": "rgba(41, 182, 246, 0.3)",
"data": [
[1569488400000, 5]
],
"zIndex": 10,
"stacking": "normal",
"stack": "moisture"
},
{
"type": "column",
xAxis: 'x-axis1',
"yAxis": "y-axis-moisture",
"marker": {
"enabled": false
},
"states": {
"hover": {
"enabled": false
}
},
"name": "Irrigation",
"seriesGroup": "irrigationSeries",
"id": "series-irrigation",
"pointWidth": 6,
"borderWidth": 0,
"color": "rgba(205,220,57, 0.3)",
"data": [
[1569574800000, 3]
],
"zIndex": 10,
"stacking": "normal",
"stack": "moisture"
}
]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
Demo:
https://jsfiddle.net/BlackLabel/juwc8f37/

Adding new Sensor to Object Model is failing

I am trying to modify the quick sample provided here.
I tried to add a few custom sensor data type but it is failing. Then I tried a few data types mentioned in the documentation which also failed.
I am getting below error
Creating Sensor: {
"DataType": "Noise",
"DeviceId": "some-device-id",
"HardwareId": "SAMPLE_SENSOR_NOISE"
}
Request: POST
https://******.*******.azuresmartspaces.net/management/api/v1.0/sensors
Response Status: 404, NotFound , {"error":
{"code":"404.600.000.001","message":"There is no SensorDataType of the
given name."}}
Can we add custom sensor datatype?
If no then what are the inbuilt data types? or if yes then what went wrong here?
You need to post the DataType when creating the Sensor object. Use “None” if you want to change it later. Swagger DOCs show the “Model” you can expand and see required fields.
If the DataType is not in the api/v1/system/types you will need to enable it or create a new DataType. Create a new DataType POST to the Types with the required information. The minimum is the TypeName and SpaceID to neat the type under. My typical pattern is to create a root space and append any custom twin objects like types to this space.
I believe these are case sensitive names as well.
https://{servicename}.{region}.azuresmartspaces.net/management/swagger/ui/index#/Types
EDIT:
Check your Ontologies with:
https://{servicename}.{region}.azuresmartspaces.net/management/api/v1.0/ontologies
Select these by ID and POST to set them to true to get all available built-in types:
[
{
"id": 1,
"name": "Required",
"loaded": true
},
{
"id": 2,
"name": "Default",
"loaded": true
},
{
"id": 3,
"name": "BACnet",
"loaded": true
},
{
"id": 4,
"name": "Advanced",
"loaded": true
}
]
Then you can query all the given types:
https://{servicename}.{region}.azuresmartspaces.net/management/api/v1.0/types?includes=Description,FullPath,Ontologies,Space
You should receive something like:
[
{
"id": 1,
"category": "DeviceSubtype",
"name": "None",
"disabled": false,
"logicalOrder": 0,
"fullName": "None",
"spacePaths": [
"/system"
],
"ontologies": [
{
"id": 1,
"name": "Required",
"loaded": true
}
]
},
{
"id": 2,
"category": "DeviceType",
"name": "None",
"disabled": false,
"logicalOrder": 0,
"fullName": "None",
"spacePaths": [
"/system"
],
"ontologies": [
{
"id": 1,
"name": "Required",
"loaded": true
}
]
},
{
"id": 3,
"category": "DeviceBlobSubtype",
"name": "None",
"disabled": false,
"logicalOrder": 0,
"fullName": "None",
"spacePaths": [
"/system"
],
"ontologies": [
{
"id": 1,
"name": "Required",
"loaded": true
}
]
},
...Objects,
]

Get OData option set values and names

I am using odata api, now I have an attribute on an entity that is an option select like :
attribute name is : status
values are: 1, 2, 3
names: done, progress, new
the thing is when I am using postman to fetch metadata and all I get for the fields 'status' its that its type integer.
Question how do I fetchj option names and values from metadata so I get values and names in response ?
Currently I get this:
<Property Name="status" Type="Edm.Int32">
<Annotation Term="Org.OData.Core.V1.Description" String="" />
</Property>
But I want to get the value and names on response ?
This could be vastly simplified, assuming all you want are the int values, and names for a particular option set attribute of an entity:
GET [Organization URI]/api/data/v8.2/EntityDefinitions(LogicalName='contact')/Attributes(LogicalName='status')/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)
The $select=LogicalName is just so it doesn't return all the other metadata for the attribute, and the $expand=OptionSet($select=Options) is for local option sets, and the GlobalOptionSet($select=Options) is for Global. If you know what type it is, you can skip it the other, but if you are putting this logic in a shared library (you are aren't you?) then adding both won't hurt:
{
"#odata.context":"http://YourOrg.com/YourInstance/api/data/v8.2/$metadata#EntityDefinitions('new_entity')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata(LogicalName,OptionSet,GlobalOptionSet,OptionSet(Options),GlobalOptionSet(Options))/$entity",
"LogicalName":"new_familyshortname",
"MetadataId":"dc11c01f-b6bd-4664-82d0-3a521841c1f5",
"OptionSet#odata.context":"http://YourOrg.com/YourInstance/api/data/v8.2/$metadata#EntityDefinitions('new_entity')/Attributes(dc11c01f-b6bd-4664-82d0-3a521841c1f5)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata/OptionSet(Options)/$entity",
"OptionSet":null,
"GlobalOptionSet":{
"#odata.type":"#Microsoft.Dynamics.CRM.OptionSetMetadata",
"Options":[
{
"Value":117280000,
"Label":{
"LocalizedLabels":[
{
"Label":"English Value 1",
"LanguageCode":1033,
"IsManaged":true,
"MetadataId":"3cb6bbd5-796f-e111-8cf3-3cd92b023782",
"HasChanged":null
},
{
"Label":"French Value 1",
"LanguageCode":1036,
"IsManaged":false,
"MetadataId":"d88be67d-4a7d-e411-8890-0050569f1654",
"HasChanged":null
}
],
"UserLocalizedLabel":{
"Label":"English Value 1",
"LanguageCode":1033,
"IsManaged":true,
"MetadataId":"3cb6bbd5-796f-e111-8cf3-3cd92b023782",
"HasChanged":null
}
},
"Description":{
"LocalizedLabels":[
{
"Label":"",
"LanguageCode":1033,
"IsManaged":true,
"MetadataId":"3db6bbd5-796f-e111-8cf3-3cd92b023782",
"HasChanged":null
}
],
"UserLocalizedLabel":{
"Label":"",
"LanguageCode":1033,
"IsManaged":true,
"MetadataId":"3db6bbd5-796f-e111-8cf3-3cd92b023782",
"HasChanged":null
}
},
"Color":null,
"IsManaged":true,
"MetadataId":null,
"HasChanged":null
},
... MORE ...
],
"MetadataId":"dcbbe460-bedb-4985-9a17-2f3dbc637594"
}
}
According to this article this is a multi-step process.
Please note that all the examples use HTTP GET.
First retrieve the entity's MetaData Id (for this example we're using the entity 'account'):
https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions?$select=LogicalName,MetadataId&$filter=LogicalName eq 'account'
Returns:
{
"#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(LogicalName,MetadataId)",
"value": [{
"LogicalName": "account",
"MetadataId": "70816501-edb9-4740-a16c-6a5efbc05d84"
}]
}
Then retrieve the attribute's MetaDataId (in this example we're using the option set 'customertypecode'):
https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)?$select=LogicalName&$expand=Attributes($select=LogicalName;$filter=LogicalName eq 'customertypecode')
Returns:
{
"#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(LogicalName,Attributes(LogicalName))/$entity",
"LogicalName": "account",
"MetadataId": "70816501-edb9-4740-a16c-6a5efbc05d84",
"Attributes#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(LogicalName)",
"Attributes": [{
"#odata.type": "#Microsoft.Dynamics.CRM.PicklistAttributeMetadata",
"LogicalName": "customertypecode",
"MetadataId": "4e33af09-ba43-4365-a747-c7e4f9992172"
}]
}
Then query with the entity's and attribute's MetadataIds to get the option set values:
https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(4e33af09-ba43-4365-a747-c7e4f9992172)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet
Returns (truncated at 2 values):
{
"#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata(LogicalName,OptionSet)/$entity",
"LogicalName": "customertypecode",
"MetadataId": "4e33af09-ba43-4365-a747-c7e4f9992172",
"OptionSet#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(4e33af09-ba43-4365-a747-c7e4f9992172)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata/OptionSet/$entity",
"OptionSet": {
"MetadataId": "3629e642-b895-41ab-8f1d-ea5bfa30e992",
"HasChanged": null,
"IsCustomOptionSet": false,
"IsGlobal": false,
"IsManaged": true,
"Name": "account_customertypecode",
"ExternalTypeName": null,
"OptionSetType": "Picklist",
"IntroducedVersion": "5.0.0.0",
"Description": {
"LocalizedLabels": [{
"Label": "Type of the account.",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "73f68e38-c78d-48a5-80cb-bee895baab2b",
"HasChanged": null
}],
"UserLocalizedLabel": {
"Label": "Type of the account.",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "73f68e38-c78d-48a5-80cb-bee895baab2b",
"HasChanged": null
}
},
"DisplayName": {
"LocalizedLabels": [{
"Label": "Relationship Type",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "e5d47366-fd09-41e6-96a1-cbfdd113b932",
"HasChanged": null
}],
"UserLocalizedLabel": {
"Label": "Relationship Type",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "e5d47366-fd09-41e6-96a1-cbfdd113b932",
"HasChanged": null
}
},
"IsCustomizable": {
"Value": true,
"CanBeChanged": false,
"ManagedPropertyLogicalName": "iscustomizable"
},
"Options": [{
"Value": 1,
"Color": null,
"IsManaged": true,
"ExternalValue": null,
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [{
"Label": "Competitor",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "6c54c2fa-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}],
"UserLocalizedLabel": {
"Label": "Competitor",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "6c54c2fa-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}
},
"Description": {
"LocalizedLabels": [],
"UserLocalizedLabel": null
}
},
{
"Value": 2,
"Color": null,
"IsManaged": true,
"ExternalValue": null,
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [{
"Label": "Consultant",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "6e54c2fa-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}],
"UserLocalizedLabel": {
"Label": "Consultant",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "6e54c2fa-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}
},
"Description": {
"LocalizedLabels": [],
"UserLocalizedLabel": null
}
}
}
}

Rails serialization of sibling objects into groups by name (active model serializers)

I'm not sure the best way of approaching this; I've got a generic system for requesting data objects from an api and returning json by using ActiveModelSerializers and it's been fantasticly simple.
For one class I need to return data formatted differently than the normal class serilization and unsure of the best approach. No matter what it seems that I'm going to have to have an 'elsif' for this one class in the return (which pains me a little bit).
Currently I've got a class named 'curve' which a user has_many of, and so requesting a user's curve gets me something like this:
[{
"id": 7,
"name": "A",
"angle": 30,
"date": "2017-05-23T01:52:00.589-04:00",
"direction": "left",
"top": "C1",
"bottom": "C4",
"risser": 3,
"sanders": 8
}, {
"id": 8,
"name": "B",
"angle": 0,
"date": "2017-05-23T01:52:56.107-04:00",
"direction": "right",
"top": "C5",
"bottom": "C6",
"risser": null,
"sanders": null
}, {
"id": 9,
"name": "A",
"angle": 22,
"date": "2017-05-25T01:56:00.656-04:00",
"direction": "right",
"top": "C3",
"bottom": "C5",
"risser": null,
"sanders": null
}, {
"id": 11,
"name": "C",
"angle": 3,
"date": "2017-05-26T01:57:08.078-04:00",
"direction": "right",
"top": "C4",
"bottom": "C7",
"risser": null,
"sanders": null
}]
But I actually need each to be grouped by the name like so:
[{
"name": "A",
"points": [{
"id": 7,
"name": "A",
"angle": 30,
"date": "2017-05-23T01:52:00.589-04:00",
"direction": "left",
"top": "C1",
"bottom": "C4",
"risser": 3,
"sanders": 8
}, {
"id": 9,
"name": "A",
"angle": 22,
"date": "2017-05-25T01:56:00.656-04:00",
"direction": "right",
"top": "C3",
"bottom": "C5",
"risser": null,
"sanders": null
}]
},
{
"name": "B",
"points": [{
"id": 8,
"name": "B",
"angle": 0,
"date": "2017-05-23T01:52:56.107-04:00",
"direction": "right",
"top": "C5",
"bottom": "C6",
"risser": null,
"sanders": null
}]
},
{
"name": "C",
"points": [{
"id": 11,
"name": "C",
"angle": 3,
"date": "2017-05-26T01:57:08.078-04:00",
"direction": "right",
"top": "C4",
"bottom": "C7",
"risser": null,
"sanders": null
}]
}
]
Now I know I can do group_by and fiddle with the response - but even then it won't be using the default Curve serializer. I could also create a custom GroupedCurve serializer and possibly process each curve with a CurveSerializer - but at that point isn't it just like getting the default array and doing a map, and constructing my own hashes?
What's the best / cleanest way of processing data from top to the bottom format?
UPDATE:
Something like the following 'does the job' but the job is dirty:
def self.reformat_curves(curves)
arr = []
curves.each do |i|
alpha = i[:name]
entry = arr.find{|chunk| chunk[:name]==alpha}
if entry.nil?
arr << {name: alpha, points: [i]}
else
entry[:points] << i
end
end
return arr
end

How do I force highcharts to pay attention to min and max on my secondary axis?

I'm trying to set a secondary axis with a min/max value, and the primary axis often overwrites the max on the secondary axis.
I know that I could use alignTicks:false, but I don't like the way that makes the ticks look. I also know that I can hide the ticks for one of the axes, but again, I don't like they it looks.
I would like to either force the right side to use min/max and figure out the proper tick intervals, or I'd like to force the left side to have a specific number of ticks.
I need some ideas, here's a jsfiddle with my code and some mock data.
http://jsfiddle.net/2s6kK/
$(function () {
$('#container').highcharts({
"title": {
"text": ""
},
"subtitle": {
"text": ""
},
"xAxis": {
"type": "datetime",
"dateTimeLabelFormats": {
"day": "%b %e"
}
},
"yAxis": [{
"min": 0,
"startOnTick": false,
"labels": {
"style": {
"color": "#4074C3"
}
},
"title": {
"text": "Revenue",
"style": {
"color": "#4074C3"
},
"margin": 5
},
"index": 0
}, {
"allowDecimals": false,
"min": 0,
"max": 100,
"maxPadding": 0.2,
"startOnTick": false,
"labels": {
"style": {
"color": "#8DAD36"
}
},
"title": {
"text": "Win Rate",
"style": {
"color": "#8DAD36"
},
"margin": 2
},
"opposite": true,
"index": 1,
// "alignTicks": false
}],
"legend": {
"enabled": true,
"align": "center",
"verticalAlign": "top",
"x": 0,
"y": -5,
"borderWidth": 0
},
"series": [{
"name": "Revenue",
"type": "line",
"yAxis": 0,
"data": [5.4,27,27,27,58,0, 0, 0, 0
],"pointStart":1377993600000,"pointInterval":86400000
}, {
"name": "Win Rate",
"type": "line",
"color": "#8DAD36",
"yAxis": 1,
"data": [60,48,48,48,48,60, 0, 0, 0, 0
],"pointStart":1377993600000,"pointInterval":86400000
}]
});
});
Thanks,
Josh
You could try setting your tickInterval to 10 in your y-axis definition:
"tickInterval": 10
http://jsfiddle.net/2s6kK/1/

Resources