diff --git a/.github/workflows/main_istat-terra-r.yml b/.github/workflows/main_istat-terra-r.yml deleted file mode 100644 index b6af37d..0000000 --- a/.github/workflows/main_istat-terra-r.yml +++ /dev/null @@ -1,50 +0,0 @@ -# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy -# More GitHub Actions for Azure: https://github.com/Azure/actions - -name: Terra R Server CI/CD - -on: - workflow_dispatch: - -jobs: - build: - runs-on: 'ubuntu-latest' - - steps: - - uses: actions/checkout@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Log in to registry - uses: docker/login-action@v1 - with: - registry: https://istatcosmo.azurecr.io/ - username: ${{ secrets.AzureAppService_ContainerUsername }} - password: ${{ secrets.AzureAppService_ContainerPassword }} - - - name: Build and push container image to registry - uses: docker/build-push-action@v2 - with: - push: true - tags: istatcosmo.azurecr.io/cosmo-r-service:run-${{ github.run_number }},istatcosmo.azurecr.io/cosmo-r-service:latest - context: ./terra-backend/R-server/ - build-args: "DOCKER_TAG=run-${{ github.run_number }}" - - - deploy: - runs-on: ubuntu-latest - needs: build - environment: - name: 'production' - url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - steps: - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v2 - with: - app-name: 'istat-cosmo-r' - slot-name: 'production' - publish-profile: ${{ secrets.AzureAppService_PublishProfile_RSERVICE }} - images: 'istatcosmo.azurecr.io/cosmo-r-service:run-${{ github.run_number }}' diff --git a/terra-backend/R-server/.dockerignore b/terra-backend/R-server/.dockerignore deleted file mode 100644 index 6320cd2..0000000 --- a/terra-backend/R-server/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -data \ No newline at end of file diff --git a/terra-backend/R-server/Dockerfile b/terra-backend/R-server/Dockerfile deleted file mode 100644 index 18bbae0..0000000 --- a/terra-backend/R-server/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM rocker/r-base - -ARG DOCKER_TAG -ENV APP_VERSION=$DOCKER_TAG -RUN echo "Bulding Docker image version: $APP_VERSION" - -COPY libraries-bin.txt . -COPY libraries.R . - -RUN apt-get update && \ - cat libraries-bin.txt | xargs apt-get install -y -qq -RUN Rscript libraries.R && rm libraries-bin.txt libraries.R - -COPY . /app -WORKDIR /app - -CMD ["Rscript", "api-controller.R"] diff --git a/terra-backend/R-server/api-controller.R b/terra-backend/R-server/api-controller.R deleted file mode 100644 index 2f3a78c..0000000 --- a/terra-backend/R-server/api-controller.R +++ /dev/null @@ -1,83 +0,0 @@ - library(RestRserve) - library(jsonlite) - library(data.table) - library(stringr) - library(stringi) - library(dplyr) - - - -basedir = ("./rscript") -basedirData=("./data") - -source(paste(basedir,"api_loadcomext_function.r",sep="/")) -source(paste(basedir,"api_data_function.R",sep="/")) -source(paste(basedir,"api_itsa.R",sep="/")) - - -app = Application$new() - -COMEXT_IMP<-load_comext("1") -COMEXT_EXP<-load_comext("2") - -#### FUNZIONI - -add_cors <- function(.req, .res) { - .res$set_header("Access-Control-Allow-Origin", "*") - .res$set_header("Access-Control-Allow-Methods","*") - .res$set_header("Access-Control-Allow-Headers", "*") -} - -add_get_cors <- function(path, fun) { - app$add_get( - path = path, - FUN = function (.req, .res) { - fun(.req, .res) - add_cors(.req, .res) - }) - - app$add_route(path, - method = "OPTIONS", - FUN = function(.req, .res) { - .res$set_header("Allow", "GET, OPTIONS") - add_cors(.req, .res) - }) -} - -add_get_cors( - path = "/hello", - fun = function(.req, .res) { - .res$set_body(paste("version ",Sys.getenv("APP_VERSION"))) - .res$set_content_type("text/plain") - }) - -### CARICAMENTO DATI COMMERCIO ESTERO - -add_get_cors( - path = "/load-comext", - fun = function(.req, .res) { - rm(COMEXT_IMP) - rm(COMEXT_EXP) - COMEXT_IMP <<- load_comext("1") - COMEXT_EXP <<- load_comext("2") - - .res$set_body(paste("Load data ok! Range data:",min(COMEXT_IMP$PERIOD),max(COMEXT_IMP$PERIOD),sep = " ")) - .res$set_content_type("application/json") - }) - - -### selezione dei dati in base ai filtri utente e visualizzazione serie -# ITSA <- itsa(1,"03","IT","US",1,1) -# http://localhost:5000/itsa?flow=1&var=03&country=IT&partner=US&dataType=1&tipovar=1 -add_get_cors( - path = "/itsa", - fun = function(.req, .res) { - resp<-itsa(.req$get_param_query("flow"),.req$get_param_query("var"), - .req$get_param_query("country"),.req$get_param_query("partner"), - .req$get_param_query("dataType"),.req$get_param_query("tipovar")) - .res$set_body(resp) - .res$set_content_type("application/json") - }) - -backend = BackendRserve$new() -backend$start(app, http_port = 5000) diff --git a/terra-backend/R-server/create_and_push_image__docker.bat b/terra-backend/R-server/create_and_push_image__docker.bat deleted file mode 100644 index 26864be..0000000 --- a/terra-backend/R-server/create_and_push_image__docker.bat +++ /dev/null @@ -1,4 +0,0 @@ -docker build -t istatcosmo.azurecr.io/cosmo-r-service . - -docker push istatcosmo.azurecr.io/cosmo-r-service - diff --git a/terra-backend/R-server/libraries-bin.txt b/terra-backend/R-server/libraries-bin.txt deleted file mode 100644 index dd94fd8..0000000 --- a/terra-backend/R-server/libraries-bin.txt +++ /dev/null @@ -1,9 +0,0 @@ -libcurl4-openssl-dev - -r-cran-factoextra -r-cran-jsonlite -r-cran-data.table -r-cran-plyr -r-cran-sandwich -r-cran-zoo -r-cran-tidyverse \ No newline at end of file diff --git a/terra-backend/R-server/libraries.R b/terra-backend/R-server/libraries.R deleted file mode 100644 index 6f8e6d6..0000000 --- a/terra-backend/R-server/libraries.R +++ /dev/null @@ -1,10 +0,0 @@ -options(repos = "https://cran.mirror.garr.it/CRAN/") - -print("Loading libraries...") - -install.packages("RestRserve") -install.packages("dplyr") -install.packages("stringr") -install.packages("stringi") - -print("Loading libraries...ok ") diff --git a/terra-backend/R-server/python-based/main.py b/terra-backend/R-server/python-based/main.py deleted file mode 100644 index 958caa4..0000000 --- a/terra-backend/R-server/python-based/main.py +++ /dev/null @@ -1,170 +0,0 @@ -import numpy as np -import pandas as pd -import datetime - -from flask import Flask,request,jsonify -from flask_cors import CORS - -import_file_path = "/data/comext_imp.csv" -export_file_path = "/data/comext_exp.csv" -c_data = pd.DataFrame() - -def load_comext(file_path): - db = pd.read_csv(file_path, dtype={"cpa": str}) - print(f"Loaded file {file_path}") - return db - -def add_cors(response): - response.headers["Access-Control-Allow-Origin"] = "*" - response.headers["Access-Control-Allow-Methods"] = "*" - response.headers["Access-Control-Allow-Headers"] = "*" - return response - -def data_function(import_data, export_data, flow, var_cpa, country_code, partner_code, dataType, tipo_var): - global c_data - if flow == "1": - c_data = import_data - elif flow == "2": - c_data = export_data - # User selects a UE country, global partner, cpa - c_data = c_data[(c_data['DECLARANT_ISO'] == country_code) & - (c_data['PARTNER_ISO'] == partner_code) & - (c_data['cpa'] == var_cpa)] - - # User selects whether data is in value or quantity - if tipo_var == "1": - c_data = c_data[['PERIOD', 'val_cpa']] - elif tipo_var == "2": - c_data = c_data[['PERIOD', 'q_kg']] - - c_data.columns = ['PERIOD', 'series'] - - if len(c_data['series']) > 0: - # Format dates for sorting - c_data['year'] = c_data['PERIOD'].astype(str).str[:4].astype(int) - c_data['month'] = c_data['PERIOD'].astype(str).str[-2:].astype(int) - - # Sort the dataset - c_data.sort_values(['year', 'month'], inplace=True) - # Create date column - c_data['date'] = pd.to_datetime(c_data['year'].astype(str) + '-' + c_data['month'].astype(str) + '-01') - - # Create date range for comparison - start_date = datetime.datetime(c_data['year'].iloc[0], c_data['month'].iloc[0], 1) - end_date = datetime.datetime(c_data['year'].iloc[-1], c_data['month'].iloc[-1], 1) - date_full = pd.date_range(start=start_date, end=end_date, freq='MS') - - # Select necessary columns - c_data = c_data[['date', 'series']] - - # Compare for missing months - if len(c_data['date']) < len(date_full): - db_full = pd.DataFrame({'date': date_full}) - c_data = pd.merge(c_data, db_full, how='outer') - - # Sort the dataset - c_data.sort_values('date', inplace=True) - - # Calculate Yearly Variation Series if dataType is 1 - if dataType == "1": - c_data['series_prev'] = c_data['series'].shift(12) - c_data['series'] = c_data['series'] - c_data['series_prev'] - c_data = c_data.dropna(subset=['series']) - c_data = c_data[['date','series']] - - dict_c_data = { "date": list(c_data["date"].dt.strftime("%Y-%m-%d")), "series": list(c_data["series"].astype(float))} - return dict_c_data - - -def itsa(import_data, export_data, flow, var_cpa, country_code, partner_code, dataType, tipo_var): - try: - # Create a dictionary to store the results for return - res_dict = {} - - # Load the dataset - data_result = data_function(import_data, export_data, flow, var_cpa, country_code, partner_code, dataType, tipo_var) - series_data = data_result['series'] - - # Check if the dataset is empty, generate error code 00 if true - status_main = "01" if len(series_data) > 0 and ~any(np.isnan(val) for val in series_data) else "00" - res_dict["statusMain"] = status_main - res_dict["diagMain"] = data_result - - # Check for missing values - #len_diff = 1 if sum(pd.isna(series_data)) >= 1 else 0 -# - #if len_diff == 0 and status_main == "01": - # ############################ ACF Plot - # acf_list = {} - # acf_result = plt.acorr(series_data, maxlags=len(series_data)-1, detrend=lambda x: x.mean(), usevlines=False) - # acf_list["lne_y"] = acf_result[1] - # acf_list["lne_x"] = np.arange(0, len(series_data)) - # conf_int_pos = 1.96 / np.sqrt(len(series_data) - 12) - # acf_list["dsh_y_pos"] = [conf_int_pos] * len(acf_list["lne_x"]) - # acf_list["dsh_x_pos"] = acf_list["lne_x"] - # acf_list["dsh_y_neg"] = [-conf_int_pos] * len(acf_list["lne_x"]) - # acf_list["dsh_x_neg"] = acf_list["lne_x"] -# - # res_dict["diagACF"] = acf_list - # res_dict["statusACF"] = ["01"] -# - # ############################ QQ-plot - # qq_result = probplot(series_data, plot=None) - # pnt_x = qq_result[0][0] - # pnt_y = qq_result[0][1] -# - # # Find 1st and 3rd quartile of data - # y = np.percentile(series_data, [25, 75]) - # # Find the 1st and 3rd quartile of the normal distribution - # x = np.percentile(np.random.normal(size=len(series_data)), [25, 75]) - # # Compute the intercept and slope of the line that passes through these points - # slope = np.diff(y) / np.diff(x) - # intercept = y[0] - slope * x[0] -# - # lne_y = intercept + slope * pnt_x - # lne_x = pnt_x - # normal = pd.DataFrame({"pnt_x": pnt_x, "pnt_y": pnt_y, "lne_x": lne_x, "lne_y": lne_y}) -# - # res_dict["diagNorm"] = normal - # res_dict["statusNorm"] = ["01"] -# - #else: - # res_dict["statusACF"] = ["00"] - # res_dict["statusNorm"] = ["00"] - - return res_dict - - except Exception as e: - res_dict = { - "statusMain": ["00"], - #"statusACF": ["00"], - #"statusNorm": ["00"], - "error": str(e) - } - return res_dict - - -COMEXT_IMP = load_comext(import_file_path) -COMEXT_EXP = load_comext(export_file_path) - -app = Flask(__name__) -CORS(app, resources=r'/*') - -@app.route('/ts', methods=['GET']) -def itsa_route(): - flow = request.args.get('flow') - var = request.args.get('var') - country = request.args.get('country') - partner = request.args.get('partner') - dataType = request.args.get('dataType') - tipovar = request.args.get('tipovar') # cambiare da tipovar a vartype - - resp = itsa(COMEXT_IMP, COMEXT_EXP, flow, var, country, partner, dataType, tipovar) - response = jsonify(resp) - response.content_type = "application/json" - return add_cors(response) - -if __name__ == '__main__': - IP='0.0.0.0' - port=5500 - app.run(host=IP, port=port) diff --git a/terra-backend/R-server/python-based/main_v2.py b/terra-backend/R-server/python-based/main_v2.py deleted file mode 100644 index 6abf740..0000000 --- a/terra-backend/R-server/python-based/main_v2.py +++ /dev/null @@ -1,206 +0,0 @@ -import numpy as np -import pandas as pd -import datetime - -from flask import Flask,request,jsonify -from flask_cors import CORS - -from sqlalchemy import Column, Integer, String, create_engine -from sqlalchemy.orm import declarative_base, sessionmaker - -DB_SETTINGS : dict = { - "DB_PROVIDER" : "", - "DB_SERVER" : "", - "DB_NAME" : "", - "DB_DRIVER" : "", - "DB_USER" : "", - "DB_PASS" : "" -} - -Base = declarative_base() -engine = create_engine(f'{DB_SETTINGS["DB_PROVIDER"]}://{DB_SETTINGS["DB_USER"]}:{DB_SETTINGS["DB_PASS"]}@{DB_SETTINGS["DB_SERVER"]}/{DB_SETTINGS["DB_NAME"]}?driver={DB_SETTINGS["DB_DRIVER"]}') - -class comextImp(Base): - __tablename__ = 'comext_imp' - - declarant_iso = Column(String, primary_key=True) - partner_iso = Column(String, primary_key=True) - flow = Column(Integer, primary_key=True) - cpa = Column(String, primary_key=True) - period = Column(Integer, primary_key=True) - val_cpa = Column(Integer) - q_kg = Column(Integer) - -class comextExp(Base): - __tablename__ = 'comext_exp' - - declarant_iso = Column(String, primary_key=True) - partner_iso = Column(String, primary_key=True) - flow = Column(Integer, primary_key=True) - cpa = Column(String, primary_key=True) - period = Column(Integer, primary_key=True) - val_cpa = Column(Integer) - q_kg = Column(Integer) - -def add_cors(response): - response.headers["Access-Control-Allow-Origin"] = "*" - response.headers["Access-Control-Allow-Methods"] = "*" - response.headers["Access-Control-Allow-Headers"] = "*" - return response - -def data_function(flow, var_cpa, country_code, partner_code, dataType, tipo_var): - Session = sessionmaker(bind=engine) - session = Session() - - flow_table = [] - column_selection = [] - if flow == "1": - flow_table = comextImp - elif flow == "2": - flow_table = comextExp - - if tipo_var == "1": - column_selection = flow_table.val_cpa - elif tipo_var == "2": - column_selection = flow_table.q_kg - - # User selects a UE country, global partner, cpa - query = session.query( - flow_table.period, column_selection - ).filter( - flow_table.declarant_iso == country_code - ).filter( - flow_table.partner_iso == partner_code - ).filter( - flow_table.cpa == var_cpa - ) - c_data = pd.read_sql(query.statement, query.session.bind) - c_data.columns = ['PERIOD', 'series'] - - if len(c_data['series']) > 0: - # Format dates for sorting - c_data['year'] = c_data['PERIOD'].astype(str).str[:4].astype(int) - c_data['month'] = c_data['PERIOD'].astype(str).str[-2:].astype(int) - - # Sort the dataset - c_data.sort_values(['year', 'month'], inplace=True) - # Create date column - c_data['date'] = pd.to_datetime(c_data['year'].astype(str) + '-' + c_data['month'].astype(str) + '-01') - - # Create date range for comparison - start_date = datetime.datetime(c_data['year'].iloc[0], c_data['month'].iloc[0], 1) - end_date = datetime.datetime(c_data['year'].iloc[-1], c_data['month'].iloc[-1], 1) - date_full = pd.date_range(start=start_date, end=end_date, freq='MS') - - # Select necessary columns - c_data = c_data[['date', 'series']] - - # Compare for missing months - if len(c_data['date']) < len(date_full): - db_full = pd.DataFrame({'date': date_full}) - c_data = pd.merge(c_data, db_full, how='outer') - - # Sort the dataset - c_data.sort_values('date', inplace=True) - - # Calculate Yearly Variation Series if dataType is 1 - if dataType == "1": - c_data['series_prev'] = c_data['series'].shift(12) - c_data['series'] = c_data['series'] - c_data['series_prev'] - c_data = c_data.dropna(subset=['series']) - c_data = c_data[['date','series']] - - dict_c_data = { "date": list(c_data["date"].dt.strftime("%Y-%m-%d")), "series": list(c_data["series"].astype(float))} - - session.close() - return dict_c_data - - -def ts(import_data, export_data, flow, var_cpa, country_code, partner_code, dataType, tipo_var): - try: - # Create a dictionary to store the results for return - res_dict = {} - - # Load the dataset - data_result = data_function(import_data, export_data, flow, var_cpa, country_code, partner_code, dataType, tipo_var) - series_data = data_result['series'] - - # Check if the dataset is empty, generate error code 00 if true - status_main = "01" if len(series_data) > 0 and ~any(np.isnan(val) for val in series_data) else "00" - res_dict["statusMain"] = status_main - res_dict["diagMain"] = data_result - - # Check for missing values - #len_diff = 1 if sum(pd.isna(series_data)) >= 1 else 0 -# - #if len_diff == 0 and status_main == "01": - # ############################ ACF Plot - # acf_list = {} - # acf_result = plt.acorr(series_data, maxlags=len(series_data)-1, detrend=lambda x: x.mean(), usevlines=False) - # acf_list["lne_y"] = acf_result[1] - # acf_list["lne_x"] = np.arange(0, len(series_data)) - # conf_int_pos = 1.96 / np.sqrt(len(series_data) - 12) - # acf_list["dsh_y_pos"] = [conf_int_pos] * len(acf_list["lne_x"]) - # acf_list["dsh_x_pos"] = acf_list["lne_x"] - # acf_list["dsh_y_neg"] = [-conf_int_pos] * len(acf_list["lne_x"]) - # acf_list["dsh_x_neg"] = acf_list["lne_x"] -# - # res_dict["diagACF"] = acf_list - # res_dict["statusACF"] = ["01"] -# - # ############################ QQ-plot - # qq_result = probplot(series_data, plot=None) - # pnt_x = qq_result[0][0] - # pnt_y = qq_result[0][1] -# - # # Find 1st and 3rd quartile of data - # y = np.percentile(series_data, [25, 75]) - # # Find the 1st and 3rd quartile of the normal distribution - # x = np.percentile(np.random.normal(size=len(series_data)), [25, 75]) - # # Compute the intercept and slope of the line that passes through these points - # slope = np.diff(y) / np.diff(x) - # intercept = y[0] - slope * x[0] -# - # lne_y = intercept + slope * pnt_x - # lne_x = pnt_x - # normal = pd.DataFrame({"pnt_x": pnt_x, "pnt_y": pnt_y, "lne_x": lne_x, "lne_y": lne_y}) -# - # res_dict["diagNorm"] = normal - # res_dict["statusNorm"] = ["01"] -# - #else: - # res_dict["statusACF"] = ["00"] - # res_dict["statusNorm"] = ["00"] - - return res_dict - - except Exception as e: - res_dict = { - "statusMain": ["00"], - #"statusACF": ["00"], - #"statusNorm": ["00"], - "error": str(e) - } - return res_dict - -app = Flask(__name__) -CORS(app, resources=r'/*') - -@app.route('/ts', methods=['GET']) -def ts_route(): - flow = request.args.get('flow') - var = request.args.get('var') - country = request.args.get('country') - partner = request.args.get('partner') - dataType = request.args.get('dataType') - tipovar = request.args.get('tipovar') # cambiare da tipovar a vartype - - resp = ts(flow, var, country, partner, dataType, tipovar) - response = jsonify(resp) - response.content_type = "application/json" - return add_cors(response) - -if __name__ == '__main__': - IP='0.0.0.0' - PORT=5500 - app.run(host=IP, port=PORT) diff --git a/terra-backend/R-server/rscript/api_data_function.R b/terra-backend/R-server/rscript/api_data_function.R deleted file mode 100644 index 344ba6b..0000000 --- a/terra-backend/R-server/rscript/api_data_function.R +++ /dev/null @@ -1,82 +0,0 @@ - -data_function<-function(flow,var_cpa,country_code,partner_code,dataType,tipo_var){ - - if (flow==1) { - dati <- COMEXT_IMP - } else if (flow==2) { - dati <- COMEXT_EXP - } - - # utente seleziona un paese UE,partner mondiale,cpa - dati <- subset(dati , DECLARANT_ISO==country_code - & PARTNER_ISO==partner_code - & cpa==var_cpa) - - #utente seleziona se dati in valore o quantità - if (tipo_var==1) { - dati <- dati[,c(5:6)] #dati in valore - } else if (tipo_var==2) { - dati <- dati[,c(5,7)] #dati in qta - } - colnames(dati)<-c("PERIOD","series") - - if (length(dati$series)>0) { - - #metto le date nel formato per l'ordinamento - dati$year<-substring(dati$PERIOD,1,4) - dati$month<-str_sub(dati$PERIOD,-2) - dati$month<-as.numeric(dati$month) - dati$year<-as.numeric(dati$year) - dati$series<-as.numeric(dati$series) - - gc() - - #ordino il dataset - dati<-dati[order(dati$year,dati$month),] - - date<-paste(dati$year,dati$month,"01",sep="-") - date<-as.Date(date) - dati$date <- date - - gc() - - #creo le date per il confronto - strdate = paste("01",paste(dati$month[1],dati$year[1],sep="/"),sep="/") - enddate = paste("01",paste(dati$month[length(dati$month)],dati$year[length(dati$year)],sep="/"),sep="/") - - date_full = seq.Date(from =as.Date(strdate, "%d/%m/%Y"), - to=as.Date(enddate, "%d/%m/%Y"),by="month") - - #selezione sono le colonne necessarie - dati<-dati[,c("date","series")] - - #confronto per mesi missing - if (length(date)% full_join(db_full) - } - - #ordino il dataset - dati<-dati[order(dati$date),] - - #lunghezza db - l<-length(dati$series) - - #### calcolo i tendenziali 1='Yearly variation series', "2=Raw data series" - if (dataType==1) { - - dati$tend<-dati$series - for (i in 13:l) - { - dati$tend[i]<-dati$series[i]-dati$series[i-12] - } - #dati$tend[c(1:12)]<-NA - dati$series<-as.numeric(dati$tend) - dati<-dati[c(13:l),c(1,2)] - - } - } - return(dati) - -} diff --git a/terra-backend/R-server/rscript/api_itsa.R b/terra-backend/R-server/rscript/api_itsa.R deleted file mode 100644 index 819ce45..0000000 --- a/terra-backend/R-server/rscript/api_itsa.R +++ /dev/null @@ -1,79 +0,0 @@ -################################################ -#grafici serie tendenziali e serie originale - -itsa<-function(flow,var_cpa,country_code,partner_code,dataType,tipo_var){ - - tryCatch( - expr = { - - #creo lista dei risultati per il return - reslist<-list() - #carico il dataset - dati<-data_function(flow,var_cpa,country_code,partner_code,dataType,tipo_var) - - l<-length(dati$series) - - #se il dataset è vuoto genera codice di errore 00 - statusMain<-ifelse(length(dati$series)>0,"01","00") - reslist[["statusMain"]]<-statusMain - - reslist[["diagMain"]]<-dati - - #se ci sono missing len_diff==1 non si possono fare i grafici successivi - len_diff<-ifelse(sum(is.na(dati$series))>=1,1,0) - len_diff<-as.numeric(len_diff) - if (len_diff==0 & statusMain=="01") { - ############################grafico acf - acf_list<-list() - acf<-acf(dati$series,plot = FALSE) - acf_list[["lne_y"]]<-as.vector(acf[["acf"]]) - acf_list[["lne_x"]]<-as.vector(acf[["lag"]]) - - conf_int_pos<-qnorm((1 + 0.95)/2)/sqrt(l-12) - acf_list[["dsh_y_pos"]]<- rep(conf_int_pos,length(acf[["lag"]])) - acf_list[["dsh_x_pos"]]<- as.vector(acf[["lag"]]) - acf_list[["dsh_y_neg"]]<- rep(-conf_int_pos,length(acf[["lag"]])) - acf_list[["dsh_x_neg"]]<- as.vector(acf[["lag"]]) - - reslist[["diagACF"]]<-acf_list - reslist[["statusACF"]]<-c("01") - - ##############################grafico qq_norm - qq<-qqnorm(dati$series, pch = 1, frame = FALSE, plot.it = FALSE) - pnt_x<-qq[[1]] - pnt_y<-qq[[2]] - - # Find 1st and 3rd quartile o data - y <- quantile(dati$series, c(0.25, 0.75), type = 5) - # Find the 1st and 3rd quartile of the normal distribution - x <- qnorm( c(0.25, 0.75)) - # Now we can compute the intercept and slope of the line that passes through these points - slope <- diff(y) / diff(x) - int <- y[1] - slope * x[1] - - lne_y<-int+(slope*pnt_x) - lne_x<-pnt_x - normal <- data.frame(pnt_x,pnt_y,lne_x,lne_y) - - reslist[["diagNorm"]]<-normal - reslist[["statusNorm"]]<-c("01") - - # se ci sono NA nella serie, non posso fare i due grafici - # inserisco status di errore - } else {reslist[["statusACF"]]<-c("00") - reslist[["statusNorm"]]<-c("00") - } - return(reslist) - }, - error = function(e){ - reslist<-list() - reslist[["statusMain"]]<-c("00") - reslist[["statusACF"]]<-c("00") - reslist[["statusNorm"]]<-c("00") - reslist[["error"]]<-e - return(reslist) - } - - ) - -} diff --git a/terra-backend/R-server/rscript/api_loadcomext_function.r b/terra-backend/R-server/rscript/api_loadcomext_function.r deleted file mode 100644 index e876617..0000000 --- a/terra-backend/R-server/rscript/api_loadcomext_function.r +++ /dev/null @@ -1,16 +0,0 @@ -load_comext <- function(flow){ - - if (flow==1) { - db <- fread(paste(basedirData,"comext_imp.csv",sep="/"), - colClasses=c("cpa"="character")) - print("loaded file COMEXT_IMP") - - } else if (flow==2) { - db <- fread(paste(basedirData,"comext_exp.csv",sep="/"), - colClasses=c("cpa"="character")) - print("loaded file COMEXT_EXP") - } - - return(db) - -} diff --git a/terra-backend/R-server/run_docker_image_5000.bat b/terra-backend/R-server/run_docker_image_5000.bat deleted file mode 100644 index 869b9f5..0000000 --- a/terra-backend/R-server/run_docker_image_5000.bat +++ /dev/null @@ -1 +0,0 @@ -docker run -p 5000:5000 mecdcme/cosmo-r-service \ No newline at end of file