{"record":{"id":"e30ee527b13afe35","repo":"ruvnet/RuView","slug":"sampling-rate-must-be-positive","errorCode":null,"errorMessage":"sampling_rate must be positive","messagePattern":"sampling_rate must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archive/v1/src/core/csi_processor.py","lineNumber":111,"sourceCode":"        self._human_detections = 0\n    \n    def _validate_config(self, config: Dict[str, Any]) -> None:\n        \"\"\"Validate configuration parameters.\n        \n        Args:\n            config: Configuration to validate\n            \n        Raises:\n            ValueError: If configuration is invalid\n        \"\"\"\n        required_fields = ['sampling_rate', 'window_size', 'overlap', 'noise_threshold']\n        missing_fields = [field for field in required_fields if field not in config]\n        \n        if missing_fields:\n            raise ValueError(f\"Missing required configuration: {missing_fields}\")\n        \n        if config['sampling_rate'] <= 0:\n            raise ValueError(\"sampling_rate must be positive\")\n        \n        if config['window_size'] <= 0:\n            raise ValueError(\"window_size must be positive\")\n        \n        if not 0 <= config['overlap'] < 1:\n            raise ValueError(\"overlap must be between 0 and 1\")\n    \n    def preprocess_csi_data(self, csi_data: CSIData) -> CSIData:\n        \"\"\"Preprocess CSI data for feature extraction.\n        \n        Args:\n            csi_data: Raw CSI data\n            \n        Returns:\n            Preprocessed CSI data\n            \n        Raises:\n            CSIProcessingError: If preprocessing fails","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/core/csi_processor.py#L93-L129","documentation":"Raised by CSIProcessor._validate_config during __init__ when the config dict contains sampling_rate but its value is <= 0. The processor divides time axes and FFT frequencies by sampling_rate, so a zero or negative rate would corrupt every downstream computation, hence the fail-fast check.","triggerScenarios":"Constructing CSIProcessor with sampling_rate=0, a negative number, or a value that coerces to <= 0 (e.g. 0.0, -100). Typical call: CSIProcessor({'sampling_rate': 0, 'window_size': 64, 'overlap': 0.5, 'noise_threshold': 0.1}).","commonSituations":"Placeholder 0 in a config template never replaced; computing rate as `n_samples / duration` when duration is misparsed; ESP32 firmware subcarrier rate config injected as 0 before hardware init; YAML that parses an empty value into 0; unit tests probing boundary values.","solutions":["Set sampling_rate to the true CSI sample rate in Hz (e.g. 100 for 100 packets/sec capture, or your hardware's rate such as 1000 for high-rate ESP32 captures).","If the rate is computed, guard it before construction: `rate = max(rate, 1)` or assert it derives from a positive duration.","Log the resolved config right before constructing CSIProcessor to catch defaults leaking in as 0.","For hardware-driven rates, ensure the extractor reports a positive measured rate before instantiating the processor."],"exampleFix":"# before\nconfig = {'sampling_rate': 0, 'window_size': 64, 'overlap': 0.5, 'noise_threshold': 0.1}\nprocessor = CSIProcessor(config)  # ValueError\n\n# after\nconfig = {'sampling_rate': 100, 'window_size': 64, 'overlap': 0.5, 'noise_threshold': 0.1}\nprocessor = CSIProcessor(config)","handlingStrategy":"validation","validationCode":"def is_valid_csi_config(config: dict) -> bool:\n    return (\n        {'sampling_rate', 'window_size', 'overlap', 'noise_threshold'} <= config.keys()\n        and config['sampling_rate'] > 0\n    )","typeGuard":null,"tryCatchPattern":"try:\n    processor = CSIProcessor(config)\nexcept ValueError as e:\n    if 'sampling_rate must be positive' in str(e):\n        config['sampling_rate'] = measured_rate  # from hardware/extractor\n        processor = CSIProcessor(config)\n    else:\n        raise","preventionTips":["Derive sampling_rate from the capture device settings, never hardcode a placeholder 0.","Assert measured_rate > 0 in the extractor before handing config to the processor.","Unit-test the config builder so 0 rates cannot be emitted."],"tags":["config","validation","csi-processing","signal-processing"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}