07-16-2014 04:17 PM
Hello,
I would like to know if there is an elegant way of solving the following:
Scenario I have an array where every element has the following format:
This are the names of .csv files found on a given directory.
My objective is to be able to sort the latest file (comparing date and/or time) that has the same bysicle s/n (or 2nd criteria on picture)
For example, inside directory Pedro there are 10 different files and amongs those there are some with bysicle s/n 1, 2 and 3 and all with different time and date (maybe 4 files hasve bicycle s/n 1, and so on.
Ideal output = three (3) files each one the latest file of a given bycicle s/n.
note: the lenght of the changing criterias are fixed.
Iam trying to avoid indexing this array and then break the name using w/e string function and so on since Iam expecting a lot of these suckers over 100K
Hope I have been clear with this weird explanation.
any help on this will be apreaciated.
regards,
07-16-2014 04:26 PM
Are you sorting files or are you sorting these strings?
If you are sorting files for latest, can you do it based on the file date? Or does it have to be the values that are stored in that string?
If in some way you are trying to sort these string values by the date embedded in it, you are going to have to break it up and sort it. Even if the date was the first thing in the string, you'd still have to rearrange it because the date isn't saved in an alphabetical/chronolgical fashion. For example if this started with YearMonthDay_Time, and the Year Month and Day all have leading zeroes, then sorting alphabetically would also sort it chronologically. But since the Year is listed last, you can't do that.
If break up each one and store the various elements in a cluster putting the field that you want to sort on first in the cluster, then sort 1-D array will automatically sort that array of clusters based on the first field.
07-16-2014 04:50 PM
I already have a function that gives me all the files of type Pedro from a given directory.
I used the Open G functions to strip down the paths all the way to the names (like this examples) those are nice because they accept whole arrays from path to string, then stripping, then stripping format etc.
the Open G function to get the creation date doesnt like arrays (so you have to index it)
converting this array to string and then fight that wouldnt be the way to go here to avoid that inexing maybe the slice string from the Open G
I did the Open G delete duplicates (and it actually delete a bunch) it is just anoying to later find which ones if any.
If the only way is to index it I will give it a shot.
regards,
07-16-2014 05:23 PM
RavensFan,
actually reading back your post (on the sorting with cluster) part
i index each element then find a way to put this string into an array of four (4) elements, then convert that to a cluster and to until iam done with all elements. (finish a 1d cluster (1d array (4 elements each (strings)))
say I want date (i put it first on the step when iam building the 4 elements 1d array)
is such array of cluster example found on the labview examples? to take a look?
regards,
07-16-2014 05:30 PM
well it looks like the parameters of the string are seperated by underscores ("_"). So you can use the Spreadsheet String To Array function with the underscore as the delimiter. Then reorganize your array elements to create a cluster. Put the cluster items in order of what you want to sort by. So you do this process in a FOR loop, iterating over the file name array and autoindexing that cluster. Then use Sort 1D Array to sort the array of clusters. As a side note, you may want to add the file name as the last element of the cluster.
07-16-2014 06:40 PM
so I start with 1d of paths of these files.
I want to end up with 1d paths of these files to later process.
on the scenario where two elements have same date but different time I would need to do process twice right? (in parallel)
Iam looking at the sort vi and what i want are indexes to go back and index the initial big 1D path array, am I missing something out the sord 1D array function?
crap I forgot to mention that the initial array will have (many times the scenario I just explained) but for different persons (males)
example Pedro, Pablo, Omar, etc (where I need latest bysicle s/n)
the Open G function I used is List directory recursively.
07-16-2014 07:22 PM
If you build the cluster array as I told you above then do the Sort 1D Array, the sort will go by the first item in the cluster, then the second, then the third, and on down the line. So there is no need to go through this sort again.
07-17-2014 04:34 PM
I havent been able to get it to where I want.
there is a constant arrray as input. lenght = 420
I get it right until index 41 on my array (the first seven element on my output array)
from then on it goes sour.
Here is the VI (I use some Open G functions)
regards,
07-17-2014 04:54 PM
Can you change the default value of the output array ("elements") to show what result you expect? (sorry, I don't have the OGTK vis and thus cannot run your VI)
07-17-2014 05:00 PM
here it is