[Stacomir-commits] r300 - in pkg/stacomir: R data inst/config inst/tests/testthat
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Mar 13 16:33:48 CET 2017
Author: briand
Date: 2017-03-13 16:33:47 +0100 (Mon, 13 Mar 2017)
New Revision: 300
Modified:
pkg/stacomir/R/BilanAnnuels.r
pkg/stacomir/R/BilanMigrationInterAnnuelle.r
pkg/stacomir/R/setAs.r
pkg/stacomir/data/bM_Arzal.rda
pkg/stacomir/inst/config/generate_data.R
pkg/stacomir/inst/tests/testthat/test-02BilanMigration.R
pkg/stacomir/inst/tests/testthat/test-06Bilan_MigrationInterAnnuelle.R
Log:
Consistency between numbers for BilanAnnuels, BilanMigrationInterAnnuelle, BilanMigrationMultiple
with checks developped in testhat
Modified: pkg/stacomir/R/BilanAnnuels.r
===================================================================
--- pkg/stacomir/R/BilanAnnuels.r 2017-03-13 13:22:20 UTC (rev 299)
+++ pkg/stacomir/R/BilanAnnuels.r 2017-03-13 15:33:47 UTC (rev 300)
@@ -100,7 +100,7 @@
(select *, extract(year from ope_date_debut) as annee FROM ",get("sch",envir=envir_stacomi),"t_operation_ope ",
" join ",get("sch",envir=envir_stacomi),"t_lot_lot on lot_ope_identifiant=ope_identifiant where ope_dic_identifiant in",dc,
" and extract(year from ope_date_debut)>=", anneedebut,
- " and extract(year from ope_date_fin)<=", anneefin,
+ " and extract(year from ope_date_debut)<=", anneefin,
" and ope_dic_identifiant in ", dc,
" and lot_tax_code in ", tax,
" and lot_std_code in ",std,
Modified: pkg/stacomir/R/BilanMigrationInterAnnuelle.r
===================================================================
--- pkg/stacomir/R/BilanMigrationInterAnnuelle.r 2017-03-13 13:22:20 UTC (rev 299)
+++ pkg/stacomir/R/BilanMigrationInterAnnuelle.r 2017-03-13 15:33:47 UTC (rev 300)
@@ -143,7 +143,7 @@
for (y in 1:length(missing_years)){
Y<-missing_years[y]
bM=new("BilanMigration")
- funout(gettextf("Running Bilanmigraton for year %s",Y,domain="R-StacomiR"))
+ funout(gettextf("Running Bilanmigration for year %s",Y,domain="R-StacomiR"))
bM=choice_c(bM,
dc=dic[i],
taxons=object at taxons@data$tax_nom_latin,
Modified: pkg/stacomir/R/setAs.r
===================================================================
--- pkg/stacomir/R/setAs.r 2017-03-13 13:22:20 UTC (rev 299)
+++ pkg/stacomir/R/setAs.r 2017-03-13 15:33:47 UTC (rev 300)
@@ -13,6 +13,17 @@
})
+setAs("BilanMigrationInterAnnuelle","BilanMigrationMult",function(from){
+ bilanMigrationMult=new("BilanMigrationMult")
+ bilanMigrationMult at dc=from at dc
+ bilanMigrationMult at taxons=from at taxons
+ bilanMigrationMult at stades=from at stades
+ bilanMigrationMult at pasDeTemps@dateDebut=strptime(stringr::str_c(from at anneeDebut@annee_selectionnee,"-01-01"),format="%Y-%m-%d")
+ bilanMigrationMult at pasDeTemps@nbStep=364
+ return(bilanMigrationMult)
+ })
+
+
setAs("BilanMigration","BilanMigrationMult",function(from){
bMM=new("BilanMigrationMult")
bMM at dc=from at dc
Modified: pkg/stacomir/data/bM_Arzal.rda
===================================================================
(Binary files differ)
Modified: pkg/stacomir/inst/config/generate_data.R
===================================================================
--- pkg/stacomir/inst/config/generate_data.R 2017-03-13 13:22:20 UTC (rev 299)
+++ pkg/stacomir/inst/config/generate_data.R 2017-03-13 15:33:47 UTC (rev 300)
@@ -112,7 +112,7 @@
stacomi(gr_interface=FALSE,
login_window=FALSE,
- database_expected=FALSE)
+ database_expected=TRUE)
bM_Arzal=new("BilanMigration")
baseODBC<-get("baseODBC",envir=envir_stacomi)
baseODBC[c(2,3)]<-rep("iav",2)
Modified: pkg/stacomir/inst/tests/testthat/test-02BilanMigration.R
===================================================================
--- pkg/stacomir/inst/tests/testthat/test-02BilanMigration.R 2017-03-13 13:22:20 UTC (rev 299)
+++ pkg/stacomir/inst/tests/testthat/test-02BilanMigration.R 2017-03-13 15:33:47 UTC (rev 300)
@@ -96,6 +96,47 @@
rm("envir_stacomi",envir =.GlobalEnv)
})
+test_that("Test that different sums are the same, for BilanMigration, BilanMigrationInterAnnuelle, BilanAnnuels",
+ {
+ stacomi(gr_interface=FALSE,
+ login_window=FALSE,
+ database_expected=TRUE)
+ # overriding user schema
+ baseODBC<-get("baseODBC",envir=envir_stacomi)
+ baseODBC[c(2,3)]<-rep("iav",2)
+ assign("baseODBC",baseODBC,envir_stacomi)
+ sch<-get("sch",envir=envir_stacomi) # "iav."
+ assign("sch","iav.",envir_stacomi)
+ # this chunk is not launched from examples but loads the bM_Arzal dataset if connection works
+ data("bM_Arzal")
+ bM_Arzal<-calcule(bM_Arzal,silent=TRUE)
+ expect_equal(
+ sum(bM_Arzal at calcdata$dc_5$data$Effectif_total),
+ sum(bM_Arzal at data[bM_Arzal at data$ope_dic_identifiant==5,"value"]))
+ write_database(object=bM_Arzal,silent=TRUE)
+ # using setAs to transform the bilanMigration into BilanMigrationInterAnnuelle
+ bili=as(bM_Arzal,"BilanMigrationInterAnnuelle")
+ bila=as(bili,"BilanAnnuels")
+ bila<-connect(bila)
+ # we test that the BilanAnnuel has the same number as
+ # BilanMigration
+ expect_equal(
+ sum(bM_Arzal at calcdata$dc_5$data$Effectif_total),
+ bila at data$effectif,
+ label="The sum of number in the BilanMigration are different to the
+number in the BilanAnnuel class"
+ )
+
+ bili<-connect(bili,check=TRUE)
+ expect_equal(
+ sum(bM_Arzal at calcdata$dc_5$data$Effectif_total),
+ sum(bili at data$bjo_valeur[bili at data$bjo_labelquantite=="Effectif_total"]),
+ label="The sum of number in the BilanMigration are different to the
+ number in the BilanMigrationInterAnnuelle")
+ rm("envir_stacomi",envir =.GlobalEnv)
+ })
+
+
test_that("print method works",
{
stacomi(gr_interface=FALSE,
Modified: pkg/stacomir/inst/tests/testthat/test-06Bilan_MigrationInterAnnuelle.R
===================================================================
--- pkg/stacomir/inst/tests/testthat/test-06Bilan_MigrationInterAnnuelle.R 2017-03-13 13:22:20 UTC (rev 299)
+++ pkg/stacomir/inst/tests/testthat/test-06Bilan_MigrationInterAnnuelle.R 2017-03-13 15:33:47 UTC (rev 300)
@@ -123,3 +123,60 @@
bmi_cha<-connect(bmi_cha)
})
+
+test_that("Test that different sums are the same, for BilanMigrationInterAnnuelle, BilanMigrationMult",
+ {
+ stacomi(gr_interface=FALSE,
+ login_window=FALSE,
+ database_expected=TRUE)
+ # overriding user schema
+ baseODBC<-get("baseODBC",envir=envir_stacomi)
+ baseODBC[c(2,3)]<-rep("iav",2)
+ assign("baseODBC",baseODBC,envir_stacomi)
+ sch<-get("sch",envir=envir_stacomi) # "iav."
+ assign("sch","iav.",envir_stacomi)
+ # this chunk is not launched from examples but loads the bM_Arzal dataset if connection works
+ bmi<-new("BilanMigrationInterAnnuelle")
+ # the following will load data for size,
+ # parameters 1786 (total size) C001 (size at video control)
+ # dc 5 and 6 are fishways located on the Arzal dam
+ # two stages are selected
+ bmi<-choice_c(bmi,
+ dc=6,
+ taxons=c("Anguilla anguilla"),
+ stades=c("AGJ"),
+ anneedebut=1997,
+ anneefin=1997,
+ silent=TRUE)
+ bmi<-connect(bmi,silent=TRUE)
+ bmM<-as(bmi,"BilanMigrationMult")
+ # we still need to load the associated classes properly
+ # so we need to launch the choice method.
+ bmM<-choice_c(bmM,
+ dc=bmM at dc@dc_selectionne,
+ taxons=bmM at taxons@data$tax_code,
+ stades=bmM at stades@data$std_code,
+ datedebut=as.character(bmM at pasDeTemps@dateDebut),
+ datefin=as.character(as.POSIXlt(DateFin(bmM at pasDeTemps))))
+ bmM<-charge(bmM)
+ bmM<-connect(bmM)
+
+ expect_equal(
+ sum(bmM at data[bmM at data$ope_dic_identifiant==6,"value"]),
+ sum(bmi at data$bjo_valeur[bmi at data$bjo_labelquantite=="Effectif_total"])
+ )
+ ######################
+ # Test for BilanAnnuel
+ #####################
+ bila=as(bmi,"BilanAnnuels")
+ bila<-connect(bila)
+ # we test that the BilanAnnuel has the same number as
+ # BilanMigration
+ expect_equal(
+ sum(bmM at data[bmM at data$ope_dic_identifiant==6,"value"]),
+ bila at data$effectif,
+ label="The sum of number in the BilanMigration are different to the
+ number in the BilanAnnuel class"
+ )
+ rm("envir_stacomi",envir =.GlobalEnv)
+ })
More information about the Stacomir-commits
mailing list