Multi Line Graph D3.js - d3.js

I'm trying to plot more than one line on my graph as per this example:
http://bl.ocks.org/mbostock/3884955
The data is being pulled from a mySQL database using PHP - with output in following format:
[{"dateTimeTaken":"2013-02-21 07:39:29","reading":"12.2","parameterType":"Flouride"},
{"dateTimeTaken":"2013-02-21 07:39:34","reading":"12.01","parameterType":"Temperature"},
{"dateTimeTaken":"2013-02-2107:39:39","reading":"12.01","parameterType":"PH"},...etc.
I would like one line per parameterType but not having any luck getting it working. At the moment getting an error "Problem Parsing d" and no lines at all displaying.
https://gist.github.com/Majella/ab32fe0151fd487da3f6
I'd appreciate it if anyone could help me understand where I'm going wrong?

The problem is in your data.map call -- it's supposed to return the modified object you want in the result array. To fix, simply modify d and return it.
Working example here.

Related

Pig XMLLoader: Cannot parse XML (Converting to CSV)

I have the following XML data:
<CompactData><my:DataSet><my:Series VAL="A" AMOUNT_TYPE="FI" IDENTIFIER="1"><my:Obs AMT="24.25" UNIT_MEASURE="KG"></my:Obs></my:Series><my:Series VAL="B" AMOUNT_TYPE="GI" IDENTIFIER="2"><my:Obs AMT="21.22" UNIT_MEASURE="KG"></my:Obs></my:Series></my:DataSet></CompactData>
I am trying to convert it to a CSV format using the following commands in PIG:
A = LOAD '/testing/mydata.xml' using org.apache.pig.piggybank.storage.XMLLoader('CompactData') as (x:chararray);
B = FOREACH A GENERATE FLATTEN(REGEX_EXTRACT_ALL(x,'<my:Series VAL="([^"]+)" AMOUNT_TYPE="([^"]+)" IDENTIFIER="([^"]+)"><my:Obs AMT="([^"]+)" UNIT_MEASURE="([^"]+)"></my:Obs></my:Series>')) AS (val:chararray,amount_type:chararray,identifier:chararray,amt:chararray,unit_measure:chararray);
Putting the regex <my:Series VAL="([^"]+)" AMOUNT_TYPE="([^"]+)" IDENTIFIER="([^"]+)"><my:Obs AMT="([^"]+)" UNIT_MEASURE="([^"]+)"><\/my:Obs><\/my:Series> into Regexr gives two perfect matches, but Pig just does not want to work with it. It always gives me an empty result whereas I expect the following:
A,FI,1,24.25,KG
B,GI,2,21.22,KG
Update 1: This seems most likely related to the issue mentioned here: Pig xmlloader error when loading tag with colon
Assuming your code does not give an error, I can think of 3 potential problems here:
Your regex is not called
Your regex (in pig) is not returning the expected result
The output of your regex is not shown
To deal with the situation, I would recommend the following steps:
Create a pig program that succesfully uses regex to find 'b' in 'aba'
Create a pig program that succesfully finds both occurrences of 'a' in 'aba'
Create a pig program that succesfully finds the firstof 'a' in 'aba'
Keep 'growing' this solution gradually untill you reach your actual solution
If you still get stuck, please share the last solution that worked, and the first one that didn't work. (including input!)

TypeError: cannot concatenate 'str' and 'pygame.Surface' objects

