import clr
clr.AddReference('Soti.Connect.SemanticEngine.Conversions')

from Soti.Connect.SemanticEngine.Conversions import Converter

print("Loading BixolonDarknessToPercentSRP_v2 Converter")

class BixolonDarknessToPercentSRP_v2(Converter):

    def Execute(self, args):        
        darkness = int(args[0])
        darkness_rounded = 5 * round(darkness / 5)        
        percent = round(((darkness_rounded - 75) / 45) * 100)        
        return max(1, min(100, percent))

plugin = BixolonDarknessToPercentSRP_v2("BixolonDarknessToPercentSRP_v2")

store.AddConverter(plugin)