Message Boards Message Boards

[HACKATHON] Analysis of Russian Social Network VKontakte

Posted 6 years ago

Introduction

We are living in the era of technologies when everything is fast and quick changing. Sometimes we don't have time to "clean up" our networks. Someone can say that we are lazy, but if we can make technologies and our knowledge work for us, why not? Our purpose was to analyse part of the popular Russian social networking service - "?????????" (VKontakte, meaning InContact). It is a standard situation when network administrators block pages of those people who break the social network rules. Some users in one day can decide that they don't want to "spend their lives on the Internet" and delete their pages. And here we are. One day you check your list of friends and understand that some of them have been blocked or deleted. Do you want to spend your time cleaning up your list of friends? We don't think so. But our programme can help you with this.

Description of our work

First of all, you need to get a list of the user's friends' IDs, which you can receive with a simple the GET method request.

Import["https://api.vk.com/method/friends.get?user_id=" <> userID <> 
   "&access_token=" <> token <> "&v=5.78", "RawJSON"] // Short

userID - user identification.

token - a system object representing the subject of access control operations.

Receive the output in the form of an Association.

<|response -> <|count -> 209, items -> {92070, 119121, 238683, 1266876, 1292342,<<199>>, 323263490, 328646963, 341263802, 395195137, 433885152}|>|>

From which select the list of IDs.

friendsResponse = 
  Import["https://api.vk.com/method/friends.get?user_id=" <> userID <>
     "&access_token=" <> token <> "&v=5.78", "RawJSON"];
friendIds = friendsResponse["response"]["items"];

Then we get additional information about each user with the help of users.get. It is worth to notice that in the user_ids parameter, you can work with a list of IDs, for this list should be comma separated.

informationResponse = 
  Import["https://api.vk.com/method/users.get?user_ids=" <> 
    StringRiffle[friendIds, ","] <> "&access_token=" <> token <> 
    "&v=5.78&fields=photo_max", "RawJSON"];
friends = informationResponse["response"];

Information about each user is in the followed form:

<|"id" -> 219746518, "first_name" -> "????", "last_name" -> "??????", 
 "photo_max" -> 
  "https://pp.userapi.com/c847219/v847219990/54e38/33d5t5h5bQ4.jpg?\
ava=1"|>

If a user has been deleted, he will have the field deactivated with meaning deleted:

<|"id" -> 207385, "first_name" -> "DELETED", "last_name" -> "", 
 "deactivated" -> "deleted", 
 "photo_max" -> "https://vk.com/images/deactivated_200.png"|> 

If a user has been blocked, he will have the field deactivated with meaning blocked:

<|"id" -> 10789003, "first_name" -> "????", 
 "last_name" -> "?????????", "deactivated" -> "banned", 
 "photo_max" -> "https://vk.com/images/deactivated_200.png"|> 

In this way, we should delete from the list of friends those who have the field deactivated.

To delete the user with the particular ID, it is necessary to execute GET request:

"https://api.vk.com/method/friends.delete?user_id=" <> id <> "&access_token=" <> token <> "&v = 5.78"

Graphical part of the work

Receive IDs of friends of the chosen user and transform it into the edge list.

Get the graph:

enter image description here

It doesn't include valuable data, and it's hard to read it. Let's do the following actions:

  1. Receive the number of messages between users. They are going to be weights of edges.
  2. To make the graph more readable we will change the length of each edge according to its weight. Then each edge rotate to the random angle Make it with the help of a rotation matrix.

    Clear[friendsVisuo]
    friendsVisuo[edgeListVisuo_, edgeWeightsVisuo_] := 
     Module[{coord1 = 
        PropertyValue[{Graph[ed, 
             VertexCoordinates -> 
              Table[{0, 
                 edgeWeightsVisuo[[i]]}.{{Sin@i, 
                  Cos@i}, {Cos@i, -Sin@i}}, {i, Length@edgeListVisuo}], 
             VertexLabels -> "Name"], #}, VertexCoordinates] & /@ 
         VertexList[
          Graph[ed, 
           VertexCoordinates -> 
            Table[{0, 
               edgeWeightsVisuo[[i]]}.{{Sin@i, 
                Cos@i}, {Cos@i, -Sin@i}}, {i, Length@edgeListVisuo}], 
           VertexLabels -> "$"]]},
      Show[
       Table[Graphics[{Pink, Opacity[0.3], EdgeForm[{Thick, Blue}], 
          Disk[First@coord1, i^2]}], {i, 5}], 
       Graph[ed, 
        VertexCoordinates -> 
         Table[{0, 
            edgeWeightsVisuo[[i]]}.{{Sin@i, Cos@i}, {Cos@i, -Sin@i}}, {i, 
           Length@edgeListVisuo}], VertexLabels -> "Name"], 
       ImageSize -> Full]]
    

ed - the list of edges. Also, draw 3 concentric translucent circles for better visualization. This is the result: enter image description here

If we use data from a social network, we can get a more pleasant look: enter image description here

Conclusion

It was our first hackathon, and we are pleased that we had the opportunity to participate in it, to work and communicate with people from Wolfram Research.We had all the facilities to work with comfort like the place, wi - fi, sockets, food. No doubt we will participate next time!

POSTED BY: Oleg Dudnik

enter image description here - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming!

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract