I have a URL that returns data in CSV format. I would like to use Google Vizualization to create an interactive chart of the data. I've looked at several examples on Google Chart and Vizualization web page but I'm a bit confused as I'm not familiar with JavaScript or web programming in general.
Question: Do I have to use JavaScript to parse the CSV string myself and manually construct the DataTable with addColumn() and addRows()? Or, is there a way to simply pass the CSV url to the charting function? I'm hoping to do something like this:
var csv_data = get_data_from_url('http://...')
var data = new google.visualization.DataTable(csv_data);
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, ...);
Can someone please help me out?
Thanks.
Yeah, it looks like they're using JSON or some close variant of JSON for the data. You could try a CSV to JSON converter. Apparently converting CSV to JSON is a fairly trivial operation, requiring only a few lines of code:
converting CSV/XLS to JSON?
Related
I am trying to build a financial dashboard with Flask and pymongo. The starting point is a flask form which saves data in a MongoDB database. One of the fields in the form is a FileField (wtforms) which allows the upload of a PDF, which is then stored in MongoDB with GridFS.
Now I manage to save the pdf and I can see the resulting entries within the .files and .chunks collections. Now I would like to build a function that retrieves the PDFs and analyses them with some basic NLP, however I struggle with the getting meaningful data.
When I do:
storage = gridfs.GridFS(db, collection)
data = storage.get('some id')
a = data.read()
The result is a binary file. If I continue with:
with open(data, 'rb') as f:
b = f.read()
The result is "ValueError: embedded null byte or sometimes an empty "byte string".
Any help on this?
To follow up on the above, I found a solution for myself that consists in 2 separate functions:
(1) Upon upload of the form and before uploading the files to MongoDB, I apply a function based on pdfminer that extracts the string content of the PDF and tranform it into a list of sentences using NLTK. I will then store this list in the .files via the storage.put(file, sent_list = sent_list) #sent_list being the variable name of the list of sentences.
Whenever I wish to run NLP operations on the file, I will just call the "sent_list" variable from mongodb.
(2) If I wish to display the stored pdf in its original content however, I included the following function as a separate route.
storage = GridFS(db, collection)
data = storage.get_last_version(filename)
response = make_response(data.read())
extension = data.filename.split('.')[-1]
response.headers['Content-Type'] = f'application/{extension}'
response.headers['Content-Disposition'] = f'inline; filename={data.filename}'
return response
(2) will open a new tab in my flask app showing the .pdf file in its original format.
I hope this helps anyone coming across a similar problem in the future.
I have a table in a database that contains all kind of attachments, images, pdf, excel, and other formats. creating an application is not an option, so I googled other options and I found this related question that mentioned LINQPad I downloaded it but I still do not know how exactly it works. Anyone please explain that to me? I can query the attachments using sql query but not sure how to dump them and preview them via the mentioned tools.
Following on from Dan's answer, once you have the data context set up you can dump the images from the database. I use this snippet for checking an image I've written to the database, you should be able to edit as required to match your scenario:-
var ii = ItemImages.Where (v => v.Id == 10).FirstOrDefault();
using (var ms = new MemoryStream(ii.Image.ToArray()))
{
System.Drawing.Image.FromStream(ms).Dump();
}
Use the Util.Image built in utility for images.
Ex:
var personPictures = PictureTable.Take(1);
Util.Image(personPictures.First().Picture).Dump();
Util.Image takes a byte array.
Depending on your database of your choice, most likely you'll need a data context driver
http://www.linqpad.net/richclient/datacontextdrivers.aspx
Once you establish a connection you can start writing queries against the data
I'm using Jmeter for testing. I need to use some keys in order to perform login, and then change the keys.
I understood that the best way to do it is to create csv file that contains two variables.
I understand how I can read the parameters (using 'CSV Data Set Config'), but I still don't know how to extract specific parameters from result (new keys) and save them in file instead the old ones.
You can use Regular Expression Extractor to extract the values from the response. This site will give you an idea how it works.
It is NOT a good idea to write in the same file which is read by CSV dataset config. Instead, you can use Beanshell post processor to create a CSV file & write as you want.
import org.apache.jmeter.services.FileServer;
f = new FileOutputStream("/your/file/path/filename.csv", true);
p = new PrintStream(f);
p.println("content,to be,written,in,csv,file");
p.close();
f.close();
So I need to transfer information from a file. An example of the heading is label=1234 I was hoping I could use a perl code to change "label" to "id", is this possible?
Cy.js supports JSON data. Convert or write your data to JSON, and you can load it in as described in the docs: http://cytoscape.github.io/cytoscape.js/
I have been developing a simple desktop app using adobe air, html and javascript to save data to sqlite (not as, no flash builder, no flex). Is there a way that i can capture an image from my webcam and save it using these technologies ? If not what else can be done to achieve the result? Thanks in advance.
This can be done, but it is absolutely not performance-friendly :) You will get enormous string-objects (bigger images = bigger strings). But I will tell you how I did it once.
First, you have to get the BitmapData from your webcam. This can be done by creating a BitmapData-object and using its draw()-function, as shown below:
var bmpd:BitmapData = new BitmapData(webcam.width, webcam.height);
bmpd.draw(webcam);
With this BitmapData, you can then call for getPixels(), which will return a ByteArray.
var ba:ByteArray = bmpd.getPixels();
This ByteArray is now ready for serialization. Since you are storing, it is best you store it as a string. This is most commonly done by Base64. You can use this class to implement the base64-encoding, as shown below:
var baseString:String = Base64.encodeByteArray(ba);
The above string can be stored in your sqlite and is a string-representation of your image. The bigger the image, the longer the conversion will take.
To get the image back from your sqlite, you can use the decodeByteArray()-method of the Base64-class I gave you, in combination with a loader-object. Example is shown below.
var baseString = StringFromYourSQLite;
var ba:ByteArray = Base64.decodeToByteArray(baseString);
var imageLoader:Loader = new Loader();
imageLoader.loadBytes(ba);
stage.addChild(imageLoader);
And this is how you can store and retrieve images from your database.