List of usage examples for org.joda.time DateTime parse
@FromString public static DateTime parse(String str)
From source file:eu.itesla_project.modules.online.OnlineWorkflowParameters.java
License:Mozilla Public License
public static OnlineWorkflowParameters loadDefault() { ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("online-default-parameters"); int states = config.getIntProperty("states"); String offlineWorkflowId = config.getStringProperty("offlineWorkflowId", null); TimeHorizon timeHorizon = TimeHorizon.fromName(config.getStringProperty("timeHorizon").trim()); Interval histoInterval = Interval.parse(config.getStringProperty("histoInterval")); String feAnalysisId = config.getStringProperty("feAnalysisId"); double rulesPurityThreshold = Double.parseDouble(config.getStringProperty("rulesPurityThreshold")); boolean storeStates = config.getBooleanProperty("storeStates", false); boolean analyseBasecase = config.getBooleanProperty("analyseBasecase", true); boolean validation = config.getBooleanProperty("validation", false); Set<SecurityIndexType> securityIndexes = config.getEnumSetProperty("securityIndexes", SecurityIndexType.class, null); boolean mergeOptimized = config.getBooleanProperty("mergeOptimized", DEFAULT_MERGE_OPTIMIZED); float limitReduction = config.getFloatProperty("limitReduction", DEFAULT_LIMIT_REDUCTION); boolean handleViolationsInN = config.getBooleanProperty("handleViolationsInN", DEFAULT_HANDLE_VIOLATIONS_IN_N); float constraintMargin = config.getFloatProperty("constraintMargin", DEFAULT_CONSTRAINT_MARGIN); String caseFile = config.getStringProperty("caseFile", null); if (caseFile != null) { if ((config.getStringProperty("baseCaseDate", null) != null) || (config.getStringProperty("caseType", null) != null) || (config.getStringProperty("countries", null) != null)) throw new RuntimeException( "caseFile and ( baseCaseDate, caseType, countries ) are mutually exclusive options"); return new OnlineWorkflowParameters(states, histoInterval, offlineWorkflowId, timeHorizon, feAnalysisId, rulesPurityThreshold, storeStates, analyseBasecase, validation, securityIndexes, mergeOptimized, limitReduction, handleViolationsInN, constraintMargin, caseFile); }/*from www . jav a 2 s .c o m*/ DateTime baseCaseDate = DateTime.parse(config.getStringProperty("baseCaseDate")); CaseType caseType = config.getEnumProperty("caseType", CaseType.class); Set<Country> countries = config.getEnumSetProperty("countries", Country.class); return new OnlineWorkflowParameters(baseCaseDate, states, histoInterval, offlineWorkflowId, timeHorizon, feAnalysisId, rulesPurityThreshold, storeStates, analyseBasecase, validation, securityIndexes, caseType, countries, mergeOptimized, limitReduction, handleViolationsInN, constraintMargin); }
From source file:eu.itesla_project.offline.forecast_errors.ForecastErrorsAnalysisParameters.java
License:Mozilla Public License
public static ForecastErrorsAnalysisParameters load() { ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("fea-parameters"); DateTime baseCaseDate = DateTime.parse(config.getStringProperty("baseCaseDate")); Interval histoInterval = Interval.parse(config.getStringProperty("histoInterval")); String feAnalysisId = config.getStringProperty("feAnalysisId"); double ir = config.getDoubleProperty("ir"); Integer flagPQ = config.getIntProperty("flagPQ"); Integer method = config.getIntProperty("method"); Integer nClusters = config.getIntProperty("nClusters"); double percentileHistorical = config.getDoubleProperty("percentileHistorical"); Integer modalityGaussian = config.getOptionalIntProperty("modalityGaussian"); Integer outliers = config.getOptionalIntProperty("outliers"); Integer conditionalSampling = config.getOptionalIntProperty("conditionalSampling"); Integer nSamples = config.getIntProperty("nSamples"); Set<Country> countries = config.getEnumSetProperty("countries", Country.class, DEFAULT_COUNTRIES); CaseType caseType = config.getEnumProperty("caseType", CaseType.class, DEFAULT_CASE_TYPE); return new ForecastErrorsAnalysisParameters(baseCaseDate, histoInterval, feAnalysisId, ir, flagPQ, method, nClusters, percentileHistorical, modalityGaussian, outliers, conditionalSampling, nSamples, countries, caseType);/*from w ww . jav a 2 s.c o m*/ }
From source file:eu.itesla_project.offline.server.OfflineApplicationResource.java
License:Mozilla Public License
@POST @Path("workflow/create") @Produces(MediaType.TEXT_PLAIN)/*from w w w . j av a2 s. com*/ public Response createWorkflow(JsonObject paramsObj) { LOGGER.debug("createWorkflow()"); String workflowId = paramsObj.getString("id", null); //DateTime parsing... DateTime baseCaseDate = DateTime.parse(paramsObj.getJsonString("baseCaseDate").getString()); DateTime histoIntervalStart = DateTime .parse(paramsObj.getJsonObject("histoInterval").getJsonString("start").getString()); DateTime histoIntervalEnd = DateTime .parse(paramsObj.getJsonObject("histoInterval").getJsonString("end").getString()); List<JsonString> countryCodes = paramsObj.getJsonArray("countries").getValuesAs(JsonString.class); Set<Country> countries = new HashSet<>(countryCodes.size()); for (JsonString countryCode : countryCodes) { countries.add(Country.valueOf(countryCode.getString())); } OfflineWorkflowCreationParameters parameters = new OfflineWorkflowCreationParameters(countries, baseCaseDate, new Interval(histoIntervalStart.getMillis(), histoIntervalEnd.getMillis()), false, // TODO false); try { return Response.status(200).entity(bean.getApplication().createWorkflow(workflowId, parameters)) .build(); } catch (Exception e) { LOGGER.error(e.toString(), e); return Response.status(500).entity(e.getMessage()).build(); } }
From source file:eu.itesla_project.offline.tools.CreateOfflineWorkflowTool.java
License:Mozilla Public License
@Override public void run(CommandLine line) throws Exception { String workflowId = line.getOptionValue("workflow"); Set<Country> countries = line.hasOption("base-case-countries") ? Arrays.stream(line.getOptionValue("base-case-countries").split(",")).map(Country::valueOf) .collect(Collectors.toSet()) : getDefaultParameters().getCountries(); DateTime baseCaseDate = line.hasOption("base-case-date") ? DateTime.parse(line.getOptionValue("base-case-date")) : getDefaultParameters().getBaseCaseDate(); Interval histoInterval = line.hasOption("history-interval") ? Interval.parse(line.getOptionValue("history-interval")) : getDefaultParameters().getHistoInterval(); boolean generationSampled = line.hasOption("generation-sampled") || getDefaultParameters().isGenerationSampled(); boolean boundariesSampled = line.hasOption("boundaries-sampled") || getDefaultParameters().isBoundariesSampled(); boolean initTopo = line.hasOption("topo-init") || getDefaultParameters().isInitTopo(); double correlationThreshold = line.hasOption("correlation-threshold") ? Double.parseDouble(line.getOptionValue("correlation-threshold")) : getDefaultParameters().getCorrelationThreshold(); double probabilityThreshold = line.hasOption("probability-threshold") ? Double.parseDouble(line.getOptionValue("probability-threshold")) : getDefaultParameters().getProbabilityThreshold(); boolean loadFlowTransformerVoltageControlOn = line.hasOption("loadflow-transformer-voltage-control-on") || getDefaultParameters().isLoadFlowTransformerVoltageControlOn(); boolean simplifiedWorkflow = line.hasOption("simplified-workflow") || getDefaultParameters().isSimplifiedWorkflow(); boolean mergeOptimized = line.hasOption("merge-optimized") || getDefaultParameters().isMergeOptimized(); Set<Country> attributesCountryFilter = line.hasOption("attributes-country-filter") ? Arrays.stream(line.getOptionValue("attributes-country-filter").split(",")).map(Country::valueOf) .collect(Collectors.toSet()) : getDefaultParameters().getAttributesCountryFilter(); int attributesMinBaseVoltageFilter = line.hasOption("attributes-min-base-voltage-filter") ? Integer.parseInt(line.getOptionValue("attributes-min-base-voltage-filter")) : getDefaultParameters().getAttributesMinBaseVoltageFilter(); OfflineWorkflowCreationParameters parameters = new OfflineWorkflowCreationParameters(countries, baseCaseDate, histoInterval, generationSampled, boundariesSampled, initTopo, correlationThreshold, probabilityThreshold, loadFlowTransformerVoltageControlOn, simplifiedWorkflow, mergeOptimized, attributesCountryFilter, attributesMinBaseVoltageFilter); parameters.print(System.out); try (OfflineApplication app = new RemoteOfflineApplicationImpl()) { String workflowId2 = app.createWorkflow(workflowId, parameters); System.out.println("offline workflow '" + workflowId2 + "' created"); }//from ww w . j a va2 s . c om }
From source file:eu.itesla_project.online.db.OnlineDbMVStore.java
License:Mozilla Public License
@Override public OnlineWorkflowParameters getWorkflowParameters(String workflowId) { Objects.requireNonNull(workflowId, "workflow id is null"); LOGGER.info("Getting configuration parameters of wf {}", workflowId); if (isWorkflowStored(workflowId)) { MVStore wfMVStore = getStore(workflowId); if (wfMVStore.hasMap(STORED_PARAMETERS_MAP_NAME)) { MVMap<String, String> storedParametersMap = wfMVStore.openMap(STORED_PARAMETERS_MAP_NAME, mapBuilder);//from www . ja v a 2 s . co m DateTime baseCaseDate = DateTime.parse(storedParametersMap.get(STORED_PARAMETERS_BASECASE_KEY)); int states = Integer.parseInt(storedParametersMap.get(STORED_PARAMETERS_STATE_NUMBER_KEY)); String offlineWorkflowId = storedParametersMap.get(STORED_PARAMETERS_OFFLINE_WF_ID_KEY); TimeHorizon timeHorizon = TimeHorizon .fromName(storedParametersMap.get(STORED_RESULTS_TIMEHORIZON_KEY)); Interval histoInterval = Interval .parse(storedParametersMap.get(STORED_PARAMETERS_HISTO_INTERVAL_KEY)); String feAnalysisId = storedParametersMap.get(STORED_PARAMETERS_FEA_ID_KEY); double rulesPurityThreshold = Double .parseDouble((storedParametersMap.get(STORED_PARAMETERS_RULES_PURITY_KEY) == null) ? "1" : storedParametersMap.get(STORED_PARAMETERS_RULES_PURITY_KEY)); boolean storeStates = Boolean .parseBoolean(storedParametersMap.get(STORED_PARAMETERS_STORE_STATES_KEY)); boolean analyseBasecase = Boolean .parseBoolean(storedParametersMap.get(STORED_PARAMETERS_ANALYSE_BASECASE_KEY)); boolean validation = Boolean .parseBoolean(storedParametersMap.get(STORED_PARAMETERS_VALIDATION_KEY)); Set<SecurityIndexType> securityIndexes = null; if (storedParametersMap.containsKey(STORED_PARAMETERS_SECURITY_INDEXES_KEY)) securityIndexes = OnlineDbMVStoreUtils .jsonToIndexesTypes(storedParametersMap.get(STORED_PARAMETERS_SECURITY_INDEXES_KEY)); CaseType caseType = CaseType.valueOf(storedParametersMap.get(STORED_PARAMETERS_CASE_TYPE_KEY)); Set<Country> countries = OnlineDbMVStoreUtils .jsonToCountries(storedParametersMap.get(STORED_PARAMETERS_COUNTRIES_KEY)); boolean mergeOptimized = OnlineWorkflowParameters.DEFAULT_MERGE_OPTIMIZED; if (storedParametersMap.containsKey(STORED_PARAMETERS_MERGE_OPTIMIZED_KEY)) mergeOptimized = Boolean .parseBoolean(storedParametersMap.get(STORED_PARAMETERS_MERGE_OPTIMIZED_KEY)); float limitReduction = OnlineWorkflowParameters.DEFAULT_LIMIT_REDUCTION; if (storedParametersMap.containsKey(STORED_PARAMETERS_LIMIT_REDUCTION_KEY)) limitReduction = Float .parseFloat(storedParametersMap.get(STORED_PARAMETERS_LIMIT_REDUCTION_KEY)); boolean handleViolations = OnlineWorkflowParameters.DEFAULT_HANDLE_VIOLATIONS_IN_N; if (storedParametersMap.containsKey(STORED_PARAMETERS_HANDLE_VIOLATIONS_KEY)) handleViolations = Boolean .parseBoolean(storedParametersMap.get(STORED_PARAMETERS_HANDLE_VIOLATIONS_KEY)); float constraintMargin = OnlineWorkflowParameters.DEFAULT_CONSTRAINT_MARGIN; if (storedParametersMap.containsKey(STORED_PARAMETERS_CONSTRAINT_MARGIN_KEY)) constraintMargin = Float .parseFloat(storedParametersMap.get(STORED_PARAMETERS_CONSTRAINT_MARGIN_KEY)); OnlineWorkflowParameters onlineWfPars = new OnlineWorkflowParameters(baseCaseDate, states, histoInterval, offlineWorkflowId, timeHorizon, feAnalysisId, rulesPurityThreshold, storeStates, analyseBasecase, validation, securityIndexes, caseType, countries, mergeOptimized, limitReduction, handleViolations, constraintMargin); if (storedParametersMap.containsKey(STORED_PARAMETERS_CASE_FILE_KEY)) { onlineWfPars.setCaseFile(storedParametersMap.get(STORED_PARAMETERS_CASE_FILE_KEY)); } return onlineWfPars; } else { LOGGER.warn("No configuration parameters of wf {} stored in online db", workflowId); return null; } } else { LOGGER.warn("No data about wf {}", workflowId); return null; } }
From source file:eu.itesla_project.online.tools.ListOnlineWorkflowsTool.java
License:Mozilla Public License
@Override public void run(CommandLine line) throws Exception { OnlineConfig config = OnlineConfig.load(); OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create(); List<OnlineWorkflowDetails> workflows = null; if (line.hasOption("basecase")) { DateTime basecaseDate = DateTime.parse(line.getOptionValue("basecase")); workflows = onlinedb.listWorkflows(basecaseDate); } else if (line.hasOption("basecases-interval")) { Interval basecasesInterval = Interval.parse(line.getOptionValue("basecases-interval")); workflows = onlinedb.listWorkflows(basecasesInterval); } else if (line.hasOption("workflow")) { String workflowId = line.getOptionValue("workflow"); OnlineWorkflowDetails workflowDetails = onlinedb.getWorkflowDetails(workflowId); workflows = new ArrayList<OnlineWorkflowDetails>(); if (workflowDetails != null) workflows.add(workflowDetails); } else/*from w w w. ja v a 2 s .co m*/ workflows = onlinedb.listWorkflows(); boolean printParameters = line.hasOption("parameters"); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); Table table = new Table(2, BorderStyle.CLASSIC_WIDE); if (printParameters) table = new Table(3, BorderStyle.CLASSIC_WIDE); List<Map<String, String>> jsonData = new ArrayList<Map<String, String>>(); table.addCell("ID", new CellStyle(CellStyle.HorizontalAlign.center)); table.addCell("Date", new CellStyle(CellStyle.HorizontalAlign.center)); if (printParameters) table.addCell("Parameters", new CellStyle(CellStyle.HorizontalAlign.center)); for (OnlineWorkflowDetails workflow : workflows) { Map<String, String> wfJsonData = new HashMap<String, String>(); table.addCell(workflow.getWorkflowId()); wfJsonData.put("id", workflow.getWorkflowId()); table.addCell(formatter.print(workflow.getWorkflowDate())); wfJsonData.put("date", formatter.print(workflow.getWorkflowDate())); if (printParameters) { OnlineWorkflowParameters parameters = onlinedb.getWorkflowParameters(workflow.getWorkflowId()); if (parameters != null) { table.addCell("Basecase = " + parameters.getBaseCaseDate().toString()); wfJsonData.put(OnlineWorkflowCommand.BASE_CASE, parameters.getBaseCaseDate().toString()); table.addCell(" "); table.addCell(" "); table.addCell("Time Horizon = " + parameters.getTimeHorizon().getName()); wfJsonData.put(OnlineWorkflowCommand.TIME_HORIZON, parameters.getTimeHorizon().getName()); table.addCell(" "); table.addCell(" "); table.addCell("FE Analysis Id = " + parameters.getFeAnalysisId()); wfJsonData.put(OnlineWorkflowCommand.FEANALYSIS_ID, parameters.getFeAnalysisId()); table.addCell(" "); table.addCell(" "); table.addCell("Offline Workflow Id = " + parameters.getOfflineWorkflowId()); wfJsonData.put(OnlineWorkflowCommand.WORKFLOW_ID, parameters.getOfflineWorkflowId()); table.addCell(" "); table.addCell(" "); table.addCell("Historical Interval = " + parameters.getHistoInterval().toString()); wfJsonData.put(OnlineWorkflowCommand.HISTODB_INTERVAL, parameters.getHistoInterval().toString()); table.addCell(" "); table.addCell(" "); table.addCell("States = " + Integer.toString(parameters.getStates())); wfJsonData.put(OnlineWorkflowCommand.STATES, Integer.toString(parameters.getStates())); table.addCell(" "); table.addCell(" "); table.addCell( "Rules Purity Threshold = " + Double.toString(parameters.getRulesPurityThreshold())); wfJsonData.put(OnlineWorkflowCommand.RULES_PURITY, Double.toString(parameters.getRulesPurityThreshold())); table.addCell(" "); table.addCell(" "); table.addCell("Store States = " + Boolean.toString(parameters.storeStates())); wfJsonData.put(OnlineWorkflowCommand.STORE_STATES, Boolean.toString(parameters.storeStates())); table.addCell(" "); table.addCell(" "); table.addCell("Analyse Basecase = " + Boolean.toString(parameters.analyseBasecase())); wfJsonData.put(OnlineWorkflowCommand.ANALYSE_BASECASE, Boolean.toString(parameters.analyseBasecase())); table.addCell(" "); table.addCell(" "); table.addCell("Validation = " + Boolean.toString(parameters.validation())); wfJsonData.put(OnlineWorkflowCommand.VALIDATION, Boolean.toString(parameters.validation())); table.addCell(" "); table.addCell(" "); String securityRulesString = parameters.getSecurityIndexes() == null ? "ALL" : parameters.getSecurityIndexes().toString(); table.addCell("Security Rules = " + securityRulesString); wfJsonData.put(OnlineWorkflowCommand.SECURITY_INDEXES, securityRulesString); table.addCell(" "); table.addCell(" "); table.addCell("Case Type = " + parameters.getCaseType()); wfJsonData.put(OnlineWorkflowCommand.CASE_TYPE, parameters.getCaseType().name()); table.addCell(" "); table.addCell(" "); table.addCell("Countries = " + parameters.getCountries().toString()); wfJsonData.put(OnlineWorkflowCommand.COUNTRIES, parameters.getCountries().toString()); table.addCell(" "); table.addCell(" "); table.addCell("Limits Reduction = " + Float.toString(parameters.getLimitReduction())); wfJsonData.put(OnlineWorkflowCommand.LIMIT_REDUCTION, Float.toString(parameters.getLimitReduction())); table.addCell(" "); table.addCell(" "); table.addCell( "Handle Violations in N = " + Boolean.toString(parameters.isHandleViolationsInN())); wfJsonData.put(OnlineWorkflowCommand.HANDLE_VIOLATION_IN_N, Boolean.toString(parameters.isHandleViolationsInN())); table.addCell(" "); table.addCell(" "); table.addCell("Constrain Margin = " + Float.toString(parameters.getConstraintMargin())); wfJsonData.put(OnlineWorkflowCommand.CONSTRAINT_MARGIN, Float.toString(parameters.getConstraintMargin())); if (parameters.getCaseFile() != null) { table.addCell(" "); table.addCell(" "); table.addCell("Case file = " + parameters.getCaseFile()); wfJsonData.put(OnlineWorkflowCommand.CASE_FILE, parameters.getCaseFile()); } } else { table.addCell("-"); } } jsonData.add(wfJsonData); } if (line.hasOption("json")) { Path jsonFile = Paths.get(line.getOptionValue("json")); try (FileWriter jsonFileWriter = new FileWriter(jsonFile.toFile())) { //JSONSerializer.toJSON(jsonData).write(jsonFileWriter); jsonFileWriter.write(JSONSerializer.toJSON(jsonData).toString(3)); } } else System.out.println(table.render()); onlinedb.close(); }
From source file:eu.itesla_project.online.tools.OnlineWorkflowTool.java
License:Mozilla Public License
@Override public void run(CommandLine line) throws Exception { OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault(); String host = line.getOptionValue(OnlineWorkflowCommand.HOST); String port = line.getOptionValue(OnlineWorkflowCommand.PORT); String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS); if (host != null) startconfig.setJmxHost(host);//from w w w.j ava 2s. c om if (port != null) startconfig.setJmxPort(Integer.valueOf(port)); if (threads != null) startconfig.setThreads(Integer.valueOf(threads)); Set<DateTime> baseCasesSet = null; OnlineWorkflowParameters params = OnlineWorkflowParameters.loadDefault(); boolean atLeastOneBaseCaseLineParam = line.hasOption(OnlineWorkflowCommand.CASE_TYPE) || line.hasOption(OnlineWorkflowCommand.COUNTRIES) || line.hasOption(OnlineWorkflowCommand.BASE_CASE) || line.hasOption(OnlineWorkflowCommand.BASECASES_INTERVAL); boolean allNeededBaseCaseLineParams = line.hasOption(OnlineWorkflowCommand.CASE_TYPE) && line.hasOption(OnlineWorkflowCommand.COUNTRIES) && (line.hasOption(OnlineWorkflowCommand.BASE_CASE) || line.hasOption(OnlineWorkflowCommand.BASECASES_INTERVAL)); if (line.hasOption(OnlineWorkflowCommand.CASE_FILE)) { if (atLeastOneBaseCaseLineParam) { showHelp("parameter " + OnlineWorkflowCommand.CASE_FILE + " cannot be used together with parameters: " + OnlineWorkflowCommand.CASE_TYPE + ", " + OnlineWorkflowCommand.COUNTRIES + ", " + OnlineWorkflowCommand.BASE_CASE + ", " + OnlineWorkflowCommand.BASECASES_INTERVAL); return; } params.setCaseFile(line.getOptionValue(OnlineWorkflowCommand.CASE_FILE)); } else { if (params.getCaseFile() != null) { if (atLeastOneBaseCaseLineParam) { if (!allNeededBaseCaseLineParams) { showHelp("to override default parameter " + OnlineWorkflowCommand.CASE_FILE + ", all these parameters must be specified: " + OnlineWorkflowCommand.CASE_TYPE + ", " + OnlineWorkflowCommand.COUNTRIES + ", " + OnlineWorkflowCommand.BASE_CASE + " or " + OnlineWorkflowCommand.BASECASES_INTERVAL); return; } params.setCaseFile(null); } } if (line.hasOption(OnlineWorkflowCommand.CASE_TYPE)) params.setCaseType(CaseType.valueOf(line.getOptionValue(OnlineWorkflowCommand.CASE_TYPE))); if (line.hasOption(OnlineWorkflowCommand.COUNTRIES)) { params.setCountries(Arrays.stream(line.getOptionValue(OnlineWorkflowCommand.COUNTRIES).split(",")) .map(Country::valueOf).collect(Collectors.toSet())); } if (line.hasOption(OnlineWorkflowCommand.BASECASES_INTERVAL)) { Interval basecasesInterval = Interval .parse(line.getOptionValue(OnlineWorkflowCommand.BASECASES_INTERVAL)); OnlineConfig oConfig = OnlineConfig.load(); CaseRepository caseRepo = oConfig.getCaseRepositoryFactoryClass().newInstance() .create(new LocalComputationManager()); baseCasesSet = caseRepo.dataAvailable(params.getCaseType(), params.getCountries(), basecasesInterval); System.out.println("Base cases available for interval " + basecasesInterval.toString()); baseCasesSet.forEach(x -> { System.out.println(" " + x); }); } if (baseCasesSet == null) { baseCasesSet = new HashSet<>(); String base = line.getOptionValue(OnlineWorkflowCommand.BASE_CASE); if (base != null) { baseCasesSet.add(DateTime.parse(base)); } else { baseCasesSet.add(params.getBaseCaseDate()); } } } String histo = line.getOptionValue(OnlineWorkflowCommand.HISTODB_INTERVAL); if (histo != null) params.setHistoInterval(Interval.parse(histo)); String states = line.getOptionValue(OnlineWorkflowCommand.STATES); if (states != null) params.setStates(Integer.parseInt(states)); String timeHorizon = line.getOptionValue(OnlineWorkflowCommand.TIME_HORIZON); if (timeHorizon != null) params.setTimeHorizon(TimeHorizon.fromName(timeHorizon)); String workflowid = line.getOptionValue(OnlineWorkflowCommand.WORKFLOW_ID); if (workflowid != null) params.setOfflineWorkflowId(workflowid); String feAnalysisId = line.getOptionValue(OnlineWorkflowCommand.FEANALYSIS_ID); if (feAnalysisId != null) params.setFeAnalysisId(feAnalysisId); String rulesPurity = line.getOptionValue(OnlineWorkflowCommand.RULES_PURITY); if (rulesPurity != null) params.setRulesPurityThreshold(Double.parseDouble(rulesPurity)); if (line.hasOption(OnlineWorkflowCommand.STORE_STATES)) params.setStoreStates(true); if (line.hasOption(OnlineWorkflowCommand.ANALYSE_BASECASE)) params.setAnalyseBasecase(true); if (line.hasOption(OnlineWorkflowCommand.VALIDATION)) { params.setValidation(true); params.setStoreStates(true); // if validation then store states params.setAnalyseBasecase(true); // if validation then analyze base case } Set<SecurityIndexType> securityIndexes = null; if (line.hasOption(OnlineWorkflowCommand.SECURITY_INDEXES)) { if (!"ALL".equals(line.getOptionValue(OnlineWorkflowCommand.SECURITY_INDEXES))) securityIndexes = Arrays .stream(line.getOptionValue(OnlineWorkflowCommand.SECURITY_INDEXES).split(",")) .map(SecurityIndexType::valueOf).collect(Collectors.toSet()); params.setSecurityIndexes(securityIndexes); } if (line.hasOption(OnlineWorkflowCommand.MERGE_OPTIMIZED)) params.setMergeOptimized(true); String limitReduction = line.getOptionValue(OnlineWorkflowCommand.LIMIT_REDUCTION); if (limitReduction != null) params.setLimitReduction(Float.parseFloat(limitReduction)); if (line.hasOption(OnlineWorkflowCommand.HANDLE_VIOLATION_IN_N)) { params.setHandleViolationsInN(true); params.setAnalyseBasecase(true); // if I need to handle violations in N, I need to analyze base case } String constraintMargin = line.getOptionValue(OnlineWorkflowCommand.CONSTRAINT_MARGIN); if (constraintMargin != null) params.setConstraintMargin(Float.parseFloat(constraintMargin)); String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":" + startconfig.getJmxPort() + "/jmxrmi"; JMXServiceURL serviceURL = new JMXServiceURL(urlString); Map<String, String> jmxEnv = new HashMap<>(); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME); LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name, LocalOnlineApplicationMBean.class, false); if (line.hasOption(OnlineWorkflowCommand.START_CMD)) { if (params.getCaseFile() != null) { System.out.println("starting Online Workflow, caseFile " + params.getCaseFile()); String workflowId = application.startWorkflow(startconfig, params); System.out.println("workflowId=" + workflowId); } else { for (DateTime basecase : baseCasesSet) { params.setBaseCaseDate(basecase); System.out.println("starting Online Workflow, basecase " + basecase.toString()); String workflowId = application.startWorkflow(startconfig, params); System.out.println("workflowId=" + workflowId); } } } else if (line.hasOption(OnlineWorkflowCommand.SHUTDOWN_CMD)) { application.shutdown(); } else { showHelp(""); } }
From source file:eu.itesla_project.online.tools.PrintOnlineWorkflowPerformances.java
License:Mozilla Public License
@Override public void run(CommandLine line) throws Exception { Path outputCsvFile = Paths.get(line.getOptionValue("csv-file")); OnlineConfig config = OnlineConfig.load(); OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create(); List<String> workflowsIds = new ArrayList<String>(); if (line.hasOption("workflow")) workflowsIds.add(line.getOptionValue("workflow")); else if (line.hasOption("workflows")) workflowsIds = Arrays.asList(line.getOptionValue("workflows").split(",")); else if (line.hasOption("basecase")) { DateTime basecaseDate = DateTime.parse(line.getOptionValue("basecase")); workflowsIds = onlinedb.listWorkflows(basecaseDate).stream().map(OnlineWorkflowDetails::getWorkflowId) .collect(Collectors.toList()); } else if (line.hasOption("basecases-interval")) { Interval basecasesInterval = Interval.parse(line.getOptionValue("basecases-interval")); workflowsIds = onlinedb.listWorkflows(basecasesInterval).stream() .map(OnlineWorkflowDetails::getWorkflowId).collect(Collectors.toList()); } else {//from w w w .ja va2 s.c o m System.out.println("You must specify workflow(s) or basecase(s)"); return; } Collections.sort(workflowsIds, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareTo(o2); } }); System.out.println("Printing performances of workflows " + workflowsIds); CsvWriter cvsWriter = null; try (FileWriter content = new FileWriter(outputCsvFile.toFile())) { cvsWriter = new CsvWriter(content, ','); String[] headers = new String[25]; int i = 0; headers[i++] = "workflow_id"; headers[i++] = "basecase"; headers[i++] = "secure_contingencies"; headers[i++] = "unsecure_contingencies"; headers[i++] = "unsecure_contingencies_ratio"; headers[i++] = "secure_contingencies_ratio"; headers[i++] = "unsecure_secure_contingencies_ratio"; headers[i++] = "wca_missed_alarms"; headers[i++] = "wca_missed_alarms_lst"; headers[i++] = "wca_false_alarms"; headers[i++] = "wca_false_alarms_lst"; headers[i++] = "wca_accuracy"; headers[i++] = "wca_efficiency"; headers[i++] = "mcla_missed_alarms"; headers[i++] = "mcla_missed_alarms_lst"; headers[i++] = "mcla_false_alarms"; headers[i++] = "mcla_false_alarms_lst"; headers[i++] = "mcla_accuracy"; headers[i++] = "mcla_efficiency"; headers[i++] = "wf_missed_alarms"; headers[i++] = "wf_missed_alarms_lst"; headers[i++] = "wf_false_alarms"; headers[i++] = "wf_false_alarms_lst"; headers[i++] = "wf_accuracy"; headers[i++] = "wf_efficiency"; cvsWriter.writeRecord(headers); // cycle over the workflows for (String workflowId : workflowsIds) { try { System.out.println("\nPrinting performances of workflow " + workflowId); OnlineWorkflowParameters parameters = onlinedb.getWorkflowParameters(workflowId); if (parameters != null && parameters.validation()) { OnlineWorkflowResults wfResults = onlinedb.getResults(workflowId); Map<String, Boolean> contigencySecure = new HashMap<String, Boolean>(); Map<String, Boolean> contigencyWCASecure = new HashMap<String, Boolean>(); Map<String, Boolean> contigencyMCLASecure = new HashMap<String, Boolean>(); Map<String, Boolean> contigencyWfSecure = new HashMap<String, Boolean>(); Map<String, Map<SecurityIndexType, Boolean>> contigencyPhenomenaSecure = new HashMap<String, Map<SecurityIndexType, Boolean>>(); Map<String, Map<SecurityIndexType, Boolean>> contigencyPhenomenaMCLASecure = new HashMap<String, Map<SecurityIndexType, Boolean>>(); int unsecureContingencies = 0; int secureContingencies = 0; int wcaFalseAlarms = 0; List<String> wcaFalseAlarmsList = new ArrayList<String>(); int wcaMissedAlarms = 0; List<String> wcaMissedAlarmsList = new ArrayList<String>(); int mclaFalseAlarms = 0; List<String> mclaFalseAlarmsList = new ArrayList<String>(); int mclaMissedAlarms = 0; List<String> mclaMissedAlarmsList = new ArrayList<String>(); int wfFalseAlarms = 0; List<String> wfFalseAlarmsList = new ArrayList<String>(); int wfMissedAlarms = 0; List<String> wfMissedAlarmsList = new ArrayList<String>(); if (wfResults != null) { if (!wfResults.getUnsafeContingencies().isEmpty()) { Network basecase = onlinedb.getState(workflowId, 0); String basecaseId = basecase.getId(); OnlineWorkflowWcaResults wfWcaResults = onlinedb.getWcaResults(workflowId); OnlineWorkflowRulesResults wfRulesResults = onlinedb.getRulesResults(workflowId); SecurityIndexType[] securityIndexTypes = parameters.getSecurityIndexes() == null ? SecurityIndexType.values() : parameters.getSecurityIndexes().toArray( new SecurityIndexType[parameters.getSecurityIndexes().size()]); for (String contingencyId : wfResults.getUnsafeContingencies()) { // initialize values contigencySecure.put(contingencyId, true); if (wfWcaResults.getClusterIndex(contingencyId) == 1) contigencyWCASecure.put(contingencyId, true); else contigencyWCASecure.put(contingencyId, false); contigencyMCLASecure.put(contingencyId, true); Map<SecurityIndexType, Boolean> phenomenaSecure = new HashMap<SecurityIndexType, Boolean>(); Map<SecurityIndexType, Boolean> phenomenaMCLASecure = new HashMap<SecurityIndexType, Boolean>(); for (SecurityIndexType securityIndexType : securityIndexTypes) { phenomenaSecure.put(securityIndexType, true); phenomenaMCLASecure.put(securityIndexType, true); } contigencyPhenomenaSecure.put(contingencyId, phenomenaSecure); contigencyPhenomenaMCLASecure.put(contingencyId, phenomenaMCLASecure); // compute values for (Integer stateId : wfResults.getUnstableStates(contingencyId)) { Map<String, Boolean> securityIndexes = wfResults .getIndexesData(contingencyId, stateId); Map<String, Boolean> securityRules = wfRulesResults .getStateResults(contingencyId, stateId); for (SecurityIndexType securityIndexType : securityIndexTypes) { if (securityIndexes.containsKey(securityIndexType.getLabel()) && !securityIndexes.get(securityIndexType.getLabel())) { contigencySecure.put(contingencyId, false); contigencyPhenomenaSecure.get(contingencyId).put(securityIndexType, false); } if (securityRules.containsKey(securityIndexType.getLabel()) && !securityRules.get(securityIndexType.getLabel())) { contigencyMCLASecure.put(contingencyId, false); contigencyPhenomenaMCLASecure.get(contingencyId) .put(securityIndexType, false); } } } if (contigencyWCASecure.get(contingencyId) || (!contigencyWCASecure.get(contingencyId) && contigencyMCLASecure.get(contingencyId))) contigencyWfSecure.put(contingencyId, true); else contigencyWfSecure.put(contingencyId, false); // compute data for performances if (contigencySecure.get(contingencyId)) secureContingencies++; else unsecureContingencies++; if (!contigencySecure.get(contingencyId) && contigencyWCASecure.get(contingencyId)) { wcaMissedAlarms++; wcaMissedAlarmsList.add(contingencyId); } if (contigencySecure.get(contingencyId) && !contigencyWCASecure.get(contingencyId)) { wcaFalseAlarms++; wcaFalseAlarmsList.add(contingencyId); } if (!contigencySecure.get(contingencyId) && contigencyMCLASecure.get(contingencyId)) { mclaMissedAlarms++; mclaMissedAlarmsList.add(contingencyId); } if (contigencySecure.get(contingencyId) && !contigencyMCLASecure.get(contingencyId)) { mclaFalseAlarms++; mclaFalseAlarmsList.add(contingencyId); } if (!contigencySecure.get(contingencyId) && contigencyWfSecure.get(contingencyId)) { wfMissedAlarms++; wfMissedAlarmsList.add(contingencyId); } if (contigencySecure.get(contingencyId) && !contigencyWfSecure.get(contingencyId)) { wfFalseAlarms++; wfFalseAlarmsList.add(contingencyId); } } // compute performances float wcaAccuracy = (unsecureContingencies == 0) ? 100 : (1f - ((float) wcaMissedAlarms / (float) unsecureContingencies)) * 100f; float wcaEfficiency = (secureContingencies == 0) ? 100 : (1f - ((float) wcaFalseAlarms / (float) secureContingencies)) * 100f; float mclaAccuracy = (unsecureContingencies == 0) ? 100 : (1f - ((float) mclaMissedAlarms / (float) unsecureContingencies)) * 100f; float mclaEfficiency = (secureContingencies == 0) ? 100 : (1f - ((float) mclaFalseAlarms / (float) secureContingencies)) * 100f; float wfAccuracy = (unsecureContingencies == 0) ? 100 : (1f - ((float) wfMissedAlarms / (float) unsecureContingencies)) * 100f; float wfEfficiency = (secureContingencies == 0) ? 100 : (1f - ((float) wfFalseAlarms / (float) secureContingencies)) * 100f; float unsecureRatio = (float) unsecureContingencies / (float) (secureContingencies + unsecureContingencies); float secureRatio = (float) secureContingencies / (float) (secureContingencies + unsecureContingencies); float secureUnsecureRatio = (secureContingencies == 0) ? Float.NaN : (float) unsecureContingencies / (float) secureContingencies; // System.out.println("contigencySecure: " + contigencySecure); // System.out.println("contigencyWCASecure: " + contigencyWCASecure); // System.out.println("contigencyMCLASecure: " + contigencyMCLASecure); // System.out.println("contigencyWfSecure: " + contigencyWfSecure); // System.out.println("contigencyPhenomenaSecure: " + contigencyPhenomenaSecure); // System.out.println("contigencyPhenomenaMCLASecure: " + contigencyPhenomenaMCLASecure); // print performances String[] values = new String[25]; i = 0; values[i++] = workflowId; values[i++] = basecaseId; values[i++] = Integer.toString(secureContingencies); values[i++] = Integer.toString(unsecureContingencies); values[i++] = Float.toString(unsecureRatio); values[i++] = Float.toString(secureRatio); values[i++] = Float.toString(secureUnsecureRatio); values[i++] = Integer.toString(wcaMissedAlarms); values[i++] = wcaMissedAlarmsList.toString(); values[i++] = Integer.toString(wcaFalseAlarms); values[i++] = wcaFalseAlarmsList.toString(); values[i++] = Float.toString(wcaAccuracy); values[i++] = Float.toString(wcaEfficiency); values[i++] = Integer.toString(mclaMissedAlarms); values[i++] = mclaMissedAlarmsList.toString(); values[i++] = Integer.toString(mclaFalseAlarms); values[i++] = mclaFalseAlarmsList.toString(); values[i++] = Float.toString(mclaAccuracy); values[i++] = Float.toString(mclaEfficiency); values[i++] = Integer.toString(wfMissedAlarms); values[i++] = wfMissedAlarmsList.toString(); values[i++] = Integer.toString(wfFalseAlarms); values[i++] = wfFalseAlarmsList.toString(); values[i++] = Float.toString(wfAccuracy); values[i++] = Float.toString(wfEfficiency); cvsWriter.writeRecord(values); cvsWriter.flush(); } else System.out.println("No data for benchmark: skipping wf " + workflowId); } else { System.out.println("No results: skipping wf " + workflowId); } } else System.out.println("No data for validation: skipping wf " + workflowId); } catch (IOException e1) { } } } finally { if (cvsWriter != null) cvsWriter.close(); onlinedb.close(); } }
From source file:eu.itesla_project.online.tools.PrintOnlineWorkflowSummaryTable.java
License:Mozilla Public License
@Override public void run(CommandLine line) throws Exception { OnlineConfig config = OnlineConfig.load(); try (OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create()) { List<String> workflowsIds = new ArrayList<String>(); if (line.hasOption("workflow")) workflowsIds.add(line.getOptionValue("workflow")); else if (line.hasOption("workflows")) workflowsIds = Arrays.asList(line.getOptionValue("workflows").split(",")); else if (line.hasOption("basecase")) { DateTime basecaseDate = DateTime.parse(line.getOptionValue("basecase")); workflowsIds = onlinedb.listWorkflows(basecaseDate).stream() .map(OnlineWorkflowDetails::getWorkflowId).collect(Collectors.toList()); } else if (line.hasOption("basecases-interval")) { Interval basecasesInterval = Interval.parse(line.getOptionValue("basecases-interval")); workflowsIds = onlinedb.listWorkflows(basecasesInterval).stream() .map(OnlineWorkflowDetails::getWorkflowId).collect(Collectors.toList()); } else {/*from w w w . j a v a 2 s.c o m*/ System.out.println("You must specify workflow(s) or basecase(s)"); return; } TableFormatterConfig tableFormatterConfig = TableFormatterConfig.load(); try (TableFormatter formatter = PrintOnlineWorkflowUtils.createFormatter(tableFormatterConfig, (line.hasOption("output-file")) ? Paths.get(line.getOptionValue("output-file")) : null, TABLE_TITLE, new Column("WorkflowId"), new Column("Basecase"), new Column("Contingency"), new Column("State"), new Column("FailureStep"), new Column("FailureDescription"), new Column("ViolationType"), new Column("Violation"), new Column("ViolationStep"), new Column("Equipment"), new Column("Value"), new Column("Limit"))) { workflowsIds.sort((o1, o2) -> (o1.compareTo(o2))); System.out.println("Printing violations and failues of workflows " + workflowsIds); workflowsIds.forEach(workflowId -> { System.out.println("Printing violations and failures of workflow " + workflowId); Network basecase = onlinedb.getState(workflowId, 0); String basecaseId = basecase.getId(); printPrecontingencyViolations(workflowId, basecaseId, onlinedb, formatter); printContingenciesViolations(workflowId, basecaseId, onlinedb, formatter); }); } } }
From source file:eu.itesla_project.online.tools.RunForecastErrorsAnalysisMpiTool.java
License:Mozilla Public License
@Override public void run(CommandLine line) throws Exception { OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault(); String host = line.getOptionValue(OnlineWorkflowCommand.HOST); String port = line.getOptionValue(OnlineWorkflowCommand.PORT); String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS); if (host != null) startconfig.setJmxHost(host);/* ww w . j av a2 s .c om*/ if (port != null) startconfig.setJmxPort(Integer.valueOf(port)); if (threads != null) startconfig.setThreads(Integer.valueOf(threads)); String analysisId = line.getOptionValue("analysis"); DateTime baseCaseDate = line.hasOption("base-case-date") ? DateTime.parse(line.getOptionValue("base-case-date")) : getDefaultParameters().getBaseCaseDate(); Interval histoInterval = line.hasOption("history-interval") ? Interval.parse(line.getOptionValue("history-interval")) : getDefaultParameters().getHistoInterval(); double ir = line.hasOption("ir") ? Double.parseDouble(line.getOptionValue("ir")) : getDefaultParameters().getIr(); int flagPQ = line.hasOption("flagPQ") ? Integer.parseInt(line.getOptionValue("flagPQ")) : getDefaultParameters().getFlagPQ(); int method = line.hasOption("method") ? Integer.parseInt(line.getOptionValue("method")) : getDefaultParameters().getMethod(); Integer nClusters = line.hasOption("nClusters") ? Integer.parseInt(line.getOptionValue("nClusters")) : getDefaultParameters().getnClusters(); double percentileHistorical = line.hasOption("percentileHistorical") ? Double.parseDouble(line.getOptionValue("percentileHistorical")) : getDefaultParameters().getPercentileHistorical(); Integer modalityGaussian = line.hasOption("modalityGaussian") ? Integer.parseInt(line.getOptionValue("modalityGaussian")) : getDefaultParameters().getModalityGaussian(); Integer outliers = line.hasOption("outliers") ? Integer.parseInt(line.getOptionValue("outliers")) : getDefaultParameters().getOutliers(); Integer conditionalSampling = line.hasOption("conditionalSampling") ? Integer.parseInt(line.getOptionValue("conditionalSampling")) : getDefaultParameters().getConditionalSampling(); Integer nSamples = line.hasOption("nSamples") ? Integer.parseInt(line.getOptionValue("nSamples")) : getDefaultParameters().getnSamples(); Set<Country> countries = line.hasOption("countries") ? Arrays.stream(line.getOptionValue("countries").split(",")).map(Country::valueOf).collect( Collectors.toSet()) : getDefaultParameters().getCountries(); CaseType caseType = line.hasOption("case-type") ? CaseType.valueOf(line.getOptionValue("case-type")) : getDefaultParameters().getCaseType(); ForecastErrorsAnalysisParameters parameters = new ForecastErrorsAnalysisParameters(baseCaseDate, histoInterval, analysisId, ir, flagPQ, method, nClusters, percentileHistorical, modalityGaussian, outliers, conditionalSampling, nSamples, countries, caseType); String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":" + startconfig.getJmxPort() + "/jmxrmi"; JMXServiceURL serviceURL = new JMXServiceURL(urlString); Map<String, String> jmxEnv = new HashMap<>(); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME); LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name, LocalOnlineApplicationMBean.class, false); String timeHorizonS = ""; if (line.hasOption("time-horizon")) { timeHorizonS = line.getOptionValue("time-horizon"); } application.runFeaAnalysis(startconfig, parameters, timeHorizonS); }