From e6e555dcacbc1dba9970625936bafdeb65bb6946 Mon Sep 17 00:00:00 2001 From: pythagodzilla Date: Thu, 18 Sep 2025 19:35:03 +0800 Subject: [PATCH] 111 --- src/__pycache__/uncertainly.cpython-38.pyc | Bin 0 -> 1617 bytes src/log.py | 1 + src/main.py | 16 +++++++++ src/uncertainly.py | 36 +++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 src/__pycache__/uncertainly.cpython-38.pyc create mode 100644 src/log.py create mode 100644 src/main.py create mode 100644 src/uncertainly.py diff --git a/src/__pycache__/uncertainly.cpython-38.pyc b/src/__pycache__/uncertainly.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1fcf63698fe88f61f5a65eb51505b42aa3954dcb GIT binary patch literal 1617 zcmZux&2Jk;6rb5IuN~*3iE#r3Wc9>Sh^zF1P#Tqj#4VSq7o&Ex+S$a8*51v`Y=tdX zs^o}p00HU&sU(O>2+>O<1QI2!`Va6Q?12NVllV|L;}h?#*Qq0Qta&r ziJ9fpc5wlU%(h`ntnQ_-%`!(4;wi{unds@!^t2p@ zc+g>8AYJIe0yzuuCA`V*!o4id3HD{pqkwBXG}zz=EWnhnf!H8ja%28BMc|uc5!$>! zzR|X@rF4MN4i%W-Xo09y~ILFqHu|cpW|P?`fGems)jhqpyTLOZ_~5+J1IyFYK9F<`iUD=?!{jDW*BO z?1br5vodWa)$HtcE6bS8ZW-ME9XAckleSB|7t3!G@ zp@r0Q_`^Vr3XC;F9tXHDGPV`FLFUObCWBB( zaF{BN0zWa=gV0r?jMyqDULZPwC9s_7{}jGDThr*o??0n3KbuCZIeN`#x~e{UKbY{c S(-M1Sgl-j?E%B`twf_Oiu$ZI( literal 0 HcmV?d00001 diff --git a/src/log.py b/src/log.py new file mode 100644 index 0000000..f09f064 --- /dev/null +++ b/src/log.py @@ -0,0 +1 @@ +import logger diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..3b36705 --- /dev/null +++ b/src/main.py @@ -0,0 +1,16 @@ +from uncertainly import Uncertainly + +number_input = input("Data input:") +type_B_uncertain: float = float(input("type_B_uncertain: ")) +param_tp: float = float(input("tp input: ")) + +number_list:tuple = number_input.split() + +try: + numbers = [float(num_str) for num_str in number_list] + print(numbers) + uncertain_processor = Uncertainly(data=numbers, type_B_uncertain=type_B_uncertain,param_tp=param_tp) + uncertain_processor.output_std() + +except Exception as e: + print(e) \ No newline at end of file diff --git a/src/uncertainly.py b/src/uncertainly.py new file mode 100644 index 0000000..693d3b4 --- /dev/null +++ b/src/uncertainly.py @@ -0,0 +1,36 @@ +from math import sqrt + +class Uncertainly: + __slots__ = [ + "average", + "length", + "standard_deviation", + "type_A_uncertain", + "type_B_uncertain", + "total_uncertain", + "data" + ] + + def __init__(self, data: tuple, type_B_uncertain: float, param_tp: float): + self.data = data + self.average:float = sum(self.data) / len(self.data) + self.length = len(self.data) + + # def cal_standard_deviation(self): + data_cut = [(datum-self.average) ** 2 for datum in self.data] + + self.standard_deviation:float = sqrt(sum(data_cut) / (self.length - 1)) + + self.type_A_uncertain:float = param_tp * self.standard_deviation / sqrt(self.length) + + self.total_uncertain = 2 * sqrt(self.type_A_uncertain**2 + type_B_uncertain**2) + self.type_B_uncertain = type_B_uncertain + + def output_std(self): + print(f"平均为:{self.data}/{self.length}={self.average}\n") + # print(f"{self.average}\n") + print(f"标准差:{round(self.standard_deviation,4)}") + print(f"3S区间:[{round(self.average - 3 * self.standard_deviation,4)},{round(self.average +3 * self.standard_deviation,4)}]") + print(f"B类不确定度确认:{self.type_B_uncertain}\n") + print(f"总不确定度:2 * ✓{round(self.type_A_uncertain,4)}^2 + {round(self.type_B_uncertain,4)}^2={round(self.total_uncertain,4)}") + print(f"结果表达式为:{round(self.average,4)}+-{round(self.total_uncertain,4)}") \ No newline at end of file