Published: 17 Oct 2011
By: Xianzhong Zhu

In the last part of the series, you've learned how to store the user into especially the re-processed info into the backend database. And later, we discussed how to bind our site traffic and statistics module to some target website or only to one page. In this last part, we are going to delve into the most interesting things how to design different kinds of statistic charts or analysis reports based upon users' requirements.

Contents [hide]

Introduction

In the last part of the series, you've learned how to store the user into especially the re-processed info into the backend database. And later, we discussed how to bind our site traffic and statistics module to some target website or only to one page. In this last part, we are going to delve into the most interesting things - how to design different kinds of statistic charts or analysis reports based upon users' requirements.

NOTE

The development environments in the sample application involve:

Windows XP Professional (SP3);

.NET 3.5 (SP1);

Visual Studio 2008 Professional (SP1);

Microsoft SQL Server 2008.

Design the Right Part of the Backend Administration Interface

As mentioned in the preceding part, the right part of the backend administration interface is rather complex, let's now give a detailed discussion with it. In fact, as you noticed, the right part corresponds to a special page - main.aspx that is embedded inside a frameset element.

The above code is easy to follow; we use the server side calculated results to render the wanted results to the client-side browser.

Next, we should define the following variables with which to query the backend database and figure out the basic traffic info.

Before processing the stat data, we need to consult the basic info from the data table CountContent and make related judgment – if there are records in the table we perform the data analysis; or else, report error. The corresponding code is shown below.

The next story happens inside the above else scope: we begin to get out of the table CountContent all total visit traffic, starting visit date, highest visit count, highest visit datetime.

The following code is used to grab the online number out of another table CounterView:

The following code is used to obtain the today and yesterday visit traffic related data from the table CountContent:

The following code is used to get this year visit traffic related data from the table CounterView:

The following code is used to grab this month visit traffic related data from the table CounterView:

The following code is used to grab visit days and average day visit traffic from the table CounterInfo:

The following code is used to grab the estimated day visit traffic from the table CounterInfo:

The following code is used to grab the current user visit traffic:

Well, now that everything has been covered concerning the three parts (acquiring user info, storing it, and making related statistical analysis) in our system, it is time to shift our mind to the most interesting part of our target system –display the result data in the forms of tables and charts.

Traffic Statistics and Analysis

Traffic statistics and analysis is a rather complex operation; users can design different types, kinds and forms of statistical charts and analysis reports on the ground of their concrete requirements. This section will introduce to you how to achieve statistical PV value, 24-hour traffic statistics, day statistics, week statistics, month statistics, client information statistics, origin analysis, visited pages statistics, IP statistics, and visitor region statistics.

Now, let's start with the PV value statistics.

PV value statistics

PV represents "page views", which means the page view traffic or hit traffic. Usually PV is the main criterion to balance a news channel, a news site or even a piece of network news. Whenever a page is refreshed, one time of PV traffic is counted. In general, PV is proportional to the number of visitors, but it does not directly determine the real page visitor number - for example, the same visitors, by constantly refreshing the page, we can create a very high PV value.

In our case, we use the page counter_pv.aspx to record info of each PV in detail, including visit time, the source region, and the width of the browser, OS used by the visitors, the browser, and web sources. The related result is shown in Figure 1.

Figure 1: PV info displayed in the sample monitoring system

PV info displayed in the sample monitoring system

Showing detailed records of PV does not require complicated calculations. We can directly query the CounterView data table, and sort the records according to the field id, and finally bind the query result to the server control DataGrid.

First, define a method BindGrid with which to bind data to the server control:

Then, define a database query string, perform data query, and finally call the preceding BindGrid method:

Since the comments between the lines have given you enough explanation, there is no need for us to dwell upon them.

24-hour real-time traffic statistics

24-hour real-time traffic statistics is based on the current time, or the current time plus the past 24 hours traffic statistics. The statistics can show the dynamic trend of the past 24-hour traffic.

Our thought to achieve a 24-hour real-time traffic statistics is: first define a helper method to query the traffic of specified clock time, and then use a loop statement to invoke this method to calculate the traffic of the different clock points in the past 24 hours. And finally, we need to render the column chart according to certain proportions.

Now, let's look at the helper method vhourcon.

And then, define another helper method named show_hour_data to call the above method with loop to obtain each clock point related hit count and finally give out a column chart using a table form.

Now, let's look at the running-time screenshot of this part.

Figure 2: 24-hour real-time traffic statistics (in Internet Explorer)

24-hour real-time traffic statistics (in Internet Explorer)

Day traffic statistics

Day traffic statistics is, referencing month, to compare the traffic amount of a specific day in the current month or a specific month. The core code is as follows:

