art-bashkirev commited on
Commit
eecb42d
·
1 Parent(s): fe5bbe9

modified: app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -2
app.py CHANGED
@@ -3,6 +3,7 @@ import numpy as np
3
  from mdutils import MdUtils
4
  import matplotlib.pyplot as plt
5
  import matplotlib.ticker as ticker
 
6
 
7
  WIDTH = 12
8
  HEIGHT = 2
@@ -13,7 +14,7 @@ def make_all(numbers) -> dict:
13
 
14
  unique, counts = np.unique(arr, return_counts=True)
15
  d = dict(zip(unique, counts))
16
- mode = np.argwhere(counts == np.max(counts))
17
  mean = np.mean(arr)
18
  rng = np.max(arr) - np.min(arr)
19
  vrnc = np.var(arr)
@@ -22,12 +23,47 @@ def make_all(numbers) -> dict:
22
  [f"{n}", f"{(mean - n):.2f}", f"{(mean - n) ** 2:.2f}"]
23
  for n in sorted(arr)
24
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  return {
26
  "Range": rng,
27
  "Mode": mode,
28
  "Mean": mean,
29
  "Variance": vrnc,
30
- "Detailed_Variance": vrncls
 
31
  }
32
 
33
 
 
3
  from mdutils import MdUtils
4
  import matplotlib.pyplot as plt
5
  import matplotlib.ticker as ticker
6
+ import base64
7
 
8
  WIDTH = 12
9
  HEIGHT = 2
 
14
 
15
  unique, counts = np.unique(arr, return_counts=True)
16
  d = dict(zip(unique, counts))
17
+ mode = ', '.join([str(unique[i]) for i in np.argwhere(counts == np.max(counts)).flatten().tolist()])
18
  mean = np.mean(arr)
19
  rng = np.max(arr) - np.min(arr)
20
  vrnc = np.var(arr)
 
23
  [f"{n}", f"{(mean - n):.2f}", f"{(mean - n) ** 2:.2f}"]
24
  for n in sorted(arr)
25
  ]
26
+
27
+ mdFile = MdUtils(file_name='Практическая работа по статистике',
28
+ title='Практическая работа по статистике')
29
+
30
+ mdFile.new_line()
31
+ mdFile.new_paragraph(",".join([str(x) for x in arr]))
32
+ mdFile.new_line()
33
+ mdFile.new_paragraph(",".join([str(x) for x in sorted(arr)]))
34
+ mdFile.new_line()
35
+ mdFile.new_paragraph(f"Размах: {(np.max(arr) - np.min(arr))}")
36
+ mdFile.new_line()
37
+ mdFile.new_paragraph(f"Мода: {', '.join([str(unique[i]) for i in np.argwhere(counts == np.max(counts)).flatten().tolist()])}")
38
+ mdFile.new_line()
39
+ mdFile.new_paragraph(f"А ср.: {mean:.2f}")
40
+ mdFile.new_line()
41
+ mdFile.new_paragraph(f"D = {vrnc:.2f}")
42
+
43
+ list_of_strings = ["Элемент"]
44
+
45
+ for x in d:
46
+ list_of_strings.extend(
47
+ [f"{str(x)}"]
48
+ )
49
+ list_of_strings.append("Кол-во")
50
+ for value in d.values():
51
+ list_of_strings.extend([f"{str(value)}"])
52
+
53
+ mdFile.new_line()
54
+ mdFile.new_table(columns=len(d)+1, rows=2, text=list_of_strings, text_align='center')
55
+ mdFile.create_md_file()
56
+
57
+ with open("Практическая работа по статистике.md", encoding="utf-8") as f:
58
+ mdfile_enc = base64.b64encode(f.read())
59
+
60
  return {
61
  "Range": rng,
62
  "Mode": mode,
63
  "Mean": mean,
64
  "Variance": vrnc,
65
+ # "Detailed_Variance": vrncls,
66
+ "mdfile": mdfile_enc
67
  }
68
 
69