From 19985dbb8c0aa66dc4bf7905abc1148de909097d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 11 Jan 2022 12:35:47 +0100 Subject: prvi-commit --- .../R/app/rsconnect/shinyapps.io/1kadsa/vizual.dcf | 10 + .../modules/mod_vizualizacija/R/app/vizual.R | 58 ++++++ .../class.SurveyVizualizacija.php | 211 +++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 admin/survey/modules/mod_vizualizacija/R/app/rsconnect/shinyapps.io/1kadsa/vizual.dcf create mode 100644 admin/survey/modules/mod_vizualizacija/R/app/vizual.R create mode 100644 admin/survey/modules/mod_vizualizacija/class.SurveyVizualizacija.php (limited to 'admin/survey/modules/mod_vizualizacija') diff --git a/admin/survey/modules/mod_vizualizacija/R/app/rsconnect/shinyapps.io/1kadsa/vizual.dcf b/admin/survey/modules/mod_vizualizacija/R/app/rsconnect/shinyapps.io/1kadsa/vizual.dcf new file mode 100644 index 0000000..7607ca2 --- /dev/null +++ b/admin/survey/modules/mod_vizualizacija/R/app/rsconnect/shinyapps.io/1kadsa/vizual.dcf @@ -0,0 +1,10 @@ +name: vizual +title: +username: +account: 1kadsa +server: shinyapps.io +hostUrl: https://api.shinyapps.io/v1 +appId: 1050397 +bundleId: 2263472 +url: https://1kadsa.shinyapps.io/vizual/ +when: 1564051902.65834 diff --git a/admin/survey/modules/mod_vizualizacija/R/app/vizual.R b/admin/survey/modules/mod_vizualizacija/R/app/vizual.R new file mode 100644 index 0000000..e3c0b95 --- /dev/null +++ b/admin/survey/modules/mod_vizualizacija/R/app/vizual.R @@ -0,0 +1,58 @@ +#--------------- NEEDED LIBRARIES ---------------# +# devtools::install_github("dreamRs/esquisse") +library(shiny) +library(esquisse) +#------------- //NEEDED LIBRARIES// -------------# + + +#-------------------------- PHP ----------------------------# +# Passing arguments to an R script from command lines +# params <- commandArgs(trailingOnly = TRUE) +# # CSV name +# filename <- params[1] +#---------------------- //PHP// ----------------------------# + + +# ---------------------- LOAD AND PREPARE DATA FOR THE APP --------------------------# +df <- + read.csv2( + url("https://test.1ka.si/admin/survey/modules/mod_vizualizacija/temp/data.csv"), + header = TRUE, + fill = TRUE, + stringsAsFactors = FALSE + ) + +# Omit the first row od the data base (Text questions) +if (df[1, 1] == ("Ustreznost") | + df[1, 1] == ("Relevance")) { + df <- df[2:nrow(df), ] +} +# Label Missing values so the app will recognize them +df[df < 0] <- NA +# -------------------- //LOAD AND PREPARE DATA FOR THE APP// ------------------------# + + +#------------------------------- SHINY APP -----------------------------# + +# CREATE USER INTERFACE (UI) # +#============================# +ui <- fluidPage( + tags$div( # needs to be in fixed height container + style = "position: fixed; top: 0; bottom: 0; right: 0; left: 0;", + esquisserUI(id = "esquisse") + ) +) + +# Define server logic required to draw plots # +#============================================# +server <- function(input, output, session) { + + callModule(module = esquisserServer, id = "esquisse") + +} +#----------------------------- //SHINY APP// ---------------------------# + + +# ShinyApp function to create a Shiny app object from the +# UI/server pair that we defined above. +shinyApp(ui, server) \ No newline at end of file diff --git a/admin/survey/modules/mod_vizualizacija/class.SurveyVizualizacija.php b/admin/survey/modules/mod_vizualizacija/class.SurveyVizualizacija.php new file mode 100644 index 0000000..1c9884b --- /dev/null +++ b/admin/survey/modules/mod_vizualizacija/class.SurveyVizualizacija.php @@ -0,0 +1,211 @@ +ul evealvacija + if ((int)$anketa > 0){ + $this->anketa = $anketa; + + # polovimo vrsto tabel (aktivne / neaktivne) + SurveyInfo :: getInstance()->SurveyInit($this->anketa); + if (SurveyInfo::getInstance()->getSurveyColumn('db_table') == 1) { + $this->db_table = '_active'; + } + } + } + + + // Prikazemo vsebino zavihka v analizah + public function display(){ + + // Zenkrat iframe aplikacije na zunanjem strezniku + //echo ''; + + echo '
'; + echo ''; + + // Zgeneriramo zacasne csv datoteke + $this->prepareCSV(); + + //$this->execute(); + } + + // Odpremom popup z vizualizacijo + public function execute(){ + global $site_path; + global $site_url; + global $lang; + global $admin_type; + + // Zgeneriramo zacasne csv datoteke + $this->prepareCSV(); + + // Poklicemo R skripto in zgeneriramo pdf + $script = $site_path . SCRIPT_FOLDER . '/Visualize_df.R'; + $file_name = 'data_'.$this->anketa.'.csv'; + + //$out = exec('Rscript '.$script.' '.$file_name.' 2>&1', $output, $return_var); + + // Testiranje - izpis errorjev + /*echo '
'; + echo 'Rscript '.$script; + //echo '
'.$out.'
'; + var_dump($output); + echo '
';*/ + + // Na koncu pobrisemo zacasne datoteke + $this->deleteTemp(); + + // Ugasnemo skripto:) + die(); + } + + // Pripravimo zacasne datoteke + private function prepareCSV(){ + global $site_path; + + $temp_folder = $site_path . TEMP_FOLDER.'/'; + + + // Poskrbimo za datoteko s podatki + $SDF = SurveyDataFile::get_instance(); + $SDF->init($this->anketa); + $SDF->prepareFiles(); + + $_headFileName = $SDF->getHeaderFileName(); + $_dataFileName = $SDF->getDataFileName(); + + if ($_headFileName != null && $_headFileName != '') { + $_HEADERS = unserialize(file_get_contents($_headFileName)); + } + else { + echo 'Error! Empty file name!'; + } + + // Zaenkrat dopuscamo samo status 6 in brez lurkerjev + $status_filter = '('.STATUS_FIELD.' ~ /6|5/)&&('.LURKER_FIELD.'==0)'; + + $start_sequence = 2; + $end_sequence = $_HEADERS['_settings']['metaSequence']-1; + + $field_delimit = ';'; + + // Filtriramo podatke po statusu in jih zapisemo v temp folder + if (IS_WINDOWS) { + $out = shell_exec('awk -F"|" "BEGIN {{OFS=\",\"} {ORS=\"\n\"}} '.$status_filter.'" '.$_dataFileName.' | cut -d "|" -f '.$start_sequence.'-'.$end_sequence.' >> '.$temp_folder.'/temp_data_'.$this->anketa.'.dat'); + } + else { + $out = shell_exec('awk -F"|" \'BEGIN {{OFS=","} {ORS="\n"}} '.$status_filter.'\' '.$_dataFileName.' | cut -d \'|\' -f '.$start_sequence.'-'.$end_sequence.' >> '.$temp_folder.'/temp_data_'.$this->anketa.'.dat'); + } + + + // Ustvarimo koncni CSV + if ($fd = fopen($temp_folder.'/temp_data_'.$this->anketa.'.dat', "r")) { + + //$fd2 = fopen($temp_folder.'/data_'.$this->anketa.'.csv', "w"); + $fd2 = fopen($temp_folder.'/data.csv', "w"); + + $convertType = 1; // kateri tip konvertiranja uporabimo + $convertTypes[1] = array('charSet' => 'windows-1250', + 'delimit' => ';', + 'newLine' => "\n", + 'BOMchar' => "\xEF\xBB\xBF"); + # dodamo boomchar za utf-8 + fwrite($fd2, $convertTypes[$convertType]['BOMchar']); + + # naredimo header row + foreach ($_HEADERS AS $spid => $spremenljivka) { + if (count($spremenljivka['grids']) > 0) { + foreach ($spremenljivka['grids'] AS $gid => $grid) { + foreach ($grid['variables'] AS $vid => $variable ){ + if ($spremenljivka['tip'] !== 'sm' && !($variable['variable'] == 'uid' && $variable['naslov'] == 'User ID')){ + $output1 .= strip_tags($variable['variable']).$field_delimit; + $output2 .= '"'.strip_tags($variable['naslov']).'"'.$field_delimit; + } + } + } + } + } + + fwrite($fd2, $output1."\r\n"); + fwrite($fd2, $output2."\r\n"); + + while ($line = fgets($fd)) { + + $temp = array(); + $temp = explode('|', $line); + + $line = '"' . str_replace(array("\r","\n","\"","|"), array("","","",'";"'), $line) . '"'; + + // Spremenimo encoding v windows-1250 + //$line = iconv("UTF-8","Windows-1250//TRANSLIT", $line); + + fwrite($fd2, $line); + fwrite($fd2, "\r\n"); + } + + fclose($fd2); + } + fclose($fd); + + + // Na koncu pobrisemo temp datoteke + if (file_exists($temp_folder.'/temp_data_'.$this->anketa.'.dat')) { + unlink($temp_folder.'/temp_data_'.$this->anketa.'.dat'); + } + } + + // Pobrisemo zacasne datoteke + private function deleteTemp(){ + global $site_path; + + $temp_folder = $site_path . TEMP_FOLDER.'/'; + + if (file_exists($temp_folder.'/data_'.$this->anketa.'.csv')) { + unlink($temp_folder.'/data_'.$this->anketa.'.csv'); + } + + // Pobrisemo zacasno CSV datoteko s podatki - UGASNEMO, KER VCASIH NE DELA:) + if (file_exists($temp_folder.'/evoli.csv')) { + unlink($temp_folder.'/evoli.csv'); + } + + // Pobrisemo pdf grafe ki so bili vstavljeni v porocilo + $files = glob($site_path . RESULTS_FOLDER . '/part-predmet-slike/*'); + foreach($files as $file){ + if(is_file($file)) + unlink($file); + } + + // Pobrisemo še vse ostalo v rezultatih + $files = glob($site_path . RESULTS_FOLDER . '/*'); + foreach($files as $file){ + if(is_file($file)) + unlink($file); + } + } + +} \ No newline at end of file -- cgit v1.2.3