ADDED: models and controllers for page "signal reducing"\n TODO: done table for page "signal reducing"

This commit is contained in:
2024-04-19 01:30:51 +04:00
parent 6e315907bc
commit b6d0eb0508
11 changed files with 228 additions and 97 deletions

View File

@@ -1,6 +1,9 @@
use std::collections::HashMap;
use crate::{controller::view_utils::input_utils::*, model::model::*};
use crate::{
controller::view_utils::{hamming_code_input_utils::*, input_utils::*},
model::model::*,
};
/// **Синдромы**
///
@@ -23,7 +26,8 @@ pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String> {
let prepared_input: String = processing_input(&raw_input);
let (fc, sc) = check_correct_input(&raw_input, &prepared_input, length_of_code);
let (fc, sc): (bool, bool) =
check_correct_binary_code(&raw_input, &prepared_input, length_of_code);
if !fc || !sc {
Err("Ошибка. Проверьте корректность ввода.".to_string())
@@ -45,7 +49,7 @@ pub fn hamming_encrypt_data(data: &Vec<u8>, result_string: &mut String, length_o
let mut i: usize = length_of_code;
while i <= data.len() {
let data_bits = &data[i - length_of_code..i];
let data_bits: &[u8] = &data[i - length_of_code..i];
let (check_bit_1, check_bit_2, check_bit_3) = (
data_bits[0] ^ data_bits[1] ^ data_bits[3],
data_bits[0] ^ data_bits[2] ^ data_bits[3],
@@ -87,30 +91,32 @@ pub fn hamming_decrypt_data(data: &Vec<u8>, result_string: &mut String, length_o
general_length += length_of_code;
continue;
} else {
let error_position = syndromes
let error_position: &usize = syndromes
.iter()
.find(move |&(&_error_position, &error)| error == checked_bits)
.unwrap()
.0;
let correctly_code: Vec<u8> = data_bits
.iter()
.enumerate()
.map(|(index, bit)| {
if index == error_position - 1 {
(*bit == 0u8).into()
} else {
*bit
}
})
.collect();
let uncorrect_code: String = from_vec_bits_to_string(&data_bits);
let correct_code: String = from_vec_bits_to_string(
data_bits
.iter()
.enumerate()
.map(|(index, &bit)| {
if index == error_position - 1 {
(bit == 0u8).into()
} else {
bit
}
})
.collect::<Vec<u8>>()
.as_slice(),
);
let error = format!(
"Ошибка в коде {} {:?}, позиция ошибки {}, корректный код: {:?}; \n",
"Ошибка в коде {} [{uncorrect_code}], позиция ошибки {}, корректный код: [{correct_code}]; \n",
general_length / 7,
&data_bits,
error_position,
correctly_code
error_position
);
errors.push_str(error.as_str());

View File

@@ -1 +1,3 @@
pub mod hamming_code_seven_four;
pub mod hamming_code_seven_four;
pub mod signal_reducer;

View File

@@ -0,0 +1,15 @@
pub fn reactive_resistance_of_capacitor(Cm: f64, L: f64, f: f64) -> f64 {
1f64 / (2f64 * 3.14f64 * f * Cm * L)
}
pub fn full_resistance_of_capacitor(Xc: f64, Rs: f64, Rm: f64, L: f64) -> f64 {
(Xc.powf(2f64) + (Rs + Rm * L).powf(2f64)).sqrt()
}
pub fn voltage_from_signal_source(Vs: f64, Xc: f64, Z: f64) -> f64 {
(Vs * Xc) / Z
}
pub fn coef_of_signal_reduce(Vs: f64, V: f64) -> f64 {
Vs / V
}