Author Topic: Separate a CSV-File (find line break)  (Read 16501 times)

BlackJack

  • Jr. Member
  • **
  • Posts: 68
Separate a CSV-File (find line break)
« on: May 15, 2016, 01:09:00 PM »
Hi,

I want import some information from a CSV file. That works really good with the
{TXTPOS:} Token. But how can I find the line ending position?

By the way, can the {TXTPOS:} search in backward direction?

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Separate a CSV-File (find line break)
« Reply #1 on: May 15, 2016, 03:21:53 PM »
Hi,

I want import some information from a CSV file. That works really good with the
{TXTPOS:} Token. But how can I find the line ending position?

By the way, can the {TXTPOS:} search in backward direction?
This is the kind of stuff that is probably a ton easier to do in a plugin rather then inside an actual command... it would be probably quick to add to mine, can you give an example of what exactly are you trying to do with the CSV?
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

BlackJack

  • Jr. Member
  • **
  • Posts: 68
Re: Separate a CSV-File (find line break)
« Reply #2 on: May 15, 2016, 05:43:39 PM »
Hi, Antaniserse

it may be easy for you, but not for me. ;) I have no programming skills.

The EDMarketConnector provides some CSVs with useful information e.g. the FlightLog, the ship locations, player status...

I made also a translation CSV, that helps me to bring the ship names or the commodity names into a TTS compatible format or tranlation (ivona Marlene). But here I can make a special character at the and of each line.

I'll attach some example files.
« Last Edit: May 30, 2016, 01:00:07 PM by BlackJack »

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Separate a CSV-File (find line break)
« Reply #3 on: May 16, 2016, 04:55:02 AM »
Hi, Antaniserse

it may be easier for you, but not for me. ;) I'm have no programming skills.

I've just updated my plugin on https://github.com/Antaniserse/VAExtensions/releases

It now supports basic CSV files, there's a sample profile included which should be easy enough to understand: specify a file name, a row and a column and it will fetch the value for you... you can also change the default delimiter from , to | or whatever you like

Feel free to ask here for more help

Note that the 'Fligh Log.csv' is likely to not work correctly... it's not a properly formed CSV file since, in the last row, the cargo column uses a comma to separate the various items, but it's not enclosed in ""; so it creates an ambiguity between the column separator and the actual content

You should try and ask the guys that mantain EDMarketConnector to use a different delimiter for the cargo items, like a semicolon or dash, so there's no conflict when parsing the file

« Last Edit: May 16, 2016, 05:03:15 AM by Antaniserse »
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

BlackJack

  • Jr. Member
  • **
  • Posts: 68
Re: Separate a CSV-File (find line break)
« Reply #4 on: May 16, 2016, 05:51:19 AM »
Quote
I've just updated my plugin on https://github.com/Antaniserse/VAExtensions/releases

Thank you Bud. That's awesome.  I'll try that and give you feedback.

BlackJack

  • Jr. Member
  • **
  • Posts: 68
Re: Separate a CSV-File (find line break)
« Reply #5 on: May 16, 2016, 09:46:16 AM »
It works great! and much faster than what I've done here in VA.

Thank you for that.

Is it possible to add an option that figures out, how many rows a CSV file has? Because I need only the last entry from the Flight Log. Otherwise I can use my VA Macro to handle this especially with this non conform format.

The commodity CSV has 270 rows and will get more with the next Elite patch. To get the correct value for the VxRow it would be very helpful, if the plugin can give me the Row which actually contains e.g. the Superconductors.

I do not know what is the effort to code this, but it would be the cherry on my cake. ;D

Thank you in advance... and thank you for the time, you've already spend on this.
« Last Edit: June 04, 2016, 11:29:19 AM by BlackJack »

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Separate a CSV-File (find line break)
« Reply #6 on: May 16, 2016, 04:40:47 PM »
It works great! and much faster than what I've done here in VA.

Thank you for that.

Is it possible to at an option to figure out, how many rows a CSV file has?
No problem, done... the 'load_csv' call now return two additional integer values, with the number of rows and columns found in the file; just look at the updated sample profile

The commodity CSV has 270 rows and will get more with the next Elite patch. To get the correct value for the VxRow it would be very helpful, if the plugin can give me the Row which actually contains e.g. the Superconductors.
If i understand correctly, you mean you would like a function that, given a column name/index and a reference string, returns the index of the row that contains said value?
Done too...   ;)

Download from the same URL
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

BlackJack

  • Jr. Member
  • **
  • Posts: 68
Re: Separate a CSV-File (find line break)
« Reply #7 on: May 17, 2016, 09:02:57 AM »
If i understand correctly, you mean you would like a function that, given a column name/index and a reference string, returns the index of the row that contains said value?

