Sorry if the code is long but maybe I missed something that create the bug...
Code: Select all
Procedure GrapheStats(fichier$)
; Cette procedure doit permettre de grapher les statistiques enregistrées par StaLaWa 2
; 1) on lit l'index du fichier et on place les noms dans une liste chainée (structure NOM, index_ou_colonne, min, max, moy)
; 2) on compte le nombre de ligne (NumberEchantillon) et on remplit déjà GlobalWAN et GlobalLAN. On créé une image (h x NumberEchantillon)
; 3) on affiche dans une liste la liste des noms de WAN ou LAN
; 4) on graphe GlobalLAN et GlobalWAN puis on copie cette image dans un buffer
; 5) un clic sur le bouton [Graph Selected] entraine la lecture des champs sélectionnés (une couleur/champ pour chaque ligne)
;
Structure reference
Nom.s ; nom du site
index.l ; son N° de colonne dans le fichier stat (index)
min.l ; données statistiques précalculées
max.l
moy.l
Cumul.d
rrel.d ; pourcentage par rapport à sa catégorie (LAN, WAN et CAST)
rabs.d ; pourcentage par rapport aux cumuls totaux
EndStructure
CumulGWAN.d = 0
CumulGLAN.d = 0
CumulGCAST.d = 0
NewList Entite.reference()
Taille = 460 ; taille du graphique en largeur
Index = 5 ; Les Cast (bradcast + Multicast)
; 1) Lecture des index :
If ReadFile(10, fichier$)
; La lecture fichier peut être longue : affiche une petite fenêtre d'attente
If OpenWindow(#Window_Wait, 10,10,150,50,"Analysing",#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(#Window_Wait))
TextGadget(#TxtWait,10,55,100,35,"Analyzing...")
EndIf
; Analyse en cours...
Legend$ = ReadString(10)
If FindString(Legend$,Chr(9),1) ; on cherche les [tab] comme séparateur
n = 0
While StringField(Legend$,n,Chr(9)) > ""
AddElement(Entite())
Entite()\nom = StringField(Legend$,n,Chr(9))
Entite()\Index = n
Entite()\min = -1
Entite()\max = 0
Entite()\moy = 0
Entite()\Cumul = 0
Entite()\rrel = 0
Entite()\rabs = 0
n + 1
Wend
EndIf
Debug "Nombre d'entité = "+Str(n)
; 2) Remplissage des données : double-boucle
While Not Eof(10) ; Tant que l'on n'est pas à la fin du fichier
a$ = ReadString(10) ; on lit une ligne du fichier de stats
NumberEchantillon = NumberEchantillon + 1 ; on en profite pour compter le nombre d'échantillons (pour la moyenne)
AddElement(LANWAN()) ; et on prépare le graphique
ResetList(Entite()) ; on remet le pointeur de la liste chainée au début et
For t = 2 To n-1 ; on commence à 2, le premier champ étant la date (la liste commence à 0)
valeur.l = Val(StringField(a$,t,Chr(9)))
Select t ; en fonction de la colonne, on cumule en WAN, en LAN ou en CAST
Case 2 ; Colonne GlobalWAN
CumulGWAN + valeur ; opération de cumul (pour moyenne)
LANWAN()\dWAN = valeur
If valeur > MaxGWAN
MaxGWAN = valeur
EndIf
Case 3 ; même chose pour la colonne GlobalLAN
CumulGLAN + valeur
LANWAN()\dLAN = valeur
If valeur > MaxGWAN
MaxGLAN = valeur
EndIf
Case Index
LANWAN()\dNET = valeur
Case 6
CumulGCAST + valeur
EndSelect
SelectElement(Entite(),t)
Debug Str(NumberEchantillon) + " = "+ Str(CountList(Entite()))
Entite()\Cumul = Entite()\Cumul + valeur
If Valeur > Entite()\max ; Calcul de la valeur max
Entite()\max = Valeur
EndIf
If Valeur < Entite()\Min ; Calcul de la valeur min
Entite()\min = Valeur
EndIf
If Entite()\min = -1 ; Cas particulier : la première valeur min
Entite()\min = Valeur
EndIf
If t = 40000
Debug "40000 -------------------------------"
EndIf
Next t
Wend
CloseFile(10)
Else
MessageRequester("File Reading error","Couldn't read Stats file.")
EndIf
; X) Vérification debug
Debug "Nombre = "+Str(NumberEchantillon)
Debug "Cumuls : LAN="+Str(CumulGLAN)+" WAN="+Str(CumulGWAN)+" CAST="+Str(CumulGCAST)
Debug "----------------------"
ResetList(Entite())
t = 0
ForEach Entite() ; Prépare la liste à afficher : uniquement les sites actifs !
If Entite()\Cumul > 0
; Debug "---------------------------"
Entite()\Moy = Int(Entite()\Cumul / NumberEchantillon)
Entite()\rabs = Entite()\Cumul / (CumulGWAN+CumulGLAN+CumulGCAST) * 100
If t > 2 And t < 7 ; Serveurs LAN
Entite()\rrel = Int(Entite()\Cumul / CumulGLAN * 10000) / 100
ElseIf t > 6 Or t = 2 ; réseaux WAN
Entite()\rrel = Int(Entite()\Cumul / CumulGWAN * 10000) / 100
EndIf
; chaine$ = Entite()\nom+" [min:"+Str(Entite()\min)+" / moy:"+Str(Entite()\moy)+" / max:"+Str(Entite()\max)+" ] ==> Cumul = "+Str(Entite()\Cumul)+" bits"
; chaine$ + " soit "+StrD(Entite()\rabs,2)+"% (relatif = "+StrD(Entite()\rrel,2)+"%)"
; Debug chaine$
EndIf
t = t + 1
Next
; Affichage
If IsWindow(#Window_Wait)
CloseWindow(#Window_Wait)
EndIf
If OpenWindow(#Windows_Graph, 100, 250, 870, 245, "StaLaWa 2 - Grapher") And CreateGadgetList(WindowID(#Window_0))
CreateGadgetList(WindowID(#Windows_Graph))
ListIconGadget(#Liste_Entites,2,10,385,180,"Sites actifs",100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#Liste_Entites,1,"% Global",55)
AddGadgetColumn(#Liste_Entites,2,"% Relatif",55)
AddGadgetColumn(#Liste_Entites,3,"Min",55)
AddGadgetColumn(#Liste_Entites,4,"Moy",55)
AddGadgetColumn(#Liste_Entites,5,"Max",55)
AddGadgetColumn(#Liste_Entites,6,"Cumul",55)
AddGadgetColumn(#Liste_Entites,7,"Index",40)
SelectElement(Entite(),1)
cpt = 0
While NextElement(Entite())
; Debug Str(cpt)+" ---> "+ Entite()\nom
If Entite()\Cumul > 0
If Val(StrD(Entite()\Cumul)) = Entite()\Cumul ; Evites l'affichage disgracieux x.000000
Cumul$ = Str(Entite()\Cumul)
Else
Cumul$ = StrD(Entite()\Cumul)
EndIf
a$ = Entite()\nom + Chr(10) + StrD(Entite()\Rabs,2) + Chr(10) + StrD(Entite()\Rrel,2) + Chr(10) + Str(Entite()\Min) + Chr(10)
a$ + Str(Entite()\moy) + Chr(10) + Str(Entite()\Max) + Chr(10) + Cumul$ + Chr(10) + Str(Cpt)
AddGadgetItem(#Liste_Entites,-1,a$)
SetGadgetItemColor(#Liste_Entites,0,#PB_Gadget_BackColor, RGB(64,127,255),-1)
SetGadgetItemColor(#Liste_Entites,1,#PB_Gadget_BackColor, RGB(64,224,240),-1)
SetGadgetItemColor(#Liste_Entites,index,#PB_Gadget_BackColor, RGB(224,0,0),-1)
EndIf
Cpt + 1
Wend
TextGadget(#StringTOT,3,195,150,15,"Actives WAN Sites : "+Str(CountGadgetItems(#Liste_Entites)-4))
ButtonGadget(#Button_GraphOne, 2,222,90,15,"Graph It")
ButtonGadget(#Button_CreateList,100,222,90,15,"Create WAN list")
ButtonGadget(#Button_CreateStat,198,222,90,15,"Create Excel Stats")
ButtonGadget(#Button_ExportStat,296,222,90,15,"Copy Report")
TrackBarGadget(#Zoom, 180,195,200,15,1,50,#PB_TrackBar_Ticks)
GadgetToolTip(#Zoom,"Zoom : from x1 on left, to x64 on right")
SetGadgetState(#Liste_Entites,3)
Colonne = Val(GetGadgetItemText(#Liste_Entites,GetGadgetState(#Liste_Entites),7))
GrapheOne(fichier$, Colonne,GetGadgetState(#Zoom),1)
; Create a gadget to display our nice image
EndIf
EndProcedure