As the case with the 24-hour statistics, we use a loop to invoke the method vdaycon to display the statistics result in the form of a column chart.

Figure 3: Day traffic statistics (in Internet Explorer)

Day traffic statistics (in Internet Explorer)

Week traffic statistics

In fact, the week traffic statistics is quite similar to month traffic statistics. This part refers to statistics in each week, used to compare the current week's daily traffic statistics. The core code is as follows:

Listing 1: counter_week.aspx.cs

In the behind-code file counter_week.aspx.cs, as you will find in the downloadable source, the above method is called in a loop statement, with the result being the current week or every day in specified week related statistic traffic. The final chart is shown in the following figure.

Figure 4: Week traffic statistics (in Internet Explorer)

Week traffic statistics (in Internet Explorer)

Client statistics

As for the client user information, since when the user visits a site, the related info has been recorded in detail into the database, what is left for us to do is only to generate the corresponding statistic results and display them.

First, the core code of grabbing the client operating system related info is as follows:

Listing 2: counter_browser.aspx.cs

Next, the core code associated with the client browser info looks like this.

Listing 3: counter_browser.aspx.cs

Sine all above code is easy to understand, we are no more discuss it. Now, let's look at the final result, as shown in the following figure.

Figure 5: The client-side related info is obtained and shown

The client-side related info is obtained and shown

IP addresses and traffic statistics

IP addresses and traffic statistics mainly need to query the data table CounterView, grouping the records according to the vip field, and then calculate the traffic in each group. Finally each IP corresponding traffic can be displayed one by one.

Listing 4: counter_ip.aspx.cs

Origin analysis

Similar to IP analysis, origion analysis needs to query the table CounterView, grouping the records by the vcome field, and then summarize each group's traffic. Finally, the traffic corresponding to each vcome will be displayed one by one.

Listing 5: counter_from.aspx.cs

Visitor region analysis

Visitor region statistics mainly need to query the data table CounterView, grouping the records according to the vwhere field, calculate the traffic of in different regions, and finally different regions related traffic statistics chart are displayed. This task is mainly achieved via the helper method show_where_data, as shown below.

Listing 6: counter_where.aspx.cs

Visited pages statistics

Visited pages statistics also mainly need to query the data table CounterView, grouping the records according to the vpage field, calculate the traffic of pages in different website, and finally different pages corresponding traffic statistics chart can be displayed. This task is mainly finished through the helper method show_page_data, as shown below.

Listing 7: counter_page.aspx.cs

Summary

In this final part of the series, you've seen the final results of the site traffic and statistics monitoring system – we've used the intuitive tables and charts to display the abstract data! Well, there are two points worth noticing: 1, although the sample application is given under ASP.NET 3.5 and SQL Server 2008, you can easily make other versions related migrations; 2, although we've not utilized attractive outlook design, the sub-modules in this series are very useful, so you can continue to process them using Ajax or jQuery and the like so as to satisfy your real cases.

<<  Previous Article Continue reading and see our next or previous articles Next Article >>

About Xianzhong Zhu

I'm a college teacher and also a freelance developer and writer from WeiFang China, with more than fourteen years of experience in design, and development of various kinds of products and applications on Windows platform. My expertise is in Visual C++/Basic/C#, SQL Server 2000/2005/2008, PHP+MyS...

This author has published 81 articles on DotNetSlackers. View other articles or the complete profile here.

Other articles in this category


jQuery Mobile ListView
In this article, we're going to look at what JQuery Mobile uses to represent lists, and how capable ...
JQuery Mobile Widgets Overview
An overview of widgets in jQuery Mobile.
jQuery Mobile Pages
Brian Mains explains how to create pages with the jQuery Mobile framework.
Code First Approach using Entity Framework 4.1, Inversion of Control, Unity Framework, Repository and Unit of Work Patterns, and MVC3 Razor View
A detailed introduction about the code first approach using Entity Framework 4.1, Inversion of Contr...
Exception Handling and .Net (A practical approach)
Error Handling has always been crucial for an application in a number of ways. It may affect the exe...

You might also be interested in the following related blog posts


GiveCamps Get a new Sponsor read more
Scenarios for WS-Passive and OpenID read more
Announcing the IIS SEO Toolkit (beta) read more
IIS Search Engine Optimization Toolkit read more
Announcing: IIS Search Engine Optimization Toolkit Beta 1 read more
Win a Govie Award Submit an Innovative Gov 2.0 Application read more
Why <i>not</i> link to Wikipedia? read more
What is this Open Cloud Manifesto...anyways??? read more
New ASP.NET 3-8x accelerator is in public beta read more
Script for Bulk Import of Active Directory Site Links read more
Top
 
 
 

Please login to rate or to leave a comment.

Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.