Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57689

Re: Printing a drop down menu for a specific field.

From Nick the Gr33k <nikos.gr33k@gmail.com>
Newsgroups comp.lang.python
Subject Re: Printing a drop down menu for a specific field.
Date 2013-10-27 02:11 +0200
Organization A noiseless patient Spider
Message-ID <l4hlnc$tp9$1@dont-email.me> (permalink)
References <l4gihj$n8f$1@dont-email.me> <03c4c838-a6da-489f-b4b5-9342b3496fa3@googlegroups.com> <l4hjcm$lf6$1@dont-email.me> <l4hkkn$qba$1@dont-email.me>

Show all headers | View raw


Στις 27/10/2013 2:52 πμ, ο/η Nick the Gr33k έγραψε:
> Ah foun it had to change in you code this line:
>              key = host, city, useros, browser, ref
>
> to this line:
>
>              key = host, city, useros, browser
>
> so 'ref' wouldnt be calculated in the unique combination key.
>
> I'am still trying to understand the logic of your code and trying to
> create a history list column for the 'referrers'
>
> I dont know how to write it though to produce the sam

Iam trying.

Ah foun it had to change in you code this line:
             key = host, city, useros, browser, ref

to this line:

             key = host, city, useros, browser

so 'ref' wouldnt be calculated in the unique combination key.

I'am still trying to understand the logic of your code and trying to 
create a history list column for the 'referrers'

I dont know how to write it though to produce the same output for referrers.

The bast i came up with is:

[code]
def coalesce( data ):
		newdata = []
		seen = {}
		for host, city, useros, browser, ref, hits, visit in data:
			# Here i have to decide how to group the rows together.
			# I want an html row for every unique combination of (host, city, 
useros, browser) and that hits should be summed together.
			key = host, city, useros, browser
			if key not in seen:
				newdata.append( [host, city, useros, browser, [ref], hits, [visit]] )
				seen[key] = len( newdata ) - 1		# Save index (for 'newdata') of this 
row.
			else:		# This row is a duplicate row with a different visit time.
				rowindex = seen[key]
				newdata[rowindex][4].append( ref )
				newdata[rowindex][5] += hits
				newdata[rowindex][6].append( visit )
		return newdata

		
	cur.execute( '''SELECT host, city, useros, browser, ref, hits, 
lastvisit FROM visitors
					WHERE counterID = (SELECT ID FROM counters WHERE url = %s) ORDER BY 
lastvisit DESC''', page )
	data = cur.fetchall()

	
	newdata = coalesce( data )
	for row in newdata:
		(host, city, useros, browser, refs, hits, visits) = row
		# Note that 'ref' & 'visits' are now lists of visit times.
		
		print( "<tr>" )
		for item in (host, city, useros, browser):
			print( "<td><center><b><font color=white> %s </td>" % item )
			
		print( "<td><select>" )
		for n, ref in enumerate( refs ):
			if n == 0:
				op_selected = 'selected="selected"'
			else:
				op_selected = ''
		print( "<option %s>%s</option>" % (op_selected, ref) )
		print( "</select></td>" )

		for item in (hits):
			print( "<td><center><b><font color=white> %s </td>" % item )
			
		print( "<td><select>" )
		for n, visit in enumerate( visits ):
			visittime = visit.strftime('%A %e %b, %H:%M')
			if n == 0:
				op_selected = 'selected="selected"'
			else:
				op_selected = ''
			print( "<option %s>%s</option>" % (op_selected, visittime) )
		print( "</select></td>" )
		
		print( "</tr>" )
[/code]

But this doesnt work correctly for refs and also doenst not print for 
some reason the hits and visit colums.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Printing a drop down menu for a specific field. Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-10-26 17:10 +0300
  Re: Printing a drop down menu for a specific field. Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-10-26 18:40 +0300
    Re: Printing a drop down menu for a specific field. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-26 16:09 +0000
  Re: Printing a drop down menu for a specific field. rurpy@yahoo.com - 2013-10-26 11:33 -0700
    Re: Printing a drop down menu for a specific field. Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-10-27 02:31 +0300
      Re: Printing a drop down menu for a specific field. Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-10-27 02:52 +0300
        Re: Printing a drop down menu for a specific field. Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-10-27 02:11 +0200
          Re: Printing a drop down menu for a specific field. rurpy@yahoo.com - 2013-10-26 21:00 -0700
            Re: Printing a drop down menu for a specific field. Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-10-27 09:31 +0200
              Re: Printing a drop down menu for a specific field. Dave Angel <davea@davea.name> - 2013-10-27 11:52 +0000
              Re: Printing a drop down menu for a specific field. rurpy@yahoo.com - 2013-10-27 22:22 -0700

csiph-web