Spaces:
No application file
No application file
File size: 11,984 Bytes
12759cd |
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 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
<?php
class Impact
{
public $data = null;
const CAUSE_TRAVAUX = 'TRAVAUX';
const CAUSE_PERTURBATION = 'PERTURBATION';
const SEVERITY_PERTURBEE = 'PERTURBEE';
const SEVERITY_BLOQUANTE = 'BLOQUANTE';
const SEVERITY_INFORMATION = 'INFORMATION';
const TYPE_RALENTI = 'RALENTI';
const TYPE_RALENTI_FORTEMENT = 'RALENTI_FORTEMENT';
const TYPE_PERTURBATION_PARTIELLE = 'PERTURBATION_PARTIELLE';
const TYPE_PERTURBATION_PARTIELLE_FORTE = 'PERTURBATION_PARTIELLE_FORTE';
const TYPE_PERTURBATION_TOTALE = 'PERTURBATION_TOTALE';
const TYPE_PERTURBATION_TOTALE_FORTE = 'PERTURBATION_TOTALE_FORTE';
const TYPE_PERTURBATION_TOTALE_REPRISE = 'PERTURBATION_TOTALE_REPRISE';
const TYPE_INTERRUPTION_PARTIELLE = 'INTERRUPTION_PARTIELLE';
const TYPE_INTERRUPTION_TOTALE = 'INTERRUPTION_TOTALE';
const TYPE_STATIONS_NON_DESSERVIES = 'STATIONS_NON_DESSERVIES';
const TYPE_GARES_NON_DESSERVIES = 'GARES_NON_DESSERVIES';
const TYPE_TRAINS_STATIONNENT = 'STATIONS_NON_DESSERVIES';
const TYPE_TRAINS_SUPPRIMES = 'TRAINS_SUPPRIMES';
const TYPE_CHANGEMENT_HORAIRES = 'CHANGEMENT_HORAIRES';
const TYPE_CHANGEMENT_COMPOSITION = 'CHANGEMENT_COMPOSITION';
const TYPE_AUCUNE = 'AUCUNE';
const MODE_RER = 'RapidTransit';
const MODE_TRAIN = 'LocalTrain';
const MODE_METRO = 'Metro';
const MODE_TRAMWAY = 'Tramway';
protected $dateStart = null;
protected $dateEnd = null;
protected $type = null;
protected $dateCreation = null;
public function __construct($data, File $file) {
$this->data = $data;
foreach($this->data->applicationPeriods as $period) {
$this->dateEnd = $period->end;
if($this->dateStart && $period->begin > $this->dateStart && $period->begin < $this->dateEnd) {
continue;
}
$this->dateStart = $period->begin;
}
$this->dateCreation = $file->getDate();
$userFile = __DIR__.'/../datas/json_userinfos/'.(clone $file->getDate())->modify('-3 hours')->format('Ymd').'.json';
if(is_file($userFile)) {
$userDisruptions = (array) json_decode(file_get_contents($userFile));
if(isset($userDisruptions[$this->getId()])) {
$this->type = $userDisruptions[$this->getId()]->type;
}
}
}
public function getId() {
return $this->data->id;
}
public function hasRealDisruptionId() {
return isset($this->data->disruption_id);
}
public function getDistruptionId() {
if($this->hasRealDisruptionId()) {
return "distruption_id:".$this->data->disruption_id;
}
return $this->getDistruptionIdCalculate();
}
public function getDistruptionIdCalculate() {
if(in_array($this->getMode(), [self::MODE_RER, self::MODE_TRAIN])) {
return "distruption_id_calculate:".md5($this->getId());
}
return "distruption_id_calculate:".md5($this->getUniqueTitle());
}
public function setDateCreation($date) {
return $this->dateCreation = $date;
}
public function getDateCreation() {
return $this->dateCreation;
}
public function getTitle() {
return $this->data->title;
}
public function isSameImpact($impact) {
if(in_array($this->getMode(), [self::MODE_METRO, self::MODE_TRAMWAY])) {
return $this->getUniqueTitle() == $impact->getUniqueTitle();
}
if(in_array($this->getMode(), [self::MODE_RER, self::MODE_TRAIN])) {
return $this->getTitle().$this->getSeverity() == $impact->getTitle().$impact->getSeverity() && ($this->isInPeriod($impact->getDateStart()) || $this->isInPeriod($impact->getDateEnd()));
}
}
public function getUniqueTitle() {
return str_replace([" - Reprise progressive / trafic reste très perturbé", " - Reprise progressive / trafic reste perturbé", " - Arrêt non desservi", " - Reprise progressive"," - Stationnement prolongé", " - Trafic interrompu", " - Trafic perturbé", " - Trafic très perturbé", " - Trains stationnent", " - Train stationne"], "", $this->getTitle());
}
public function getSuggestionType() {
if(preg_match("/(trafic sera très perturbé|trafic sera interrompu|le trafic de la ligne [A-Z0-9]+ sera perturbé|trafic sera également interrompu|trafic de la ligne sera légèrement perturbé|rendez-vous la veille|pourraient perturber la circulation)/i", $this->getMessagePlainText())) {
return self::TYPE_AUCUNE;
}
if(preg_match("/Le trafic est fortement perturbé[àéèîếa-zA-z\ '0-9]*entre/i", $this->getMessagePlainText())) {
return self::TYPE_PERTURBATION_PARTIELLE_FORTE;
}
if(preg_match("/Le trafic est fortement perturbé sur l'ensemble de la ligne/i", $this->getMessagePlainText())) {
return self::TYPE_PERTURBATION_TOTALE_FORTE;
}
if(preg_match("/Le trafic reprend mais reste perturbé sur l'ensemble de la ligne/i", $this->getMessagePlainText())) {
return self::TYPE_PERTURBATION_TOTALE_REPRISE;
}
if(preg_match('/Le trafic est interrompu entre/i', $this->getMessagePlainText())) {
return self::TYPE_INTERRUPTION_PARTIELLE;
}
if(preg_match("/trafic (est |)interrompu sur l'ensemble de la ligne/i", $this->getMessagePlainText())) {
return self::TYPE_INTERRUPTION_TOTALE;
}
if(preg_match("/Le trafic est perturbé sur l'ensemble de la ligne/i", $this->getMessagePlainText())) {
return self::TYPE_PERTURBATION_TOTALE;
}
if(preg_match("/Le trafic est perturbé[àéèîếa-zA-z\ '0-9]*entre/i", $this->getMessagePlainText())) {
return self::TYPE_PERTURBATION_PARTIELLE;
}
if(preg_match("/(Trains|Tramways)?[a-zA-z\ ]*supprimés?/i", $this->getMessagePlainText())) {
return self::TYPE_TRAINS_SUPPRIMES;
}
if(preg_match("/Gares? non desservies?/i", $this->getTitle())) {
return self::TYPE_GARES_NON_DESSERVIES;
}
if(preg_match("/Le trafic est fortement ralenti/i", $this->getMessagePlainText())) {
return self::TYPE_RALENTI_FORTEMENT;
}
if(preg_match("/Le trafic est ralenti/i", $this->getMessagePlainText())) {
return self::TYPE_RALENTI;
}
if(preg_match("/ralenti/i", $this->getTitle())) {
return self::TYPE_RALENTI;
}
if(preg_match("/arrêt bus de remplacement/i", $this->getTitle())) {
return self::TYPE_AUCUNE;
}
if(preg_match('/(Alerte orages|Alerte forte pluies et orages|Vigilance orange Météo France)/i', $this->getTitle())) {
return self::TYPE_AUCUNE;
}
if(preg_match("/risquent de perturber le trafic/i", $this->getMessagePlainText())) {
return self::TYPE_AUCUNE;
}
if(preg_match("/risque de perturbation/i", $this->getTitle())) {
return self::TYPE_AUCUNE;
}
if(preg_match('/Modifications de compositions/', $this->getTitle())) {
return self::TYPE_AUCUNE;
}
if(preg_match('/adaptation/i', $this->getTitle())) {
return self::TYPE_AUCUNE;
}
if(preg_match('/offre de transport est adaptée/i', $this->getTitle())) {
return self::TYPE_AUCUNE;
}
if(preg_match("/(modifications horaires|horaires modifiés|Modifications d'horaires|Changement d'horaires|modification horaire|Changement de service)/i", $this->getTitle())) {
return self::TYPE_CHANGEMENT_HORAIRES;
}
if(preg_match('/Modification de desserte/', $this->getTitle())) {
return self::TYPE_AUCUNE;
}
if(preg_match('/train court/i', $this->getTitle())) {
return self::TYPE_AUCUNE;
}
if(preg_match("/(modification arrêt de bus|Emplacement des bus de remplacement)/i", $this->getTitle())) {
return self::TYPE_AUCUNE;
}
return null;
}
public function getSuggestionOrigine() {
if(preg_match('/(Métro|Tramway)/', $this->getTitle())) {
return preg_replace('/ - .*$/', '', preg_replace('/^[^:]*: /', '', $this->getTitle()));
}
return null;
}
public function getMessage() {
return $this->data->message;
}
public function getCause() {
return $this->data->cause;
}
public function getSeverity() {
return $this->data->severity;
}
public function getType() {
return $this->type;
}
public function getColorClass() {
$cssClass = 'ok';
if($this->getCause() == Impact::CAUSE_PERTURBATION && $this->getSeverity() == Impact::SEVERITY_BLOQUANTE) {
$cssClass = 'bq';
}
if($cssClass == 'ok' && $this->getCause() == Impact::CAUSE_TRAVAUX) {
$cssClass = 'tx';
}
if($this->getCause() == Impact::CAUSE_PERTURBATION && $this->getSeverity() == Impact::SEVERITY_PERTURBEE) {
$cssClass = 'pb';
}
return $cssClass;
}
public function getLigneId() {
return preg_replace('/^[^ ]+ /', '', strtoupper(implode("", $this->getLignes())));
}
public function getMode() {
return preg_replace('/ [^ ]+$/', '', implode("", $this->getLignes()));
}
public function getLignes() {
return isset($this->data->lines) ? $this->data->lines : [];
}
public function isToExclude() {
if($this->getSeverity() == self::SEVERITY_INFORMATION) {
return true;
}
if($this->getType() == self::TYPE_AUCUNE) {
return true;
}
if($this->getType() == self::TYPE_CHANGEMENT_HORAIRES) {
return true;
}
if($this->getSuggestionType() == self::TYPE_AUCUNE) {
return true;
}
if($this->getSuggestionType() == self::TYPE_CHANGEMENT_HORAIRES) {
return true;
}
if(!count($this->getLignes())) {
return true;
}
return false;
}
public function getDateStart() {
return DateTime::createFromFormat('Ymd\THis', $this->dateStart);
}
public function setDateStart($date) {
return $this->dateStart = $date;
}
public function getDateEnd() {
return DateTime::createFromFormat('Ymd\THis', $this->dateEnd);
}
public function setDateEnd($date) {
return $this->dateEnd = $date;
}
public function getDuration() {
$dateEnd = $this->getDateEnd();
if($this->getDateEnd() > new DateTime()) {
$dateEnd = new DateTime();
}
return $dateEnd->diff($this->getDateStart());
}
public static function generateDurationText(DateInterval $duration) {
$nbMinutes = ($duration->d * 24 * 60) + ($duration->h * 60) + $duration->i;
$nbHours = ($duration->d * 24) + ($duration->h);
if($nbMinutes < 180) {
return sprintf("%d min", $nbMinutes);
}
return sprintf("%d h", $nbHours);
}
public function getDurationText() {
return self::generateDurationText($this->getDuration());
}
public function isInProgress() {
$current = new DateTime();
return $current > $this->getDateStart() && $current < $this->getDateEnd();
}
public function isInPeriod(DateTime $date) {
return $date >= $this->getDateStart() && $date <= $this->getDateEnd();
}
public function getMessagePlainText() {
return str_replace('"', '', html_entity_decode(strip_tags(str_replace("<br>", "\n", $this->getMessage()))));
}
public function getLastUpdate() {
return DateTime::createFromFormat('Ymd\THis', $this->data->lastUpdate);
}
}
|