|
How would I handle reading times that are like: 23:32.6 1:02:55.7 Where it's usually in MM:SS but occasionally HH:MM:SS I tried using datetime, but that has issue with the tenths of a second. And I'm also wondering how to handle checking whether or not there's an hour present. Should I search to see if there are two colons present in the string? I need to plot the data, so I have just been trying to read all of the times and then convert it all to seconds. Unless there's a way to plot datetime data?
|
# ? Jul 17, 2014 01:23 |
|
|
# ? May 9, 2024 19:22 |
|
the posted:How would I handle reading times that are like: I'm not sure if it will handle it for you, but look at python-dateutil's parser module.
|
# ? Jul 17, 2014 01:48 |
|
the posted:How would I handle reading times that are like: %f treats the microsecond value as a fraction, so '.6' gets correctly parsed into '600000' microseconds. \/ \/ \/ onionradish fucked around with this message at 02:53 on Jul 17, 2014 |
# ? Jul 17, 2014 02:16 |
|
onionradish posted:If you're on Python 2.6+, datetime has added a '%f' format for Not sure if this will work, looks like microsecond only takes stuff like "000000, 000001, ..., 999999" according to the official docs. edit: NM, I got it to work, thanks for the help the fucked around with this message at 02:39 on Jul 17, 2014 |
# ? Jul 17, 2014 02:37 |
|
I'm late and you said you got it already, but I'd do something like this, looping over the formats in order of which ever is expected to occur more often. I threw in a bad value to show that it raises the most recent exception if it can't find a match.code:
|
# ? Jul 17, 2014 03:14 |
|
I did it a more idiotic way, but whatever works. I'd like to get your guys opinions on this. I decided I wanted to look at race data from a 5k, and see if there's a correlation between age and time. It's obvious there is one, right? Older people tend to finish slower. Younger people tend to finish faster. Much younger people may end up finishing slower. There's a sweet spot right around 20-35, I'd think. I found a bunch of race sites that had their results in CSV files, and I downloaded a bunch of them (10 or so race results). I ended up with 4500+ participants. code:
|
# ? Jul 17, 2014 03:43 |
|
Well you should at least check what kind of correlation you do have, that's not completely uncorrelated. Best way, IMO, is to pip install seaborn thenPython code:
SurgicalOntologist fucked around with this message at 04:43 on Jul 17, 2014 |
# ? Jul 17, 2014 04:36 |
|
SurgicalOntologist posted:It could be that your data is correct but in regard to this particular race there's only a small correlation between age and time. I mean, where was the race? Who put it on? Etc. The relative lack of people around age 20 strikes me as unusual. The jointplot includes histograms so it can help you get a sense of the distributions as well as the correlation. It's around 10-11 different races. I'm thinking I should try to find even more to see if it evens out, but I thought 4500 total runners would be a sufficient data sample. Another theory is that maybe older runners tend to be more experienced, so they'll still put down roughly consistent good times, but younger runners are all over the map. A 25 year old could just as likely be a first timer as well as a serious athlete, but a 45 year old most likely won't be doing it for the first time. However, you can kinda see the shape I was looking for if you look at the limits of times around 20-30 minutes with respect to the elderly. No 80 year old puts down faster than 30. No 70 year old puts down faster than 25. No 60 year old puts down faster than 23, and so on. Maybe looking at median times would be a better option?
|
# ? Jul 17, 2014 04:58 |
|
Don't overthink it, just plot a bunch of different stuff and see what happens. IPython and pandas are great for this sort of rapid experimentation with data.
|
# ? Jul 17, 2014 05:15 |
|
the posted:It's around 10-11 different races. I'm thinking I should try to find even more to see if it evens out, but I thought 4500 total runners would be a sufficient data sample. Like I said, instead of talking about what you can kinda see, actually run a correlation and actually look at the distributions of age and time. Then you can start thinking about theories.
|
# ? Jul 17, 2014 05:27 |
|
the posted:It's around 10-11 different races. I'm thinking I should try to find even more to see if it evens out, but I thought 4500 total runners would be a sufficient data sample. Race data is tricky for a couple of reasons. First while I've never done the research, I've heard that runners don't come into their prime until their mid thirties a number of times. Second races tend to self select people of a certain fitness level who are confident they can finish the race. Realistically age counts for less than your conditioning/fitness level/amount of training time. If you picked 4,500 random people and forced them to run a 5k out of the blue I bet you would see the visual correlation you were expecting. The data is probably right and it is just your expectations that are wrong. I would follow SurgicalOntologist's advice and run an actual correlation. Lyon fucked around with this message at 07:36 on Jul 17, 2014 |
# ? Jul 17, 2014 07:34 |
|
edit: Fixed my problem
the fucked around with this message at 17:26 on Jul 17, 2014 |
# ? Jul 17, 2014 17:01 |
|
So I completed the codeacademy course, well kinda and skipped the repetition. So I now need a small manageable project to get goign with. Also whats my best option for messing around in python. Running OSX with xcode installed and working.
|
# ? Jul 17, 2014 22:59 |
|
thegasman2000 posted:So I completed the codeacademy course, well kinda and skipped the repetition. So I now need a small manageable project to get goign with. Also whats my best option for messing around in python. Running OSX with xcode installed and working. Find a problem that you have and solve it. Even if it is solved adequately by some existing project. It's a lot more motivating when you're making something for yourself, not just to have done it.
|
# ? Jul 17, 2014 23:03 |
|
thegasman2000 posted:So I completed the codeacademy course, well kinda and skipped the repetition. So I now need a small manageable project to get goign with. Also whats my best option for messing around in python. Running OSX with xcode installed and working. Find every prime number between 0 and 100. edit: in 20 lines or less
|
# ? Jul 18, 2014 00:26 |
|
the posted:Find every prime number between 0 and 100. Show us a jointplot of your data already. I'm legitimately curious.
|
# ? Jul 18, 2014 00:27 |
|
SurgicalOntologist posted:Show us a jointplot of your data already. I'm legitimately curious. Haha, sorry. I was doing ~work stuff~ all day (beatbox, salesforce, etc). So now I have some downtime and can finally learn Pandas.
|
# ? Jul 18, 2014 01:52 |
|
Haha fair enough. You don't need pandas for that though (well you need it installed as a dependency), you can make the plots straight from your existing lists in one line, with Seaborn. But take your time, I was just being impatient.
|
# ? Jul 18, 2014 03:30 |
|
Sorry I am sure your all fed up of answering this but whats the text editor of choice for a python newbie? Looking for something that will prompt and highlight errors such as indentation before compiling if possible. Trying out textmate at the moment but its not highlighting an error I am getting.
|
# ? Jul 18, 2014 12:51 |
|
thegasman2000 posted:Sorry I am sure your all fed up of answering this but whats the text editor of choice for a python newbie? Looking for something that will prompt and highlight errors such as indentation before compiling if possible. Trying out textmate at the moment but its not highlighting an error I am getting. It catches syntax errors before the script is run, warns when code isn't following PEP8 "best practices" in formatting so I learned good habits early, can pop-up documentation on functions and arguments, and includes breakpoint debugging and other tools to inspect variables, step through loops, etc. I've grown into using some of its advanced features like integration with version control and test automation, but you can ignore all of those kinds of features when starting and just use it to edit scripts. The Community Edition is free.
|
# ? Jul 18, 2014 13:19 |
|
perfect thanks!
|
# ? Jul 18, 2014 13:34 |
|
This might be dumb but I can't see it right now. I'm trying to make images using misc.imsave and it seems the function works unlike I thought it would? The doc is very unspecific as to how it owrks so I'd just like to make sure I'm getting this right. I have this code: code:
edit: I guess it's fine this way, I was just surprised because I thought it would work the other way, but switching around the indices makes it work the way I want, kinda. Colonel J fucked around with this message at 16:58 on Jul 18, 2014 |
# ? Jul 18, 2014 16:54 |
|
How do I do a conditional IF statement that checks to see if a datetime object is newer than a certain date? The dates are in the format: datetime.datetime(2013, 8, 26, 17, 21, 35) And I need to do something like: code:
code:
the fucked around with this message at 18:44 on Jul 18, 2014 |
# ? Jul 18, 2014 18:41 |
the posted:How do I do a conditional IF statement that checks to see if a datetime object is newer than a certain date? Compare it to another datetime object. Check out the "Supported operations" for datetime. edit: code:
|
|
# ? Jul 18, 2014 18:45 |
|
code:
|
# ? Jul 18, 2014 18:47 |
|
First time touching python. Trying to send some serial commands to an lcd display. The docs give a Dec and Hex code for each command. Dec 17(hex 11) enables the backlight for example. So to enable the backlight, I use: port.write(chr(17).encode()) To actually write text I use: s = "My Text" port.write(s.encode()) All is well. Moving on, you can also play sounds. Dec 221(hex DD) should play A#. So I tried: port.write(chr(221).encode()) And got nothing. I looped through all the notes and got nothing. So I thought maybe I should try sending the hex instead of the decimal. I tried: cmd = "\xDD" port.write(str(cmd).encode()) and got nothing. Is this the right way to send hex in python 3? Any other suggestions?
|
# ? Jul 18, 2014 23:38 |
|
bobua posted:First time touching python. Trying to send some serial commands to an lcd display. The docs give a Dec and Hex code for each command. Dec 17(hex 11) enables the backlight for example. Beware of encoding! By default str.encode will encode strings as utf-8, so you'll get: code:
Now your way should work if you encode as latin1, which is sometimes handy if you get a string from other sources: code:
code:
|
# ? Jul 19, 2014 00:44 |
|
Hey all, Anyone got any good tutorials or explanations for using an oracle wallet to connect to an oracle database in Python? I've googled the crap out of it and I can't find anything.
|
# ? Jul 19, 2014 02:13 |
|
Have you looked into what cx_oracle can do? That's the oracle driver SQLalchemy uses.
|
# ? Jul 19, 2014 14:45 |
|
Haystack posted:Have you looked into what cx_oracle can do? That's the oracle driver SQLalchemy uses. I've been using cx-oracle. I need to use the oracle wallet with cx-oracle, which seems like it should be possible. Thanks for the link, I'll take a closer look at it.
|
# ? Jul 19, 2014 23:07 |
|
Do the various Python web frameworks (Django, Flask, Bottle, etc.) all spawn a separate process or separate thread for each incoming user hitting a given route? Does this vary if you switch from the internal test webserver to something serious?
|
# ? Jul 20, 2014 08:58 |
|
No. Simple dev servers generally just only handle one request at a time and hope that they can process requests fast enough that any additional ones that come in don't time out. Real production deployments involve a fixed (or bounded to a small range) number of worker processes with a load balancer.
|
# ? Jul 20, 2014 15:52 |
|
I'm trying to write a program that would model movement to a changing target every t seconds. i.e. Say we deal only in 1 dimension, and I start at position x = 0. I receive some data every (say) 5 seconds that says the target position is a new position P. I then want to model the position of my point x so it moves say + 1 towards the target every second until the next update of target position, when it adjusts and starts moving towards the new target position from its current position. Is there a simple way to do this? I've been getting bogged down in trying to understand the Threading module since that is what a quick browse of StackOverflow seemed to suggest I would need to use, but I've never used it before and I'm getting myself more and more confused each time...
|
# ? Jul 20, 2014 16:30 |
|
I need to parse ISO 8601 dates and I found the dateutil module (https://pypi.python.org/pypi/python-dateutil/1.5). However, the latest version for python 2.X is 1.5, which is 4 years old by now. Is there any recommendations against it?
|
# ? Jul 20, 2014 17:35 |
|
dateutil 2.2 is listed as supporting Python 2.6, 2.7, 3.2, and 3.3 according to https://pypi.python.org/pypi/python-dateutil/2.2. It's fine on 3.4 too, but the package classifiers haven't been updated yet.
|
# ? Jul 20, 2014 17:58 |
|
I thought the author just picked all those versions as a catch-all. Thanks.
|
# ? Jul 20, 2014 18:25 |
|
ShadowHawk posted:Do the various Python web frameworks (Django, Flask, Bottle, etc.) all spawn a separate process or separate thread for each incoming user hitting a given route? Does this vary if you switch from the internal test webserver to something serious? It depend on the framework and the server. IIRC CherryPy has a decent threaded server for development mode, while Flask and Bottle just uses a single-threaded server. When you're using a separate WSGI server, it will usually spawn a number of worker processes or threads and delegate incoming requests to them, but I think most of them can be configured to thread/process-per-request. The WSGI PEP specifies how a framework indicates support for multithreading or multiprocessing. quote:wsgi.multithread This value should evaluate true if the application object may be simultaneously invoked by another thread in the same process, and should evaluate false otherwise.
|
# ? Jul 20, 2014 19:13 |
|
Carrier posted:I'm trying to write a program that would model movement to a changing target every t seconds. i.e. Say we deal only in 1 dimension, and I start at position x = 0. I receive some data every (say) 5 seconds that says the target position is a new position P. I then want to model the position of my point x so it moves say + 1 towards the target every second until the next update of target position, when it adjusts and starts moving towards the new target position from its current position. Explain a little more what the requirements are for your program. Are you recording the data, plus interpolating, and recording all the points? Or do you want to provide some sort of interface with which an another thread can ask for the current estimated position whenever it wants? When you say "my point" and "target" are these two different physical things? In other words, is "my point" an estimate of the current position of the target or is it some modeled point that's chasing a physically separated target?
|
# ? Jul 20, 2014 19:15 |
|
SurgicalOntologist posted:Explain a little more what the requirements are for your program. Are you recording the data, plus interpolating, and recording all the points? Or do you want to provide some sort of interface with which an another thread can ask for the current estimated position whenever it wants? I'm basically trying to simulate an object responding to commands to move to a certain position and I want to simulate some sort of delay in this response so that sometimes, it might not make it to the position its supposed to reach before it gets given another command. Sorta simulating like a car being told to go to point A, then to point B, and so on but it can only travel at a certain speed to get there. In the long term I was hoping to plot this movement on a graph as I read a set of preset target positions from a file, but for now I'd settle for just numerically being able to do this kind of simulation. So visually, I'd have something like (using O for object, T for target position): code:
|
# ? Jul 20, 2014 19:28 |
|
|
# ? May 9, 2024 19:22 |
|
Carrier posted:I'm basically trying to simulate an object responding to commands to move to a certain position and I want to simulate some sort of delay in this response so that sometimes, it might not make it to the position its supposed to reach before it gets given another command. Sorta simulating like a car being told to go to point A, then to point B, and so on but it can only travel at a certain speed to get there. In the long term I was hoping to plot this movement on a graph as I read a set of preset target positions from a file, but for now I'd settle for just numerically being able to do this kind of simulation. So visually, I'd have something like (using O for object, T for target position): Maybe try a low pass filter, like an exponential smoother or something? Also try asking here: http://forums.somethingawful.com/showthread.php?threadid=3359430
|
# ? Jul 20, 2014 20:16 |