[Stacomir-commits] r306 - pkg/stacomir/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Mar 16 12:22:09 CET 2017
Author: legrand
Date: 2017-03-16 12:22:08 +0100 (Thu, 16 Mar 2017)
New Revision: 306
Modified:
pkg/stacomir/R/BilanAnnuels.r
Log:
Modified: pkg/stacomir/R/BilanAnnuels.r
===================================================================
--- pkg/stacomir/R/BilanAnnuels.r 2017-03-16 10:05:15 UTC (rev 305)
+++ pkg/stacomir/R/BilanAnnuels.r 2017-03-16 11:22:08 UTC (rev 306)
@@ -86,6 +86,7 @@
setMethod("connect",signature=signature("BilanAnnuels"),
definition=function(object,silent=FALSE)
{
+
bilA<-object
req=new("RequeteODBC")
req at baseODBC<-get("baseODBC", envir=envir_stacomi)
@@ -96,6 +97,57 @@
dc = vector_to_listsql(bilA at dc@dc_selectionne)
tax=vector_to_listsql(bilA at taxons@data$tax_code)
std=vector_to_listsql(bilA at stades@data$std_code)
+
+ reqdiff=new("RequeteODBC")
+ reqdiff at baseODBC<-get("baseODBC", envir=envir_stacomi)
+ #Pour Marion
+ sch<-get("sch",envir=envir_stacomi) # "iav."
+ assign("sch","iav.",envir_stacomi)
+
+ reqdiff at sql= paste("select ope_dic_identifiant, extract(year from ope_date_debut) as annee_debut, extract(year from ope_date_fin) as annee_fin
+ 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('5','6','12')
+ and extract(year from ope_date_debut)>=1996
+ and extract(year from ope_date_fin)<=2015
+ and ope_dic_identifiant in ('5','6','12')
+ and lot_tax_code in ('2038')
+ and lot_std_code in ('AGG','AGJ')
+ and lot_lot_identifiant is null
+ order by ope_dic_identifiant, annee_debut,annee_fin; ",sep="")
+ reqdiff at sql<-stringr::str_replace_all(reqdiff at sql,"[\r\n\t]" , "")
+ reqdiff<-stacomirtools::connect(reqdiff)
+ diff<-new("BilanAnnuels")
+ diff at data=reqdiff at query
+
+ #If there are some operations whith year of date_debut different to the year of date_fin we need to find these operations
+ # and apply on it the overlaps function to separate fish that arrive during the first year from the all
+ #If we don't have operation on two years we apply the simple sum per year
+ if (diff at data$ope_dic_identifiant==diff at data$ope_dic_identifiant && diff at data$annee_debut!=diff at data$annee_fin){
+ reqdiffan=new("RequeteODBC")
+ reqdiffan at baseODBC<-get("baseODBC", envir=envir_stacomi)
+ #Pour Marion
+ sch<-get("sch",envir=envir_stacomi) # "iav."
+ assign("sch","iav.",envir_stacomi)
+
+ reqdiffan at sql= paste("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('5','6','12')
+ and extract(year from ope_date_debut)>=1996
+ and extract(year from ope_date_fin)<=2015
+ and ope_dic_identifiant in ('5','6','12')
+ and lot_tax_code in ('2038')
+ and lot_std_code in ('AGG','AGJ')
+ and lot_lot_identifiant is null
+ and extract(year from ope_date_debut)<>extract(year from ope_date_fin)
+ order by ope_dic_identifiant,annee; ",sep="")
+ reqdiffan at sql<-stringr::str_replace_all(reqdiffan at sql,"[\r\n\t]" , "")
+ reqdiffan<-stacomirtools::connect(reqdiffan)
+ diffan<-new("BilanAnnuels")
+ diffan at data=reqdiffan at query
+ }
+ else {
+
+
req at sql = paste(" select sum(lot_effectif) as effectif, annee, ope_dic_identifiant,lot_tax_code, lot_std_code from
(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,
@@ -111,6 +163,7 @@
req<-stacomirtools::connect(req)
bilA at data=req at query
return(bilA)
+ }
})
#' command line interface for \link{BilanAnnuels-class}
More information about the Stacomir-commits
mailing list