Gamestudio Links
Zorro Links
Newest Posts
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (7th_zorro, Aku_Aku, henrybane, flink, 1 invisible), 739 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
CSV to History Multiple Files #472630
05/08/18 23:46
05/08/18 23:46
Joined: Mar 2017
Posts: 65
G
Ger1 Offline OP
Junior Member
Ger1  Offline OP
Junior Member
G

Joined: Mar 2017
Posts: 65
Hi,

I am trying to convert multiple csv files into t6. I coded up a loop to run through each csv files and to convert it into t6, however all created t6 files contain the history of the first csv file only.


#define SPLIT // split into separate years

string Format = "+%d/%m/%Y,f3,f1,f2,f4,f6,f5";

function convert(string InName, string OutName)
{
int Records = dataParse(1,Format,InName);
printf("n%d lines read",Records);

#ifndef SPLIT
if(Records) dataSave(1,OutName);
#else

int i, Start = 0, Year, LastYear = 0;
for(i=0; i<Records; i++)
{
Year = atoi(strdate("%Y",dataVar(n,i,0)));
if(!LastYear) LastYear = Year;
if(i == Records-1)
{ // end of file
LastYear = Year; Year = 0;
}
if(Year != LastYear)
{
string NewName = strf("%s_%4i.t6",strxc(OutName,'.',0),LastYear);
printf("n%s",NewName);
dataSave(1,NewName,Start,i-Start);
Start = i;
LastYear = Year;
}
}
#endif
}

function main()
{
int x = assetList("HistorySP500AssetsSP500.csv");
int i;
for(i=0; i<x; i++)
{
string down = Assets[i];
convert(down,down);
}
}

I have used the csvToExport File from Zorro and added a loop.

However, as mentioned it does not properly created the t6 files. All of them contain the history of the first csv.

Could someone explain what goes wrong here?

Cheers

Last edited by Ger1; 05/09/18 00:26.
Re: CSV to History Multiple Files [Re: Ger1] #472633
05/09/18 07:40
05/09/18 07:40
Joined: Mar 2017
Posts: 65
G
Ger1 Offline OP
Junior Member
Ger1  Offline OP
Junior Member
G

Joined: Mar 2017
Posts: 65
I was finally able to solve it myself.

The issue was that I did not change the Handle.

Below the solution that works for me:




#define SPLIT // split into separate years


string Format = "+%d/%m/%Y,f3,f1,f2,f4,f6,f5";

int n;

function convert(string InName, string OutName)
{
int Records = dataParse(n,Format,InName);
printf("n%d lines read",Records);

#ifndef SPLIT
if(Records) dataSave(n,OutName);
#else

int i, Start = 0, Year, LastYear = 0;
for(i=0; i<Records; i++)
{
Year = atoi(strdate("%Y",dataVar(n,i,0)));
if(!LastYear) LastYear = Year;
if(i == Records-1)
{ // end of file
LastYear = Year; Year = 0;
}
if(Year != LastYear)
{
string NewName = strf("%s_%4i.t6",strxc(OutName,'.',0),LastYear);
printf("n%s",NewName);
dataSave(n,NewName,Start,i-Start);
Start = i;
LastYear = Year;
}
}
#endif
}

function main()
{
int x = assetList("History\SP500\AssetsSP500.csv");
int i;
n=1;

for(i=0; i<x; i++)
{
string down = Assets[i];
convert(down,down);
n++;
}
}


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1