[Scilab-users] How to read in date & time ?

classic Classic list List threaded Threaded
5 messages Options
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] How to read in date & time ?

Hello,
I have logfiles in the following form:
DESC: AAA 2017
Datum;Zeit;kWh
01.01.2017;06:00;419,942
01.01.2017;07:00;513,273
01.01.2017;08:00;478,268
01.01.2017;09:00;711,572
01.01.2017;10:00;606,592
01.01.2017;11:00;594,92
01.01.2017;12:00;594,92
01.01.2017;13:00;524,933
...

I can read these in either as double or string
[log_data, comments] = csvRead(log_file, ";", ",", "double",[],
"/^[^0-9\-]/");

[log_data, comments] = csvRead(log_file, ";", ",", "string",[],
"/^[^0-9\-]/");

However what I'm missing is a way to convert the date & time column to a
date format in scilab. There doesn't seem to be function for this in scilab.
Is there a recommended way of doing so?

Thanks & regards
richard


PS:
I'm so glad the list is working again! Would have been nice tho to inform
the users in advance and with some sort of status.scilab.org site or
something...



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
amonmayr amonmayr
Reply | Threaded
Open this post in threaded view
|

Re: How to read in date & time ?

Hello Richard,

There are:

datevec
datenum
getdate

that could do the job.
I am not sure whether there is a recommended way of doing the conversion.

Cheers,

Antoine



Le 07/11/2017 à 15:38, Richard llom a écrit :

> Hello,
> I have logfiles in the following form:
> DESC: AAA 2017
> Datum;Zeit;kWh
> 01.01.2017;06:00;419,942
> 01.01.2017;07:00;513,273
> 01.01.2017;08:00;478,268
> 01.01.2017;09:00;711,572
> 01.01.2017;10:00;606,592
> 01.01.2017;11:00;594,92
> 01.01.2017;12:00;594,92
> 01.01.2017;13:00;524,933
> ...
>
> I can read these in either as double or string
> [log_data, comments] = csvRead(log_file, ";", ",", "double",[],
> "/^[^0-9\-]/");
>
> [log_data, comments] = csvRead(log_file, ";", ",", "string",[],
> "/^[^0-9\-]/");
>
> However what I'm missing is a way to convert the date & time column to a
> date format in scilab. There doesn't seem to be function for this in scilab.
> Is there a recommended way of doing so?
>
> Thanks & regards
> richard
>
>
> PS:
> I'm so glad the list is working again! Would have been nice tho to inform
> the users in advance and with some sort of status.scilab.org site or
> something...
>
>
>
> --
> Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

--
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  Antoine Monmayrant LAAS - CNRS
  7 avenue du Colonel Roche
  BP 54200
  31031 TOULOUSE Cedex 4
  FRANCE

  Tel:+33 5 61 33 64 59
 
  email : [hidden email]
  permanent email : [hidden email]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
JLan JLan
Reply | Threaded
Open this post in threaded view
|

Re: How to read in date & time ?

In reply to this post by Richard llom
Hello

Assuming you have two header lines in your files, try this:

tt=csvRead(log_file,";",[],"double",[".",";";":",";";",",";"],[],[],2)

tv=datenum(tt(:,3),tt(:,2),tt(:,1),tt(:,4),tt(:,5),0)

td=datevec(tv)

Jan


On 07.11.2017 15:38, Richard llom wrote:

> Hello,
> I have logfiles in the following form:
> DESC: AAA 2017
> Datum;Zeit;kWh
> 01.01.2017;06:00;419,942
> 01.01.2017;07:00;513,273
> 01.01.2017;08:00;478,268
> 01.01.2017;09:00;711,572
> 01.01.2017;10:00;606,592
> 01.01.2017;11:00;594,92
> 01.01.2017;12:00;594,92
> 01.01.2017;13:00;524,933
> ...
>
> I can read these in either as double or string
> [log_data, comments] = csvRead(log_file, ";", ",", "double",[],
> "/^[^0-9\-]/");
>
> [log_data, comments] = csvRead(log_file, ";", ",", "string",[],
> "/^[^0-9\-]/");
>
> However what I'm missing is a way to convert the date & time column to a
> date format in scilab. There doesn't seem to be function for this in scilab.
> Is there a recommended way of doing so?
>
> Thanks & regards
> richard
>
>
> PS:
> I'm so glad the list is working again! Would have been nice tho to inform
> the users in advance and with some sort of status.scilab.org site or
> something...
>
>
>
> --
> Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Philippe Roux Philippe Roux
Reply | Threaded
Open this post in threaded view
|

Re: How to read in date & time ?

In reply to this post by Richard llom
Le 07/11/2017 à 15:38, Richard llom a écrit :
>
>
> However what I'm missing is a way to convert the date & time column to a
> date format in scilab. There doesn't seem to be function for this in scilab.
> Is there a recommended way of doing so?

use datenum and datevec , example :

yourline=["01.01.2017"; "06:00";"419,942"]
// D=day, M=month,Y=year
DMY=tokens(yourline(1),".")
execstr(strsplit("DMY","")+"="+DMY)
DT=datenum(y,m,d)
[Ye,Mo,Da,ho,mi,se]=datevec(DT)
// h=hhours, m=minutes, s=secondes
hm=tokens(yourline(2),":")
execstr(strsplit("hM","")+"="+hM)
s=27
DT=datenum(y,m,d,h,M,s)
[Ye,Mo,Da,ho,mi,se]=datevec(DT)


best regards,

Philippe

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|

Re: How to read in date & time ?

In reply to this post by JLan
Hello,
thanks for all the replies! Somehow datenum and datevec slipped thorugh my
search ... :-/

Jan's approach seems the most suitable to me, however I forget to mention
that my log file also contains some missing / empty values, e.g.
01.01.2017;06:00;419,942
01.01.2017;07:00;513,273
01.01.2017;08:00;478,268
01.01.2017;09:00;
01.01.2017;10:00;606,592
01.01.2017;11:00;
01.01.2017;12:00;594,92
01.01.2017;13:00;524,933

But I could fix this with:
[log_data, comments] =
csvRead(log_file,';',',','double',['.',';';':',';'],"/^[^0-9\-]/");

and using
log_date =
datenum(log_data(:,3),log_data(:,2),log_data(:,1),log_data(:,4),log_data(:,5),0);
mprintf('Log Start:   %d-%02d-%02d at %02d:%02d\n',datevec(log_date(1,1)));
etc...

richard


> Hello,
> Assuming you have two header lines in your files, try this:
> tt=csvRead(log_file,";",[],"double",[".",";";":",";";",",";"],[],[],2)
> tv=datenum(tt(:,3),tt(:,2),tt(:,1),tt(:,4),tt(:,5),0)
> td=datevec(tv)
>
> Jan
>
> On 07.11.2017 15:38, Richard llom wrote:
>>
>> Hello,
>> I have logfiles in the following form:
>> DESC: AAA 2017
>> Datum;Zeit;kWh
>> 01.01.2017;06:00;419,942
>> 01.01.2017;07:00;513,273
>> 01.01.2017;08:00;478,268
>> 01.01.2017;09:00;711,572
>> 01.01.2017;10:00;606,592
>> 01.01.2017;11:00;594,92
>> 01.01.2017;12:00;594,92
>> 01.01.2017;13:00;524,933
>> ...



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users