Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tokenaufbereiter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IMEBI
LimeSurvey
tokenaufbereiter
Commits
793be844
Commit
793be844
authored
1 month ago
by
richard beer
Browse files
Options
Downloads
Patches
Plain Diff
Anpassungen und Einfuegen eine komplett neuen Funktion
parent
09e8a0e8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
function_load.R
+143
-70
143 additions, 70 deletions
function_load.R
with
143 additions
and
70 deletions
function_load.R
+
143
−
70
View file @
793be844
...
...
@@ -30,67 +30,71 @@ if (length(commandArgs(trailingOnly = TRUE)) > 0) {
#create global variable for the readline-command
choice
<-
T
function_create_validfrom
<-
function
(
combinedDataFrame
){
#nrow(cleaned_df)
# Format für validfrom
# 2023-10-23 08:02
#erhöht den Tag immer um 1, damit das Skript ab dem nächsten Tag startet.
date
<-
paste
(
year
(
Sys.time
()),,,
sep
=
"-"
)
zyear
<-
year
(
Sys.time
())
zmonth
<-
month
(
Sys.time
())
zday
<-
day
(
Sys.time
())
+1
list_for_hour
<-
c
()
for
(
i
in
0
:
23
){
if
(
i
<
10
){
list_for_hour
<-
c
(
list_for_hour
,
paste0
(
zyear
,
"-"
,
zmonth
,
"-"
,
zday
,
" "
,
"0"
,
i
,
":00"
))
}
else
{
list_for_hour
<-
c
(
list_for_hour
,
paste0
(
zyear
,
"-"
,
zmonth
,
"-"
,
zday
,
" "
,
i
,
":00"
))
}
}
print
(
list_for_hour
)
# es werden 300-500 Mails in einer Stunde versendet.
# bei 24h werden somit zwischen 7200 und 12000 Mails versendet.
# bei 100.000 werten und 7200 Mails muss ich also über 14 Tage gehen.
# Erstelle einen leeren Vektor für die Datumswerte
date_values
<-
c
()
# Schleife von 0 bis 23 Stunden
for
(
i
in
0
:
23
)
{
# Erhöhe das Datum um eine Stunde
current_date
<-
start_date
+
hours
(
i
)
# Füge das Datum zum Vektor hinzu
date_values
<-
c
(
date_values
,
current_date
)
# Wenn die Stunde 23 ist, erhöhe den Tag um eins und setze die Stunde auf 0
if
(
i
==
23
)
{
start_date
<-
start_date
+
days
(
1
)
# Erhöhe den Tag um eins
start_date
<-
start_date
-
hours
(
23
)
# Setze die Stunde auf 0
}
}
anzahl_zeilen
<-
nrow
(
cleaned_df
)
# Schleife über die Anzahl der Zeilen
for
(
i
in
1
:
anzahl_zeilen
)
{
# Schreibe den aktuellen Wert in die Spalte 'column_name'
cleaned_df
$
validfrom
[
i
]
<-
date
# Aktualisiere den Wert nach jeweils 300 Zyklen
if
(
i
%%
300
==
0
)
{
date
<-
wert
+
1
}
}
combined_token_with_download
}
# Funktion findet keine Verwendung. -> nicht fertig geschrieben!!
# wird in Limesurvey über die Menge geregelt.
# function_create_validfrom <- function(combinedDataFrame){
# # Probleme die bei der automatischen Datumssetzung entstehen:
# # Beim übergang auf den nächsten Monat muss aufgepasst werden.
# # Format für validfrom
# # 2023-10-23 08:02
#
# #erhöht den Tag immer um 1, damit das Skript ab dem nächsten Tag startet.
# date <- paste(year(Sys.time()),,,sep="-")
# zyear <- year(Sys.time())
# zmonth <- month(Sys.time())
# zday <- day(Sys.time())+1
# list_for_hour <- c()
#
# for (i in 0:23){
# if(i<10){
# list_for_hour <- c(list_for_hour,paste0(zyear,"-",zmonth,"-",zday," ","0",i,":00"))
# } else{
# list_for_hour <- c(list_for_hour,paste0(zyear,"-",zmonth,"-",zday," ",i,":00"))
# }
# }
# print(list_for_hour)
#
# # es werden 300-500 Mails in einer Stunde versendet.
# # bei 24h werden somit zwischen 7200 und 12000 Mails versendet.
# # bei 100.000 werten und 7200 Mails muss ich also über 14 Tage gehen.
#
# # Erstelle einen leeren Vektor für die Datumswerte
# date_values <- c()
#
# # Schleife von 0 bis 23 Stunden
# for (i in 0:23) {
# # Erhöhe das Datum um eine Stunde
# current_date <- start_date + hours(i)
#
# # Füge das Datum zum Vektor hinzu
# date_values <- c(date_values, current_date)
#
# # Wenn die Stunde 23 ist, erhöhe den Tag um eins und setze die Stunde auf 0
# if (i == 23) {
# start_date <- start_date + days(1) # Erhöhe den Tag um eins
# start_date <- start_date - hours(23) # Setze die Stunde auf 0
# }
# }
#
#
# anzahl_zeilen <- nrow(cleaned_df)
#
# # Schleife über die Anzahl der Zeilen
# for (i in 1:anzahl_zeilen) {
# # Schreibe den aktuellen Wert in die Spalte 'column_name'
# cleaned_df$validfrom[i] <- date
#
# # Aktualisiere den Wert nach jeweils 300 Zyklen
# if (i %% 300 == 0) {
# date <- wert + 1
# }
# }
#
#
#
# combined_token_with_download
# }
#first: define all functions:
...
...
@@ -143,15 +147,19 @@ function_start <- function(){
cat
(
" wird verwendet, wenn TN angeschrieben werden, bei denen in der Mail keine Haushalts-ID angegeben wird.\n"
)
cat
(
" Tokenliste OHNE Haushald-ID erhält man von den wissenschaftlichen Mitarbeiter*innen\n"
)
cat
(
"-------------------------------------------------------------------------------------------------------------------\n"
)
cat
(
"5 = Tokenaufbereiter CoPrep Radiologie:\n"
)
#cat(" wird verwendet, wenn TN angeschrieben werden, bei denen in der Mail keine Haushalts-ID angegeben wird.\n")
#cat(" Tokenliste OHNE Haushald-ID erhält man von den wissenschaftlichen Mitarbeiter*innen\n")
cat
(
"-------------------------------------------------------------------------------------------------------------------\n"
)
cat
(
"9 = mir ist ein Fehler passiert. Es wird nichts gespeichert!\n"
)
function_read_prompt
()
if
(
!
choice
%in%
c
(
"1"
,
"2"
,
"3"
,
"4"
,
"9"
)){
if
(
!
choice
%in%
c
(
"1"
,
"2"
,
"3"
,
"4"
,
"
5"
,
"
9"
)){
cat
(
"\n"
)
cat
(
"\n"
)
cat
(
"##################\n"
)
cat
(
"Ungültige Auswahl! Bitte verwende: 1, 2, 3, 4 oder 9. Danke.\n"
)
cat
(
"Ungültige Auswahl! Bitte verwende: 1, 2, 3, 4
, 5
oder 9. Danke.\n"
)
cat
(
"##################\n"
)
cat
(
"\n"
)
cat
(
"\n"
)
...
...
@@ -168,13 +176,15 @@ function_start <- function(){
function_Tokenaufbereiter_MIT_HHID_als_firstname
()
}
else
if
(
choice
==
4
)
{
function_Tokenaufbereiter_OHNE_HHID
()
}
else
if
(
choice
==
5
)
{
function_Tokenaufbereiter_coprep_radiologie
()
}
else
{
function_exit
()
}
}
}
#Nummer 1
function_Tokenaufbereiter_alle_TN
<-
function
()
{
cat
(
"\n"
)
cat
(
"Tokenaufbereiter alle TN\n"
)
...
...
@@ -192,7 +202,7 @@ function_Tokenaufbereiter_alle_TN <- function() {
combined_token_with_download
<-
combined_token_with_download
|>
relocate
(
id
,
.before
=
firstname
)
#save the file
#setwd("
H
:/
01_Limesurvey_TokenVergleich
")
#setwd("
P
:/
IMEBI/DigiHero_Teilnehmerdaten/Massenmails/tokenaufbereiter/erstellte_Dateien
")
write.csv
(
combined_token_with_download
,
paste0
(
"./Umfrageteilnehmertabelle_"
,
format
(
Sys.Date
(),
"%Y_%m_%d"
),
"_alle_TN.csv"
),
row.names
=
F
)
...
...
@@ -200,6 +210,7 @@ function_Tokenaufbereiter_alle_TN <- function() {
}
#Nummer 2
function_Tokenaufbereiter_Newsletter
<-
function
()
{
cat
(
"\n"
)
cat
(
"Tokenaufbereiter Newsletter\n"
)
...
...
@@ -241,7 +252,7 @@ function_Tokenaufbereiter_Newsletter <- function() {
filter
(
!
token
%in%
token_for_newsletter_to_remove
$
token
)
#save the file
#setwd("
H
:/
01_Limesurvey_TokenVergleich
")
#setwd("
P
:/
IMEBI/DigiHero_Teilnehmerdaten/Massenmails/tokenaufbereiter/erstellte_Dateien
")
write.csv
(
combined_token_with_download
,
paste0
(
"./Umfrageteilnehmertabelle_"
,
format
(
Sys.Date
(),
"%Y_%m_%d"
),
"_Newsletter.csv"
),
row.names
=
F
)
function_end
()
...
...
@@ -252,7 +263,7 @@ function_Tokenaufbereiter_Newsletter <- function() {
}
}
# Nummer 3
function_Tokenaufbereiter_MIT_HHID_als_firstname
<-
function
()
{
cat
(
"\n"
)
cat
(
"Tokenaufbereiter MIT HHID als firstname\n"
)
...
...
@@ -303,17 +314,18 @@ function_Tokenaufbereiter_MIT_HHID_als_firstname <- function() {
combined_token_with_download
<-
combined_token_with_download
|>
relocate
(
token
,
.after
=
emailstatus
)
#save the file
#setwd("
H
:/
01_Limesurvey_TokenVergleich
")
#setwd("
P
:/
IMEBI/DigiHero_Teilnehmerdaten/Massenmails/tokenaufbereiter/erstellte_Dateien
")
write.csv
(
combined_token_with_download
,
paste0
(
"./Umfrageteilnehmertabelle_"
,
format
(
Sys.Date
(),
"%Y_%m_%d"
),
"_mit_HHID_as_firstname.csv"
),
row.names
=
F
)
function_end
()
}
else
{
#Eing
e
be: irgenwas auser [ENTER] -> Abbruch
#Eing
a
be: irgen
d
was aus
s
er [ENTER] -> Abbruch
function_exit
()
}
}
#Nummer 4
function_Tokenaufbereiter_OHNE_HHID
<-
function
()
{
cat
(
"\n"
)
cat
(
"Tokenaufbereiter OHNE HHID\n"
)
...
...
@@ -332,6 +344,7 @@ function_Tokenaufbereiter_OHNE_HHID <- function() {
if
(
choice
==
"y"
||
choice
==
""
){
#Eingabe: [ENTER] -> weiter gehts
#token_list <- read_xlsx(file.choose())
#laden und joinen
token_list
<-
tryCatch
({
read_xlsx
(
file.choose
())
...
...
@@ -351,7 +364,7 @@ function_Tokenaufbereiter_OHNE_HHID <- function() {
#save the file
setwd
(
"
H
:/
01_Limesurvey_TokenVergleich
"
)
#
setwd("
P
:/
IMEBI/DigiHero_Teilnehmerdaten/Massenmails/tokenaufbereiter/erstellte_Dateien
")
write.csv
(
combined_token_with_download
,
paste0
(
"./Umfrageteilnehmertabelle_"
,
format
(
Sys.Date
(),
"%Y_%m_%d"
),
"_ohne_HHID.csv"
),
row.names
=
F
)
function_end
()
...
...
@@ -360,11 +373,71 @@ function_Tokenaufbereiter_OHNE_HHID <- function() {
#Eingabe: irgenwas auser [ENTER] -> Abbruch
function_exit
()
}
}
#Coprep-Radiologie
#Nummer 5 _ Neu Eingefügt am 12.11.2024 nach Anfrage von Mareike
function_Tokenaufbereiter_coprep_radiologie
<-
function
()
{
cat
(
"\n"
)
cat
(
"Tokenaufbereiter für CoPrep Radiologie\n"
)
cat
(
"---------------------------------------\n"
)
if
(
use_powershell
){
cat
(
"Hast du die Datei? Press [y + ENTER]. Ansonsten kann das Script mit Eingabe von [e + ENTER] beendet werden\n"
)
}
else
{
cat
(
"Hast du die Datei? Press [ENTER]. Ansonsten kann das Script mit Eingabe von [e + ENTER] beendet werden\n"
)
}
function_read_prompt
()
if
(
choice
==
"y"
||
choice
==
""
){
#Eingabe: [ENTER] -> weiter gehts
#laden und joinen
token_list
<-
tryCatch
({
read_xlsx
(
file.choose
())
},
error
=
function
(
e
)
{
message
(
"Failure: "
,
conditionMessage
(
e
))
NULL
function_exit
()
})
names
(
token_list
)
<-
tolower
(
names
(
token_list
))
combined_token_with_download
<-
inner_join
(
token_list
,
cleaned_df
,
by
=
c
(
"hhid"
=
"token"
))
#rename
combined_token_with_download
<-
combined_token_with_download
%>%
rename
(
first
=
firstname
)
combined_token_with_download
<-
combined_token_with_download
%>%
rename
(
last
=
lastname
)
combined_token_with_download
$
lastname
<-
paste
(
combined_token_with_download
$
first
,
combined_token_with_download
$
last
,
sep
=
" "
)
combined_token_with_download
<-
combined_token_with_download
%>%
rename
(
firstname
=
hhid
)
combined_token_with_download
$
first
<-
NULL
combined_token_with_download
$
last
<-
NULL
# zeilennummer erzeugen
combined_token_with_download
<-
combined_token_with_download
%>%
mutate
(
id
=
row_number
())
#relocate
combined_token_with_download
<-
combined_token_with_download
|>
relocate
(
id
,
.before
=
firstname
)
combined_token_with_download
<-
combined_token_with_download
|>
relocate
(
lastname
,
.after
=
firstname
)
combined_token_with_download
<-
combined_token_with_download
|>
relocate
(
token
,
.after
=
emailstatus
)
#save the file
#setwd("P:/IMEBI/DigiHero_Teilnehmerdaten/Massenmails/tokenaufbereiter/erstellte_Dateien")
write.csv
(
combined_token_with_download
,
paste0
(
"./Umfrageteilnehmertabelle_"
,
format
(
Sys.Date
(),
"%Y_%m_%d"
),
"_CoPrep_Radiologie.csv"
),
row.names
=
F
)
function_end
()
}
else
{
#Eingabe: irgendwas ausser [ENTER] -> Abbruch
function_exit
()
}
}
function_exit
<-
function
()
{
cat
(
"\n"
)
cat
(
"Script wird beendet. Es erfolgt keine Speicherung irgendwelcher Dateien.\n"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment