grapher.py 2.83 KB
Newer Older
Linedwell's avatar
Linedwell committed
1 2 3
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Script de mise à jour de graphe
4

Linedwell's avatar
Linedwell committed
5
# (C) Linedwell, 2011-2018
6 7 8 9
#
# Distribué sous licence GNU GPLv3
# Distributed under the terms of the GNU GPLv3 license
# http://www.gnu.org/licenses/gpl.html
Linedwell's avatar
Linedwell committed
10 11 12 13

import sys
sys.path.insert(1, '..') #ajoute au PYTHONPATH le répertoire parent

14
import mylogging
Linedwell's avatar
Linedwell committed
15

Linedwell's avatar
Linedwell committed
16 17 18
import pywikibot

# Déclarations
Linedwell's avatar
Linedwell committed
19
site = pywikibot.Site('fr', 'wikipedia')
20
page = pywikibot.Page(site, u"Projet:Maintenance/Suivi d'admissibilité/graphe")
Linedwell's avatar
Linedwell committed
21 22

# Met à jour le graphe de la page passée en paramètre avec la nouvelle valeur
23
def update(val):
Linedwell's avatar
Linedwell committed
24
    last_values = file('_grapher.dat', 'r').readlines()[-14:]
Linedwell's avatar
Linedwell committed
25 26 27 28 29
    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
30
    ymin = min(last_values) - min(last_values) % 100
Linedwell's avatar
Linedwell committed
31 32 33
    step = ymax - ymin
    step2= 100

34
    fields = """
Linedwell's avatar
Linedwell committed
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
 | 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}
Linedwell's avatar
Linedwell committed
67
 | points = oui
68
"""
Linedwell's avatar
Linedwell committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    
    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],
90 91 92 93
    }
    
    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"
Linedwell's avatar
Linedwell committed
94

95 96
    page.text = template
    page.save(summary)
Linedwell's avatar
Linedwell committed
97
    
Linedwell's avatar
Linedwell committed
98 99 100
    gr_dat = open('_grapher.dat', 'w')
    for value in last_values:
        gr_dat.write(str(value) + '\n')
101
    gr_dat.close()