Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computing word, image, video and audio file counts in a scalable way?

I am attempting to gather as much interesting metadata as possible to display for readers of an expression engine site I'm developing and am looking for guidance on methods (or indeed the feasibility) of computing specific bits of this metadata in a scalable way.

Expression Engine allows for quite a few bits of data to be gathered and displayed natively, for example post totals and dates, comment totals and dates, tag totals, etc. However I'm specifically interested in finding a method to count and display totals for data like number of words, images, videos, or audio files, not only within individual posts but across a channel, as well as site-wide.

These totals would be displayed contextually depending on where they were accessed. So for example search results would display the number of words/images/etc contained in individual posts, a channel's "about" page would display totals for the entire channel, and the site's "about" page would display site-wide totals. I'm not clear on the best approach or whether this is even really feasible.

I'm not a professional web designer, so my knowledge of anything beyond html5/css3/ee is somewhat limited, but I've pondered:

  • Entering these numbers on a per-post basis, in custom fields, but am not clear on whether they can be added together for channel and site-wide totals.
  • Using PHP's "count" method, but am not very familiar with PHP so unsure of it's appropriate.
  • Using some mySql method to query the database, again unsure.
  • Utilizing the Expression Engine "Query Module." !?
  • Using some Jquery plug-in to do the counting individually and then adding after the fact.

It may be that the counting of words, images, video, and audio files and the scalability are different questions all together but the truth is I'm very confused as to what avenue to even explore. So any and all suggestions or guidance would be greatly appreciated.

Update: I'm looking into database methods to collect and add the results but am still interested in identifying the best ways to actually perform the word/image/video/audio file counts.

like image 562
Jmorriso Avatar asked Nov 13 '22 06:11

Jmorriso


1 Answers

There's many solutions but I have a few in mind that may help you out. I'll just show the one I like really well that I even use for my own site.

One solution is to make a count column in tables you are interested in that is automatically updated when someone posts or does something. You can also make a new table called globalcount or whatever that counts everything site wide. This can then later just be displayed. You would need to first have a method/function of counting words and such if you want that info. And when someone makes a post, just count one up from the previous.

The above is what I use. I use a misc table (It has one row that contains all the data. You could instead make each row contain your info like 'name' 'value') that looks something like:

(`views`, `totalusers`, `totalgroups`, `totalthreads`, `totalposts`, `totalarticles`, `totalcomments`, `totalpms`, `activeusercount`)

And in something like my 'news' table I use 'totalcomments' to count the local comments posted in that article. So I have both the local and global comments.

In my case, if I wanted to update 'totalusers' in the 'misc' table after a new user registers, I'd just call my $misc array and go: $newtotalusers = intval($misc['totalusers'] + 1);

mysql_query("UPDATE `misc` SET `totalusers`='$newtotalusers'");

Or you could instead just use "totalusers+1".

Same can be done with any other thing you wish to do, such as with any file count or visa versa. Hope this helps :)

One last thing, you could also make a script that in the case the data becomes off because of an error that would update and fix any table's count values.

like image 162
Scrydan Avatar answered Nov 16 '22 03:11

Scrydan