+ Näytä koodi- Piilota koodi
library(OpasnetUtils)
sivu <- 'Liikenteen palvelumarkkinat'
jaeid <- "L6"
liit <- NULL
sis <- NULL
names <- c(
'Liikenne ja viestintä palveluna',
'Liikenteen palvelumarkkinat',
'Liikenteen energiareformi',
'Älykkäät käyttäjälähtöiset digitaaliset palvelut',
'Monipuoliset sisällöt',
'Oma Painotus Teema I',
'Digitaalinen tieto hyvinvoinnin ja kilpailuedun lähteenä',
'Käyttäjän oikeus omaan tietoonsa ja sen hyödyntämiseen',
'Luottamuksen palauttaminen internettiin',
'Datan liiketoiminta- ja käyttömahdollisuudet',
'Tieto ja digitalisaatio liikenteessä',
'Oma Painotus Teema II',
'Infrastruktuuri kasvun alustana',
'Toimintavarmuus ja turvallisuus',
'Liikenne- ja viestintäyhteydet',
'Arktinen strategia',
'Liikennejärjestelmän rahoitus ja taloudellinen ohjaus',
'Oma Painotus Teema III'
)
ids <- c(4248, 4253, 4254, 4255, 4256, 4257, 4250, 4258, 4259, 4260, 4261, 4262, 4251, 4263, 4264, 4265, 4266, 4267)
ids <- paste("Op_fi", ids, sep = "")
id <- ids[match(sivu, names)]
jaehakukone <- function(main_ident, series_id, page, page_ident, jaeid = NULL) {
main_subset <- "jakeet"
added_subset <- "jakeenlisays"
deleted_subset <- "jakeenpoistot"
comment_subset <- "kommentit"
deleted_comment_subset <- "Kommenttipoistot"
general_loc <- "Yleinen"
dl <- TRUE
filter <- list()
filter$Sivu <- c(page, general_loc)
if (!is.null(jaeid)){
a <- !grepl("^[a-zA-Z]", jaeid)
if(sum(a) > 0) {
filter$JaeID <- jaeid[a]
} else {
dl <- FALSE
}
}
if (dl) {
dat <- opbase.data(
main_ident,
series_id,
main_subset,
include = filter
)
} else {
dat <- data.frame()
}
if (!is.null(jaeid)){
a <- grepl("^L", jaeid)
dl <- TRUE
if(sum(a) > 0) {
filter$JaeID <- jaeid[a]
} else {
dl <- FALSE
}
}
datlisays <- NULL
if (dl) {
datlisays <- tryCatch(
opbase.data(
main_ident,
subset = added_subset,
include = filter
),
error = function(...) return(NULL)
)
}
if (!is.null(datlisays)) dat <- rbind(dat, datlisays)
datpoisto <- tryCatch(
opbase.data(
main_ident,
subset = deleted_subset,
include = filter
),
error = function(...) return(NULL)
)
if (!is.null(datpoisto)) dat <- dat[!dat$JaeID %in% datpoisto$Result,]
filter <- list()
if (!is.null(jaeid)){
a <- grepl("^K", jaeid)
dl <- TRUE
if(sum(a) > 0) {
filter$JaeID <- jaeid[a]
} else {
dl <- FALSE
}
}
if (length(filter) == 0) filter <- NULL
komm <- NULL
if (dl) {
komm <- tryCatch(
opbase.data(
page_ident,
subset = comment_subset,
include = filter
),
error = function(...) return(NULL)
)
}
if (!is.null(komm)) {
komm <- komm[c("Obs", "Kommentti")]
colnames(komm) <- c("JaeID", "Result")
kommpois <- tryCatch(
opbase.data(
page_ident,
subset = deleted_comment_subset
),
error = function(...) return(NULL)
)
if (!is.null(kommpois)) {
komm <- komm[!komm$JaeID %in% kommpois$Kommenttinro,]
}
if (nrow(komm) > 0) {
komm$JaeID <- paste("K", komm$JaeID, sep = "")
komm$Sivu <- sivu
}
dat <- rbind(dat, komm)
}
return(dat)
}
test <- jaehakukone("Op_fi4362", 12748, sivu, id, jaeid)
oprint(test)
rel1 <- tryCatch(
opbase.data("Op_fi4362", subset = "Relaatiot", include = list(Sivu = sivu, Jae = jaeid)),
error = function(...) return(NULL)
)
rel2 <- tryCatch(
opbase.data("Op_fi4362", subset = "Relaatiot", include = list(Sivu = sivu, Liittymäjae = jaeid)),
error = function(...) return(NULL)
)
if (is.null(rel1)) rel1 <- data.frame()
if (is.null(rel2)) rel2 <- data.frame()
rel <- rbind(rel1, rel2)
if (!is.null(liit)) rel <- rel[rel$"Liittyminen" == liit , ]
if (!is.null(sis)) rel <- rel[rel$"Sisällytys" == sis , ]
if (nrow(rel) == 0) {
oprint("Jakeelle ei löytynyt kysyttyjä relaatioita tietokannassa.")
} else {
liittymäjae <- jaehakukone("Op_fi4362", 12748, sivu, id, c(as.character(rel$Jae), as.character(rel$Liittymäjae)))
#jae <- rbind(jae, liittymäjae)
temp <- rel
colnames(temp)[colnames(temp) == "Jae"] <- "Lähtöjae"
colnames(liittymäjae)[colnames(liittymäjae) == "JaeID"] <- "Liittymäjae"
temp <- temp[colnames(temp) != "Result"]
rel_out1 <- merge(liittymäjae, temp)
colnames(liittymäjae)[colnames(liittymäjae) == "Liittymäjae"] <- "Lähtöjae"
rel_out2 <- merge(liittymäjae, temp)
rel_out1 <- rel_out1[rel_out1$Liittmäjae != jaeid,]
if (nrow(rel_out1)) {
oprint(
rel_out1[c("Lähtöjae", "Liittymäjae", "Liittyminen", "Sisällytys", "Result")],
include.rownames = FALSE,
caption = "Liittyvät lähtöjakeet",
caption.placement = "top"
)
}
rel_out2 <- rel_out2[rel_out2$Lähtöjae != jaeid,]
if (nrow(rel_out2)) {
oprint(
rel_out2[c("Lähtöjae", "Liittymäjae", "Liittyminen", "Sisällytys", "Result")],
include.rownames = FALSE,
caption = "Liittyvät liittymä-/kohdejakeet",
caption.placement = "top"
)
}
}
| |