List top 10 gold badge medalists in Code Review - data.stackexchange.com

What I want to achieve in particular is getting top 10 gold badge medalists in Code Review.
(A Data Explorer solution is acceptable, too.)
Is there a way to do it?

Using the Stack Exchange Data Explorer (SEDE) what you're asking is much easier.
From the Badges table, filter only the badges awareded that are gold, group by users and sort by the count.
SELECT
TOP 100 UserId AS [User Link],
COUNT(*)
FROM Badges
WHERE class = 1
GROUP BY UserId
ORDER BY COUNT(*) DESC
You can see the query live here.
Reference: Database schema documentation for the public data dump and SEDE

Related

How to show all the value of all customers that have even one of filtered values in power bi

I have the table of customers with different statuses in different months
.
I have added Status value In Power BI Slicer Visual to filter the Matrix Data. And when, selecting for example A, it only shows customers who has A status in certain period.
Filtered Customer Data
.
(6 an 8 are missing because they don't have status A in any period). The Problem is that I want to see all the statuses of the customers who even once had status A. is it possible somehow in Power BI ?
Result I want to See
Good news: there is a pretty easy fix for this.
Create a new table using DAX.
FilterableStatuses =
SUMMARIZE(
DemoData,
DemoData[CustomerID],
DemoData[Status]
)
Create a relationship in your model between CustomerID on this new table and CustomerID on the table from your visual. It will be Many to Many and I prefer to not leave the filter direction as 'both' -- make it so FilterableStatus filters your original table.
Create a slicer using the status from FilterableStatuses rather than the original table, and that should give you the behavior that you're after. In essence, rather than filter the visual by [Status], you are filtering the list of CustomerIDs by status, and then letting the new relationship filter your visual to CustomerIDs
Hope it helps!

Google Data Studio - Advanced Filter "Which other brands do customers of a spefic brand buy"

My datasets contains the following columns:
- person_ID
- brand
- purchase_date
Now I'd like to use Google Data Studio to create a Dashboard which shows what other brands are purchased by persons who also bought brand X.
with identification as
(
select person_ID
where brand = 'X'
from dataset
)
select count(distinct(data.person_ID)), data.brand
from dataset data
inner join identification ident on data.person_id = ident.person_id
Using Google Data Studio to transform the SQL-code (shown above) in an interactive dashboard solution.
"what other brands are purchased by persons who also bought brand X"
So first you need to get your data into the format you want to present it in. The following SQL should provide data which has every combination of product bought by a customer for example.
SELECT data1.brand brand_purchased, data2.brand other_brands_purchased,
count(distinct(data.person_ID)) uniqueCustomers
FROM dataset data1
INNER JOIN dataset data2 on data1.person_id = data2.person_id
AND data1.brand <> data2.brand
Once you've got the data in a format you need, you'd link that via a connector to data studio.
You can then choose the presentation style you wish to show back to the customer (bar chart, table, etc) and add a filter which has the "brand_purchased" dimension to filter your data by.
It's hard to tell you exactly what to do as there are so many viable solutions depending on how you store your data and how you want to visualise it.
Data Studio's strength is in visualising the data especially to those who aren't data savvy. If you're strong in SQL however, you may find it easier to get to the answers you need through SQL.

Using GORM efficiently to retrieve join data - Grails 2.3

I have User, and Follow Domain class that construct the Follower, Following relationship like Twitter. When my User visits another User's page, and click on their Follower list. I pop-up the list of the visited person's follower list, and then show a button in front of it that is labeled "Follow" or "Unfollow" depending on if you already following that person. So I do it the following way, but I'm not sure if this is efficient or maybe there is a better way of doing it. In order to make it efficient, I only retrieve 20 follower at a time and allow pagination.
> example of pop-up:
> ----------------------------------------------
> alex [follow]
> dave [unfollow]
> sarah[follow]
> paul [follow]
> ----------------------------------------------
Follow domain class has:
// The person to follow
User follow
// The person who is following the follow
User follower
// The status of the relationship if removed or still following
boolean status
User domain class is the typical Spring Security User class with a bunch of extra fields like locations and etc.
In my controller when I receive a request for follower list I do the following.
def visitedUser = User.get(visitedUserId)
// get the list of top 20 followers of this user
def followerList = Follow.findAllByFollow(visitedUser, [max:20])
// get the list of all people current user follow who is in the 20 follower list
def mutualFollow = Follow.findAllByFollowerAndFollowInList(currentUser, followerList)
Now I have the list of all the followers in profile of the person I'm visiting, and also the list of those who are mutual. Then I pass both to my GSP and while loop through the followerList in GSP, I compare the id of that follower, if the follower exist in my mutualFollow list I tweak the button to "unfollow" otherwise I keep the button as follow.
One step further to optimize this is to user projection to only retrieve the id of the mutualFollow instead of the whole USER domain object, but since USERs coming back are proxied and they have wrapper around them, I'm not sure that makes a big difference. Because All I retrieve is the id.
I appreciate any suggestion to improve this approach or an alternative. Thanks
I decided to use HQL and only retrieve the necessary info of those USERs within the follow list, and then I did a join to get the mutual people they both follow. And used that in the GSP page. Here is the simplified solution in SQL:
SELECT Ur.follow_id, Urs.follow_id as mutual FROM (SELECT * FROM FOLLOW WHERE FOLLOWER_ID=1)as Urs
RIGHT JOIN (SELECT * FROM FOLLOW WHERE FOLLOWER_ID=3) as Ur
ON Urs.follow_id=Ur.follow_id order by Ur.follow_id;

Creating a page to show data with foreign keys

I'm creating an APEX application that allows students to apply to job placements, and allows an admin to see all interactions. I want to create a page to show all of the students applications.
First off, here's the database schema for the tables involved:
Full sized link: http://i.stack.imgur.com/QU1Pr.png
I have a report with a list of students and I've added a "View Applications" column. I've made the "View Applications" column linkable, and it goes to the new page. The problem is, I have no idea how to show all of the applications for the student that the admin is currently looking up.
The only way I can think of doing it is passing RECORD_NUMBER (PK in students table) to the new page and then executing some SQL using that, and populating the page fields with what's returned. But I have no idea how to do that. I don't know how to grab the RECORD_NUMBER value to use in SQL and I don't know how to populate form fields with what's returned by the SQL.
Any help is appreciated.
So you've got one page that lists applications and the students that have applied. We'll call that page 1. If I understand what you're trying to do, you can create a page 2, with a report and a hidden page item. Call the page item P2_RECORD_NUMBER.
Create the report with the query:
SELECT *
FROM tbl_jobs j
INNER JOIN tbl_applications a on a.job_id = j.id
INNER JOIN tbl_students s ON s.record_number = j.record_number
WHERE s.record_number = :P2_RECORD_NUMBER
Now edit the link on page 1 so it points to page 2 and populates P2_RECORD_NUMBER with the record_number of the row that the user clicked on. I don't have Apex in front of me, but I think you can do that by editing the report attributes for that column. Also, you can use the url of the form http://site.com/f?p=<APP_ID>:<PAGE_ID>:0::::P2_RECORD_NUMBER:<record_number>. (I'm doing that from memory and may have the number of colons wrong.)
You'll also want to have some default text in place in case the query above returns no rows.
Just create a new page for the admin and enter a query like
SELECT *
FROM tbl_students s
JOIN tbl_applications a USING (record_number)
JOIN tbl_jobs j ON a.job_id = j.id
Do you know where to add the query?

