Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Do something in 5 with apps scripts number 6 - fusion crossfilter

548 vues

Publié le

Number 6 in the do something useful in 5 minutes with apps script. This time we'll use crossfilter to analyze data from a Fusion Table

Publié dans : Données & analyses
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Do something in 5 with apps scripts number 6 - fusion crossfilter

  1. 1. do something useful with Apps Script in 5 minutes 6. Fusion, Crossfilter and Sheets Bruce McPherson www.mcpher.com
  2. 2. Snippet objectives ● Use the lessons learned in ‘using a spreadsheet as a database’ ● Get data from a Fusion Table ● Use Crossfilter to summarize data and write it to a sheet Libraries used ● database abstraction ● driver sheet ● crossfilter ● driver fusion
  3. 3. Add libraries to script ● create a spreadsheet ● get its id ● create a script ● Open resources ● Add references to libraries MHfCjPQlweartW45xYs6hFai_d-phDA33 Mrckbr9_w7PCphJtOzhzA_Cz3TLx7pV4j MyhWrchJeGiOowTfrMNidiSz3TLx7pV4j M-tju_1qulZXW63vIuwyLOqi_d-phDA33
  4. 4. Add Fusion service in advanced services, enable Fusion
  5. 5. Enable Fusion on cloud console
  6. 6. Workaround for fusion issue ● When the Fusion API is called from a library, the script doesn’t know it needs authorization ● You need to mention Fusion in your script, even as a comment to provoke an authorization dialog. ● Put this somewhere in your script - amazing but true, // FusionTables.Table - this will provoke a fusion authorization
  7. 7. layout what you are going to do function myFunction() { // open fusion table // open spreadsheet as database // get all the data // load it to crossFilter // create a states dimension // create a summary of how many airports in each state // clear sheet // write results } // FusionTables.Table - this will provoke a fusion authorization
  8. 8. Open Fusion data source Open a Fusion table - this table has a list of all airports in each state // open fusion table var fusionHandler = new cDbAbstraction.DbAbstraction (cDriverFusion, { dbid:'airports', siloid:'1Ug6IA-L5NKq79I0ioilPXlojEklytFMMtKDNzvA' }); if (!fusionHandler.isHappy()) throw 'unable to open fusion table';
  9. 9. Open Sheet for results Open a Sheet … we’ll write the results here. Replace the key with the one for the spreadsheet you created // open spreadsheet as database var handler = new cDbAbstraction.DbAbstraction (cDriverSheet, { siloid:'airporcountbystate', dbid:'1a4oHUWS4sgR_VwjlU6ycyqc0DlUVpKNtEIVXKVwyfLs', }); if (!handler.isHappy()) throw 'unable to open sheet';
  10. 10. Get all the data from Fusion This will pick up all the airport data from the Fusion Table // get all the data var result = fusionHandler.query(); if (result.handleCode < 0) throw result.handleError;
  11. 11. Use crossfilter Crossfilter is cool library for data wrangling. Great for summarizing and grouping. // load it to crossFilter var cf = cCrossFilter.crossfilter(result.data); // create a states dimension var states = cf.dimension ( function (d) { return d.state }); // write a summary of how many airports in each state var stateSummary = states.filter(null).group().all();
  12. 12. Write results to a sheet Clear any current contents, and write the results out // clear sheet var result = handler.remove(); if (handler.handleCode < 0) throw handler.handleError; var result = handler.save(stateSummary); if (handler.handleCode < 0) throw handler.handleError;
  13. 13. Homework Read up about crossfilter and see what other kind of summarization, filtering and analysis you can do with this dataset
  14. 14. Follow up materials Take a copy of this script Take a copy of these slides Join me on G+, or the G+ community More on desktop liberation More on database abstraction More 5 minute things

×