-
Notifications
You must be signed in to change notification settings - Fork 1
/
grapher.py
101 lines (89 loc) · 2.83 KB
/
grapher.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Script de mise à jour de graphe
# (C) Linedwell, 2011-2018
#
# Distribué sous licence GNU GPLv3
# Distributed under the terms of the GNU GPLv3 license
# http://www.gnu.org/licenses/gpl.html
import sys
sys.path.insert(1, '..') #ajoute au PYTHONPATH le répertoire parent
import mylogging
import pywikibot
# Déclarations
site = pywikibot.Site('fr', 'wikipedia')
page = pywikibot.Page(site, u"Projet:Maintenance/Suivi d'admissibilité/graphe")
# Met à jour le graphe de la page passée en paramètre avec la nouvelle valeur
def update(val):
last_values = file('_grapher.dat', 'r').readlines()[-14:]
last_values = [int(el.strip()) for el in last_values]
last_values.append(val)
#On fixe ymax (resp. ymin) à la valeur extrème trouvée +100 (resp. -100) arrondi à la centaine inférieure
ymax = max(last_values) - max(last_values) % 100 + 100
ymin = min(last_values) - min(last_values) % 100
step = ymax - ymin
step2= 100
fields = """
| coul_fond = white
| largeur = 500
| hauteur = 350
| marge_g = 40
| marge_d = 15
| marge_h = 10
| marge_b = 20
| nb_series = 1
| nb_abscisses = 15
| y_max = {ymax}
| y_min = {ymin}
| grille = oui
| pas_grille_principale = {step}
| pas_grille_secondaire = {step2}
| lb_x1 = -14 | lb_x2 = -13 | lb_x3 = -12 | lb_x4 = -11 | lb_x5 = -10
| lb_x6 = -9 | lb_x7 = -8 | lb_x8 = -7 | lb_x9 = -6 | lb_x10 = -5
| lb_x11 = -4 | lb_x12 = -3 | lb_x13 = -2 | lb_x14 = -1 | lb_x15 = 0
| S01V01 = {val01}
| S01V02 = {val02}
| S01V03 = {val03}
| S01V04 = {val04}
| S01V05 = {val05}
| S01V06 = {val06}
| S01V07 = {val07}
| S01V08 = {val08}
| S01V09 = {val09}
| S01V10 = {val10}
| S01V11 = {val11}
| S01V12 = {val12}
| S01V13 = {val13}
| S01V14 = {val14}
| S01V15 = {val15}
| points = oui
"""
context = {
"ymax" : ymax,
"ymin" : ymin,
"step" : step,
"step2": step2,
"val01": last_values[0],
"val02": last_values[1],
"val03": last_values[2],
"val04": last_values[3],
"val05": last_values[4],
"val06": last_values[5],
"val07": last_values[6],
"val08": last_values[7],
"val09": last_values[8],
"val10": last_values[9],
"val11": last_values[10],
"val12": last_values[11],
"val13": last_values[12],
"val14": last_values[13],
"val15": last_values[14],
}
template = u"<noinclude>{{Mise à jour bot|Linedwell}}</noinclude>\n<center>\n{{Graphique polygonal" + fields.format(**context) + u"}}\n\n'''Évolution au cours des deux dernières semaines'''\n</center>"
summary = "[[WP:Bot|Robot]] : mise à jour"
page.text = template
page.save(summary)
gr_dat = open('_grapher.dat', 'w')
for value in last_values:
gr_dat.write(str(value) + '\n')
gr_dat.close()