How make a list in the Info Window of a Fusion Map from a comma separated list? - google-fusion-tables

Can a cell with comma separated information be turned into a list? I've got uneven amounts of data (companies) and would like to just have it display as a basic List when the flag is clicked on in the Fusion Map.
Say I have:
Location: Seminole County, FL
Companies: Acme Co, Box Inc, Cogs LLC
------
Location: Orange County, FL
Companies: Acme Co, Dirt Inc, Shell Co
On Map it should be two flags, which it is. But how can I then have the companies displayed as a basic list?
I can go into the record and change it to contain the HTML:
Companies:<ul><li>Acme Co</li><li>Box Inc</li><li>Shell Co</li></ul
but that's pretty clunky. Is there a way to template it into the Custom Info Window to automate this:
I looked online but couldn't find anything and the Fusion User Group says to ask here.
Edit:
Based on first answer, my rows:
Resulting problem:

If you format the Companies values as JSON lists, you can loop over them with Closure templates. The latter are described in this help page, though the looping constructs are not currently documented.
First, go to Edit > Change columns and set the format of the Companies to JSON text. Then format your values as, say, ["Acme Co", "Dirt Inc", "Shell Co"]. Then in the Closure template you can loop over it it with
{template .contents}
...wrapper div and other columns if desired...
Companies:
<ul>
{foreach $company in $data.value.Companies}
<li>{$company}
{/foreach}
</ul>
...other stuff...
{/template}

Related

Google sheet function (sort by name)

So I have two csv files, one is the all member information, one is a poll event result,
which is like:
Member information:
[Member Name],[Member Tier]
Apple, Bronze
Banana, Silver
Cat, Gold
Poll event result:
[Member Name],[OptionA],[OptionB],[OptionC]
Apple,0,0,1
Banana,1,0,0
Cat,0,1,0
I want to do is weight the vote value with member's tier, for example, Cat is gold member so in this poll OptionB will win.
But the poll csv file is lack of member's tier parameter, so, I'm thinking to do a function like:
Create list "tier Bronze","tier Silver","tier Gold"
in member information file, loop for everyone, if tier match, add to that list
and then go to poll file, loop for everyone, if name match the name in tier list, mark them.
I'm not sure is this the right way, and how to do it, any help will be appreciated :^)
What you need is a vlookup function.
Take 2 lists with member name (as ID) in first left column and tier in 2nd and then use vlookup.
Put vlookup on the right part of your poll table and write:
=vlookup(ID location;range with poll results;2;false)
Then copy down vlookup formula
Or you can do it in more elegant way using Arrayformula:
=ArrayFormula(
ifna(
vlookup(E3:E;$B$3:$C;2;false)
)
)

How to count cypher labels with specific condition?

I have a graph database with information about different companies and their subsidiaries. Now my task is to display the structure of the company. This I have achieved with d3 and vertical tree.
But additionally I have to write summary statistics about the company that is currently displayed. Companies can be chosen from a dropdown list which is fetching this data dynamically via AJAX call.
I have to write in the same HTML a short summary like :
Total amount of subsidiaries for CompanyA: 300
Companies in Corporate Havens : 45%
Companies in Tax havens 5%
My database consists of two nodes: Company and Country, and the country has label like CH and TH.
CREATE (:TH:Country{name:'Nauru', capital:'Yaren', lng:166.920867,lat:-0.5477})
WITH 1 as dummy MATCH (a:Company), (b:Country) WHERE a.name=‘CompanyA ' AND b.name='Netherlands' CREATE (a)-[:IS_REGISTERED]->(b)
So how can I find amount of subsidiaries of CompanyA that are registered in corporate and tax havens? And how to pass this info further to html
I found different cypher queries to query all the labels as well as apocalyptic.stats but this does not allow me to filter on mother company. I appreciate help.
The cypher is good because you write a query almost in natural language (the query below may be incorrect - did not check, but the idea is clear):
MATCH (motherCompany:Company {name: 'CompanyA'})-[:HAS_SUBSIDIARY]->(childCompany:Company)
WITH motherCompany,
childCompany
MATCH (childCompany)-[:IS_REGISTERED]->(country:Country)
WITH motherCompany,
collect(labels(country)) AS countriesLabels
WITH motherCompany,
countriesLabels,
size([countryLabels IN countriesLabels WHERE 'TH' IN countryLabels ]) AS inTaxHeaven
RETURN motherCompany,
size(countriesLabels) AS total,
inTaxHeaven,
size(countriesLabels) - inTaxHeaven AS inCorporateHeaven

How to sort by salary with Ransack and ignoring the dollar symbol?

