土豆炒青椒
土豆炒青椒

Community Activities Counting Bonus Experience

(edited)
I don't know how other event moderators calculate the bonus, I usually use GraphQL+pandas to calculate. The efficiency is pretty good, so far I haven't missed it 😅

There is a time point at the end of the event. I don’t know how the official operation works. I think it is more reliable to collect data manually.

Of course I will try to make the process of collecting data as simple as possible.


1 Collect the data required for the award

The rules for awarding prizes are invented by themselves.

For example, in this event, I need to know the following 4 data to calculate the bonus:

So I go to Matters API ( https://server.matters.news/playground ) to get the data I want with GraphQL. The sample code is as follows:

 query {
  article (
    input: {
      mediaHash: "bafyreieqexsfcxp6zvubbn4xwkdr2dh6sksi52ijwwyz46wr42ysmig33y"
    }) {
    id
    title
    summary
    wordCount
    readTime
    author {
      displayName
      followers(input: {
        oss: false
      }) {
        totalCount
      }
    }
    appreciationsReceivedTotal
  	transactionsReceivedBy(input: {
      purpose: donation
    }) {
      totalCount
    }
  }
}


Using the above code, enter an article media hash value, and then return the four kinds of data I want:

"appreciationsReceivedTotal" is what we commonly call the number of clapping hands🤣.

If you compare the article page, you will find that the data obtained through the Matters API is consistent with the data displayed on the article page, so there is no mistake.


2 Get all submission data with tag ID

Of course, at the end of a normal event, there will definitely not be only one submission.

If there are 100 submissions at the end of the campaign, I certainly don't want to lose the hash 100 times and repeat it 100 times. . . . . . So figure out how to get all the articles under the contribution tab at once .

According to the Matter API documentation, it seems that the only way to get all the articles under the same tag at once is through node. . . . . . The process is slightly cumbersome. . . . . .

As shown in the figure below, the articles that have effectively participated in the event will be displayed under the theme page of the event tab. For example like this:

For example, this activity now has 12 works. Then at the end of the event, I need to get the data of these 12 works, and then calculate who won the prize.

The red box is the active tag id

I first get the activity tag id at the url of the activity submission page, and then use the Matters API to get the data I need to calculate the bonus. This time the code is slightly more complicated. . . . . . 🥲 (If anyone knows how to simplify the code, welcome to add...)

 query {
  node (
    input: {
      id: "VGFnOjcwMDg1"
    }
  ) {
    id 
    ... on Tag {
      content
      articles (input: {
        oss: false
        first: 12
      }) {
        totalCount
        pageInfo {
          hasNextPage
        }
        edges {
          node {
                title
                wordCount
                readTime
                appreciationsReceivedTotal
                transactionsReceivedBy(input: {
                  purpose: donation
                }) {
                  totalCount
                }
                author {
                  displayName
                  followers(input: {
                    oss: false
                  }) {
                    totalCount
                  }
                }
          }
        }
      }
    }
  }
}


At the end of the event, I ran the above code once, and I got the necessary data for all the articles. . . . . . . Rare to trouble the official. . . . . . .

If the official does not work at the end of the event. . . . . . . I don't know how the official records are made by time. . . . . . So it's better to collect it manually. . . . . .


3 Quickly save the fresh data at the moment of the event

Because the bonus is calculated later, I will use python pandas, so I will use python. . . . . .

 import requests
import json
url = 'https://server.matters.news/graphql'
req = requests.post(url, json={'query': query})
print(req.status_code)
df_data = json_data['data']['node']['articles']['edges']


Anyway, we have to use pandas in the end. After getting the data, we can directly make it into a dataframe. . . . . .

 data = []

for item in df_data:
    article = {}
    article['title'] = item['node']['title']
    article['wordCount'] = item['node']['wordCount']
    article['readTime'] = item['node']['readTime']
    article['clap'] = item['node']['appreciationsReceivedTotal']
    article['support'] = item['node']['transactionsReceivedBy']['totalCount']
    article['author'] = item['node']['author']['displayName']
    article['follower'] = item['node']['author']['followers']['totalCount']
    data.append(article)

df = pd.DataFrame(data=data)


After making it into a dataframe, check it again, it is the data I need. . . . . .

Save after checking! ! ! ! ! ! Because when the time passes, someone will like it again. . . . . . If it is not saved in time, the API data will be inaccurate if you run it again. . . . . .

The code to save the dataframe to a local csv file is as follows:

 df.to_csv("data.csv")

The above completes the process of writing a letter to the official to ask for excel data. . . . . . 😅 Except for the number of words, which is shown as null because of the revised re-release, all other data are accurate. . . . . . 😅




If you prepare the above code in advance, run it again at the end of the event and save the data locally, it should take less than 10 minutes to collect the data. . . . . .

The above code can be reused depending on the required parameters. . . . . . I don't know if the official is interested in adding a button to the activity tab page. . . . . . When the time is up, click the button to download Excel directly, saving a lot of trouble. . . . . . 😅


As for the bonus. . . . . . Both excel and python can do the math. . . . . . Use whichever you like. . . . . . The principle is to enter the bonus formula, and then calculate. . . . . . As long as you're not wrong. . . . . . Whichever is used is the same. . . . . .

Therefore, the process of calculating the bonus is relatively simple. . . . . .

What's really annoying is the bonus. . . . . . 😅

The reward API should be payTo, but it has not been tested yet. . . . . . So I still use the method of sending money from community activities to send it manually🤣. . . . . . If you want to send 100 times, it is easy to get sleepy and distracted. . . . . . It's embarrassing to lose money by sending out the wrong bonus. . . . . . 😅

CC BY-NC-ND 2.0

Like my work?
Don't forget to support or like, so I know you are with me..

was the first to support this article
Loading...

Comment