Attention span is the amount of concentrated time on a task without becoming distracted(Wikipedia). attention span for a video/audio is a chart that shows the amount of users watching/listening per a period of time. it can be per second or more or less.
if we look at the following chart, we can say the video has more viewer in second 10 than the rest of video.
There are so many ways to calculate attention span. but at the end, the goal is having a key-value table (collection for no-sqls) of time and values. imagine you are going to have a attention span for a 100 seconds movie and you want to have attention span for each second. in this case we are going to have a final attention span of “time” per second and “value” that shows the number of visitors of that second. I am going to explain different methods for this movie.
Although this method is practical for other proposes, It was hard for me to think this way for calculating the attention span and if I didn’t see a developer how thought and did this way, I never mention it. Any way if you ever did such a thing, you should leave developing and data processing ASAP and change your field totally.
in this method for each second that movie plays, the related second for the movie is being saved in a table. at the end of the day the table has several records for each second. for example we could have 5 row for second 1, 6 rows for second 20, it means movie played 5 times in first second and 6 times in second 20.
A Cron job should take care of calculation of number of record every day or every hour or every minute (called it map reduced) and add the result to the attention span table ( a key -value table). for above example, add 5 to “value” of “time” of 1 and add 6 “value” of “time” of 20.
2. Good but not very smart:
Although it is not a smart way for media, it is a useful and smart method when there is not a huge attention. any way it is much better than the first method. if you have a super boring and old movie that might have 1 or 2 audience per day use this method.
in this method, for each second that movie plays, we increment the “value” of that second (“time”).
The advantage of this method is we don’t need map reduce and our table is real time. but the disadvantage is we have so many request (every second) to the server and it is too much request for a very popular movie. imagine if your movie has one thousand online visitors or you have thousand movie on your site and each of them has several online user, your site must send thousand AJAX request per second ( no differences in updating the database ). again it is very good if you don’t expect so many audiences or real time is very important for you.
This method is seems better for me but it has a disadvantage; it is not real time that I don’t think it is an important factor for attention span. Actually if you are smart you can make it real time with some extra lines of code.
in this method every time that play event is triggered, we save the start moment in the session or cookie (or database for having real time result). then we wait…and wait and wait as long as movie plays. when pause or stop (or complete) event happens, or when the user leaves the page, we send the start moment (that we already saved it in cookie or session ) and the stop moment to a temporary database. then for each time a user plays a period of time, we only send one request to server and one save in application database.
at the end of the day or maybe every minute (depend on you ), you can check this temporary database and increment the value of each second.
one of the biggest advantage of this method is you can use another server for handling and calculation. Also all calculations is doing on the server side.
4. The best
The best way is really based on the application and number of users and number of media. My main concern was a very popular site with so many videos/audios that each of them has so many visitors.