Gamestudio Links
Zorro Links
Newest Posts
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (PeWi, AndrewAMD, Quad, VoroneTZ), 463 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
print(TO_CSV,...) too slow? #475718
01/05/19 00:25
01/05/19 00:25
Joined: Sep 2016
Posts: 26
London - Prague - Kho Yao Noi
S
Sinuhet Offline OP
Newbie
Sinuhet  Offline OP
Newbie
S

Joined: Sep 2016
Posts: 26
London - Prague - Kho Yao Noi
Hi all
I would like to export some data as recommended by JCL here.
The export of 1min 1 year 1 forex pair OHLC data takes 2 to 3 minutes depending which from the below codes I use.
This is the time needed to write the CSV file with some 358636 rows (1 min data of EURUSD for 2013) and 6 columns.
This AFTER I turned off the Windows Defender on Windows 10 (otherwise it takes about an hour).

Can I optimise the speed of print(TO_CSV,...) ?
I am asking since the same task takes ZHistoryEditor about 8 sec.
Also the Multicharts are significantly faster in the CSV export.
Thx for help

Code 1 (2 mins):
Code:
function run()
{
  BarPeriod = 1;		  
  StartDate = 2013;
  EndDate = 2013;		
  LookBack = 0;

  print(TO_CSV,"%02i/%02i/%02i %02i:%02i, %.5f, %.5f, %.5f, %.5fn",
		  day(),month(),year(),hour(),minute(),
		  priceOpen(),priceHigh(),priceLow(),priceClose());
}



Code 2 (3 mins):
Code:
function run()
{
  BarPeriod = 1;		
  StartDate = 2013;
  EndDate = 2013;		
  LookBack = 0;

  string line = strf(
    "%02i/%02i/%02i %02i:%02i, %.5f, %.5f, %.5f, %.5fn",
    day(),month(),year()%100,hour(),minute(),
    priceOpen(),priceHigh(),priceLow(),priceClose());
  
  if(is(INITRUN))
  file_delete("Dataexport.csv");
  else
  file_append("Dataexport.csv",line);
}




Last edited by Sinuhet; 01/05/19 00:38.
Re: print(TO_CSV,...) too slow? [Re: Sinuhet] #475725
01/05/19 07:23
01/05/19 07:23
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Dont print to csv, print to a large string and at the end save the string to a csv file.

Re: print(TO_CSV,...) too slow? [Re: Spirit] #475830
01/09/19 12:28
01/09/19 12:28
Joined: Sep 2016
Posts: 26
London - Prague - Kho Yao Noi
S
Sinuhet Offline OP
Newbie
Sinuhet  Offline OP
Newbie
S

Joined: Sep 2016
Posts: 26
London - Prague - Kho Yao Noi
Can someone please advise me what function in this 2 step process I should use?

sprintf or strf for printing into string?

and then at the end of run()

if(is(EXITRUN))
print(TO_CSV,...); ?

I am asking since not sure how big string can be optimally used here. Remember 1min OHLC data have some 370000 rows with 5-6 columns. Most of them containing 5 decimal numbers.

Any guidance or modifying the above code would be highly appreciated.
It is all about how to create a CSV file in zorro in the fastest way.

Re: print(TO_CSV,...) too slow? [Re: Sinuhet] #475833
01/09/19 18:49
01/09/19 18:49
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
I think its 3 steps, first strf, then copying the string to a large byte array and in the exitrun, save the array to a file.

Its the file saving that is slow.

Re: print(TO_CSV,...) too slow? [Re: Spirit] #475837
01/09/19 19:56
01/09/19 19:56
Joined: Sep 2016
Posts: 26
London - Prague - Kho Yao Noi
S
Sinuhet Offline OP
Newbie
Sinuhet  Offline OP
Newbie
S

Joined: Sep 2016
Posts: 26
London - Prague - Kho Yao Noi
Thank you Spirit
indeed that what I have done, but still cannot get the output right (getting a CSV only 1 row of data for the 31.12.2013).
Any idea what is wrong with my code?

Code:
function run()
{
  BarPeriod = 1;		
  StartDate = 20130101;
  EndDate = 20131231;		
  LookBack = 0;

  string line = strf("%02i/%02i/%02i %02i:%02i, %.5f, %.5f, %.5f, %.5fn",
    day(),month(),year()%100,hour(),minute(),
    priceOpen(),priceHigh(),priceLow(),priceClose());
  
  if(is(INITRUN))
  file_delete("Data\\export.csv");
  else
  char str[50000];
  strcat(str,line);
  
  if(is(EXITRUN))
  file_write("Data\\export.csv",str,0);
 }


Last edited by Sinuhet; 01/09/19 22:59.
Re: print(TO_CSV,...) too slow? [Re: Sinuhet] #475864
01/10/19 19:20
01/10/19 19:20
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Your else clause is missing the brackets. Also, allocate the array with malloc in the INITRUN, and check before the strcat call that its length is not exceeded.

Re: print(TO_CSV,...) too slow? [Re: jcl] #475930
01/14/19 13:08
01/14/19 13:08
Joined: Sep 2016
Posts: 26
London - Prague - Kho Yao Noi
S
Sinuhet Offline OP
Newbie
Sinuhet  Offline OP
Newbie
S

Joined: Sep 2016
Posts: 26
London - Prague - Kho Yao Noi
Thank you Johann
I have to admit I have minimal experience with malloc, so before I will give a go, may I ask you what would be your expected script time? The time to write a csv with some 380.000 rows and 5 columns was 2-3 min with spripts using either file_append or printtocsv (see above).
Thank you
Sinuhet

Re: print(TO_CSV,...) too slow? [Re: Sinuhet] #475943
01/14/19 22:02
01/14/19 22:02
Joined: Jul 2017
Posts: 784
Z
Zheka Offline
User
Zheka  Offline
User
Z

Joined: Jul 2017
Posts: 784
The simplest way would be:

dataLoad(..)
dataSaveCSV(..)

How long would it take?


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1