-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
textuur voor files met 1 staal en voor staalnamen waar geen appendix …
…aanhangt in de vorm van _xx (#16)
- Loading branch information
Showing
5 changed files
with
61 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,56 @@ | ||
## LD Texture_processor COULTER files from LAB | ||
## Programmed by Pieter Verschelde 9/06/2022 | ||
## adapted by Bruno De Vos | ||
## readapted by Pieter Verschelde 28/08/2024 | ||
|
||
### IMPORTANT | ||
### !!! Be sure to have VPN connection to link to LIMS system !!! | ||
|
||
|
||
#load necessary libraries | ||
|
||
library(dplyr) | ||
library(jsonlite) | ||
library(tidyverse) #package met veel datafunctionaliteit | ||
library(DBI) #package voor DB communicatie | ||
library(tidyverse) | ||
library(DBI) | ||
library(readxl) | ||
|
||
# Download/update met laatste versie | ||
|
||
remotes::install_github('inbo/inbolims') | ||
library(inbolims) #package die de verwerking van de textuurfiles regelt | ||
getwd() #gewoon om te tonen in welke werkdirectory je zit | ||
|
||
## CENTRAL LOOP | ||
|
||
## load raw filenames in folder "C:/R/IN/LDTEX/" voor labproject V-22V057 (Cmon) | ||
|
||
source_path <- "tests/testdata/" | ||
source_pattern <- "sample" | ||
target_path <- "tests/testdata/result/" | ||
|
||
list_fn <- list.files(path = source_path, | ||
pattern = source_pattern, | ||
full.names = TRUE) | ||
n_list_fn <- length(list_fn) | ||
|
||
## Loop to process all files serially #### | ||
for (i in 1:n_list_fn) { | ||
filename <- list_fn[i] | ||
|
||
#parse de file naar een geldige R dataset | ||
# Download/update inbolims (core texture parsing functionalities) | ||
remotes::install_github("inbo/inbolims") | ||
library(inbolims) | ||
getwd() | ||
|
||
# get input files | ||
file_input_path <- "." | ||
files_list <- list.files(file_input_path, | ||
pattern = "V-24V057", | ||
full.names = TRUE) | ||
n_files <- length(files_list) | ||
|
||
#output path | ||
target_dir <- "./output" | ||
dir.create(target_dir) | ||
|
||
#db connection | ||
conn <- lims_connect() #connect to dwh to link lab id | ||
|
||
# main loop parsing | ||
for (i in 1:n_files) { | ||
filename <- files_list[i] | ||
print(filename) | ||
textuur_parsed <- parse_texture_content(filename, delim = "\t") | ||
View(textuur_parsed) | ||
|
||
#interpreteer de dataset tot een inhoudelijk bruikbaar formaat | ||
textuur_interpreted <- interpret_texture_content(textuur_parsed) | ||
View(textuur_interpreted) | ||
|
||
#maak een connectie met het LIMS datawarehouse | ||
conn <- lims_connect() #connect to dwh | ||
textuur_linked <- link_labo_id(conn, textuur_interpreted) | ||
dim(textuur_linked) | ||
|
||
#schrijf de files weg in /R/OUT/LDTEX/ | ||
write_texture_files(target_path, textuur_linked) | ||
|
||
} # loop end | ||
|
||
#### Process files and save to CSV and json #### | ||
|
||
|
||
# listFNOUT<-list.files(path="C:/R_scripts/_GIT_REPO/Cmon/out/LDTEX/2023/deel2", pattern=".csv", full.names = TRUE) | ||
# nlist<-length(listFNOUT) | ||
# | ||
# | ||
# for (j in 1:nlist) { | ||
# TEMPfile<-read.csv2(listFNOUT[j]) | ||
# dim(TEMPfile) | ||
# UNIfile<-distinct(TEMPfile) ## remove all duplicate rows | ||
# dim(UNIfile) | ||
# # write output csv file | ||
# write.csv2(UNIfile,listFNOUT[j], row.names = FALSE) | ||
# | ||
# # run function to convert to json and write in same directory | ||
# TEX_CSV2JSON(listFNOUT[j]) | ||
# } | ||
# | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
write_texture_files(target_dir, textuur_linked) | ||
} | ||
|
||
#conversion output to json | ||
files_list_out <- list.files(target_dir, pattern = ".csv", full.names = TRUE) | ||
n_files_out <- length(files_list_out) | ||
|
||
for (j in 1:n_files_out) { | ||
tmp <- read.csv2(files_list_out[j]) | ||
tmp_uni <- distinct(tmp) #remove all duplicate rows | ||
write.csv2(tmp_uni, files_list_out[j], row.names = FALSE) | ||
tex_csv_2_json(files_list_out[j]) | ||
} |