Spaces:
Build error
Build error
Commit ·
6befecd
1
Parent(s): adc507f
chore: black
Browse files
app.py
CHANGED
|
@@ -14,19 +14,25 @@ def make_all(numbers) -> dict:
|
|
| 14 |
|
| 15 |
unique, counts = np.unique(arr, return_counts=True)
|
| 16 |
d = dict(zip(unique, counts))
|
| 17 |
-
mode =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
mean = np.mean(arr)
|
| 19 |
rng = np.max(arr) - np.min(arr)
|
| 20 |
vrnc = np.var(arr)
|
| 21 |
|
| 22 |
# Detailed Variance
|
| 23 |
vrncls = [
|
| 24 |
-
[f"{n}", f"{(mean - n):.2f}", f"{(mean - n) ** 2:.2f}"]
|
| 25 |
-
for n in sorted(arr)
|
| 26 |
]
|
| 27 |
|
| 28 |
-
mdFile = MdUtils(
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
mdFile.new_line()
|
| 31 |
mdFile.new_paragraph(",".join([str(x) for x in arr]))
|
| 32 |
mdFile.new_line()
|
|
@@ -42,33 +48,35 @@ def make_all(numbers) -> dict:
|
|
| 42 |
list_of_strings = ["Элемент"]
|
| 43 |
|
| 44 |
for x in d:
|
| 45 |
-
list_of_strings.extend(
|
| 46 |
-
[f"{str(x)}"]
|
| 47 |
-
)
|
| 48 |
list_of_strings.append("Кол-во")
|
| 49 |
for value in d.values():
|
| 50 |
list_of_strings.extend([f"{str(value)}"])
|
| 51 |
|
| 52 |
mdFile.new_line()
|
| 53 |
-
mdFile.new_table(
|
|
|
|
|
|
|
| 54 |
mdFile.create_md_file()
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
mdFile.new_line()
|
| 61 |
-
|
| 62 |
list_of_strings = ["Элемент", "Отклонение", "Квадрат отклонения"]
|
| 63 |
|
| 64 |
for x in sorted(arr):
|
| 65 |
-
list_of_strings.extend(
|
| 66 |
-
[f"{x}", f"{(mean - x):.2f}", f"{(mean - x) ** 2:.2f}"]
|
| 67 |
-
)
|
| 68 |
print(list_of_strings)
|
| 69 |
|
| 70 |
mdFile.new_line()
|
| 71 |
-
mdFile.new_table(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
mdFile.create_md_file()
|
| 73 |
|
| 74 |
with open("Практическая работа по статистике.md", encoding="utf-8") as f:
|
|
@@ -81,17 +89,19 @@ def make_all(numbers) -> dict:
|
|
| 81 |
"Mode": mode,
|
| 82 |
"Mean": f"{mean:.2f}",
|
| 83 |
"Variance": f"{vrnc:.2f}",
|
| 84 |
-
"mdfile": mdfile_enc,
|
| 85 |
-
"detailed_variance_mdfile": mdfile_var_enc
|
| 86 |
-
|
| 87 |
|
| 88 |
|
| 89 |
def getints(numbers: str):
|
| 90 |
-
ls = list(map(int, numbers.split(
|
| 91 |
make_all(ls)
|
| 92 |
return f"{make_all(ls)}"
|
| 93 |
|
| 94 |
|
| 95 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
| 96 |
iface.launch()
|
| 97 |
-
# 62, 67, 57, 71, 66, 82, 64, 56, 63, 71, 92, 79, 59, 72, 55, 67, 73, 84, 44, 48
|
|
|
|
| 14 |
|
| 15 |
unique, counts = np.unique(arr, return_counts=True)
|
| 16 |
d = dict(zip(unique, counts))
|
| 17 |
+
mode = ", ".join(
|
| 18 |
+
[
|
| 19 |
+
str(unique[i])
|
| 20 |
+
for i in np.argwhere(counts == np.max(counts)).flatten().tolist()
|
| 21 |
+
]
|
| 22 |
+
)
|
| 23 |
mean = np.mean(arr)
|
| 24 |
rng = np.max(arr) - np.min(arr)
|
| 25 |
vrnc = np.var(arr)
|
| 26 |
|
| 27 |
# Detailed Variance
|
| 28 |
vrncls = [
|
| 29 |
+
[f"{n}", f"{(mean - n):.2f}", f"{(mean - n) ** 2:.2f}"] for n in sorted(arr)
|
|
|
|
| 30 |
]
|
| 31 |
|
| 32 |
+
mdFile = MdUtils(
|
| 33 |
+
file_name="Практическая работа по статистике",
|
| 34 |
+
title="Практическая работа по статистике",
|
| 35 |
+
)
|
| 36 |
mdFile.new_line()
|
| 37 |
mdFile.new_paragraph(",".join([str(x) for x in arr]))
|
| 38 |
mdFile.new_line()
|
|
|
|
| 48 |
list_of_strings = ["Элемент"]
|
| 49 |
|
| 50 |
for x in d:
|
| 51 |
+
list_of_strings.extend([f"{str(x)}"])
|
|
|
|
|
|
|
| 52 |
list_of_strings.append("Кол-во")
|
| 53 |
for value in d.values():
|
| 54 |
list_of_strings.extend([f"{str(value)}"])
|
| 55 |
|
| 56 |
mdFile.new_line()
|
| 57 |
+
mdFile.new_table(
|
| 58 |
+
columns=len(d) + 1, rows=2, text=list_of_strings, text_align="center"
|
| 59 |
+
)
|
| 60 |
mdFile.create_md_file()
|
| 61 |
|
| 62 |
+
mdFile = MdUtils(
|
| 63 |
+
file_name="Практическая работа по статистике_2",
|
| 64 |
+
title="Расчет дисперсии по отклонениям и их квадратам",
|
| 65 |
+
)
|
| 66 |
mdFile.new_line()
|
| 67 |
+
|
| 68 |
list_of_strings = ["Элемент", "Отклонение", "Квадрат отклонения"]
|
| 69 |
|
| 70 |
for x in sorted(arr):
|
| 71 |
+
list_of_strings.extend([f"{x}", f"{(mean - x):.2f}", f"{(mean - x) ** 2:.2f}"])
|
|
|
|
|
|
|
| 72 |
print(list_of_strings)
|
| 73 |
|
| 74 |
mdFile.new_line()
|
| 75 |
+
mdFile.new_table(
|
| 76 |
+
columns=3,
|
| 77 |
+
rows=len(arr) + 1,
|
| 78 |
+
text=list_of_strings,
|
| 79 |
+
)
|
| 80 |
mdFile.create_md_file()
|
| 81 |
|
| 82 |
with open("Практическая работа по статистике.md", encoding="utf-8") as f:
|
|
|
|
| 89 |
"Mode": mode,
|
| 90 |
"Mean": f"{mean:.2f}",
|
| 91 |
"Variance": f"{vrnc:.2f}",
|
| 92 |
+
"mdfile": mdfile_enc.decode(),
|
| 93 |
+
"detailed_variance_mdfile": mdfile_var_enc.decode(),
|
| 94 |
+
}
|
| 95 |
|
| 96 |
|
| 97 |
def getints(numbers: str):
|
| 98 |
+
ls = list(map(int, numbers.split(", ")))
|
| 99 |
make_all(ls)
|
| 100 |
return f"{make_all(ls)}"
|
| 101 |
|
| 102 |
|
| 103 |
+
iface = gr.Interface(
|
| 104 |
+
fn=getints, inputs="text", outputs="text", title="Tilted Calculator"
|
| 105 |
+
)
|
| 106 |
iface.launch()
|
| 107 |
+
# 62, 67, 57, 71, 66, 82, 64, 56, 63, 71, 92, 79, 59, 72, 55, 67, 73, 84, 44, 48
|