code: def _derive_autoscaling_config_from_ray_cr(
      ray_cr: Dict[str, Any]
  ) -> Dict[str, Any]:
      provider_config = _generate_provider_config(
          ray_cr["metadata"]["namespace"]
      )
  
      available_node_types = (
          _generate_available_node_types_from_ray_cr_spec(
              ray_cr["spec"]
          )
      )
  
      # The autoscaler expects a global max workers field. We set it to the sum of
      # node type max workers.
      global_max_workers = sum(
          node_type["max_workers"]
          for node_type in available_node_types.values()
      )
  
      # Legacy autoscaling fields carry no information but are required for compatibility.
      legacy_autoscaling_fields = (
          _generate_legacy_autoscaling_config_fields()
      )
  
      # Process autoscaler options.
      autoscaler_options = ray_cr["spec"].get(
          AUTOSCALER_OPTIONS_KEY, {}
      )
      if IDLE_SECONDS_KEY in autoscaler_options:
          idle_timeout_minutes = (
              autoscaler_options[IDLE_SECONDS_KEY] / 60.0
          )
      else:
          idle_timeout_minutes = 1.0
  
      if (
          autoscaler_options.get(UPSCALING_KEY)
          == UPSCALING_VALUE_CONSERVATIVE
      ):
          upscaling_speed = 1  # Rate-limit upscaling if "Conservative" is set by user.
      # This elif is redudant but included for clarity.
      elif (
          autoscaler_options.get(UPSCALING_KEY)
          == UPSCALING_VALUE_DEFAULT
      ):
          upscaling_speed = (
              1000  # i.e. big, no rate-limiting by default
          )
      # This elif is redudant but included for clarity.
      elif (
          autoscaler_options.get(UPSCALING_KEY)
          == UPSCALING_VALUE_AGGRESSIVE
      ):
          upscaling_speed = 1000
      else:
          upscaling_speed = 1000
  
      autoscaling_config = {
          "provider": provider_config,
          "cluster_name": ray_cr["metadata"]["name"],
          "head_node_type": _HEAD_GROUP_NAME,
          "available_node_types": available_node_types,
          "max_workers": global_max_workers,
          # Should consider exposing `idleTimeoutMinutes` in the RayCluster CRD,
          # under an `autoscaling` field.
          "idle_timeout_minutes": idle_timeout_minutes,
          # Should consider exposing `upscalingSpeed` in the RayCluster CRD,
          # under an `autoscaling` field.
          "upscaling_speed": upscaling_speed,
          **legacy_autoscaling_fields,
      }
  
      # Make sure the config is readable by the autoscaler.
      validate_config(autoscaling_config)
  
      return autoscaling_config
  
imports: import decimal
  import json
  import logging
  import time
  from typing import Any, Dict, Optional
  import requests
  from ray.autoscaler._private.constants import DISABLE_LAUNCH_CONFIG_CHECK_KEY, DISABLE_NODE_UPDATERS_KEY, FOREGROUND_NODE_LAUNCH_KEY, WORKER_LIVENESS_CHECK_KEY, WORKER_RPC_DRAIN_KEY
  from ray.autoscaler._private.kuberay import node_provider, utils
  from ray.autoscaler._private.util import validate_config
label_desc: Use image node_id 1 for calling a global function with example usage: _derive_autoscaling_config_from_ray_cr(ray_cr) and returns: autoscaling_config