-1

I developed a python script to send JSON messages to an IoT infrastructure. The message incl. a lot of simulated sensor values that are based on a "master" device. There is one valuepair to measure the filling degree of a container [0 - 100 %].

The valuepair should increment starting with 0 to 100 over a few days. The script runs every 20 secs.

Currently I pass a "static" value but I would like to simulate an increase of the value with the result that every simulated device has a different filllevel over 24 hours. I would like to use something as a "trend" to define how much time the device should take to reach 100%.

CoolDive
  • 26
  • 1

1 Answers1

0

If each device has a time t (in seconds) that it would take to fill, then lets say T is a tuple of all the devices T = (t1, t2, .... tn,)

On average, the number of seconds that each device would need to increment (if increment in integer percentages) would be t/100.

So for each iteration, there should be a probability 20/t/100 of an increment.

So for N devices, to return a list of (device #, do I increment?) pairs you could do this.

from random import random

class devices():
    def __init__(self, T, interval=20):
        self.devices = N * [0]
        self.T = T

    def iteration(self):
        for i in range(len(self.devices)):
            self.devices[i] = min(100, self.devices[i] + \
                    (1 if random() < (interval * 100 / self.T[i])) else 0) 
        return [[i, self.devices[i] for i in range(len(self.T))]

To use it

devs = devices([t1, t2, t3, ..., tn])

then every 20 seconds
state = devs.iteration()

There may be other factors you want like not having a purely random selection. I don't know what kind of devices you are simulating but perhaps the process that fills them has time-of-day, weather, or other factors that might be incorporated into the simulation

Deepstop
  • 3,627
  • 2
  • 8
  • 21