[SOLVED] DSL to Jython, gRoup.members.size?

hello,

i am currently tinkering with the transfer of the following code lines from dsl to jython, but unfortunately i have had no success so far …

var randLightIndex = (new java.util.Random).nextInt(gAnwensenheitsSimulation.members.size) //Randomly pick a light out of the group gAnwensenheitsSimulation
var randLightNrON = gAnwensenheitsSimulation.members.filter[s|s.state == ON].size		   //Amount of the lights in the group which were switched on
.....
sendCommand(gAnwensenheitsSimulation.members.get(randLightIndex), OFF)

I have already tried the following without success:

randLightIndex = ir.getItem("gAnwensenheitsSimulation").members.size
randLightIndex = len(ir.getItem("gAnwensenheitsSimulation").members)
1 Like

Hopefully these are helpful…

from random import choice
from core.log import logging, LOG_PREFIX
LOG = logging.getLogger("{}.TEST".format(LOG_PREFIX))

random_light_member = choice(list(itemRegistry.getItem("gAnwensenheitsSimulation").members))# Randomly pick a light out of the group gAnwensenheitsSimulation

LOG.warn("random.choice of gAnwensenheitsSimulation.members: {}".format(random_light_member))

random_light_member = choice([item for item in itemRegistry.getItem("gAnwensenheitsSimulation").members if item.state == OFF])# Randomly pick a light that is OFF from the members of the group gAnwensenheitsSimulation

LOG.warn("random.choice of OFF gAnwensenheitsSimulation.members: {}".format(random_light_member))

random_light_number_on = len([item for item in itemRegistry.getItem("gAnwensenheitsSimulation").members if item.state == ON])# Amount of the lights in the group which were switched on

LOG.warn("number of members of gAnwensenheitsSimulation that are ON: {}".format(random_light_number_on))

Thank you both have helped me a lot!

1 Like