Skip to content

Commit

Permalink
dimension parameters names #22
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienird committed Jul 18, 2023
1 parent 9bb8581 commit 27c2665
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions tunaatlas_scripts/generation/convert_units.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ convert_units = function (con, df_input, df_conversion_factor, codelist_geoident
cat(paste0("\n BEGIN tunaatlas::convert_units() => converting units and measures"))
columns_df_input = colnames(df_input)
df_input <- data.table(df_input)
units_source <- unique(df_conversion_factor$unit)
units_source <- unique(df_conversion_factor$measurement_unit)
units_target <- unique(df_conversion_factor$unit_target)
df_conversion_factor$conversion_factor = as.numeric(df_conversion_factor$conversion_factor)
if ("geographic_identifier" %in% colnames(df_conversion_factor)) {
Expand Down Expand Up @@ -85,15 +85,15 @@ convert_units = function (con, df_input, df_conversion_factor, codelist_geoident
df_input <- left_join(df_input, data_zone_0)
df_input$conv_factor_df_geo_id[which(!is.na(df_input$zone0))] <- "0"
df_input <- df_input %>% dplyr::select(-zone0, -unit_target)
class(df_input$value) <- "numeric"
class(df_input$measurement_value) <- "numeric"
}
if (nrow(df_input) == nrow(left_join(df_input, df_conversion_factor) %>%
filter(is.na(conversion_factor)))) {
if (length(intersect(unique(df_conversion_factor$gear),
unique(df_input$gear))) == 0) {
if (length(intersect(unique(df_conversion_factor$gear_type),
unique(df_input$gear_type))) == 0) {
df_conversion_factor_no_gear <- df_conversion_factor %>%
group_by_at(setdiff(colnames(df_conversion_factor),
"gear")) %>% summarise(conversion_factor = mean(conversion_factor))
"gear_type")) %>% summarise(conversion_factor = mean(conversion_factor))
df_input <- left_join(df_input, df_conversion_factor_no_gear)
}
}
Expand All @@ -108,12 +108,12 @@ convert_units = function (con, df_input, df_conversion_factor, codelist_geoident
# summarise(sum_unit_source_before_conversion = sum(value)) %>%
# filter(!is.na(unit_target))
index.not_na.conv_factor <- which(!is.na(df_input$conversion_factor))
df_input$value[index.not_na.conv_factor] <- df_input$value[index.not_na.conv_factor] *
df_input$measurement_value[index.not_na.conv_factor] <- df_input$measurement_value[index.not_na.conv_factor] *
df_input$conversion_factor[index.not_na.conv_factor]
# stats_after_conversion <- df_input %>% group_by(unit, unit_target) %>%
# summarise(sum_unit_target_after_conversion = sum(value)) %>%
# filter(!is.na(unit_target))
df_input$unit[index.not_na.conv_factor] <- df_input$unit_target[index.not_na.conv_factor]
df_input$measurement_unit[index.not_na.conv_factor] <- df_input$unit_target[index.not_na.conv_factor]
df_input <- df_input %>% dplyr::select(all_of(columns_df_input))
# sum_after_conversion <- df_input %>% group_by(unit) %>%
# summarise(sum_value_after_conversion = sum(value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function_raising_georef_to_nominal<-function(con, opts,entity,

cat("filter by source_authority\n")
dataset_to_raise<-dataset_to_raise[which(dataset_to_raise$source_authority %in% source_authority_filter),]
config$logger.info(paste0("Total catch for dataset_to_raise before raising is ",sum(dataset_to_compute_rf$measurement_value)," \n"))
config$logger.info(paste0("Total catch for dataset_to_raise before raising is ",sum(dataset_to_raise$measurement_value)," \n"))

dataset_to_compute_rf<-dataset_to_compute_rf[which(dataset_to_compute_rf$source_authority %in% source_authority_filter),]
config$logger.info(paste0("Total catch for dataset_to_compute_rf before raising is ",sum(dataset_to_compute_rf$measurement_value)," \n"))
Expand All @@ -49,8 +49,8 @@ function_raising_georef_to_nominal<-function(con, opts,entity,

cat(paste0("raise_get_rf function has",nrow(df_rf),"rows \n"))
cat(paste0(" write csv file to check \n"))
filename <- paste0("/tmp/DFPartialInfo_rf_",gsub(Sys.time(),pattern = " ", replacement = "_"),".csv")
write.csv(x = df_rf, file = filename)
# filename <- paste0("DFPartialInfo_rf_",gsub(Sys.time(),pattern = " ", replacement = "_"),".csv")
# write.csv(x = df_rf, file = filename)

cat("function raise_get_rf has been executed ! \n")
config$logger.info(paste0("Rows number in df_rf ",nrow(df_rf)," \n"))
Expand All @@ -65,7 +65,7 @@ function_raising_georef_to_nominal<-function(con, opts,entity,

# raise dataset
cat("Executing raise_incomplete_dataset_to_total_dataset \n")
source("https://raw.githubusercontent.com/firms-gta/geoflow-tunaatlas/master/sardara_functions/raise_incomplete_dataset_to_total_dataset.R")
source("~/Documents/geoflow-tunaatlas/sardara_functions/raise_incomplete_dataset_to_total_dataset.R")

data_raised<-raise_incomplete_dataset_to_total_dataset(df_input_incomplete = dataset_to_raise,
df_input_total = nominal_dataset_df,
Expand All @@ -90,11 +90,11 @@ function_raising_georef_to_nominal<-function(con, opts,entity,
if (raising_raise_only_for_PS_LL==TRUE){

# @juldebar => check if gear codes are correct
gears_PS_LL<-dbGetQuery(con,"SELECT distinct(src_code) FROM gear.gear_mapping_view WHERE trg_codingsystem='geargroup_tunaatlas' AND trg_code IN ('PS','LL')")$src_code
gears_PS_LL<-dbGetQuery(con,"SELECT distinct(src_code) FROM gear_type.gear_type_mapping_view WHERE trg_codingsystem='geargroup_tunaatlas' AND trg_code IN ('PS','LL')")$src_code
# config$logger.info("Now filtering gear codes with those returned by SLQ query", gears_PS_LL)

dataset_not_PS_LL<-dataset_to_raise %>% filter(!(gear_type %in% gears_PS_LL))
dataset_to_raise<-dataset_to_raise %>% filter(gear_type %in% gears_PS_LL)
dataset_not_PS_LL<-dataset_to_raise %>% dplyr::filter(!(gear_type %in% gears_PS_LL))
dataset_to_raise<-dataset_to_raise %>% dplyr::filter(gear_type %in% gears_PS_LL)

config$logger.info(paste0("Since option raising_raise_only_for_PS_LL==TRUE, kept rows number is ",nrow(dataset_to_raise)," and number of removed rows is ",nrow(dataset_not_PS_LL),"\n"))

Expand Down

0 comments on commit 27c2665

Please sign in to comment.