Re: [Tutor] postgreSQL + psycopg2
nitin chandra wrote: > Thanks Alan, Peter > > but didn't work > > nextrow=(cursor1.execute(query, (design1,))).fetchone() > AttributeError: 'NoneType' object has no attribute 'fetchone' Try without the method chaining: cursor1.execute(query, (design1,)) nextrow = cursor1.fetchone() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] postgreSQL + psycopg2
IT WORKED THANK YOU SSS MUCH ...phew .. Thank you here is the result. 1 ('Supervisor',) 1 Vinayak Salunke 1 Now I need to remove the braces and quotes .. :) Thank you Nitin On 10 May 2016 at 12:30, Peter Otten <__pete...@web.de> wrote: > nitin chandra wrote: > >> Thanks Alan, Peter >> >> but didn't work >> >> nextrow=(cursor1.execute(query, (design1,))).fetchone() >> AttributeError: 'NoneType' object has no attribute 'fetchone' > > Try without the method chaining: > > cursor1.execute(query, (design1,)) > nextrow = cursor1.fetchone() > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] is there a better way to do this?
On 10/05/16 12:01, Steven D'Aprano wrote: On Mon, May 09, 2016 at 06:13:32PM +1000, Chris Roy-Smith wrote: data = [[" " for x in range(9)] for y in range(count)] for (ddate, mood, walk, lag, sleep) in curs: data[row][0]=ddate data[row][1]=mood data[row][2]=walk data[row][3]=lag data[row][4]=sleep row +=1 While I don't know a better way to do this, it seems a bit awkward, is there a better way? Hmmm, it's hard to be sure because we don't really know what count is. Do you want a bunch of empty rows at the end? My guess is No. In your code above, you initialise each row with ten spaces, and only replace five of them. So assuming you need the extra five spaces: data = [record + [" "]*5 for record in curs] provided curs returns lists, rather than tuples. (If not, it's easy to just convert using `list(record)`. If you don't need the extra five columns, the code is even simpler: data = list(curs) Thank you, that's much better I thought I needed the extra columns, but I changed things to use 2 lists of lists (one generated with the above line and another to hold my calculated results) What if you do want extra blank rows? Easiest to just add them at the end: # initialise data as above, then add blanks for i in range(how_many_extra_rows): data.append([" "]*10) which can be simplified to: data.extend([[" "]*10 for i in range(how_many_extra_rows)]) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] is there a better way to do this?
On 10/05/16 07:03, Ondřej Rusek wrote: Dne 9.5.2016 v 10:13 Chris Roy-Smith napsal(a): Hi Python 3.4 Linux (ubuntu) This code does what I want. curs is the result of a mysql query data = [[" " for x in range(9)] for y in range(count)] for (ddate, mood, walk, lag, sleep) in curs: data[row][0]=ddate data[row][1]=mood data[row][2]=walk data[row][3]=lag data[row][4]=sleep row +=1 if you want 'lists in list' (like your solution): data = [] for ddate, mood, walk, lag, sleep in curs: data += [ [ddate, mood, walk, lag, sleep] ] or 'tuples in list': data = [] for ddate, mood, walk, lag, sleep in curs: data += [ (ddate, mood, walk, lag, sleep) ] but for 'tuples in list'... simple: data = [] for record in curs: data += [record] Thanks, I hadn't considered having a second list of lists for my calculations, Your solution is the sort of thing I was looking for. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Rate transition from 60hz to 1000hz
Good Evening; I'm collecting both video and force plate data, and I need to be able to synchronize the two, so I can make some calculations. The video data is at 60hz, and the force plate data is at 1000hz. I don't want to truncate the force plate data. So, how do I perform a rate transition (or interpolation, or whatever) to expand the data that is captured at 60hz to be able to synchronize it with the data that has been captured at 1000hz? Also, if I'm not using the correct terms, please let me know. I'm new to Python and programing, and I'm trying to learn as fast as i can. Thanks, David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rate transition from 60hz to 1000hz
On 10/05/16 04:08, David Wolfe wrote: > I'm collecting both video and force plate data, and I need to be able to > synchronize the two, so I can make some calculations. The video data is at > 60hz, and the force plate data is at 1000hz. I don't want to truncate the > force plate data. I have no idea what force plate data is but assuming it's nothing special you have two sets of data, one at 1000Hz and one at 60Hz. And you want to join them together at the appropriate points. The problem is that 60 is not an exact factor of 1000 so you will need to decide how you align the samples. > So, how do I perform a rate transition (or interpolation, or whatever) to > expand the data that is captured at 60hz to be able to synchronize it with > the data that has been captured at 1000hz? Interpolation over such a large sample range is tricky and risky. The simplest way is to assume a straight line between samples. So each interpolated value is just S2-S1/17 higher than the previous value(S1). A better way is to try to determine the current curve shape and apply that. But it's much harder to do unless you know what kind of data to expect! > Also, if I'm not using the correct terms, please let me know. I'm new to > Python and programing, and I'm trying to learn as fast as i can. This has nothing to do with Python or even programming per se. Its really a math question. The same issues would apply if you were tabulating the data by hand on paper. That having been said, there may be some math libraries around that you could use to do the sums for you. But it's not my area of expertise so maybe some of the other tutor members will suggest something in numpy or pandas or whatever. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rate transition from 60hz to 1000hz
On Mon, May 09, 2016 at 11:08:37PM -0400, David Wolfe wrote: > Good Evening; > > I'm collecting both video and force plate data, and I need to be able to > synchronize the two, so I can make some calculations. The video data is at > 60hz, and the force plate data is at 1000hz. I don't want to truncate the > force plate data. > > So, how do I perform a rate transition (or interpolation, or whatever) to > expand the data that is captured at 60hz to be able to synchronize it with > the data that has been captured at 1000hz? You need to explain in more detail what you actually have. What format is this data? What were you planning on doing with it? What sort of calculations were you intending to do? Are you using Numpy for the calculations? -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rate transition from 60hz to 1000hz
On 10 May 2016 at 04:08, David Wolfe wrote: > Good Evening; > > I'm collecting both video and force plate data, and I need to be able to > synchronize the two, so I can make some calculations. The video data is at > 60hz, and the force plate data is at 1000hz. I don't want to truncate the > force plate data. > > So, how do I perform a rate transition (or interpolation, or whatever) to > expand the data that is captured at 60hz to be able to synchronize it with > the data that has been captured at 1000hz? > > Also, if I'm not using the correct terms, please let me know. I'm new to > Python and programing, and I'm trying to learn as fast as i can. The normal term for this is "resampling" and scipy has a function called resample that does exactly this. Here's a demonstration: >>> from scipy.signal import resample >>> plate_signal = [1, 2, 1, 3, 1, 4, 2, 3, 4, 2] >>> video_signal = [7, 8, 4] >>> video_resampled = list(resample(video_signal, len(plate_signal))) >>> video_resampled [7.0009, 8.230109890796971, 8.735715605706849, 8.3236929465402536, 7.1514205649637077, 5.667, 4.4365567758696969, 3.9309510609598171, 4.3429737201264125, 5.5152461017029593] This resamples the signal using interpolation. Notice that the last samples of resample are increasing away from 4 (towards 7). This is because resample uses a DFT-based method so it implicitly assumes that the signal is periodic. This leads to a bit of distortion at the end of your resampled signal - often that doesn't matter but it's worth noticing. You can read more about resample here: http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.signal.resample.html I've added a list call because resample returns a numpy array. Do you know what that is? Presumably in your application video_signal is actually a 3D array since at each frame you would have a 2D array of pixel values. Resamples can handle this case too but exactly how to call it depends on what sort of array you're using to store the video data. I'm assuming here that you want to work offline. If you actually want to do this computation online (as the data comes in) then you'd need something different. -- Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] postgreSQL + psycopg2
> here is the result. > > 1 > ('Supervisor',) > > 1 > Vinayak > Salunke > 1 > > Now I need to remove the braces and quotes .. :) By the way, be very careful about generating HTML via naive string concatenation. If you can use a template engine such as Jinja (http://jinja.pocoo.org/), please do so. The main problem here is that the content you're using from the database might have characters that look "html"-ish, in which case the use of string concatenation is a vector for a Bobby-tables-like injection attack. https://xkcd.com/327/ If you can't use a templating engine that knows about HTML escaping, then you still need to add html escaping where the rows are being constructed here: for row in line1: print ""+str(row)+"" See: https://docs.python.org/3/library/html.html#html.escape Basically, any place where something "structured" (SQL queries, HTML) is being constructed from something unstructured (string concatenation), that's where injection attacks like to live. Be careful. Hope this helps! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] postgreSQL + psycopg2
On 10/05/16 08:33, nitin chandra wrote: > here is the result. > > 1 > ('Supervisor',) > > 1 > Vinayak > Salunke > 1 > > Now I need to remove the braces and quotes .. :) No you don't. Those are just part of the string representation that Python uses when printing a string inside a tuple. If you print nextRow[0] instead of nextRow you will get the bare string. BTW Why are you using triple quotes? You only need them if your string wraps over multiple lines. Single quotes (" or ') will be fine for your purposes and are easier to type... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] postgreSQL + psycopg2
Thank you Danny, Alan, @ Danny I added 'str(formt(line1[0]))' will this do ? @ Alan I did just that nextRow[0] Triple quotes .. there is some part of code in multi-line so... me being just lazyyy ... copy pasted / edited ... and left what is working . just my excuse :P On 11 May 2016 at 03:57, Alan Gauld via Tutor wrote: > On 10/05/16 08:33, nitin chandra wrote: > >> here is the result. >> >> 1 >> ('Supervisor',) >> >> 1 >> Vinayak >> Salunke >> 1 >> >> Now I need to remove the braces and quotes .. :) > > No you don't. Those are just part of the string representation > that Python uses when printing a string inside a tuple. > > If you print nextRow[0] instead of nextRow you > will get the bare string. > > BTW Why are you using triple quotes? You only need them if > your string wraps over multiple lines. Single quotes (" or ') > will be fine for your purposes and are easier to type... > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] postgreSQL + psycopg2
On Tue, May 10, 2016 at 10:37 PM, nitin chandra wrote: > Thank you Danny, Alan, > > @ Danny > > I added 'str(formt(line1[0]))' will this do ? Unfortunately, I don't know: what makes me hesitant is the following: * The above is doing something just to line1[0], which looks odd. Why just line1[0]? * What's the type of line1? Is it a list of strings? If so, then calling str() on a string is redundant. * I don't know what "formt" is. So, yeah, I have enough questions and uncertainty that I need to hedge. This is not to say that you got it right or wrong, but rather that I don't have enough information to decide either way. There are a lots of little details to get right when we program. Rather than handwave and assume that things are ok, I'll be truthful and admit my ignorance. Hope that makes sense! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor