Message Boards Message Boards

RunScheduledTask outputting more data than programmed to

Posted 9 years ago

I'm having difficulty with RunScheduledTask. I'm working on a cooling project for a class and I am getting many more data points than I want. I used the project outline from this post: http://community.wolfram.com/groups/-/m/t/196759

temp := N[ ToExpression[ StringTake[ Import["/sys/bus/w1/devices/28-02146790bbff/w1_slave"], -5]]/ 1000]

wig = {} RunScheduledTask[(deg = temp; AppendTo[wig, deg]), {60, 60}]

I only need to read the temperature every 60 seconds and only need sixty repetitions, but when I evaluate wig, I get many more than that. As a result, it's scaling my ListLinePlot for visual analysis. Instead of the time axis only have 60 data points, some have 120+.

wig = {87., 86.562, 86.437, 85.312, 85., 84.75, 83.125, 82.937, 82.625, 81.625, 81.187, 80.937, 80.062, 79.875, 79.437, 78.5, 78., 77.937, 77.312, 77., 76.562, 76., 75.437, 75.312, 74.562, 74.25, 74., 73.375, 73.125, 72.937, 72.25, 71.875, 71.687, 71.062, 70.812, 70.625, 70.062, 69.75, 69.562, 69., 68.75, 68.5, 68., 67.812, 67.562, 67.062, 66.812, 66.687, 66.187, 65.875, 65.75, 65.25, 65., 64.875, 64.312, 64.187, 64., 63.562, 63.375, 63.187, 62.75, 62.5, 62.437, 61.937, 61.812, 61.562, 61.125, 61., 60.875, 60.437, 60.312, 60.187, 59.75, 59.625, 59.562, 59.125, 58.812, 58.687, 58.312, 58.125, 58., 57.75, 57.5, 57.375, 57., 56.875, 56.75, 56.437, 56.25, 56.125, 55.75, 55.625, 55.562, 55.187, 55.062, 54.937, 54.625, 54.5, 54.375, 54.062, 53.875, 53.812, 53.5, 53.375, 53.312, 53., 52.875, 52.812, 52.5, 52.375, 52.25, 52., 51.875, 51.75, 51.5, 51.375, 51.25, 51., 50.875, 50.812, 50.562, 50.437, 50.312, 50.125, 50., 49.875, 49.625, 49.562, 49.5, 49.25, 49.125, 49.062, 48.812, 48.687, 48.625, 48.375, 48.312, 48.187, 48.062, 47.875, 47.812, 47.562, 47.5, 47.437, 47.25, 47.125, 47., 46.812, 46.687, 46.687, 46.5, 46.375, 46.312, 46.125, 46., 45.937, 45.75, 45.625, 45.562, 45.375, 45.312, 45.25, 45.062, 45., 44.937, 44.75, 44.625, 44.562, 44.437, 44.312, 44.312, 44.062, 44., 43.937, 43.625, 43.312 };

enter image description here

Does anyone have any advice? I've attempting to contact my professor and have yet to hear back. I've also searched all over the internet for the solution and I can't find one. I'm desperate.

POSTED BY: Alexis Ploss
2 Replies
Posted 9 years ago

Thank you for your helpful response Bob. I was able to get it working on a preliminary basis (I ran some trials and got the expected number of data points)!

POSTED BY: Alexis Ploss

The semicolon is very important. Right now you are multiplying wig by the ScheduledTaskObject making for a very nested and likely memory-intensive operation (in addition to giving you results you don't want).

The appropriate format of your command:

wig = {}; RunScheduledTask[(deg = temp; AppendTo[wig, deg]), {60,60}]

While we are here, I'll note that using AppendTo can get burdensome when the amount of data being collected is large. A more efficient alternative is to use and Association like this:

temp:=RandomVariate[NormalDistribution[60,10]] (* To simulate the temperature reading *)
wig = Association[];
RunScheduledTask[wig[Length@wig+1]=temp,{5,10}] (* I use {5,10} for demonstration here *)

When completed, wig contains an association instead of a list; however it can still be passed to ListPlot without a problem, and if you really want the list, you can get it with Values[wig]

The nice thing about using the Association is that we can grab the actual time that the datapoint was collected, since it's possible that the scheduled task cannot perform the task at the desired time.

wig = Association[];
RunScheduledTask[wig[Date[]]=temp,{5,10}]

Example output is:

<|{2015,5,5,14,32,56.773218}->77.5722,{2015,5,5,14,33,1.781956}->60.4348,{2015,5,5,14,33,6.775996}->74.7136,{2015,5,5,14,33,11.784881}->54.5009,{2015,5,5,14,33,16.775621}->56.98,{2015,5,5,14,33,21.789526}->70.3364,{2015,5,5,14,33,26.775327}->84.3416,{2015,5,5,14,33,31.785066}->55.1334,{2015,5,5,14,33,36.774200}->48.3789,{2015,5,5,14,33,41.782761}->63.8248|>

and this can be plot with DateListPlot[wig] to handle the timestamp that is being used as the key for the association.

POSTED BY: BoB LeSuer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract