-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
563 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Description : Programme permettant de générer un fichier SVG | ||
# contenant un graphique à partir d'un fichier historique | ||
# stockant les données du serveur snmp | ||
# Description : Programme permettant de generer un fichier SVG | ||
# contenant un graphique a partir d'un fichier historique | ||
# stockant les donnees du serveur snmp | ||
# Auteurs : Lucas Bulloni, Malik Fleury et Bastien Wermeille | ||
# Data : 02.06.2017 | ||
# Version : 1.0 | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import datetime | ||
|
||
# Lecture des données | ||
# Lecture des donnees | ||
def ReadFile(filePath): | ||
time = [] | ||
octets = [] | ||
#Récupération des données | ||
firstLine = True | ||
date = "" | ||
TimeStamp = 0 | ||
BaseOctets = 0 | ||
#Recuperation des donnees | ||
with open(filePath, "r") as f: | ||
for line in f.readlines(): | ||
if line != "\n" : | ||
t, o = line.split(" ") | ||
time.append(t) | ||
octets.append(o) | ||
if firstLine == True: | ||
firstLine = False | ||
TimeStamp = int(t) | ||
BaseOctets = int(o) | ||
date = datetime.datetime.fromtimestamp(int(t)).strftime('%Y-%m-%d %H:%M:%S') | ||
time.append(int(t)-TimeStamp) | ||
octets.append(int(o)-BaseOctets) | ||
f.close() | ||
return (time,octets) | ||
return (None,None) | ||
if len(time) <= 0: | ||
print("Error file empty") | ||
exit(-1) | ||
if len(time) != len(octets): | ||
print("Incorrect file") | ||
exit(-1) | ||
return (time,octets,date) | ||
print("Error while file loading") | ||
exit(-1) | ||
|
||
# Generation du graphique | ||
def GenerateFile(data): | ||
plt.plot(data[0], data[1]) | ||
plt.ylabel('bytes (o)') | ||
plt.xlabel('time (s)') | ||
plt.title('Bytes at time') | ||
plt.title('Bytes from '+data[2]) | ||
plt.grid(True) | ||
plt.savefig("graph.svg",type="svg") | ||
#plt.show() | ||
|
||
# Main programme | ||
GenerateFile(ReadFile("historique")) | ||
print("Successful Generation !!!") | ||
exit(1) |
Oops, something went wrong.