-
Notifications
You must be signed in to change notification settings - Fork 88
/
wiki_stats.py
executable file
·75 lines (49 loc) · 1.75 KB
/
wiki_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python3
import os
import sys
import math
import array
import statistics
from matplotlib import rc
rc('font', family='Droid Sans', weight='normal', size=14)
import matplotlib.pyplot as plt
class WikiGraph:
def load_from_file(self, filename):
print('Загружаю граф из файла: ' + filename)
with open(filename) as f:
(n, _nlinks) = (0, 0) # TODO: прочитать из файла
self._titles = []
self._sizes = array.array('L', [0]*n)
self._links = array.array('L', [0]*_nlinks)
self._redirect = array.array('B', [0]*n)
self._offset = array.array('L', [0]*(n+1))
# TODO: прочитать граф из файла
print('Граф загружен')
def get_number_of_links_from(self, _id):
pass
def get_links_from(self, _id):
pass
def get_id(self, title):
pass
def get_number_of_pages(self):
pass
def is_redirect(self, _id):
pass
def get_title(self, _id):
pass
def get_page_size(self, _id):
pass
def hist(fname, data, bins, xlabel, ylabel, title, facecolor='green', alpha=0.5, transparent=True, **kwargs):
plt.clf()
# TODO: нарисовать гистограмму и сохранить в файл
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Использование: wiki_stats.py <файл с графом статей>')
sys.exit(-1)
if os.path.isfile(sys.argv[1]):
wg = WikiGraph()
wg.load_from_file(sys.argv[1])
else:
print('Файл с графом не найден')
sys.exit(-1)
# TODO: статистика и гистограммы