That's exactly what I meant. Thank you! Excuse my english.

I have one more question: There is a offset in the resulting token number and the CSV.
Is it possible to bring these values into line? It's for convenience only.
« Last Edit: May 17, 2016, 09:27:31 AM by BlackJack »

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Separate a CSV-File (find line break)
« Reply #8 on: May 17, 2016, 10:12:07 AM »
I have one more question: There is a offset in the resulting token number and the CSV.
Is it possible to bring these values into line? It's for convenience only.
One offset was actually intended... a proper CSV use the first line for the column headers, and since I keep them separated from the rows, it is not considered (so when the plugin says that the file contains 'X' rows it means 'X' rows of actual data)

The second offset on the other hand is just my code using a 0-based index, instead of a 1-based index like Excel... it's just an habit, so i guess I might change that; the change will impact columns too, so in the updated version (uploaded just now) the first column will be '1' and so on
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

BlackJack

  • Jr. Member
  • **
  • Posts: 68
Re: Separate a CSV-File (find line break)
« Reply #9 on: May 17, 2016, 11:27:36 AM »
One offset was actually intended... a proper CSV use the first line for the column headers, and since I keep them separated from the rows, it is not considered (so when the plugin says that the file contains 'X' rows it means 'X' rows of actual data)

OK., Antaniserse.

I'm really impressed about your work. Especially how fast you can do that.
So, thank you again.
« Last Edit: June 04, 2016, 11:32:40 AM by BlackJack »

Astral_Nomad

  • Newbie
  • *
  • Posts: 14
Re: Separate a CSV-File (find line break)
« Reply #10 on: May 18, 2016, 10:31:52 AM »
Hi,

I want import some information from a CSV file. That works really good with the
{TXTPOS:} Token. But how can I find the line ending position?

By the way, can the {TXTPOS:} search in backward direction?
This is the kind of stuff that is probably a ton easier to do in a plugin rather then inside an actual command... it would be probably quick to add to mine, can you give an example of what exactly are you trying to do with the CSV?

I would agree. In programming terms, the "end line" is marked by a '\n' or a "\r\n" depending on your OS.. this is usually marked by a 0x0D0A code.. Writing a plugin could help you deal with that but theres no way to do it in VA..

BlackJack

  • Jr. Member
  • **
  • Posts: 68
Re: Separate a CSV-File (find line break)
« Reply #11 on: May 19, 2016, 11:35:55 AM »
I would agree. In programming terms, the "end line" is marked by a '\n' or a "\r\n" depending on your OS.. this is usually marked by a 0x0D0A code.. Writing a plugin could help you deal with that but theres no way to do it in VA..

Thanks for the info. Since there are more and more  opportunities to process text in VA, it would be a very useful, logical feature. Is it worth a request? What would you say?

Astral_Nomad

  • Newbie
  • *
  • Posts: 14
Re: Separate a CSV-File (find line break)
« Reply #12 on: May 19, 2016, 07:24:18 PM »
No idea.. i dont deal with parsing files in VA.. cant be bothered at this point.

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Separate a CSV-File (find line break)
« Reply #13 on: May 19, 2016, 11:58:17 PM »
Thanks for the info. Since there are more and more  opportunities to process text in VA, it would be a very useful, logical feature. Is it worth a request? What would you say?
I'm playing devil's advocate here, since I can write my own code as you saw, but I think this kind of stuff is the perfect scope for plugins, not for the main application.

There's "features" and there's "too much features"; as hinted by Gary numerous times, the more complexity you add to the command parsing of VA, the more you risk to make it less responsive for the main job he has to do: recognize speech and issue commands to games.

The base application code has to take many things into account, since it has to run in the most "generalistic" way for everyone, while a plugin on the other hand can be highly dedicated to a single feature and so be coded to use every possible trick, shortcut and optimization to make it efficient at that specific task
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

TheGrayFox

  • Newbie
  • *
  • Posts: 16
Re: Separate a CSV-File (find line break)
« Reply #14 on: May 20, 2016, 10:58:56 AM »
I'm playing devil's advocate here, since I can write my own code as you saw, but I think this kind of stuff is the perfect scope for plugins, not for the main application...
Absolutely.  As a developer myself, I have to agree with you on this, for the very reasons you mention.  Let VA focus on its job at hand and let plugins do the "extra" stuff.  I'm pretty sure the "extra" stuff is almost always going to be stuff for which most VA users don't really have a need.

Gary stays in touch with the VA community. He knows pretty well how, and for what, VA is mostly used.  If there were to come a situation where something outside of VA's "normal" bounds became really popular or needed, I'm sure he would consider adding it to the list of features.