This question is related to this post that Kelvin Lawrence answered very helpfully, wanted to post it as a separate question bec the first question was answered well already.
From this query:
g.V('a2661f57-8aa7-4e5c-9c89-55cf9b7e4cf8').as('self')
.sideEffect(out('rated').store('movies'))
.out('friended')
.group()
.by(valueMap(true).by(unfold()))
.by(out('rated').where(within('movies')).count())
.order(local)
.by(values,desc)
.unfold()
.select(keys)
i get this result:
1 {<T.id: 1>: 'fdc45bd3-be08-4716-b20f-b4f04987c5e0', <T.label: 4>: 'user', 'username': 'elin102dev', 'name': 'elin obrien', 'avatarUrl': 'public/avatars/fdc45bd3-be08-4716-b20f-b4f04987c5e0.jpg'}
2 {<T.id: 1>: 'bbf1b0db-68cc-41f1-8c7a-5fd77b698e39', <T.label: 4>: 'user', 'username': 'iris', 'name': 'Iris Ebert', 'avatarUrl': 'public/avatars/bbf1b0db-68cc-41f1-8c7a-5fd77b698e39.jpg'}
3 {<T.id: 1>: '34c2ea80-4f84-4652-a7c3-48ce43d9aea7', <T.label: 4>: 'user', 'username': 'iris103dev', 'name': 'iris obrien', 'avatarUrl': 'public/avatars/34c2ea80-4f84-4652-a7c3-48ce43d9aea7.jpg'}
I want to convert the T.id and T.label values in the response to simply "id" and "label". Kelvin, if you're reading this, i i tried appending the following to the query above but it returns 0 results:
.select('id', 'label', 'username', 'name', 'avatarUrl')
.by(T.id)
.by(T.label)
.by('username')
.by('name')
.by('avatarUrl')
.toList()
I could use a little more help figuring this out, not having much success. Thanks in advance.
It is not possible to do a select(T.id) inside a query. In code if you get a map back you can access the T.id field. For a case such as this, it is better to delay fetching the properties until you finally need them. You might try rewriting the query like this.
g.V('a2661f57-8aa7-4e5c-9c89-55cf9b7e4cf8').as('self').
sideEffect(out('rated').store('movies')).
out('friended').
group().
by().
by(out('rated').where(within('movies')).count()).
order(local).
by(values,desc).
unfold().
select(keys).
project('id','label','username').
by(id).
by(label).
by('username')
Related
I am trying to write a Python code so that I can apply a questionnaire to my physics students remotely. They would receive and reply to the quiz via
a Telegram bot. I'm using the python-telegram-bot module. I can already identify which users replied, but I can't get yet their answers.
I am starting with the example code pollbot.py from here: https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/examples/pollbot.py
The specific methods are these:
def quiz(update: Update, context: CallbackContext) -> None:
"""Send a predefined poll"""
questions = ["1", "2", "4", "20"]
message = update.effective_message.reply_poll(
"How many eggs do you need for a cake?", questions, type=Poll.QUIZ, correct_option_id=2
)
# Save some info about the poll the bot_data for later use in receive_quiz_answer
payload = {
message.poll.id: {"chat_id": update.effective_chat.id, "message_id": message.message_id}
}
context.bot_data.update(payload)
def receive_quiz_answer(update: Update, context: CallbackContext) -> None:
"""Close quiz after three participants took it"""
# the bot can receive closed poll updates we don't care about
if update.poll.is_closed:
return
if update.poll.total_voter_count == 3:
try:
quiz_data = context.bot_data[update.poll.id]
# this means this poll answer update is from an old poll, we can't stop it then
except KeyError:
return
context.bot.stop_poll(quiz_data["chat_id"], quiz_data["message_id"])
The telegram app shows to the user if s/he answered correctly or not. I already know which user answered the quiz. I would like to know programmatically which of the possible options of the quiz the user answered.
I did print message in the quiz method and I found this:
{'message_id': 93, 'date': 1614250320, 'chat': {'id': xxxxxxxx, 'type': 'private', 'first_name': 'user', 'last_name': 'name'}, 'entities': [], 'caption_entities': [], 'photo': [], 'new_chat_members': [], 'new_chat_photo': [], 'delete_chat_photo': False, 'group_chat_created': False, 'supergroup_chat_created': False, 'channel_chat_created': False, 'poll': {'id': '5024004102909067266', 'question': 'How many eggs do you need for a cake?', 'options': [{'text': '1', 'voter_count': 0}, {'text': '2', 'voter_count': 0}, {'text': '4', 'voter_count': 0}, {'text': '20', 'voter_count': 0}], 'total_voter_count': 0, 'is_closed': False, 'is_anonymous': True, 'type': 'quiz', 'allows_multiple_answers': False, 'correct_option_id': 2, 'explanation_entities': [], 'close_date': None}, 'from': {'id': 144******6, 'first_name': 'my_own', 'is_bot': True, 'username': '_my_own_Bot'}}
It seems the info on the user answer is nowhere here.
Also voter_count is not changing, it stays at zero no matter how many
answers I click on at the chat group.
I added these lines in the method receive_quiz_answer:
quiz_data = context.bot_data[update.poll.id]
print(quiz_data)
and I only got this info:
{'chat_id': 15******53, 'message_id': 87}
which is not relevant for what I want. I believe the answer should be in
telegram.PollAnswer, which is not listed in the code above.
I added the following lines:
answer = update.poll_answer
print("answer is {}". format(answer))
in receive_quiz_answer method, but I got the reply:
answer is None
Any help appreciated.
Thanks a lot.
For a small app prototype I'm building, I would like to use firestore (firebase) to store some data. I'm wondering if the following is a good way of going about a nosql database.
I have Paths, that belong to Categories. A Path can have courses and comments. I would like users to see the likes a path has, and get categories sorted by the amount of paths inside.
That's why I'm adding the paths_count on the categories table, I will use Cloud Functions to update the counts for the likes and paths on each database update.
categories: [
1: {name: "productivity", paths_count: 10},
2: {name: "cooking", paths_count: 5},
]
paths: [
1: {
name: "Productivity 101",
category_id: 1,
likes_count: 5,
likes: [],
courses: [],
comments: []
}
]
Is this a good start?
I'm running into an issue that I'm hoping someone might know how to resolve. In the reporting api, I can get information based on a sku. Something like so:
{
'reportRequests': [{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
'metrics': [
{"expression": "ga:productDetailViews"},
{"expression": "ga:itemQuantity"},
{"expression": "ga:uniquePurchases"},
{"expression": "ga:itemRevenue"}
],
'dimensions': [{'name':'ga:productSku'}]
}
]
}
This is great for getting the data tied to a sku, but I was wondering if there is a way to get additional product information for each sku rather than metric information. For example, given a set of skus, I'd like to see the category hierarchy (section, category, subcategory) as well as the product name:
SKU, Name, Section,Category, Subcategory
1, Blah, Shoes, Basketball,
2, Another,Shoes, Soccer, Mens
...
Given that information like this is all correlated on a page when sent from a website, I don't see why this shouldn't be possible.
ga('ec:addProduct', {
'id': '1',
'name': 'Blah',
'category': 'Shoes/Basketball',
});
Adobe has something similar with their Saint Classifications and I was hoping it would be something possible to get out of GA. I can't seem to find anything like this across any of the apis, so am hoping someone can point me in the right direction!
As you look to have specified categories with the correct '/' delimiter you can use the dimension ga:productCategoryLevelXX, you do need to have at least one metric in your request but you could do something like
{
'reportRequests': [{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
'metrics': [{"expression": "ga:productDetailViews"}],
'dimensions': [
{"expression": "ga:productSku"},
{"expression": "ga:productCategoryLevel1"},
{"expression": "ga:productCategoryLevel2"},
{"expression": "ga:productCategoryLevel3"}
]
]
}
Hitting the Historical Follower Count API documented at
https://developer.linkedin.com/docs/company-pages#historical_followers
URL is:
https://api.linkedin.com/v1/companies/{id}/historical-follow-statistics?time-granularity=day&start-timestamp=1501718400000&end-timestamp=1501718400000&format=json
Those timestamps are both for today. Response is:
[
"_total" => 1,
"values" => [
[
"organicFollowerCount" => 932,
"paidFollowerCount" => 84,
"time" => 1501718400000.0,
"totalFollowerCount" => 1016,
],
],
]
But the actual current follower count on the Company's page is 1009
Which of these number is correct? The follower count for this company does not fluctuate that much to account for this difference.
Thanks!
Company Followers count mismatch between num-followers and statistics endpoints.
API Endpoint1: https://api.linkedin.com/v1/companies/{id}/company-statistics? API Endpoint2 : https://api.linkedin.com/v1/companies/{id}/num-followers?
Here in second api endpoint , you can get accurate followers count. But company statistics endpoint returning more followers count than actual count. dont know why
I have run the following query in the Freebase MQL query editor:
[{
"id" : "/en/barack_obama",
"/type/reflect/any_master":
[{ "link" : null,
"name" : null }],
"limit": 200
}]
I believe this should return all the links that originate from Barack Obama and whose destiantion is a topic. While it does return the links, it fails to return the children of Barack Obama which is also a link, right? Why does it fail to return this link?
The query is returning the complete set of results that you asked for. There are three things wrong with it for the purpose you are trying to use it for:
The limit clause is in the wrong place
The President Obama topic has many more than 200 links, both outgoing (558) and incoming (1527)
The relationship that you're looking for is the reverse of the /people/person/parent relationship, so you need to use any_reverse, not any_master
This query will find the relationship you're looking for:
[{
"id": "/en/barack_obama",
"/type/reflect/any_reverse": [{
"link": null,
"name": null,
"limit": 1600
}]
}]