DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Separate data and calculate statistics

Hello,

The problem is that I want to separate some data and make some calculations with them.

I want to make a graph of the daily consumption ('CONSS') of each animal.
To do this I use a vbs that sums the consumption of each day using the statblockcalc. But I need the sums of each animal ('ANIMAL'), not only the daily ones.

For example: I need the consumption ('CONSS') of the animal  137 ('ANIMAL')of 15/11/2003('DATE') and the same with each animal and day. And do a graph of these values.

Is it possible to do this? I attach the tdm file and the vbs I use

Thank you very much,

Nuria
0 Kudos
Message 1 of 11
(4,476 Views)
Hello Nuria,

I am attatching a ZIP file with an example script I created. The script should be working fine for your purposes - if I understood the task you have to do correctly.
As a result you get a 3D Matrix with accumulated values.
In the X-channel you will find all the dates where there is data to be processed. The Y-channel is containing one line for every animal that was found in the dataset and the z-Matrix the results.

In the script I am using  the VBS library object to create a list of dates and animals. The add method is giving an error if a channel name is allready existing. With the on error resume next statement I am suppressing these errors, though.

  Set XDate = CreateObject("Scripting.Dictionary")
  for row=1 to cl("DATE")
    XDate.add chdx(row,cno("DATE")),row
  next


In this way I am creating a list of unique keywords. As dictonary items assigned to the keywords I am storing the line number which I can use to index the matrix later on. With help of the keys I am creating X ynd Y reference channels of the matrix

i = 0
for each row in XDate.keys
  i=i+1
  chdx(i,chX) = row
  XDate.item(row)=i
next
cl(ChX)=i

After creating the 3D structure of the matrix I am filling it, accumulating the conumtion values if there are more than one event for a certain animal on a certain day.

for i = 1 to cl("CONSS")
  row= XDate.item(chdx(i,cno("DATE")))
  col= YAnimal.item(chdx(i,cno("ANIMAL")))+ChZ0
  chdx(row,col)=chdx(row,col)+chdx(i,cno("CONSS"))
next


The example script is coded a bit quick and dirty but I hope you will understand it nevertheless.
Just let me know if you have further questions.





Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
Message 2 of 11
(4,457 Views)

Hello Ingo,

All the channels in Daily Totals group are NoValues. I tried these to find the solution but it was impossible. Is it maybe because I use DIAdem 9.0? Then, what do I have to change?

Thank you very much!!

0 Kudos
Message 3 of 11
(4,439 Views)
Hello Nuria,

to be honest, I developed the script on Version 9.1 and did not test it on 9.0 but actually, its mostly using VBS functionality - and this should work quite the same on 9.0. What about the X and Y channels? Are they filled with NoValues as well? Then maybe the error happens all in the beginning, during the creation of the dictionary.
Verify that your channels really are called "ANIMAL" and "DATE"
Try using the debugger and execute the script step by step.
If necessary, add messagebox lines as msgbox (chdx(row,cno("DATE"))) in line 13 and 18.

Let me know if you dont get any further
regards
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 4 of 11
(4,417 Views)

Hello Ingo,

The X and Y channels are also filled with NoValues and the channels are really called "ANIMAL" and "DATE".

I tried what you suggested and I add messagebox lines. The message showed always the same number "63235987200". I am a little bit lost with this problem. 

0 Kudos
Message 5 of 11
(4,408 Views)
Hi,
the number you get from the message box is actually a date - only that its not formatted. Trying msgbox rtt(63235987200,"#dd.mm.yy hh:nn:ss") will show you its actually the 15.11.03. So its the first day you have valid data for. Maybe the dictionary object is not working properly on your system - and you dont get the expected error because we are using the on error resume next statement.
I verified that the script is running perfectly on a version 9.01 as well - so that wont be the problem. I takes longer to execute though, but there are no Novalues.

Check out this one:


Set XDate = CreateObject("Scripting.Dictionary")
on error resume next
 for row=1 to cl("DATE")
    XDate.add chdx(row,cno("DATE")),row
    if err.number > 0 then msgbox row : exit for
  next


With the dataset you posted I expect the result to be a message "2". In the 1st row there is a new dare which van be added to the dictionary without errors. The second row contains the same date and this causes the error.
If you get a result "1" it means that you have  problems writing to the dictionary. If the script stops before you seem to have problems creating the object.
The dictionary is not part of DIAdem or the SCRIPT module, it belongs to the Windows Scripting Host. So maybe this one is not installed properly on your PC.

regards


Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 6 of 11
(4,392 Views)
Hello Ingo,
 
Here I am once again...Smiley Wink .
I checked what you suggested :
 
Set XDate = CreateObject("Scripting.Dictionary")
on error resume next
 for row=1 to cl("DATE")
    XDate.add chdx(row,cno("DATE")),row
    if err.number > 0 then msgbox row : exit for
  next
 
And all the channels are another time filled with NoValues, but now after the message "2" it gives me the following error message:
 
 **** Error registered on 28/11/2005 at 18:15:01 [Message file:GFSAUTED / Text area:4 / Text number:1]
     Error in <analysis.VBS> (Row: 51, Column: 3):
     Error message from DIAdem command kernel:
     Illegal access to data matrix "CHDX("",9)" !

 I also checked the Windows Scripting Host and I think it is correctly installed in the computer. 
 
 
Thank you!
 
Nuria
 
0 Kudos
Message 7 of 11
(4,365 Views)
Hi Nuria,
yes I think this is getting us a bit closer at least. Allthough I am still wondering what exactly is going wrong with your script.
But it seems that the dictonary object is working - otherwise you would have got another error message. So there is nothing wrong with your WSH. The message "2" means, that when the variable row=2 there is something going wrong - which is expected since we are trying to put a key into the dictionary which allready exists. (The second row contains the same date as the first).

Stragely though, you are getting this error message out of row 51. What exactly is the command in row 51? I am having a next in my version which cant be the reason. CHDX("",9) looks like you are using an undefined variable as first parameter in the chx command. Actually this should be row or i.

For further testing, use the original script again and not the code I posted last time; this was just to test if the dictionary was working.
Check the variable in line 51, maybe its miss-spelled. And try the debugging features to step through the script, whatching when errors occure the first time and why.

regards



Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 8 of 11
(4,358 Views)

Hello IngoS,

The row 51 is:

48  for i = 1 to cl("CONSS")
49       row= XDate.item(chdx(i,cno("DATE")))
50      col= YAnimal.item(chdx(i,cno("ANIMAL")))+ChZ0
51      chdx(row,col)=chdx(row,col)+chdx(i,cno("CONSS"))
52  next

I am now running the original script and using the debbugger, and this time I changed to another computer and now it works fine!!! I will keep working with this computer.
Thank you very much for your help IngoS!!Smiley Very Happy
 
Nuria
0 Kudos
Message 9 of 11
(4,350 Views)
Good to know!

But honestly, I dont have an explanation why the script is not running on the first computer (maybe because of different service packs in DIadem??) Well, there are some things we will never understand Smiley Happy
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 10 of 11
(4,338 Views)