List help

Trying to create unique lists of items

Page 1 of 1

5 Replies - 1256 Views - Last Post: 05 October 2009 - 07:50 AM Rate Topic: -----

#1 lamrod   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

List help

Posted 28 April 2009 - 01:23 PM

I am currently doing a college project and have been stuck at a brick wall for some time. My tutor has been a great help to me but he is only onje person and there he has about a hundred other students to look after.

I have done a large ammount of this project and this is the major domo which is biting me in the rear end.



Anyway heres the scenario.
This is a web statistic analyzer, log files are filed by date and the user can read multiple log files at once. To do this the user selects the start date and the number of extra days to collect data for. I read the log files direct from the internet line by line. Each value in the log file is separated by a semicolon, this is split and loaded into a list. code for this is below.
	'#################
	'##   Webstats  ##
	'#################

	Private Sub btnParse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParse.Click
		Dim dteStart As Date
		Dim intRange As Integer
		Dim intDay As Integer = 0
		Dim strDates(100) As String
		Dim arrValues(10000, 7) As String
		Dim strLine As String
		Dim strValues() As String
		Dim intCount As Integer
		Dim intLine As Integer
		Dim FileRequest As HttpWebRequest
		Dim resp As HttpWebResponse
		Dim InfoList As New List(Of LogEntries)
		Dim ErrorsBU1 As New List(Of ErrorsByUser1)
		Dim ErrorsBU2 As New List(Of ErrorsByUser2)
		Dim ErrorsBP As New List(Of ErrorsByPage)
		Dim ErrorsBC As New List(Of ErrorsByCode)
		Dim VisitsPP As New List(Of VisitsPerPage)
		Dim VisitsBU As New List(Of VisitsByUser)

		'Find start date and range
		dteStart = calStart.Value
		intRange = nudRange.Value

		'Store each of the dates from the range
		intCount = 0
		For intCount = 0 To intRange
			strDates(intCount) = dteStart.ToString("ddMMyy")
			dteStart = DateAdd(DateInterval.Day, 1, dteStart)
		Next intCount


		'Read each line of each of the log files and load 
		'it into a list.
		intLine = 0
		intCount = 0
		For intCount = 0 To intRange
		   'grab the current file to read
			FileRequest = WebRequest.Create("http://www.anson.info/CW/logs/CW" & strDates(intCount) & ".log")
			FileRequest.Method = "GET"
			resp = FileRequest.GetResponse
		   
			'If file has been found then open a reader and begin parse each line
			If resp.StatusCode = HttpStatusCode.OK Then
				Dim reader As New StreamReader(resp.GetResponseStream)
				'Add each line into its own list
				While Not reader.EndOfStream
					strLine = reader.ReadLine()
					strValues = strLine.Split(";")
					'Add each item to the corresponding list
					Dim LE As New LogEntries
					LE.Time = strValues(0)
					LE.Page = strValues(1)
					LE.Errno = strValues(2)
					LE.Browser = strValues(3)
					LE.IP = strValues(4)
					InfoList.Add(LE)
				End While


				reader.Close()
			End If
		Next intCount


		'Find the selected graph to run.
		If lstSelect.SelectedIndex <> -1 Then
			Select Case lstSelect.SelectedItem
				Case "Visits per Page"
					'Find All of the visits from the each unique ip address.
					 
					
	 
					'Build Graphical output of the results

					'Build Textual output of the results

					Next
				Case "Visits per User"
					'Print to text area
				Case "Errors by User"
					'Print to text area

				Case "Errors by Page"
					'Print to text area

					'Draw Graphic

				Case "Errors by Code"
					'Print to text area

					'Draw graphic

			End Select
		Else
			MessageBox.Show(("Please select a criteria"), "Nothing Selected", MessageBoxButtons.OK, _
							MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		End If

	End Sub

End Class
Public Class LogEntries
	Public IP As String
	Public Page As String
	Public Errno As String
	Public Time As String
	Public Browser As String

End Class
Public Class VisitsPerPage
	Public MatchStrVPP As String
	Public intVPPCount As Integer
End Class
Public Class VisitsByUser
	Public MatchStrVPU As String
	Public intVPUCount As Integer
End Class
Public Class ErrorsByUser1
	Public MatchStrEBU1 As String
	Public intEBU1Count As Integer
End Class
Public Class ErrorsByUser2
	Public MatchStrEBU2 As String
	Public intEBU2Count As String
End Class
Public Class ErrorsByPage

End Class
Public Class ErrorsByCode

End Class



The trouble is I need to index the list to be able find the unique items. My tutor has told me i will need to write my own sub routine to do this but I do not know how. I dont want anyone to do this for me but any help would be great.

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: List help

#2 JhoeOendus   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 27-April 09

Re: List help

Posted 29 April 2009 - 04:40 PM

A solution might be for you to create a linked list. This would only allow you to run through the entire list when searching, but depending on what you are looking, for this may not be bad.

To better understand what you are trying to do, I think we have to ask what 'unique items' are you trying to find? What criteria are you searching through and for?
Was This Post Helpful? 0
  • +
  • -

#3 lamrod   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

Re: List help

Posted 30 April 2009 - 11:15 AM

This first list is the log entries themselves, I am then going to create a new list for the following catagories.....
Visits per Page
Visits per User
Errors by User
Errors by Page
Errors by Code

I provide a line of the log which is split and inserted into the first list.

00:54:46;bands/chasingtails.htm;0;Internet Explorer;170.107.149.159

What the new list(of T) will do is create a basis for building graphs by using a count for each item.

I want to do this by reading theough the first list, and then for every unique entry add a new item into the new list, any existing items get their appending count appended to a new total.

To be able to do this i need to index my lists so that the program can reference against each matched string.... I think :/
Was This Post Helpful? 0
  • +
  • -

#4 T3hC13h   User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: List help

Posted 30 April 2009 - 12:06 PM

I'm just throwing this out there but try this, but what if you created a Hashtable for each time and used the item ("bands/chasingtails.htm") as the key and the value as your counter value.

 
Dim ht_Page_Visits as new Hashtable

'While parsing record'
if ht_Page_Visits.ContainsKey(str_Page) Then
	ht_Page_Visits(str_Page) = cint(ht_Page_Visits(str_Page)) +1
else
   ht_Page_Visit.Add(str_Page,1)


end if

This post has been edited by T3hC13h: 30 April 2009 - 12:06 PM

Was This Post Helpful? 0
  • +
  • -

#5 lamrod   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

Re: List help

Posted 01 May 2009 - 03:16 PM

I dont think a hash table would work. please correct me if I am worng. I basically need to read the log file and show how many times an IP address has visited the site or which page has the most number of hits.

I was thinking of somthing more like this.


		 'Example of creating a list of visits by page
		 'read the list of log entries
		 If InfoList.IndexOf(IP) <> -1 Then '####I'm not sure on how the if statement should read
			 'Create a new object in the class VisitsBP
			 Dim VBP as New VisitsBP
			 VBP.MatchStr = 0
			 VBP.Count = 1
			 VisitsBP.add(VBP)
		Else
			'Append the Matched String to have a new count
			'Also not sure on how this part should work either
			'But I think that You reference to the existing item in the list using its index and then append the items count.
		End If


Was This Post Helpful? 0
  • +
  • -

#6 lowlyGiant   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-October 09

Re: List help

Posted 05 October 2009 - 07:50 AM

I don't really have the time ( or patience ) to get intimate with your code right now, so I'll just explain ( in terms I hope you'll understand ) how to create a void function, or sub routine in VB.NET:

It's really easy to create void functions ( aka sub routines ) in VB.net, you don't even need a prototype:

Start with a header, first say "Private Sub" then create an identifier for the routine ( i.e. how you'll reference it later ), say ListIterator:

Private Sub ListIterator

Then , immediately after your identifier, type an open paren to declare what values you'll be giving it to work with: "(" and declare the values you'll use, also indicating whether you'll give the variables address of copy it's value into the var local to the routine, by "ByVal," or ByRef" seperating each parameter with commas: "," and then use a close-paren: ")"

Private Sub ListIterator(ByVal index As Int16)

That's a sub routine header. Hit enter and your IDE will auto print "End Sub" below the line with the cursor. Now, inside your routine ( between the header and end statement ), write the code you want to run EVERYTIME it's called and BE SURE not to try to use a variable declared in some other function/routine but the parameter identifiers ( NOTE: you can use other class members ( i.e. variables declared outside any function or sub ) in your new sub ):

Private Sub ListIterator(ByVal index As Int16)

{... your code here ...}

End Sub

Then, In your MAIN code, you can call ListIterator however/whenever you want:

For intCount = 0 To intRange

ListIterator(intCount)

Next intCount

Or,...you could just write the loop in the function ( sub ) and call it ONCE from main(),...whatever you wanna do
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1