Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: editing a csv file using a macro help

  1. #1
    Join Date
    Apr 2016
    Location
    Melbourne
    Posts
    4,533
    Total Downloaded
    0

    editing a csv file using a macro help

    Hello more knowledgeable people.

    I'm trying to edit a csv file with data from the 1Gauge logger.
    1Gauge logs all the input data into csv files, and does so on every session(ie. start/stop time).
    The format is easy to use, and graph for each individual 'session' but if you want to see the data over a longer period(eg. day/week/month) the time column convolutes the graphs.

    Basic recording is that the time data is just time from initialisation, not a date time format(the 1Gauge is not time aware as such).

    So the time data column will rise from about a value of 5(sec) and then stop when the car is turned off. The last time data entry could be any value obviously depending on how long that drive was.

    So what I'm trying to do is to append the initial time(eg. 3 or 5 or whatever) to the last time data point on the previous session.

    So as an example I may have a basic session where time column reads:

    3, 3.15, 3.30(for one session) then 3, 5.15, 8.30(for the next session)

    What I want for the full csv sheet I've created is for that value of 3 (in session 2) to be added to the 3.30 value (of the 1st session), and then add 5.15 to the value of as the next cell(downwards) to the value of (3.30+3) and repeat the process downwards the column list.

    I tried creating a macro but I'm not a programmer type and all I get is 'syntax error' for any tests I try to do.

    Basically my macro would be something like:

    If (cell)A(x) < (cell)A(x+1), then Sum or Append (cells)A(x)A(x+1).
    The other part of the issue is that the macro can only operate on column A(the time column). The other columns log sensor data.

    But not being a programmer type, obviously LibreOffice's Macro recording function thinks I'm an idiot!

    I have a few text editing software(freewares) that may also be able to help with this issue, but I'm not entirely sure how they work either.
    I've used them for editing OziExplorer .map files en masse but that was using search and replace functions and other stuff like that.

    Any help would be muchly appreciated.
    TIA.

  2. #2
    Join Date
    Jun 2010
    Location
    Central Coast NSW
    Posts
    1,888
    Total Downloaded
    0
    I havent found the macro capability of libre office to be that great. I could help much more if it was in excel. Does it have to be in libreoffice?

    Do you have a worksheet you can post up for people to have a look at for you?

  3. #3
    Join Date
    Aug 2006
    Location
    Melbourn(ish)
    Posts
    26,505
    Total Downloaded
    0
    theres a way of doing it excel where you just import the data one chunk at a time and it will append the time log, the problem is...

    if you go over the 24 hour day you might wind up with some funky numbers and date management issues.

    its also a manual process but it should be automateble by modifying the converter to read the time date column as a sequence rather than a list... (as in row 2 = row 1+ the value in row 2, row 3 = the value now in row 2 + the value in row 3. yes I know that sounds like a rcurring loop but there is away of doing it on import so it only process each line once and in order.)
    Dave

    "In a Landrover the other vehicle is your crumple zone."

    For spelling call Rogets, for mechanicing call me.

    Fozzy, 2.25D SIII Ex DCA Ute
    Tdi autoManual d1 (gave it to the Mupion)
    Archaeoptersix 1990 6x6 dual cab(This things staying)


    If you've benefited from one or more of my posts please remember, your taxes paid for my skill sets, I'm just trying to make sure you get your monies worth.
    If you think you're in front on the deal, pay it forwards.

  4. #4
    Join Date
    Jan 1970
    Location
    Perth WA 6149
    Posts
    1,308
    Total Downloaded
    0
    As Disco-tastic suggests posting an example file up here would be useful.

    I can think of a number of approachs, but they may or may not work depending on the time field format and reading rate, so having an actual file to tinker with would be great. Is your time field formatted as minutes.seconds or decimal minutes and are the readings within a session regularly spaced in time?

    Cheers

    Steve

  5. #5
    Join Date
    Apr 2016
    Location
    Melbourne
    Posts
    4,533
    Total Downloaded
    0
    Quote Originally Posted by Disco-tastic View Post
    I havent found the macro capability of libre office to be that great. I could help much more if it was in excel....
    Yeah. kind'a.
    Don't have Office anymore(and TBH don't think I need it).
    I once tried Open Office (proper) and it ruined my (important) xls and xlsx files. Libre Office has been no issue for me since I started using it.

    I've converted two of the log files into a single xls file.
    At line 94 of the sheet is where the time changes.
    The original second sheet had a header row as well, but I delete them as it confuses things, so you'll see the time(column) rises up to about 24.54 and then at line 94 is the start of the second log at about 5.09 again.

    I generally get about 200 log files per month, and I merge them all with the copy command(quick and easy) and make one large csv file.
    I didn't see any point in continuing to add more data and inflate the size of the xls file(note that odf is so much smaller for many spreadsheets by comparison too!).

    So the basic idea is where the time reaches 24 on line 93 then changes to 5.09 on 94 .. I'm trying to add 5.09 to 24.54(ie. 29.63) and continue on recursively adding the time values to the previous one to get a continuous time line.

    If I don't do this, merging more than 2 data sets into a graph becomes messy where the graph then fold back onto itself and makes it impossible to read the data.

    ps. the time value is not a time value as in day date or actual time.
    This is my biggest regret and complaint about the 1Gauge, in that it's great that it logs the sensor data, but it would have been greater if it could put that sensor data into some sort of context.
    So the time value is a simple number value only, which I assume is in seconds.

    And I just realised another problem with what I wanted to do.
    If I simply add the value of the next cell below to the previous cell, it stuffs the actual time constant up.
    What I actually need to do is to add the time values of the next sheet to the final time value of the previous sheet.
    The csv files are all named coherently LOG0001, LOG0002, etc.
    Attached Files Attached Files

  6. #6
    Join Date
    Jun 2010
    Location
    Central Coast NSW
    Posts
    1,888
    Total Downloaded
    0
    How much manual work do you currently do importing the values? Could you add an extra column which just adds the times together, and use that as your horizontal axis?

    I've attached a file showing what I mean. It was writtent in excel, so you may need to translate into Libre-speak.

    Cheers

    Dan
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 1970
    Location
    Perth WA 6149
    Posts
    1,308
    Total Downloaded
    0
    Looking at the files, I can't suggest anything more elegant that Dan's formula of comparing the readings and adding the previous reading or the difference.

    The only other thought would be to have a dummy time column. The time difference between readings is always either 0.21 or 0.22, so you could also populate a column with a start reading of 0 and a sequence of 0.21, 0.42, 0.63 etc

    Cheers

    Steve

  8. #8
    Join Date
    Apr 2016
    Location
    Melbourne
    Posts
    4,533
    Total Downloaded
    0
    Quote Originally Posted by Rok_Dr View Post
    .... The time difference between readings is always either 0.21 or 0.22, so you could also populate a column with a start reading of 0 and a sequence of 0.21, 0.42, 0.63 etc

    Cheers

    Steve
    Thanks for the help guys.
    That was one of the things I was thinking too, but even more simple with rising integer values starting at 1 .. 2, 3, etc.

    Work done to import the values is minimal.
    Only really the time taken to type: copy *.csv file1.csv in the command prompt.
    This amalgamates however many csv files into one large one.
    The number of files varies but can be as many as 300 or more files per mth.
    Work to append all those files into one large file is about 30sec.
    Then I open in a text editor just to remove all the header rows using find and replace(delete), another 10 sec or so.

    I'll have a go at Dan's method and see if it'll work in Libre.

    ps. the other reason I'm doing this is not just to get the data into a usable format, but also to expand my knowledge a little further(ie. a bit of programming know how never hurt anyone! )

    Oh! .... and of course the alternator on the Tdi decided to take it's long service leave an hour or so ago and all the shops are closed/closing and don't even know what a Landrover is!

    Shop assistant: Landrover! how do you spell that.
    Me: L for Larry, A for apple, N for November ...
    Shop assistant: What model is it?
    Me: 300 Tdi diesel, 2.5 Lt turbo diesel 98 model Discovery.
    Shop Assistant: is that a V8?
    Me: .. err, I think so
    Shop assistant: Doesn't look like we have them in stock, but I can order one in.
    Me: I'll get back to 'ya.

    Anyhow. once again, thanks for the help so far.
    I'll get back with any results.

  9. #9
    Join Date
    Jun 2010
    Location
    Central Coast NSW
    Posts
    1,888
    Total Downloaded
    0
    If you're happy doing that them I'd see if the extra column works and make a template out of it. Import your csv files as per above, then copy the values into the template. The extra row will calculate itself and your graph should update automatically it will take an extra 5 secs.

    If you're really keen on learning join a site like [URL = "http://stackoverflow.com/q/11638170/5266309"]Stack Exchange.[/URL] there is heaps of info on that site

  10. #10
    Join Date
    Apr 2016
    Location
    Melbourne
    Posts
    4,533
    Total Downloaded
    0
    Quick update:
    Awesome!!
    Thanks Dan.
    All I got to do now is record a macro when I create that conversion process and re use the macro as needed.


Page 1 of 2 12 LastLast

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search AULRO.com ONLY!
Search All the Web!