[Tutor] write program to extract data
Wayne
srilyk at gmail.com
Fri Aug 14 22:14:58 CEST 2009
Whoops, I forgot the reply-all.
On Fri, Aug 14, 2009 at 3:03 PM, Michael Miesner
<michael.miesner at gmail.com>wrote:
> That is one distinct advantage, It'll always be just like that. However, I
> dont know where to even begin; I dont know what command pulls text out
> ($string?) or how to import it into a spreadsheet.
>
Alan Gauld has a spiffy python tutorial here:
http://www.freenetpages.co.uk/hp/alan.gauld/
I presume you have at least a little programming experience. Python is
really simple to pick up if you've done any other language. Check out
"Handling Text" and "Handling Files" for some specific pointers. Are you
familiar with comma separated value (.csv) files? It's fairly trivial to
import those into a spreadsheet program, and if you're the one writing the
.csv it's not too difficult to get them written the right way.
HTH,
Wayne
>
>
> On Fri, Aug 14, 2009 at 3:54 PM, Wayne <srilyk at gmail.com> wrote:
>
>> On Fri, Aug 14, 2009 at 12:08 PM, Michael Miesner <
>> michael.miesner at gmail.com> wrote:
>>
>>> Hi-
>>> I work in a research lab and part of the lab I'm not usually associated
>>> with uses a program that outputs data in a .txt file for each participant
>>> that is run.
>>> The participant # is the title of the text document (ie E00343456.txt)
>>> style and I'd like to be able to take this and other data in the file and
>>> draw it into a spreadsheet.
>>> The first 3/4 of the output is the scenario. I've bolded the areas that I
>>> really want to be able to draw out. In case some people cant see the bold,
>>> they are the sections called "driver mistakes" and individual mistakes.
>>>
>>>
>>> Preferably, what I'd really like to do is make the script so that I
>>> execute it, and in doing so, tell it what folder to look in, and it takes
>>> all the .txt's out of that folder, and adds them to the spreadsheet. I'd
>>> like the title of the .txt to be the first column, and the data held in the
>>> spreadsheet to be the be the next columns.
>>
>>
>>> <snip copious amounts of irrelevant? data>
>>>
>>>
>>> *Driver mistakes:
>>>
>>> Total number of off road accidents = 1
>>> Total number of collisions = 3
>>> Total number of pedestrians hit = 3
>>> Total number of speed exceedances = 11
>>> Total number of speeding tickets = 0
>>> Total number of traffic light tickets = 1
>>> Total number of stop signs missed = 0
>>> Total number of centerline crossings = 5
>>> Total number of road edge excursions = 4
>>> Total number of stops at traffic lights = 2
>>> Total number of correct DA responses = 0
>>> Total number of incorrect DA responses = 0
>>> Total number of DAs with no response = 0
>>> Total run length (Drive T, X, Total T) = 761.92 34000
>>> 761.92
>>> Total number of illegal turns = 0
>>> Total number of low speed warnings = 0
>>> Total number of high speed warnings = 0
>>> Over speed limit (% Time, % Distance) = 27.15 47.77
>>> Out of lane (% Time, % Distance) = 4.22 3.74
>>>
>>> Individual mistakes (Time, Distance, Elapsed distance or object number,
>>> Elapsed time, Maximum value):
>>>
>>> Centerline crossing 68.16 3311.11 110.69 2.60
>>> -3.46
>>> Centerline crossing 94.26 4598.99 252.83 4.45
>>> -3.19
>>> Centerline crossing 127.85 6758.39 109.70 1.92
>>> -2.78
>>> Centerline crossing 162.14 9082.09 273.04 3.27
>>> -9.72
>>> Speed exceedance 162.80 9135.05 4596.82 48.87
>>> 120.00
>>> Road edge excursion 166.34 9438.89 77.08 0.83
>>> 13.45
>>> Hit pedestrian 204.46 13731.87 1
>>> Speed exceedance 221.51 13829.40 912.17 22.75
>>> 67.13
>>> Hit pedestrian 237.05 14741.43 5
>>> Speed exceedance 259.93 15171.25 746.18 13.35
>>> 60.35
>>> Centerline crossing 317.69 16126.40 14.76 8.15
>>> -4.37
>>> Vehicle collision (F) 318.63 16141.15 66
>>> Vehicle collision (F) 341.91 16166.52 91
>>> Red light ticket 452.04 16548.74 2
>>> Speed exceedance 458.24 16802.82 1484.23 18.15
>>> 95.58
>>> Speed exceedance 516.14 20362.78 685.87 10.13
>>> 68.67
>>> Speed exceedance 551.24 21996.05 2111.93 24.31
>>> 91.76
>>> Vehicle collision (F) 580.58 24459.77 163
>>> Speed exceedance 606.49 25376.76 3929.19 42.84
>>> 120.00
>>> Road edge excursion 622.00 26916.68 86.74 0.77
>>> 13.30
>>> Road edge excursion 623.62 27100.59 251.81 2.17
>>> 14.42
>>> Road edge excursion 641.31 29212.44 93.52 8.02
>>> 19.52
>>> Off road accident 642.11 29305.93
>>> Speed exceedance 664.99 30081.20 777.80 10.76
>>> 82.64
>>> Hit pedestrian 695.29 31013.94 30
>>> Speed exceedance 719.30 31513.55 915.64 14.16
>>> 71.88
>>> Speed exceedance 742.46 32837.36 81.72 1.57
>>> 52.90
>>> Speed exceedance 749.76 33199.52 801.52 12.16
>>> 76.04
>>> *
>>>
>>
>> Is the data always going to be at the end of the file? I.e. will there be
>> any more data after what you really want?
>>
>> If it's always going to be at the end of the file you can just check for
>> the line that starts with "Driver mistakes:"
>>
>> Once you find that line, then you know you'll want the rest of the file.
>>
>> There are several different methods, but it's certainly possible. Let us
>> know if you run into any roadblocks and we'll be happy to help point you in
>> the right direction.
>>
>> -Wayne
>>
>
>
>
> --
> Michael Miesner
> Doctoral Student in Clinical Psychology
> East Tennessee State University
>
>
--
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090814/61034105/attachment-0001.htm>
More information about the Tutor
mailing list