⬆️ ⬇️

Google+ user activity visualization

It has long been fond of visualization of various statistics in the program code_swarm and gource.

Recently, I decided to master Google api for Google Plus , and decided that the most convenient and interesting would be to come up with an algorithm for collecting statistics on user activity and then visualize this information using the above mentioned tools. This article will discuss the results of the work done.





What i used





The source code of the application is on github ( Installer ).

I will not go deep into implementation, I will describe only highlights.





Javascript first



First of all, I decided to try to get the data through js. For this, I made a page on the people . Get the data was very simple:

var request = gapi. client . plus . activities . list ( {

'userId' : profileID ,

'collection' : 'public' ,

'maxResults' : nextCount ,

'pageToken' : nextPage

} ) . execute ( createLog ) ;


')

Then the task was to come up with an algorithm for generating file names to demonstrate activity. The task was solved using templates.

rules for the formation of file names.

A piece of code that translates this:

  1. fnc = filePattern [ o ] . comment . trim ( ) ;
  2. fnc = fnc. replace ( / type / gi, "comment" )
  3. . replace ( / postId / gi, post. id )
  4. . replace ( / id / gi, comment. id )
  5. . replace ( / postactor / gi, post. actorId )
  6. . replace ( / actor / gi, comment. actor . id )
  7. . replace ( / postdate / gi, post. date )
  8. . replace ( / date / gi, date )
  9. . replace ( / sharepath / gi, fns )
  10. . replace ( / postfilename / gi, fn )
  11. . replace ( //// gi, '/');




Any user can create their own file names. The file here refers to any user activity, the creation of: posts, comments, reshar, setting pros. Each log line is formed on behalf of the one who carried out this activity.

The result of the visualization of the log obtained using this page:

Gource





  • General concepts
    • Google plus users are bees.
    • Points (posts, comments, etc.) are elements of honeycombs, points of different colors.
  • Types of points
    • Emerald - post
    • Green - comments
    • Blue - plus
    • Light green - repost
    • etc


  • Types of rays
    • Green - create item
    • Orange - commenting, plus, repost
  • Bees are honeycomb (well, or molecule).
  • In this video, below and then left, these are the user's main posts for whose profile the activity was generated.
  • On the right, these are reposts made by this user to others, they have their comments and advantages.


Code_swarm





  • General concepts
    • Circles - google plus users
    • Lights - user activity (creating posts, comments, pluses and more)
  • Users are repelled by users
  • Lights are repelled by the lights
  • Lights are attracted to the user who performs an action on him.
  • Users are attracted to each other through a general event, that is, if users comment on the same post.
  • Everything flies to the user from whose id the log was generated. But there are also clusters of users and lights in other places. These are reposts of other users made by this profile, all new events are associated with it. This can be changed in the file name generation rules.




But naturally this kind of tasks are not solved in the browser and I decided to write an application in C #.





Now C #



In fact, everything is done on a simple example that is shown here . Here is a piece:

  1. [ STAThread ]
  2. static void Main ( string [ ] args )
  3. {
  4. // Display the header and initialize the sample.
  5. CommandLine. EnableExceptionHandling ( ) ;
  6. CommandLine. DisplayGoogleSampleHeader ( "Plus user activity" ) ;
  7. // Create the service.
  8. var service = new PlusService ( ) ;
  9. RunSample ( service ) ;
  10. CommandLine. PressAnyKeyToExit ( ) ;
  11. }
  12. private static void RunSample ( PlusService service )
  13. {
  14. // Run the request.
  15. CommandLine. WriteAction ( "Executing List-request ..." ) ;
  16. var result = service. Activities . List ( "MY PROFILE ID" , Google. Apis . Plus . V1 . ActivitiesResource . Collection . Public ) . Fetch ( ) ;
  17. // Display the results.
  18. if ( result. Items ! = null )
  19. {
  20. foreach ( var item in result. Items )
  21. {
  22. CommandLine. WriteResult ( item. Id , itme. Actor . DisplayName ) ;
  23. }
  24. }
  25. }


Naturally, you need to connect to a project or a project with a wrapper for Google Plus Apis or an assembled library.

But in fact, everything will become clear from this guide .



Application sources on github . Exe here



Change log generation for code_swarm



Since mass-subscribers have a lot of subscribers, then for the code_swarm scheme, user-activity we get a very large amount of users and a bunch of points for which nothing can be understood. That's why I decided that the post (his id) will act as the user, and all the activity (file names) will be generated by the user id. We’ll get that users with different colors will fly to the post depending on their activity (comments, reshara, plus, etc.), and then it will be clearly seen who and how is active. Yes, file names are also formed using the template:

program for generating activity logs



The results of visualization of logs received by the program



Code_swarm





  • The central point in the circle (or the center of the circle) is a post.
  • Highlighted points are comments, pros, reshars.


Each point has a unique name corresponding to the user who left it, so some of the points are the largest and fly from post to post - this active user.




Gource





  • Lilac points - Reshar.
  • Lettuce points - comments.
  • Turquoise dots - pluses.
  • Point between the three branches - post.






Result



I was once again convinced that in order to study any technology, it is necessary to motivate yourself, in this case, the motivation is a visual representation of the analyzed data, which in my case is very stimulating. I am planning to study Google Analytics and also plan to do a visualization of the statistics obtained, if you have any ideas on this issue you can share, api last.fm is also interesting.



Your questions, comments are waiting in the comments.



UPD: As promised in the comments, added log generation for logstalgia . Here are the visualization results:

Source: https://habr.com/ru/post/136491/



All Articles