I am currently attempting to create multiple sort functions for my rails project using ransack gem. The issue that I am having with ransacker, is that I cannot read past the format of the string, because it has a ($) in some of the post and commas as well. What I would like to do is still sort the data attribute and ignore both the $ conditional dollar symbol and thousand position commas (may not be included in certain cases) & append current input from search box
For example:
string = "$30,000" -> parse to remove $ and leave only 30000 for the search engine to find the records that include the number & what was written in the search_form input (job.job_title). The code that I wrote is below, it may not be correct as I was trying multiple approaches. Final result: Ransack should search for "30000 marketing position"
rails view
<li>$30,000+ <%= sort_link(#q, :salary_between_30_and_40k, default_order: :desc) %></li>
job.rb
ransacker :salary_between_30_and_40k do
Arel.sql('SELECT * FROM JOBS WHERE job.hourly_wage_salary BETWEEN 30000 AND 40000')
end
The correct approach here is to migrate your database so that salary details are stored as a numeric value rather than a string with formatting.

Jquery autocomplete to search within more than one columns of a table

Jquery UI's autocomplete has given the solution to searching through one column of a table. So if you get the source from a table with firstname field then you can only search with firstname.
But say you have more than one fields to search against like firstname, lastname, postcode, contactNumber. Then in that case how would you implement something like this for autosuggest.
I mean that user should be able to search with whatever field they like and the autosuggest should be able to give them the suggestions based on that.
Is this possible?
The source can be an array, a string or a function.
You'd have to write a custom function to read all the values in all the columns of the tables and store them in an array. Then call the .source method with your array.
For bonus points, a series of checkboxes above the search field would ask the user to search only those columns.
[ ] FirstName [X] Lastname [X] Department
_Smith_____
John Smith IT
Waylon Smithers Assistant to the Assistant Regional Manager
Jackie Brown Gunsmith

How can I iterate through a hash created with Rails' Hash#to_xml?

I'm working with thetvdb.com API to get episode listings for a show. In general, the XML format is something like:
<Data>
<Series>...</Series>
<Episode><EpisodeName>Foo</EpisodeName><EpisodeNumber>1</EpisodeNumber></Episode>
<Episode><EpisodeName>Bar</EpisodeName><EpisodeNumber>2</EpisodeNumber></Episode>
</Data>
What I do is to parse the XML using Hash.from_xml and then process the data. To iterate through the episodes, I do something like:
hash_data['Data']['Episode'].each do ...
This works great if there are multiple episodes. But if there's only one episode, the each method actually iterates through the hash entries for that single particular episode, rather than just running the each method once. That breaks all of my code following it.
I tried:
hash_data['Data']['Episode'].to_a.each do ...
with the same results. There must be a "right" way to do this?
UPDATE: I thought this question was fairly clear, but it appears people are confused by it. To clarify, I'm really trying to just iterate through the episodes and look at the contents. The data is initially received as XML, so in order to examine it in Ruby, I convert it to a hash using Hash.from_xml(xml_response).
In terms of "expected behaviour", take this example:
hash_data['Data']['Episode'].each do |e| { puts e['EpisodeNumber'] }
I would expect that given this initial data:
<Data>
<Series>...</Series>
<Episode><EpisodeName>Foo</EpisodeName><EpisodeNumber>1</EpisodeNumber></Episode>
<Episode><EpisodeName>Bar</EpisodeName><EpisodeNumber>2</EpisodeNumber></Episode>
</Data>
The output would be:
1
2
That works. However, if I'm given input like this:
<Data>
<Series>...</Series>
<Episode><EpisodeName>Foo</EpisodeName><EpisodeNumber>1</EpisodeNumber></Episode>
</Data>
I get a crash, because e['EpisodeNumber'] is not valid. It's not valid because in the case of only one episode, the each actually iterates through each key of the Hash (so the first value coming into the each block is a key-value pair of EpisodeName) instead of being an array of Hashes as it was when there was more than one element.
In other words, when there are multiple episodes, hash_data['Data']['Episode'] is an Array of Hash types. When there is only one episode, it's just a Hash. My code would work properly if, when there was one episode, it was still an Array, but with only one item in it. But that's not the case. How can I deal with this properly?
I hope that clears it up?
UPDATE 2: It's been requested that I post Hash#inspect for the returned data. Here it is for a show with a single episode:
{"Data"=>{"Series"=>{"id"=>"263752", "Actors"=>"||", "Airs_DayOfWeek"=>"Thursday", "Airs_Time"=>"10pm", "ContentRating"=>nil, "FirstAired"=>"2013-01-17", "Genre"=>"|Game Show|Reality|", "IMDB_ID"=>"tt2401129", "Language"=>"en", "Network"=>"TBS Superstation", "NetworkID"=>nil, "Overview"=>"Hosted by Robert Carradine and Curtis Armstrong, King of the Nerds is the ultimate nerd-off. The series will follow eleven fierce competitors from across the nerd spectrum as they set out to win $100,000 and be crowned the greatest nerd of them all.\n\nKing of the Nerds will take the glory of geekdom to a whole new level as the eleven competitors live together in \"Nerdvana.\" Each week, they must face challenges that will test their intellect, ingenuity, skills and pop culture prowess. In each episode, the nerds will first compete as teams and then as individuals, facing challenges that range from live gaming to a dance-off to life-sized chess. One competitor will be eliminated each week until one nerd stands alone as the ultimate champion off all things nerdy.", "Rating"=>nil, "RatingCount"=>"0", "Runtime"=>"60", "SeriesID"=>nil, "SeriesName"=>"King of the Nerds", "Status"=>"Continuing", "added"=>"2012-10-31 21:53:29", "addedBy"=>"348252", "banner"=>"graphical/263752-g2.jpg", "fanart"=>"fanart/original/263752-1.jpg", "lastupdated"=>"1357501598", "poster"=>nil, "zap2it_id"=>nil}, "Episode"=>{"id"=>"4428487", "Combined_episodenumber"=>"1", "Combined_season"=>"1", "DVD_chapter"=>nil, "DVD_discid"=>nil, "DVD_episodenumber"=>nil, "DVD_season"=>nil, "Director"=>nil, "EpImgFlag"=>nil, "EpisodeName"=>"Welcome to the Nerdvana", "EpisodeNumber"=>"1", "FirstAired"=>"2013-01-17", "GuestStars"=>nil, "IMDB_ID"=>nil, "Language"=>"en", "Overview"=>nil, "ProductionCode"=>nil, "Rating"=>nil, "RatingCount"=>"0", "SeasonNumber"=>"1", "Writer"=>nil, "absolute_number"=>nil, "filename"=>nil, "lastupdated"=>"1357501766", "seasonid"=>"504427", "seriesid"=>"263752"}}}
Notice that Episode is a Hash type.
Here it is for a show with more than one episode:
{"Data"=>{"Series"=>{"id"=>"220441", "Actors"=>"||", "Airs_DayOfWeek"=>"Saturday", "Airs_Time"=>"8:30PM", "ContentRating"=>"TV-PG", "FirstAired"=>"2010-12-25", "Genre"=>"|Children|Drama|", "IMDB_ID"=>"tt1765510", "Language"=>"en", "Network"=>"The Hub", "NetworkID"=>nil, "Overview"=>nil, "Rating"=>"7.0", "RatingCount"=>"1", "Runtime"=>"30", "SeriesID"=>nil, "SeriesName"=>"R L Stine's The Haunting Hour", "Status"=>"Continuing", "added"=>"2011-01-10 15:59:43", "addedBy"=>"66501", "banner"=>"graphical/220441-g.jpg", "fanart"=>"fanart/original/220441-1.jpg", "lastupdated"=>"1354439519", "poster"=>"posters/220441-1.jpg", "zap2it_id"=>nil}, "Episode"=>[{"id"=>"3453441", "Combined_episodenumber"=>"1", "Combined_season"=>"1", "DVD_chapter"=>nil, "DVD_discid"=>nil, "DVD_episodenumber"=>nil, "DVD_season"=>nil, "Director"=>nil, "EpImgFlag"=>"2", "EpisodeName"=>"Really You (Part 1)", "EpisodeNumber"=>"1", "FirstAired"=>"2010-10-29", "GuestStars"=>"|Bailee Madison|Connor Price|", "IMDB_ID"=>nil, "Language"=>"en", "Overview"=>"A girl named Lilly (Bailee Madison) is given her very own life-sized \"Really You\" doll which is named Lilly D.; because she is good at manipulating her dad. Lilly remains a spoiled brat, bragging about Lilly D, even going as far as ripping the leg off a friends doll, after the friend informs Lilly that \"Lilly D hates Lilly\". Soon after, strange events begin to occur which Lilly's mother accuses Lilly of doing; despite how Lilly maintains she is innocent, and that Lilly D is alive.", "ProductionCode"=>nil, "Rating"=>"8.0", "RatingCount"=>"1", "SeasonNumber"=>"1", "Writer"=>nil, "absolute_number"=>nil, "filename"=>"episodes/220441/3453441.jpg", "lastupdated"=>"1350772755", "seasonid"=>"393441", "seriesid"=>"220441"}, ...
Notice Episode is now an Array of Hash types.
It sounds like Rails' Array#wrap method would solve your problem. I believe this should work:
Array.wrap(hash_data['Data']['Episode']).each do ...
Documentation here.
Use Hash Key/Value Methods
Rather than Enumerator#each, you probably want to use Hash#each_key, Hash#each_value, or Hash#each_pair to iterate through your hash.

Resources