-5

I am struggling with this for quite some time now, can someone explain a solution to this problem

if i = {'x': 123, 'y': 456} {'x': 675, 'y': 098}

turn it into

message: {
      columns: [
        ["x": 123, "y": "456"],
        ["x": 675, "y": 098]
      ]

More Insights:

I have the following Data structure

[<OldSample {u'counter_name': u'cpu_util', u'user_id': u'id', u'resource_id': u'id', u'timestamp': u'2015-06-30T15:53:55', u'counter_volume': 0.043}]

I need to make it something like this to put in EON pubnub charting libaray (see link: http://www.pubnub.com/developers/eon/chart/spline/)

message: {
      columns: [
        ["y": 0.043, "x": "2015-06-30T15:53:55"],
        ["y": 0.045, "x": "2015-06-30T15:53:55"]
      ]

Now I have the following code

def get_clean_Json(data):
  for each in data:
    timestamp = each.timestamp
    volume =  each.counter_volume
    i = {'x': timestamp, 'y': volume}
    print i

Which returns results like this

{'x': 123, 'y': 456} {'x': 675, 'y': 098}

and I am stuck here, no matter what I do I get errors

Craig Conover
  • 4,710
  • 34
  • 59
Imo
  • 1,455
  • 4
  • 28
  • 53

2 Answers2

1

As an alternative you can publish the EON data in any format from the back end and transform it on the front end using javascript. See the transform parameter here: https://github.com/pubnub/eon-chart#quickstart

And an example here:

https://github.com/pubnub/eon-chart/blob/master/examples/transform.html

Ian Jennings
  • 2,219
  • 1
  • 14
  • 10
  • I am actually getting the data through an openstack python API that is why I want to publish this data via python, makes things easier for me. – Imo Jul 01 '15 at 21:38
0

List concat in python is just []+[], but it doesn't seem that this is what you are looking for. What you are actually seeking here is how to format your JSON to fit the schema that EON requires.

(This is one of the reasons you've been downvoted multiple times! So make sure to ask a right question!)

Try

coords = []
def get_clean_Json(data):
  for each in data:
    timestamp = each.timestamp
    volume =  each.counter_volume
    i = {'x': timestamp, 'y': volume}
    coords.append( i )
get_clean_Json(your_data)
message = {
    columns : coords
}
girlie_mac
  • 593
  • 5
  • 7
  • I tried a similar solution before but it returns none, tried your code above as well it throws the error columns : coords NameError: name 'columns' is not defined – Imo Jul 01 '15 at 20:59
  • Thank you for the suggestion about correcting the question, fully agreed. I am actually going nuts trying to solve this issue. – Imo Jul 01 '15 at 21:40