def __init__ (self, targetSimInfoOrID: typing.Union[sim_info.SimInfo, int, None]): """ An object to save information for and handle interactions with the dot menstrual cycle tracker app. """ if not isinstance(targetSimInfoOrID, (sim_info.SimInfo, int)) and targetSimInfoOrID is not None: raise Exceptions.IncorrectTypeException(targetSimInfoOrID, "targetSimInfoOrID", (sim_info.SimInfo, int, None)) super().__init__() self._targetSimPointer = SimPointer.SimPointer() self._targetSimPointer.ChangePointer(targetSimInfoOrID) self._simulating = False # type: bool self.Enabled = False self.TrackingMode = TrackingMode.Cycle self.ShowFertilityNotifications = False self.TimeSinceCycleStart = None self.LastSimulatedTick = services.time_service().sim_now.absolute_ticks() encodeEnum = lambda value: value.name if value is not None else None decodeTrackingMode = lambda valueString: Parse.ParsePythonEnum(valueString, TrackingMode) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("Enabled", "Enabled", self.Enabled)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("TrackingMode", "TrackingMode", self.TrackingMode, encoder = encodeEnum, decoder = decodeTrackingMode)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("ShowFertilityNotifications", "ShowFertilityNotifications", self.ShowFertilityNotifications)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("TimeSinceCycleStart", "TimeSinceCycleStart", self.TimeSinceCycleStart))
def _WoohooIsTryingForBaby(woohooInteraction: interaction.Interaction) -> bool: tryForBabyTag = Parse.ParseS4Enum("Interaction_TryForBaby", tag.Tag) if tryForBabyTag in woohooInteraction.interaction_category_tags: return True return False
def _ParseValueString (self, valueString: str) -> typing.Union[float, int]: if not isinstance(valueString, str): raise Exceptions.IncorrectTypeException(valueString, "valueString", (str,)) parsedInput = Parse.ParseNumber(valueString) # type: typing.Union[float, int] if not Numbers.IsRealNumber(parsedInput): raise Exception("Input string cannot be parsed to a real number.") return parsedInput
def __init__ (self, trackingSystem: ReproductionShared.ReproductiveSystem): super().__init__(trackingSystem) self.CycleStartTestingEvent = Events.EventHandler() self.CycleAbortTestingEvent = Events.EventHandler() self.CycleGeneratingEvent = Events.EventHandler() self.CycleChangedEvent = Events.EventHandler() self.CycleCompletedEvent = Events.EventHandler() self.CycleReleaseOvumTestingEvent = Events.EventHandler() self.CycleStartTestingEvent += self._CycleStartTestingCallback self.CycleAbortTestingEvent += self._CycleAbortTestingCallback self.CompletedInitialCycle = False self.CompletedFirstCycle = False self.CycleStartTestingSeed = None self.TimeSinceLastCycle = None self.LastCycleCompletionReason = None self.CurrentCycle = None self._cycleObjectsGenerated = 0 # type: int encodeLastCycleCompletionReason = lambda value: value.name if value is not None else None decodeLastCycleCompletionReason = lambda valueString: Parse.ParsePythonEnum(valueString, CycleShared.CompletionReasons) if valueString is not None else None self.RegisterSavableAttribute(Savable.StandardAttributeHandler("CompletedInitialCycle", "CompletedInitialCycle", self.CompletedInitialCycle, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("CompletedFirstCycle", "CompletedFirstCycle", self.CompletedFirstCycle, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("CycleStartTestingSeed", "CycleStartTestingSeed", self.CycleStartTestingSeed, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("TimeSinceLastCycle", "TimeSinceLastCycle", self.TimeSinceLastCycle, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.StandardAttributeHandler( "LastCycleCompletionReason", "LastCycleCompletionReason", self.LastCycleCompletionReason, requiredSuccess = False, encoder = encodeLastCycleCompletionReason, decoder = decodeLastCycleCompletionReason )) self.RegisterSavableAttribute(Savable.StandardAttributeHandler("CycleObjectsGenerated", "_cycleObjectsGenerated", self.CycleObjectsGenerated, requiredSuccess = False)) self.RegisterSavableAttribute(Savable.DynamicSavableAttributeHandler( "CurrentCycle", "CurrentCycle", lambda typeIdentifier: CycleTypes.GetCycleType(typeIdentifier)(), lambda: None, requiredSuccess = False, nullable = True, multiType = True, typeFetcher = lambda attributeValue: attributeValue.TypeIdentifier, typeSavingKey = "CurrentCycleType" ))
def _ParseValueString(self, valueString: str) -> typing.Union[float, int]: if not isinstance(valueString, str): raise Exceptions.IncorrectTypeException(valueString, "valueString", (str, )) requestedHumanPregnancyDays = Parse.ParseNumber( valueString) # type: typing.Union[float, int] if not Numbers.IsRealNumber(requestedHumanPregnancyDays): raise Exception("Input string cannot be parsed to a real number.") humanRealLifePregnancyDays = Guides.HumanPregnancyGuide.Guide.PregnancyTime / 1440 # type: float value = requestedHumanPregnancyDays / humanRealLifePregnancyDays # type: float return value
def _ParseValueString(self, valueString: str) -> typing.Union[float, int]: if not isinstance(valueString, str): raise Exceptions.IncorrectTypeException(valueString, "valueString", (str, )) requestedHumanCycleDays = Parse.ParseNumber( valueString) # type: typing.Union[float, int] if not Numbers.IsRealNumber(requestedHumanCycleDays): raise Exception("Input string cannot be parsed to a real number.") humanCycleGuide = Guides.HumanCycleMenstrualGuide.Guide humanRealLifeCycleDays = ( humanCycleGuide.FollicularLength.Mean + humanCycleGuide.LutealLength.Mean) / 1440 # type: float value = requestedHumanCycleDays / humanRealLifeCycleDays return value
def _UpdateSettings() -> None: global _loggingEnabled, _writeChronological, _writeGroups, _logLevel, _logInterval, _logSizeLimit loggingEnabledChange = Settings.LoggingEnabled.Get() # type: bool writeChronologicalChange = Settings.WriteChronological.Get() # type: bool writeGroupsChange = Settings.WriteGroups.Get() # type: bool logLevelChange = Settings.LogLevel.Get() # type: str logLevelChange = Parse.ParsePythonEnum( logLevelChange, Debug.LogLevels) # type: Debug.LogLevels logIntervalChange = Settings.LogInterval.Get() # type: float logSizeLimitChange = Settings.LogSizeLimit.Get() # type: float loggingEnabledLast = _loggingEnabled # type: bool writeChronologicalLast = _writeChronological # type: bool writeGroupsLast = _writeGroups # type: bool logLevelLast = _logLevel # type: enum_lib.Enum logIntervalLast = _logInterval # type: float logSizeLimitLast = _logSizeLimit # type: float if loggingEnabledLast != loggingEnabledChange: if loggingEnabledLast is not None: Debug.Log("Updating setting '" + Settings.LoggingEnabled.Key + "' to '" + str(loggingEnabledChange) + "'.", This.Mod.Namespace, Debug.LogLevels.Info, group=This.Mod.Namespace, owner=__name__) _loggingEnabled = loggingEnabledChange if writeChronologicalLast != writeChronologicalChange: if writeChronologicalLast is not None: Debug.Log("Updating setting '" + Settings.WriteChronological.Key + "' to '" + str(writeChronologicalChange) + "'.", This.Mod.Namespace, Debug.LogLevels.Info, group=This.Mod.Namespace, owner=__name__) _writeChronological = writeChronologicalChange if writeGroupsLast != writeGroupsChange: if writeGroupsLast is not None: Debug.Log("Updating setting '" + Settings.WriteGroups.Key + "' to '" + str(writeGroupsChange) + "'.", This.Mod.Namespace, Debug.LogLevels.Info, group=This.Mod.Namespace, owner=__name__) _writeGroups = writeGroupsChange if logLevelLast != logLevelChange: if logLevelLast is not None: Debug.Log("Updating setting '" + Settings.LogLevel.Key + "' to '" + str(logLevelChange) + "'.", This.Mod.Namespace, Debug.LogLevels.Info, group=This.Mod.Namespace, owner=__name__) _logLevel = logLevelChange if logIntervalLast != logIntervalChange: if logIntervalLast is not None: Debug.Log("Updating setting '" + Settings.LogInterval.Key + "' to '" + str(logIntervalChange) + "'.", This.Mod.Namespace, Debug.LogLevels.Info, group=This.Mod.Namespace, owner=__name__) _logInterval = logIntervalChange if logSizeLimitLast != logSizeLimitChange: if logSizeLimitLast is not None: Debug.Log("Updating setting '" + Settings.LogSizeLimit.Key + "' to '" + str(logSizeLimitChange) + "'.", This.Mod.Namespace, Debug.LogLevels.Info, group=This.Mod.Namespace, owner=__name__) _logSizeLimit = logSizeLimitChange global _flushTicker if not loggingEnabledLast and loggingEnabledChange: if loggingEnabledLast is not None: _logger.ChangeLogFile() if _flushTicker is not None: _flushTicker.Stop() _flushTicker = None if _logInterval != 0: _flushTicker = Timer.Timer(_logInterval, _logger.Flush, repeat=True) _flushTicker.start() elif loggingEnabledLast and not loggingEnabledChange: if _flushTicker is not None: _flushTicker.Stop() _flushTicker = None _logger.Flush() elif (logIntervalLast == 0 or logIntervalLast is None) and logIntervalChange != 0: if _flushTicker is not None: _flushTicker.Stop() _flushTicker = None _flushTicker = Timer.Timer(_logInterval, _logger.Flush, repeat=True) _flushTicker.start() elif logIntervalLast != 0 and logIntervalChange == 0: if _flushTicker is not None: _flushTicker.Stop() _flushTicker = None _logger.Flush() elif logIntervalLast != logIntervalChange: if logIntervalChange != 0: if _flushTicker is None: _flushTicker = Timer.Timer(_logInterval, _logger.Flush, repeat=True) _flushTicker.start() else: _flushTicker.Interval = _logInterval if loggingEnabledLast is None and not loggingEnabledChange: _logger._reportStorage = list() if logIntervalLast != 0 and ( (writeChronologicalLast and not writeChronologicalChange) or (writeGroupsLast and not writeGroupsChange)): _logger.Flush()
def _TypeCheckValue(cls, value: str) -> None: if not isinstance(value, str): raise Exceptions.IncorrectTypeException(value, "value", (str, )) Parse.ParsePythonEnum(value, Debug.LogLevels)