Looking for help with YQL movie showtimes - yql

I had been using the undocumented Yahoo movies API until it was pulled a few days ago, so I'm looking for another way to retrieve local movie showtimes (ideally by theater). I found this thread about YQL datatables on SO, and the last post looked really promising. I just can't seem to figure out how to query the data to return local movies and showtimes. I've been trying variations on "SELECT * from movies.showtimes where location='myzip'" with no success. Any ideas?

select * from movies.showtimes
To get a list of all movies. Then:
select * from movies.showtimes with location='myzip' and name='one of the movies'
You could also do
select * from movies.showtimes with location='myzip' and name in whatever
There's no list by location, unfortunately

Related

AdWords Scripts. report ORDER BY not working

This function suppose to show in which hours adverts are clicked more often.
It works fine however I have problem with sorting it by "HourOfDay". When I add ORDER BY HourOfDay to the end of the query I get en error.
function exportReportToSpreadsheet() {
var spreadsheet = SpreadsheetApp.create('INSERT_REPORT_NAME_HERE');
var report = AdWordsApp.report("SELECT Clicks, Impressions, AverageCpc, HourOfDay FROM ACCOUNT_PERFORMANCE_REPORT DURING LAST_MONTH ORDER BY HourOfDay");
report.exportToSheet(spreadsheet.getActiveSheet());
Logger.log("Report available at " + spreadsheet.getUrl());
}
exportReportToSpreadsheet();
Anyone knows what is wrong with ORDER BY in AdWordsApp.report ?
https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_report
According to AWQL query language documentation it should work as expected.
https://developers.google.com/adwords/api/docs/guides/awql#using_awql_with_reports
BUG?
You cannot sort reports. From the AWQL documentation:
ORDER BY and LIMIT (sorting and paging) are NOT supported for reports.
Including these clauses in a query will generate an error.
Ordering is only possible when you use the different entities` selectors, e.g. to iterate over campaigns sorted by cost you could do
campaignIterator = AdWordsApp
.campaigns()
.forDateRange("LAST_MONTH")
.orderBy("Clicks DESC");

Sort users based on most recent response to a particular answer in a survey?

I'm trying to sort users based on their most recent response to a certain question in a survey using Rails 5, PostgeSQL 9.4.5
So far I've got:
User.includes(responses: [answer: :question]).where(questions: {id: X}).order(...)
Not sure what to put in the order. The responses all have numerical 'scores' representing which answer it is. I'm imagining something at the end like:
.order("answers.score ASC")
But I'm struggling to get the two to attach. I only want to sort the Users by their most recent answer to that specific question. (They can take the survey multiple times)
I'm assuming I need to set a string function in some SELECT, but I'm struggling to wrap my head around it.
Any help is appreciated!
You can print the actual SQL of the rails query like this:
User.includes(responses: [answer: :question]).where(questions: {id: X}).to_sql
Then you can order by the right table.field (find the table name in the SQL returned by to_sql) and the field in db/schema.rb
It should be a created_at. User...order('responses.created_at DESC')
UPDATE
But this will sort all responses and not users by their last response on question, as you've commented below.
In this case you have to:
group the users by their responses
calculate the last response(MAX(user_responses.created_at)) for each user
sort the users by last response
Something like this:
User
.includes(responses: [answer: :question])
.where(questions: {id: X})
.group('users.id')
.order('MAX(responses.created_at) DESC')

rails - count records by value

I am trying to group records based on a value from a column, so I can use it to display the information elsewhere. At the moment I have this working if I specify the values in the column -
#city_count = People.select('city,count(*)').where("city in ('london', 'paris')").group(:city).count
This works fine if I want a list of people in London and Paris but if the city list also has Sydney, New York, Rio etc I don't want to keep adding the extra cities to the 'city in', I would like this to just find the people selected by each city.
Does anyone know the best way of doing this? Also if it can include NULL values as well.
Just use:
#city_count = People.group(:city).count
to get counts for all cities. This will include an entry for nil.
A more efficient way would be to use the distinct and count methods together.
#city_counts = Person.distinct.count(:city)
That way the work is done in the db instead of in Ruby.

Cypher: Is it possible to find creepy people following my friends?

Let's say I've pulled down the Twitter graph local to myself into Neo4J. I want to find people who follow my friends in number larger that should be expected. More specifically, I want to find people who follow the people I follow, but I want the results to be sorted so that the person following the highest number of my friends is sorted first. Possible in Cypher?
Here's a console example:
http://console.neo4j.org/r/p36cgj
create (me {n:"a"}), (fo1 {n:"fo1"}), (fo2 {n:"fo2"}), (fo3 {n:"fo3"}), (fr1 {n:"fr1"}),
(fr2 {n:"fr2"}), (fr3 {n:"fr3"}),
fo1-[:follows]->me, fo2-[:follows]->me, fo3-[:follows]->me, me-[:follows]->fr1,
me-[:follows]->fr2, me-[:follows]->fr3, fo1-[:follows]->fr1, fo2-[:follows]->fr2,
fo1-[:follows]->fr2, fo1-[:follows]->fr3;
start me=node:node_auto_index(n="me")
match me-[:follows]->friends<-[:follows]-follower-[:follows]->me
return follower, count(friends) as creepinessFactor, length(me-[:follows]->()) as countIFollow
order by creepinessFactor desc;
I'm curious to hear the results, btw. :P
You could also throw in a where like:
where not(me-[:follows]->follower)
To avoid getting friends within your circle.

getting random rows with yql?

I want to use javascript to fetch data with yql from flickr,
e.g.
select id from flickr.photos.search(10) where text = 'music' and license=4
however, I would like to fetch 10 random rows, rather then the latest, since the latest tend to be 10 photos all from the same person.
ist that possible in yql itself (I suspect not),
or any workarounds that could bring the same effect?
(it does not have to be complete random, the main thing I want to avoid is to get 10 photos from the same poster)
To get only results from unique owners, you can use the unique() function (docs).
My suggestion would be to query for a larger result set (more likely to have 10 unique people) then call unique() followed by truncate() to limit to 10 results, as below.
select id from flickr.photos.search(100) where text = 'music' and
license=4 | unique(field="owner") | truncate(count=10)

Resources