Does Google App Engine Projection Queries are supported by Web2py? - google-app-engine

I'm making a good progress using Web2py and Google App Engine, but now I have to decide how to store images without waste GAE resources!
I have a "table" were I store products.
Each product can have a maximum of 12 picutes.
When I request the product page, lets say:
/product/7484/
I need only the product informations, without the pictures, but GAE engine get all fields from datastore! I thought that using Google App Engine Projection Queries, this could be solved and I would only fetch the fields I need!
Is that possible with Web2py or will I have to change my database to store imagens on another "table"?
I only will need fetch each picute field when they get requested by browser... but now, each picture requested cause the whole product entity being fetched from database!

We have it as an experimental feature in trunk. Perhaps you can help us test it. Nothing special to do just the usual:
db(query).select(db.table.field1, db.table.field2, etc.)
unless the query selects a single record by id, the arguments of select are converted into a projection query. Unfortunately GAE does not support projection for get_by_id().
Thanks to Christian (howesc) who pulled this off within 24 hrs from you requesting the feature. Please join us on the web2py google group if you can help testing.

Related

Return top viewed items by country using data from Google Analytics

So I have an app written in Go on App Engine where I have items in Datastore and provide search through the Search API. Users can view the items and doing so feeds view events with country information to Google Analytics.
I would like to understand how to use that information to e.g. return Top Viewed Items by Country?
I have researched this topic quite a bit, but have not found a good approach yet. There is a rank in Search, but that value will be different for each country so I cannot use that.
I can see that having different indexes (one per country) and using that rank field or a rank field per country would provide what I want. What if the items are hundreds of thousands or more? What if I would like to offer trending that might need to be updated often across the whole dataset and not just a counter? Is this the best approach?
Maybe this is a limitation of what I currently can do on App Engine?
How would one approach this generally and maybe with another Search like Elastic Search?
Thanks in advance!
Try this report:
Google Analytics > Reporting > Behavior > Site Content > All Pages

How can I avoid write operations while deleting the all data from Google App Engine datastore?

I am new to Google App Engine development. We have developed application with android and Google App Engine.We tried to delete all data but write operations became 100% and we can not simply delete further records. How can we manage to delete the data without exceeding 100%.
Can someone please explain us so we can follow the steps.
Thanks,
Prashant
You simply cannot delete records without accounting it for in the quota.
Ref: https://cloud.google.com/appengine/pricing#costs-for-datastore-calls
Entity Delete (per entity) --> 2 writes + 2 writes per indexed property value + 1 write per composite index value
So if you are in free-quota, you cannot delete or write any further, without enable billing.
Work around
Google allows 25 free app-engine projects to each user id. Create a new project and upload the old project code to new project id. If your daily traffic is within the free quota, you can use it as long as you want.

Track user selected values on ecommerce(amazon.com) website (GAE Python) using Google Analytics API

I have designed an ecommerce website like amazon.com. I want to collect user analytics data on my website. I am still evaluating options and Google Analytics API looks good as it does not charge anything for a good amount of usage. And it should be fast.
What information do I want to collect about user behavior on my website:
What "dropdown" menu values do they select(say for narrowing down the exact product category)
What "checkboxes" do they select to filter out based on price range, size, type, or a specific feature
Which result entries(matched products) on the search page do they click
It would be good if I could get the time of day when the above happened
Also how long the user viewed a page (with an upper limit for cases when a user opens a tab and forgets to close it)
I hope the Google Analytics API has some feature to prepare charts based on the above data, as well as provide the average monthly values for the above counts
I decided to use an external Analytics tool since writing into NDB would take time, increase writes and increase the storage requirement
Any guidance is highly appreciated.. Anyone who has implemented similar analytics for their website, please share your advice..

Sync google contacts by group to a limited number of users

I am trying to build an open-source python code hosted at GAE to sync contacts by group to a limited number of users. In a web interface users will be able to pick their group and whom it will be synced with.
I understand there is a lot of applications on market place withe the same functionality, but my organization is concerned about those provides selling contacts to 3rd parties. We are a non-profit organization, so the code could be hosted at google project or github for community contribution.
(sorry for the long intro)
How is the best way to start? is there tutorial available with similar functionality that I can expand?
What is the best way to compare two Contact kind elements? To see if they need to be sync.
Is there a last update on the Contact kind elements? In case I want to implement a last update wins?
thanks!
I don't know of any tutorials for syncing and comparing contacts specifically, but there is a getting started guide for the Google Contacts API at https://developers.google.com/google-apps/contacts/v3/.
The contacts are sent as XML blobs, so you could compare two contacts by parsing them and looking at the individual elements within them. I don't think there's a better way to do this but there are libraries to handle it for you.
There is a last updated field sent as part of the contacts when retrieving them with the API. It is an XML element labeled <updated>.
how are you getting different user's contacts feeds?
i tried to save the tokens in the datastore when the
users grant the access, but when i get the token back
from datastore for 2 users at a time, after an hour
when the token expires,
all tokens start working like the current users token
and i can only get current users contacts.
token = Get_Shared_User_Token(user_email)
contact_client = gdata.contacts.client.ContactsClient(source=USER_AGENT)
authorized_client = token.authorize(contact_client)
contacts_feed = authorized_client.GetContacts(q = query)
can you please tell how one can get any user's contacts?

Google App Engine large IN clause query

I have an Account entity that has a facebook id.
Sometimes, the client might send all facebook ids (the clients facebook friends) to the server.
We want to select all Accounts IN the facebook ids the client provided.
Looping and calling get on each facebook id seems rather slow, considering people might have 1000+ friends. Further more, GAE is limited to 30 queries with IN clause.
Has anyone had a similar situation? How did you handle it?
Thanks!
You can set up a model that uses the facebook ID as a key which allows you to use Model. get_by_key_name(key_names=fb_ids) to fetch all the models with keys in fb_ids at once.
e.g.
class FBModel(db.Model):
account = db.ReferenceProperty(reference_class=Account)
When creating the model:
model = FBModel(key_name=fb_id)

Resources