There´s a way to receive all output fields using Batch Geocode endpoint?
I´m using this endpoint but I would like get all outCols fields available:
https://batch.geocoder.ls.hereapi.com/6.2/jobs?apiKey={MY_KEY}&action=run&inDelim=;&outDelim=;&outCols={WAY_TO_GET_ALL_FIELDS}&language=pt-BR&gen=8&header=true&outputCombined=true
outcols Enumeration, Required List of columns to return in the output.
So in outcols, we will have to provide the list of columns to return in the output.
Refer more details : https://developer.here.com/documentation/batch-geocoder/dev_guide/topics/request-parameters.html
Also , there are hundreds of out put fields but in customer use case all are not required at once.
details of all output fields : https://developer.here.com/documentation/batch-geocoder/dev_guide/topics/read-batch-request-output.html
Related
I've multiple fields in my model, and I need to remove the average of only the columns user inputs
Could be
How can I do it dynamically?
I know I can do
mean = results.aggregate(Avg("student_score"))
This is one, I want to add multiple Avg statements dynamically
I tried making a loop as well to get all names and add all fields given by user one by one
eg - Avg('students'), Avg('playtime'), Avg('grade'), Avg('sales')
But I get
QuerySet.aggregate() received non-expression(s): <class 'django.db.models.aggregates.Avg'>('students'), <class 'django.db.models.aggregates.Avg'>('sales').
I've even tried raw query, but it needs a unique ID because of which that isn't working
Any workaround ideas?
I am using MySQL DB
Aggregate return single result from the list of objects. You need to annotate if you need multiple result like following,
YourModel.objects.values("YOUR GROUP BY VALUES HERE").annotate(Avg('students'), Avg('playtime'), Avg('grade'), Avg('sales')
I am working on customer document (data like fname, lname, orderAmount etc.) which is configured on AWS CloudSearch. Now the situation is that I am showing this data on jquery datatable. for pagination I required to have total items available for search. Is there any way I can get count of all available document on cloudsearch ?
I am getting response for matching count, But not the total items available on cloudsearch doamin.
I have search for this under https://docs.aws.amazon.com/cloudsearch/latest/developerguide/what-is-cloudsearch.html but did not found any useful thing.
Any trick to get total document count on particular cloudsearch domain ?
amazon does not have an easy way to fetch all the records, so we basically pass a condition which would never be true & return all the record.
Key Points
Get only single item (pageSize = 1)
Get item without fields
For Example
http://search-movies-rr2f34ofg56xneuemujamut52i.us-east-1.cloudsearch.amazonaws.com/2013-01-01/search?q=(and+(id:0))&q.parser=structured&return=_no_fields&size=1
I show a model of sales that can be aggregated by different fields through a form. Products, clients, categories, etc.
view_by_choice = filter_opts.cleaned_data["view_by_choice"]
sales = sales.values(view_by_choice).annotate(........).order_by(......)
In the same form I have a string input where the user can filter the results. By "product code" for example.
input_code = filter_opts.cleaned_data["filter_code"]
sales = sales.filter(prod_code__icontains=input_code)
What I want to do is filter the queryset "sales" by the input_code, defining the field dynamically from the view_by_choice variable.
Something like:
sales = sales.filter(VARIABLE__icontains=input_code)
Is it possible to do this? Thanks in advance.
You can make use of dictionary unpacking [PEP-448] here:
sales = sales.filter(
**{'{}__icontains'.format(view_by_choice): input_code}
)
Given that view_by_choice for example contains 'foo', we thus first make a dictionary { 'foo__icontains': input_code }, and then we unpack that as named parameter with the two consecutive asterisks (**).
That being said, I strongly advice you to do some validation on the view_by_choice: ensure that the number of valid options is limited. Otherwise a user might inject malicious field names, lookups, etc. to exploit data from your database that should remain hidden.
For example if you model has a ForeignKey named owner to the User model, he/she could use owner__email, and thus start trying to find out what emails are in the database by generating a large number of queries and each time looking what values that query returned.
I have a Message class which has fromUser, toUser, text and createdAt fields.
I want to imitate a whatsapp or iMessage or any SMS inbox, meaning I want to fetch the last message for each conversation.
I tried:
messages = Message.objects.order_by('createdAt').distinct('fromUser', 'toUser')
But this doesn't work because of SELECT DISTINCT ON expressions must match initial ORDER BY expressions error.
I don't really understand what it means, I also tried:
messages = Message.objects.order_by('fromUser','toUser','createdAt').distinct('fromUser', 'toUser')
and such but let me not blur the real topic here with apparently meaningless code pieces. How can I achieve this basic or better said, general well-known, result?
Your second method is correct. From the Django docs:
When you specify field names, you must provide an order_by() in the QuerySet, and the fields in order_by() must start with the fields in distinct(), in the same order.
For example, SELECT DISTINCT ON (a) gives you the first row for each value in column a. If you don’t specify an order, you’ll get some arbitrary row.
This means that you must include the same columns in your order_by() method that you want to use in the distinct() method. Indeed, your second query correctly includes the columns in the order_by() method:
messages = Message.objects.order_by('fromUser','toUser','createdAt').distinct('fromUser', 'toUser')
In order to fetch the latest record, you need to order the createdAt column by descending order. The way to specify this order is to include a minus sign on the column name in the order_by() method (there is an example of this in the docs here). Here's the final form that you should use to get your list of messages in latest-first order:
messages = Message.objects.order_by('fromUser','toUser','-createdAt').distinct('fromUser', 'toUser')
I am using the open_graph Explorer tool to test this out and I need to be able to get the first_name, last_name and installed from 1000 users. At the moment I group up the users in grouped of 50 for a single query and batch them into up to 20 queries in a batch request.
A single query looks as follows
?ids=100003825998801,100003825998802,547884299,100003825998803,100003825998804,100003825998805,100003825998806&fields=first_name,last_name,installed
Now, the question is, when you use multiple ids in a single query like I did, facebook seems to "force" certain fields on you, large fields, such as "metadata" and "fields". Is it possible to remove these fields from the result set of the query?
Also, any advice on how to make this more efficient would also be great.
Thank.
Have you considered using FQL instead …?
SELECT first_name, last_name, is_app_user FROM user
WHERE uid IN (100003825998801,100003825998802,547884299,100003825998803,
100003825998804,100003825998805,100003825998806)
– that gives you just the info you want, you only have to watch out for the fact that the installed field is named is_app_user in FQL.