I am currently teaching myself game programming, and I've started nice and easy with pygame. I went through a tutorial that showed me how to build a simple game, and now that I am finished with it, I am in the process of trying to reorganize the code in a manner that makes sense to me, and also to edit it and add to it.
Part of what I tried to change is that instead of loading one '.png' file for a character, I load a list of them that will be iterated through in a 'move()' function I designed to make the characters look like they are moving. However I keep running into an error and I don't know why. Near the beginning of my code (all I've done is imported necessary modules and initialized pygame and some necessary variables) I tried to do the following code:
badguyimgs = ['badguy.png', 'badguy2.png', 'badguy3.png', 'badguy4.png']
for img in badguyimgs:
badguyimgs.append(pygame.image.load("resources/images/" + img))
badguyimgs.remove(img)
I keep getting the following error:
TypeError: cannot concatenate 'str' and 'pygame.Surface' objects
So far I have tried to initialize a new variable (resource = "resources/images/" + img) and place that at the beginning of the "for" loop and then insert that into the pygame.image.load(). I've also tried using os.path.join("resource/images/" + img). I've tried using the full path name ("c:\\Users\\ . . . \\resources\\images\\" +img). But any time I try to concatenate the pathname with the file name in the list, I get the above error code. I tried looking in the pygame documentation, but didn't see anything that helped in this situation. I've tried googling the error, but get nothing in reference to this. (a lot of issues with people tring to concatenate int types to strings though. . . ) I would appreciate any help anyone could give in pointing out why I am experiencing this, and what could fix it. Thanks.
It looks like what you're doing is appending the pygame.surface object (that you loaded from a png file) to the list while you're iterating through it. You are loading the images successfully. However after your function adds the first image and removes the string, your list looks like this:
badguyimgs = ['badguy2.png', 'badguy3.png', 'badguy4.png', pygame.image]
You are still iterating through the list, so your function starts trying to concatenate the string and the pygame.surface object. I would recommend creating an empty list, and add your loaded images to that list without adding or removing anything from the original. Hope this helped!
Here's an example to go with PlatypusVenom's explanation:
file_names = ['badguy.png', 'badguy2.png', 'badguy3.png', 'badguy4.png']
images = []
for file_name in file_names:
images.append(pygame.image.load("resources/images/" + file_name))
Now the pygame.Surface objects are in images, and the variable names for the lists are less confusing. Another option is to use a list comprehension:
images = [pygame.image.load("resources/images/" + file_name) for file_name in \
("badguy.png", "badguy2.png", "badguy3.png", "badguy4.png")]
This is similar to what you were going for in the code posted. The list of strings will be removed from memory, leaving only pygame.Surface objects in the images list.

ImportXML Xpath Query Return txt

I need to use Google Spreadsheet ImportXML return a value from this website...
http://www.e-go.com.au/calculatorAPI2?pickuppostcode=2000&pickupsuburb=SYDNEY+CITY&deliverypostcode=4000&deliverysuburb=BRISBANE&type=Carton&width=40&height=35&depth=65&weight=2&items=3
the website simply displays the below in text and code...
error=OK
eta=Overnight
price=64.69
I need to return the values after last line 'price=', being a newbee I'm struggling with xpath query (?) required to make this happens...
=importxml("url",?)
Your help is greatly appreciated.
Thank you in advance.
Regards
first of all, IMPORTXML() won't work because your webpage is not formatted correctly for XML, and google sheets doesn't like it.
All hope is not lost tho, as your output is so simple. you can simply load the whole output using IMPORTDATA() and then process within google sheets
have a look at the output of the following formulae (where the url is stored in A1)
=IMPORTDATA(A1)
=transpose(IMPORTDATA(A1))
=index(IMPORTDATA(A1),3,1) - IF there are always 3 results, and price will always be in the third one this will work
=filter(IMPORTDATA(A1),left(IMPORTDATA(A1),5)="price") - if the price can appear in any of the result lines, but always starting with "price"

Apply updated data to line/path?

I have a line graph which is updated based on values chosen from two dropdown lists. The data is updated as per gist below. Everything is working perfectly and all data is being returned correctly but when try to apply this updated data to the existing line/path and update the graph - the line/path disappears and I get a parsing error. Know it is something to do with how I'm applying this new data to the line/path - can anyone help?
https://gist.github.com/Majella/202df0a4a5a3ad20fb92
I'm not quite sure if you'd like to (a) update the existing line with new data, or (b) keep the existing line and add a second line with the new data.
For (a), you would need to re-join newdata to the original line and then redraw it. This can be achieved with a simple redraw function where the function parameter is the dataset. You can see an implementation of this in Mike Bostock's General Update Pattern post or in an even simpler example I made to demonstrate this.
If (b), you would perform a data-join for the new data as you did for the first dataset, something like:
var data2 = svg.selectAll('.newData')
.data(newdata)
.enter().append('path')
.attr('class', 'newData)
.attr( "d", line(newdata));
And it would add a second line to the graph.

Getting text from a form and evaluate in selenium using ruby

I am testing a registration form and one of the questions before submitting is:
"What is 8 + 4?"
The values will be different every time. I am using Selenium 2 with Ruby and want to to see if anyone knows how to a) get the text from the question and then b) compute the addition and return the correct answer in the field.
Thanks!
Using ruby code try to get the values in between is and ? Store this in Variable and now split the text with deliminator + now you will get the Values in array in different location. Now you can add these two and use for your evaluation. I don't have idea about ruby but its possible in PHP as I have done the same. Its should be in Ruby too.
Getting text between is and ? can be done strpos() in php that gives the position of the string see similar function for ruby.

Resources