what would be a good algorithm to keep count of unread items In an online feed aggregator implementation?

Assume the database has tables for Users, Feeds, Items, and an ability to know which Items the user has already seen. I am looking for a design paradigm that can be used on the server to compute in a short amount of time [feed id, num_unread] for each feed that the user has subscribed to.
Assume plenty of users and that the feeds are getting updated periodically in the backend.
Edit: I wanted to solve the problem Nick J has brought up (see below). But I appreciate the solution posted by cletus. I am not so worried about the db queries, but want a "design paradigm" -- like keeping a watchdog process that keeps the unread counts in memory so that it can be served at any point.
I'm not sure what to tell you exactly because what you're asking is reasonably straightforward.
First off, use Google Reader as a reference for online feed aggregators/readers. And if you're trying to recreate the functionality, Google Reader has pretty much nailed it already (imho).
Google Reader works simply by storing a list of feeds. In DB terms, you'd probably have these entities
User: id, name, email, etc...
Feed: id, feed_name, feed_url
Content: id, feed_id, title, content
User Feed: id, user_id, feed_id, user_label, has_read
Unread items:
SELECT COUNT(1)
FROM user u
JOIN user_feed uf ON uf.user_id = u.id
JOIN feed f ON f.id = uf.feed_id
WHERE has_read = 0
Unread items by feed:
SELECT feed_id, feed_name, COUNT(1)
FROM user u
JOIN user_feed uf ON uf.user_id = u.id
JOIN feed f ON f.id = uf.feed_id
WHERE has_read = 0
GROUP BY feed_id, feed_name
And then you just need some mechanism for marking items as read. In Google Reader's case, there are just AJAX calls triggered by mouseover events with additional links to mark everything as read, leave an item marked as unread and so on.

Resources