version corrigée pour que ça fonctionne encore
This commit is contained in:
commit
ac04797b07
8 changed files with 1751 additions and 0 deletions
15
.gitignore
vendored
Normal file
15
.gitignore
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
# History files
|
||||
.Rhistory
|
||||
.Rapp.history
|
||||
|
||||
# Example code in package build process
|
||||
*-Ex.R
|
||||
|
||||
# RStudio files
|
||||
.Rproj.user/
|
||||
*.Rproj
|
||||
|
||||
# produced vignettes
|
||||
vignettes/*.html
|
||||
vignettes/*.pdf
|
||||
.Rproj.user
|
166
LICENSE
Normal file
166
LICENSE
Normal file
|
@ -0,0 +1,166 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# pipelineViz
|
||||
Working with pipeline incidents data from http://ouvert.canada.ca/data/fr/dataset/da1be1b4-5e2b-4c9a-ae0e-e8551fd6b265
|
27
dd-20150216.csv
Normal file
27
dd-20150216.csv
Normal file
|
@ -0,0 +1,27 @@
|
|||
Nom de colonne PODS,Nom du champ,Description du champ
|
||||
OCC_NO,Numéro d'événement,"Le numéro d'identification de l'événement. Le « P » sert à désigner le mode pipeline, suivi de deux chiffres qui indiquent l'année de l'événement. La lettre qui vient après l'année sert à désigner la région de l'événement, suivie du numéro de séquence attribué par le système PODS."
|
||||
OCC_YEAR,Année,L'année civile de l'événement.
|
||||
OCC_DATE,Date,"La date de l'événement, soit AAAA-MM-JJ. Le format de la date dépend de l'application utilisée pour ouvrir le fichier csv."
|
||||
CLASS_ID,Catégorie,"La classification d'enquête du BST pour l'événement. Lorsqu'un événement est en cours d'évaluation, la valeur 10 lui est assignée temporairement pour indiquer qu'il est « en cours d'évaluation »."
|
||||
OCC_TYPE,Type d'événement,Détermine si l'événement était un accident ou un incident à signaler.
|
||||
ACC_INC_TYPE,Type d'accident/d'incident,Détermine le type de l'accident ou de l'incident à signaler.
|
||||
PROVINCE,Province,La province du lieu de l'événement.
|
||||
LOCATION,Lieu,Ville ou village le plus proche du lieu où s'est produit l'évènement.
|
||||
TERRAIN_TYPE,Type de terrain,Zonage autorisé de l'utilisation des terres du lieu où s'est produit l'évènement.
|
||||
FACILITY_NAME,Nom de l'installation,Nom de l'installation.
|
||||
FACILITY_TYPE,Type d'installation,"Type d'installation tel que : station de compression, usine de traitement du gaz naturel, station de pompage, etc."
|
||||
PIPELINE_CO,Société de pipeline,Nom de la société de pipeline.
|
||||
PIPELINE_TYPE_CO,Type de société de pipeline,Type de société de pipeline : gaz ou HPV/FPV (haute/faible pression de vapeur)
|
||||
PROD_RELEASED_IND,Indicateur de produit déversé,Pour indiquer si un produit a été déversé relativement ou consécutivement à l'évènement.
|
||||
PRODUCT_TYPE,Type de produit,Type de produit déversé relativement ou consécutivement à l'évènement.
|
||||
QUANTITY_LOST,Quantité perdue,Quantité de produit déversée lorsque le déversement peut être quantifié et que cette information a été communiquée au BST. On mesure cette quantité en mètres cubes.
|
||||
DETECTION_METHOD,Méthode de détection,Moyen par lequel l'évènement a été détecté.
|
||||
LOCATION_ON_PIPELINE,Emplacement sur le pipeline,L'emplacement sur le pipeline où l'évènement s'est produit.
|
||||
ENVIRO_DAMAGE_IND,Indicateur de dégâts environnementaux,Pour indiquer si des dégâts ont été causés à l'environnement.
|
||||
PROPERTY_DAMAGE_IND,Indicateur de dégâts matériels,Pour indiquer si des biens ont été endommagés.
|
||||
FIRE_IND,Indicateur d'incendie,Indique s'il y a eu un incendie durant l'événement ou à la suite de l'événement.
|
||||
EXPLOSION_IND,Indicateur d'explosion,Indique s'il y a eu une explosion durant l'événement ou à la suite de l'événement.
|
||||
NO_EVACUATED,Nombre évacuées,Le nombre total de personnes évacuées à la suite de l'événement.
|
||||
FATALITIES,Total de morts,Nombre total connu de morts.
|
||||
SERIOUS_INJURIES,Total de blessés graves,Nombre total connu de blessés graves.
|
||||
PRODUCTION_DT,Date de production,La date et l'heure à laquelle le fichier de données a été généré. Format de date AAAA-MM-JJThh:mm:ss.
|
|
BIN
geocodedLocations.Rdata
Normal file
BIN
geocodedLocations.Rdata
Normal file
Binary file not shown.
BIN
openstreetmap1.Rdata
Normal file
BIN
openstreetmap1.Rdata
Normal file
Binary file not shown.
1362
p2015-07-fr.csv
Normal file
1362
p2015-07-fr.csv
Normal file
File diff suppressed because it is too large
Load diff
179
pipelineViz.Rmd
Normal file
179
pipelineViz.Rmd
Normal file
|
@ -0,0 +1,179 @@
|
|||
---
|
||||
title: "PipelineViz"
|
||||
author: "François Pelletier"
|
||||
date: "26 août 2015"
|
||||
output:
|
||||
html_document:
|
||||
fig_caption: yes
|
||||
fig_height: 8
|
||||
fig_width: 10
|
||||
keep_md: yes
|
||||
number_sections: yes
|
||||
toc: yes
|
||||
---
|
||||
|
||||
# Analyse d'un jeu de données ouvertes
|
||||
|
||||
Source: [Données sur les évenements de pipeline de Janvier 2004 au présent](http://ouvert.canada.ca/data/fr/dataset/da1be1b4-5e2b-4c9a-ae0e-e8551fd6b265)
|
||||
|
||||
## Chargement du dictionnaire de données
|
||||
|
||||
```{r}
|
||||
# install.packages(c("data.table", "dplyr","maps","ggmap"))
|
||||
options(unzip = 'internal')
|
||||
library("data.table")
|
||||
library("dplyr")
|
||||
library("maps")
|
||||
library("ggmap")
|
||||
library("reshape2")
|
||||
library("lubridate")
|
||||
library("rpart")
|
||||
library("rpart.plot")
|
||||
```
|
||||
|
||||
## Lecture des données
|
||||
|
||||
```{r}
|
||||
datadict <- read.csv(file = "dd-20150216.csv",header = TRUE, stringsAsFactors = TRUE, encoding = "latin1") %>%
|
||||
as.data.table()
|
||||
donnees <- read.csv(file = "p2015-07-fr.csv",header = TRUE,stringsAsFactors = TRUE) %>%
|
||||
as.data.table()
|
||||
|
||||
class_donnees <- sapply(donnees,class)
|
||||
character_columns <- names(donnees)[class_donnees == "character"]
|
||||
num_columns <- names(donnees)[class_donnees != "character"]
|
||||
|
||||
donnees_conv <- cbind(donnees[, lapply(.SD, iconv, "utf-8", "latin1"),
|
||||
.SDcols = character_columns],donnees[,.SD,.SDcols = num_columns])
|
||||
```
|
||||
|
||||
## Geocoder les incidents
|
||||
|
||||
```{r, eval=FALSE}
|
||||
LocationsUnique <- unique(donnees_conv[,.(LOCATION,PROVINCE)])
|
||||
catLocationsUnique <- unique(paste(LocationsUnique$LOCATION, ifelse(!is.na(LocationsUnique$PROVINCE),LocationsUnique$PROVINCE, ""), "CANADA", sep = " "))
|
||||
geocodedLocations <- cbind(LocationsUnique,geocode(catLocationsUnique))
|
||||
save(geocodedLocations, file = "geocodedLocations.Rdata")
|
||||
```
|
||||
|
||||
## Joindre les données géocodées aux données existantes
|
||||
|
||||
```{r}
|
||||
load("geocodedLocations.Rdata")
|
||||
donnees_conv2 <-as.data.table(merge(donnees_conv,geocodedLocations, by=c("LOCATION","PROVINCE")))
|
||||
donnees_conv3 <- donnees_conv2[!is.na(PROVINCE) & !is.na(LOCATION)]
|
||||
```
|
||||
|
||||
## Préparation de la carte de fond
|
||||
|
||||
```{r, eval=FALSE}
|
||||
range_lat <- range(donnees_conv3$lat)
|
||||
range_lon <- range(donnees_conv3$lon)
|
||||
|
||||
openstreetmap1 <- get_openstreetmap(bbox = c(left = range_lon[1],
|
||||
bottom = range_lat[1],
|
||||
right = range_lon[2],
|
||||
top = range_lat[2]),
|
||||
scale = 32500000,
|
||||
format = c("png"),
|
||||
crop = TRUE, messaging = FALSE, urlonly = FALSE, color = c("color", "bw"))
|
||||
|
||||
save(openstreetmap1, file = "openstreetmap1.Rdata")
|
||||
```
|
||||
|
||||
## Chargement de la carte de fond
|
||||
|
||||
```{r}
|
||||
load("openstreetmap1.Rdata")
|
||||
```
|
||||
|
||||
|
||||
## Carte des incidents avec déversement
|
||||
|
||||
```{r, dev='png'}
|
||||
donnees_incidents <- donnees_conv3[QUANTITY_LOST > 0]
|
||||
ggmap(openstreetmap1) +
|
||||
geom_point(aes(x = lon,
|
||||
y = lat,
|
||||
colour = PRODUCT_TYPE,
|
||||
size = QUANTITY_LOST),
|
||||
data = donnees_incidents) +
|
||||
scale_size(range = c(2, 8), name=datadict[datadict$Nom.de.colonne.PODS=="QUANTITY_LOST"][2]) +
|
||||
scale_colour_discrete(name=datadict[datadict$Nom.de.colonne.PODS=="PRODUCT_TYPE"][2]) +
|
||||
ggtitle(label = "Incidents avec déversement") +
|
||||
xlab("Longitude") +
|
||||
ylab("Latitude")
|
||||
```
|
||||
|
||||
## initiales
|
||||
|
||||
Cette fonction extrait les initiales d'un mot
|
||||
|
||||
```{r}
|
||||
initials <- function(str)
|
||||
{
|
||||
regex <- '(?<=^|\\s|-)[[:alpha:]]'
|
||||
ini <- regmatches(str, gregexpr(regex, str, perl=TRUE))
|
||||
toupper(sapply(ini, paste0, collapse=''))
|
||||
}
|
||||
```
|
||||
|
||||
## Distribution des accidents et incidents
|
||||
|
||||
```{r}
|
||||
dist_incidents <- donnees_conv3 %>%
|
||||
select(PROVINCE,OCC_TYPE,PRODUCT_TYPE) %>%
|
||||
group_by(PROVINCE=factor(initials(PROVINCE)),OCC_TYPE=factor(OCC_TYPE)) %>%
|
||||
summarise(N = n())
|
||||
```
|
||||
|
||||
```{r, dev='png'}
|
||||
ggplot(dist_incidents,aes(x=PROVINCE,fill=OCC_TYPE)) +
|
||||
geom_bar(aes(y=N),stat="identity") +
|
||||
ggtitle(paste0(datadict[datadict$Nom.de.colonne.PODS=="OCC_TYPE"][2],", par ",datadict[datadict$Nom.de.colonne.PODS=="PROVINCE"][2])) +
|
||||
scale_fill_discrete(name=datadict[datadict$Nom.de.colonne.PODS=="OCC_TYPE"][2]) +
|
||||
xlab(datadict[datadict$Nom.de.colonne.PODS=="PROVINCE"][2]) +
|
||||
ylab("Nombre")
|
||||
```
|
||||
|
||||
## Série chronologique
|
||||
|
||||
```{r}
|
||||
data_serie <- donnees_conv3 %>%
|
||||
select(PIPELINE_CO,OCC_DATE,QUANTITY_LOST) %>%
|
||||
mutate(N=1, date_clean = parse_date_time(OCC_DATE, orders = "%Y-%m-%d")) %>%
|
||||
arrange(PIPELINE_CO,date_clean) %>%
|
||||
group_by(PIPELINE_CO,date_clean) %>%
|
||||
summarise(Nsum = sum(N)) %>%
|
||||
mutate(Ncumsum = cumsum(Nsum))
|
||||
```
|
||||
|
||||
### Nombre d'évènements cumulés
|
||||
|
||||
```{r, dev='png'}
|
||||
ggplot(data_serie,aes(x=date_clean,y=Ncumsum,color=PIPELINE_CO)) +
|
||||
geom_line(stat="identity") +
|
||||
xlab("Date") +
|
||||
ylab("Nombre d'indicents cumulés") +
|
||||
ggtitle("Nombre d'incidents cumulés, par compagnie")
|
||||
```
|
||||
|
||||
## Arbre de décision
|
||||
```{r}
|
||||
tree1 <- rpart(OCC_TYPE~FACILITY_TYPE+PROD_RELEASED_IND+PIPELINE_TYPE_CO+ENVIRO_DAMAGE_IND+PROPERTY_DAMAGE_IND+FIRE_IND+EXPLOSION_IND, data=donnees_conv3, method="class")
|
||||
summary(tree1)
|
||||
```
|
||||
|
||||
### Affichage de l'arbre de décision
|
||||
|
||||
```{r}
|
||||
rpart.plot::rpart.plot(tree1, main = paste0("Arbre de classification pour ",
|
||||
datadict[datadict$Nom.de.colonne.PODS=="OCC_TYPE"]$Nom.du.champ))
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue