Thread Tools Display Modes
11/29/14, 03:02 AM   #1
CausaMortis
Join Date: Nov 2014
Posts: 2
Converting lua to excel file?

Anyone has a tutorial or link that shows me how I can convert data stored in savedvariabels to an excel database?

Tx
  Reply With Quote
11/29/14, 03:57 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
You can't easily do an export of LUA file with ESOUI, because the only way to write something on the disk is to pass trought SavedVars, so you'll need another scripting language (it's really really faster). Here you can write this script in any language, you only need to pass as arg the text in the saved file or thhe file itself.

Then this scripting language must convert the file into something your other tool (here, Excel) can understand.

I suggest you to use JSON format, because converting from LUA to JSON is really easy. Then use a convert tool to import this format into excel.
I quickly looked at XML, but it looks little bit harder.

Here is a quick script (in php) which convert LUA into JSON, I think you can easily adapt the format to C#, perl, ruby or anything else. I didn't look if you can have problems with special chars if you export strings, but it shouldn't be complicated to protect strings with this format.

For private and little use, I strongly suggest you to use something more "human compliant" : Notepad++, Delete button, Ctrl+H, etc.

Code:
function convert($luaText)
{
	
	// Search for \r\n as long eso build dos files
	
	if((explode("\r\n", $luaText)) > 0)
	{
		
		//Array conversion
		$luaSymbols = array("[\"", 	"\"] = "); 
		$phpSymbols = array("\"",	"\":");
		$luaText = str_replace($luaSymbols, $phpSymbols, $luaText);
		$jsonFile = null;
		
		$firstLine = true;
		
		foreach(explode("\r\n", $luaText) as $lua_line)
		{
			
			//Don't parse 1st line, it's VARNAME =
			if ($firstLine)
			{
				$firstLine = false;
			}
			else
			{
				$jsonFile .= $jsonFile . rtrim($lua_line);
			}
		}
		
		//JSON doesn't accept ",}"
		$jsonFile = str_replace(array("\r\n", ",}"), array(null, "}"), $jsonFile);
		
	}
	
	return $jsonFile;
	
}

Last edited by Ayantir : 11/29/14 at 04:00 AM.
  Reply With Quote
12/11/14, 12:08 PM   #3
dopiate
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 142
Originally Posted by CausaMortis View Post
Anyone has a tutorial or link that shows me how I can convert data stored in savedvariabels to an excel database?

Tx
For what purpose? Depending on the answer I have different suggestions.

My current addon does this every time it's run (GSA) -- it is the only way to get data from "in game" to an external program. Mine creates a database.

depending on the addon you are trying to do this with I could just give you my 100% working subroutine and with a few minor changes it would work as a VBS.

It's basically - open .lua file
read line by line
trim spaces - check if it's something you are trying to keep
if yes add it to a string + ","
decide when to insert a line break
repeat until EOF

when done write all to a .csv

there are certain tricks to making it more efficient like

If InStr(line, "},") > 0 or If InStr(line, "{,") > 0 then
ignore and read next line

-d

Last edited by dopiate : 12/11/14 at 12:19 PM.
  Reply With Quote
12/11/14, 03:09 PM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
If you want to do it the "right" way, you should use a lua script outside of the game to load the savevars file and export it into the required form from there.
A short search on google shows that there is a library that allows you to create excel files from lua, which should make this rather easy.

But in the end it depends on what you plan to do. If you want to use it for an addon, it will probably be more user friendly if you just write your own program and don't force users to install a lua interpreter.

Regardless of the method you choose, you will need to
1) somehow get the data out of the game client (-> saved variables)
2) read the exported data (-> anything that can read files will do)
3) parse it (-> depends on how you structured the data before you exported it)
4) put it wherever you want to have it (-> excel)
  Reply With Quote
12/11/14, 09:04 PM   #5
dopiate
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 142
Originally Posted by sirinsidiator View Post
If you want to do it the "right" way, you should use a lua script outside of the game to load the savevars file and export it into the required form from there.
A short search on google shows that there is a library that allows you to create excel files from lua, which should make this rather easy.
She said saved variables not using lua source to manipulate Excel, so I'm not sure that link is helpful (but I could be wrong - we didn't get much information to go on).

I have already done what she asked - it's ESO LUA savariables to csv.

An example from one sale is...

from saved variables...

Code:
                    ["SalesData"] = 
                    {
                        [45061] = 
                        {
                            ["1:0:1:12"] = 
                            {
                                ["sales"] = 
                                {
                                    [1] = 
                                    {
                                        ["buyer"] = "@FootJuice",
                                        ["wasKiosk"] = false,
                                        ["guild"] = "Black Market Traders",
                                        ["timestamp"] = 1416586399,
                                        ["seller"] = "@dOpiate",
                                        ["itemLink"] = "|H0:item:45061:30:1:0:0:0:0:0:0:0:0:0:0:0:0:3:0:0:10000:0|hiron sabatons^p|h",
                                        ["price"] = 350,
                                        ["quant"] = 1,
                                    },
                                },
                                ["itemIcon"] = "/esoui/art/icons/gear_orc_heavy_feet_a.dds",
                            },
                        },

my program produces...

Code:
Black Market Traders,iron sabatons,1,1416586399,350,@FootJuice,@dOpiate,1:0:1:12
hundreds and hundreds of times (my current database has 773 lines) - I even offered her the code.

It works flawlessly.

there are 700+ GSA users and I'm getting no complainants - and since I check and re-check for new items I have routines to weed out duplicates.

Anyway -- I guess we aren't clear on exactly what she wants until she replies.

-d
  Reply With Quote
12/12/14, 01:41 AM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
The saved vars file is lua source code.
It defines a global table when you load it, so you don't even have to parse it, you can simply use it the way it is.
Combined with the library mentioned in the linked SO answer, you can just load the saved vars file and write it to an excel file.

I know that your way works too, but the safest and easiest way to read a lua file will always be to load it in lua
  Reply With Quote
12/12/14, 05:36 AM   #7
dopiate
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 142
Originally Posted by sirinsidiator View Post
I know that your way works too, but the safest and easiest way to read a lua file will always be to load it in lua
agreed

-d
  Reply With Quote
12/12/14, 12:15 PM   #8
dopiate
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 142
My programming exercise

I'm not sure if anyone cares - but as a programming exercise (slow day at work) I made a quick little saved variables parser.

It grabs all the variable names and splits them into two lists - ones that contain data and ones that don't

It doesn't output anything but it could be configure to do any number of things. You can multi-select from either list.

I put the exe and the form1.vb (all the actual code) in the zip.

Maybe it will spark an idea in someone or give someone a head start trying to parse the important variabls from a LUA file.

Here is an example - I opened the saved variables file for Combat Log Stats



The title on the GUI is incorrect because it doesn't create a csv -- I was just trying some things at work (sneaking in the coding)

As I said the code is in the zip also.

-d

Last edited by dopiate : 12/12/14 at 07:31 PM. Reason: added image
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Converting lua to excel file?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off