Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update TD #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
out.csv
13 changes: 13 additions & 0 deletions antares-rpackageTD.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: ISO8859-1

RnwWeave: Sweave
LaTeX: pdfLaTeX
79 changes: 53 additions & 26 deletions init.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
library(dplyr)
library(antaresRead)
setSimulationPath()

### chargement des donn�es depuis une �tude ANTARES====
# Cette �tape peut ne pas �tre pr�sent�e
setSimulationPath()
areas <- readAntares() # equivalent to readAntares(areas="all")
links <- readAntares(links="all")
save(areas,links, file="TD_RTE.Rdata")


### chargement des donn�es depuis un Rdata ====
load("TD_RTE.Rdata")

# visualiser la base, en afficher les statistiques descriptives ====
Expand All @@ -29,15 +33,14 @@ areas[,mean(`MRG. PRICE`),by=area]
areas[,.(prix_moyen = mean(`MRG. PRICE`)),by=area]


# calculer pour chaque area a chauqe tranche horainre le MRG price moyen ====
# calculer pour chaque area a chaque tranche horaire le MRG prix moyen ====

areas %>% group_by(area,hour) %>% summarise(prix_moyen=mean(`MRG. PRICE`))
areas[,mean(`MRG. PRICE`),by=.(area,hour)]
areas[,.(prix_moyen = mean(`MRG. PRICE`)),by=.(area,hour)]



# calculer pour chaque area a chaque heure la moyenne de tous les maximum ====
# calculer pour chaque area a chaque heure la moyenne de tous les maximums (exemple de maximum : BALANCE_max) ====
areas %>% group_by(area,hour) %>% summarise_each(funs(mean),ends_with("max"))
areas %>% group_by(area,hour) %>% summarise_each(funs(mean),contains("max"))
areas %>% group_by(area,hour) %>%
Expand All @@ -54,6 +57,8 @@ areas[,lapply(.SD,mean),

areas[,c("area","hour",select_vars(names(areas), contains("max"))),with=FALSE][,lapply(.SD,mean),by=.(area,hour)]
areas[,c("area","hour",select_vars(names(areas), contains("max"))),with=TRUE]

## effectuer un benchemark sur les traitements pr�c�dents
microbenchmark::microbenchmark(areas[,lapply(.SD,mean),
.SDcols= select_vars(names(areas), contains("max")),
by=.(area,hour)],areas[,c("area","hour",select_vars(names(areas), contains("max"))),with=FALSE][,lapply(.SD,mean),by=.(area,hour)]
Expand Down Expand Up @@ -81,34 +86,44 @@ areas2 <- areas %>% filter(area=="a")
areas2b <- areas[area=="a",]



# supprimer la colonne area ====

areas3 <- areas2 %>% select(-area)
areas3b <- areas2b[,area:=NULL]
areas3b <- areas2b[,area:=NULL] #la colonne area est aussi supprim� dans areas2b

##� voir si vous voulez aborder ce point ici
is.null(areas3b$area) #TRUE
is.null(areas2b$area) #TRUE

areas2b <- areas[area=="a",]
areas4b <- copy(areas2b)
areas4b<-areas4b[,area:=NULL]

# ne garder que les colonnes de cout et de prix et d'emission de CO2 ====
is.null(areas4b$area) #TRUE
is.null(areas2b$area) #FALSE

areas4 <- areas3 %>% select(contains("COST"),contains("PRICE"),`CO2 EMIS.`)
# ne garder que les colonnes de consommation et d'�olien ====

areas4 <- areas3 %>% select(contains("LOAD"),contains("WIND"), `OV. COST`)

areas4b <- areas3b[,
select_vars(names(areas3b),contains("COST"),contains("PRICE"),`CO2 EMIS.`),
select_vars(names(areas3b),contains("LOAD"),contains("WIND")),
with=FALSE]

# rajouter une colonne qui correspon au ratio de CO2 EMIS. par PRICE MRG.====
# Arrondir le résulat a 2 chiffres apres la virgule ====
# rajouter une colonne qui correspond au ratio de `WIND` par LOAD ====
# Arrondir le resulat a 2 chiffres apres la virgule ====

areas5 <- areas4 %>% mutate(ratio =`CO2 EMIS.`/`MRG. PRICE`,
areas5 <- areas4 %>% mutate(ratio=WIND/LOAD,
ratio=round(ratio,2))


areas4b[,ratio := round(`CO2 EMIS.`/`MRG. PRICE`,2)]
areas4b[,ratio := `CO2 EMIS.`/`MRG. PRICE`
areas4b[,ratio := round(WIND/LOAD,2)]
areas4b[,ratio := WIND/LOAD
][,ratio := round(ratio,2)]


# changer le nom de la colonne CO2 EMIS. par "emission_co2 ====
setnames(areas4b,'CO2 EMIS.',"emission_co2")
# changer le nom de la colonne OV. COST par "cout_total ====
setnames(areas4,'OV. COST',"cout_total")


# exporter le resultat en CSV====
Expand All @@ -117,23 +132,30 @@ setnames(areas4b,'CO2 EMIS.',"emission_co2")
areas %>%
filter(area=="a") %>%
select(-area) %>%
select(contains("COST"),contains("PRICE"),`CO2 EMIS.`) %>%
mutate(ratio =`CO2 EMIS.`/`MRG. PRICE`,
select(contains("LOAD"),contains("WIND"),`OV. COST`) %>%
mutate(ratio=WIND/LOAD,
ratio=round(ratio,2)) %>%
arrange(ratio) %>%
rename(emission_co2 = `CO2 EMIS.`) %>%
rename(cout_total = `OV. COST`) %>%
write.csv2(file="out.csv",row.names=FALSE)

browseURL("out.csv")

### Cr�er un package R contenant cette derni�re instruction ====
## document� (roxygen2) et test� (testhat)

areas[area=="a",
select_vars(names(areas),contains("COST"),contains("PRICE"),`CO2 EMIS.`),
with=FALSE][,ratio := round(`CO2 EMIS.`/`MRG. PRICE`,2)][order(ratio)]
select_vars(names(areas),contains("LOAD"),contains("WIND"),`OV. COST`),
with=FALSE][,ratio := round(WIND/LOAD,2)][order(ratio)]

browseURL("out.csv")

### Cr�er un package R contenant cette derni�re instruction ====
## document� (roxygen2) et test� (testhat)


browseURL("out.csv")

# changer le nom de la colonne CO2 EMIS. par "emission_co2 ===
# changer le nom de la colonne OV. COST par "cout_total ====


# exporter le résultat dans un fichier csv
Expand All @@ -151,13 +173,18 @@ browseURL("out.csv")
areas %>%
filter(area=="a") %>%
select(-area) %>%
select(contains("COST"),contains("PRICE"),`CO2 EMIS.`) %>%
mutate(ratio =`CO2 EMIS.`/`MRG. PRICE`,
select(contains("LOAD"),contains("WIND"),`OV. COST`) %>%
mutate(ratio =WIND/LOAD,
ratio=round(ratio,2)) %>%
arrange(ratio) %>%
rename(emission_co2 = `CO2 EMIS.`) %>%
rename(cout_total = `OV. COST`) %>%
write.csv2(file="out.csv",row.names=FALSE)

browseURL("out.csv")

areas


### Cr�er un package R contenant cette derni�re instruction ====
## document� (roxygen2) et test� (testhat)