-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc-wire.sh
More file actions
executable file
·257 lines (228 loc) · 7.55 KB
/
c-wire.sh
File metadata and controls
executable file
·257 lines (228 loc) · 7.55 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
PROG="codeC/prog"
# Fonction d'erreur
erreur()
{
echo "Affichage de l'aide"
echo
cat help.txt
exit $1
}
# Vérification de la présence de l'option -h
for arg in $@
do
if [ $arg = '-h' ]
then
cat help.txt
exit 0
fi
done
# Vérification du nombre d'arguments
if (($# < 3))
then
echo "Erreur : Nombre d'arguments invalide"
erreur 2
fi
# Vérification de l'argument 1 "fichier d'entrée"
if [ ! -f $1 ] || [ ! -r $1 ]
then
echo "Erreur : '$1' n'est pas un fichier valide"
erreur 3
else
chemin_entree=$1
fi
# Vérification de l'argument 2 "type de station"
type_station=-1
case $2 in
'hvb') type_station=0
;;
'hva') type_station=1
;;
'lv') type_station=2
;;
*)
echo "Erreur : Type de station inconnu '$2'"
erreur 4
;;
esac
# Vérification de l'argument 3 "type de consommateur"
type_conso=-1
case $3 in
'all') type_conso=0
if (($type_station != 2))
then
echo "Erreur : Impossible d'utiliser l'option 'all' avec une station $2"
erreur 5
fi
;;
'comp') type_conso=1 ;;
'indiv') type_conso=2
if (($type_station != 2))
then
echo "Erreur : Impossible d'utiliser l'option 'indiv' avec une station $2"
erreur 5
fi
;;
*)
echo "Type de consommateur inconnu '$3'"
erreur 6
;;
esac
# Vérification de l'argument 4 "identifiant de centrale"
id_centrale=-1
if (($# >= 4))
then id_centrale=$4
fi
# Vérification de la compliation
if [ ! -f $PROG ]
then
echo "Compliation du programme..."
cd codeC
make
if (($? != 0)); then
echo "Erreur de compliation du programme"
erreur 7
fi
cd ..
echo "Compilation terminée"
fi
# Vérification du dossier tmp
if [ -d tmp ]
then cd tmp; rm -f *; cd ..;
else mkdir tmp
fi
# Vérification du dossier graphs
if [ ! -d graphs ]
then mkdir graphs
fi
# Vérification du dossier tests
if [ ! -d tests ]
then mkdir tests
fi
# Initialisation du temps d'exécution
temps_debut=`date +%s.%N`
# Filtrage des données avec grep et obtention du chemin sortie
chemin_sortie="" # chemin de sortie final
chemin_sortie_minmax="" # chemin de sortie pour le traitement lv_all_minmax
tete_sortie="" # en-tête du fichier CSV de sortie
nblignes=0 # nombre de lignes du fichier temporaire envoyé au programme C
# Traitement pour une centrale spécifique
# Envoi des données de type (station;capacité;consommation) dans tmp/input.csv
if (($id_centrale != -1))
then
chemin_sortie="tests/${2}_${3}_${4}.csv"
chemin_sortie_minmax="tests/lv_all_minmax_${4}.csv"
if (($type_station == 0)) # hvb
then
grep -E "^$4;[0-9]+;-" $chemin_entree | cut -d';' -f2,7,8 | tr '-' '0' > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Station_HV-B:Capacité:Consommation(entreprises)"
elif (($type_station == 1)) # hva
then
grep -E "^$4;[0-9-]+;[0-9]+;-" $chemin_entree | cut -d';' -f3,7,8 | tr '-' '0' > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Station_HV-A:Capacité:Consommation(entreprises)"
else # lv
case $3 in
'all')
grep -E "^$4;-;[0-9-]+;[0-9]+;" $chemin_entree | cut -d';' -f4,7,8 | tr '-' '0' > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Poste_LV:Capacité:Consommation(tous)"
;;
'comp')
grep -E "^$4;-;[0-9-]+;[0-9]+;[0-9-]+;-;" $chemin_entree | cut -d';' -f4,7,8 | tr '-' '0' > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Poste_LV:Capacité:Consommation(entreprises)"
;;
'indiv')
grep -E "^$4;-;[0-9-]+;[0-9]+;-;[0-9-]+" $chemin_entree | cut -d';' -f4,7,8 | tr '-' '0' > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Poste_LV:Capacité:Consommation(particuliers)"
;;
esac
fi
fi
# Traitement pour toutes les centrales
# Envoi des données de type (station;capacité;consommation) dans tmp/input.csv
if (($id_centrale == -1))
then
chemin_sortie="tests/${2}_${3}.csv"
chemin_sortie_minmax="tests/lv_all_minmax.csv"
if (($type_station == 0)) # hvb
then
grep -E "^[0-9-]+;[0-9]+;-" $chemin_entree | cut -d';' -f2,7,8 | tr '-' '0' | cat > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Station_HV-B:Capacité:Consommation(entreprises)"
elif (($type_station == 1)) # hva
then
grep -E "^[0-9-]+;[0-9-]+;[0-9]+;-" $chemin_entree | cut -d';' -f3,7,8 | tr '-' '0' | cat > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Station_HV-A:Capacité:Consommation(entreprises)"
else # lv
case $3 in
'all')
grep -E "^[0-9]+;-;[0-9-]+;[0-9]" $chemin_entree | cut -d';' -f4,7,8 | tr '-' '0' | cat > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Poste_LV:Capacité:Consommation(tous)"
;;
'comp')
grep -E "^[0-9]+;-;[0-9-]+;[0-9]+;[0-9-]+;-;" $chemin_entree | cut -d';' -f4,7,8 | tr '-' '0' | cat > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Poste_LV:Capacité:Consommation(entreprises)"
;;
'indiv')
grep -E "^[0-9]+;-;[0-9-]+;[0-9]+;-;[0-9-]+" $chemin_entree | cut -d';' -f4,7,8 | tr '-' '0' | cat > tmp/input.csv
nblignes=`wc -l tmp/input.csv | cut -f1 -d' '`
tete_sortie="Poste_LV:Capacité:Consommation(particuliers)"
;;
esac
fi
fi
# Exécution du pprogramme
if (($nblignes == 0))
then
echo "Aucune donnée ne correspond aux critères sélectionnés"
erreur 8
fi
$PROG $nblignes < tmp/input.csv > tmp/output.csv
# Sortie : (station;capacité;consommation;capacité-consommation)
# Vérification que le programme C s'est bien déroulé
erreur_c=$?
if ((erreur_c != 0)); then
echo "Erreur lors de l'exécution du programme C : erreur $erreur_c"
erreur 15
fi
# Tri des données en sortie du programme C
echo $tete_sortie > $chemin_sortie # écriture de l'en-tête
cut -d: -f1,2,3 "tmp/output.csv" | sort -k2 -t: -n >> $chemin_sortie # tri par capacité
echo "Fichier $chemin_sortie généré"
# Traitement lv_all_minmax
if (($type_conso == 0))
then
# Création du fichier lv_all_minmax.csv
nbstations=`wc -l tmp/output.csv | cut -f1 -d' '`
if (($nbstations >= 20))
then
sort "tmp/output.csv" -k4 -t: -n | tee | { head -n10 ; tail -n10 ; } | cut -d: -f1,2,3 > $chemin_sortie_minmax
else
sort "tmp/output.csv" -k4 -t: -n | cut -d_ -f1,2,3 > $chemin_sortie_minmax
fi
echo "Fichier $chemin_sortie_minmax généré"
# Création du graphique de consommation des stations extrémales
if [ -f plot_script ]; then
gnuplot -e "data='$chemin_sortie_minmax'" plot_script
if (( $? != 0 )); then
echo "Errur lors de la génération du graphique"
else
echo "Graphique généré dans graphs/graph.png"
fi
else
echo "Script de génération du graphique introuvable"
fi
fi
# Calcul du temps d'exécution
temps_fin=`date +%s.%N`
temps_tot=`echo $temps_fin-$temps_debut | bc | sed 's/....$//'`
echo "Le programme s'est terminé avec succès"
# Affichage du temps d'exécution
echo "Temps d'exécution : $temps_tot secondes"