List of usage examples for org.apache.commons.configuration Configuration getDouble
Double getDouble(String key, Double defaultValue);
From source file:org.mot.core.simulation.SimulationLoader.java
public static void main(String[] args) { Options options = new Options(); options.addOption("c", true, "Config directory"); options.addOption("n", true, "Provide the name of the simulation class"); options.addOption("l", true, "List of instruments - separated by comma (no spaces!)."); options.addOption("t", true, "Transaction costs - normally 0.0024 bps"); options.addOption("s", true, "Start date in the format of 2014-07-01"); options.addOption("e", true, "End date in the format of 2014-07-31"); options.addOption("w", true, "Week of Year to process - this will ignore -s / -e flag"); if (args.length == 0) { System.out.println("*** Missing arguments: ***"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("runSimulationLoader.sh|.bat", options); System.exit(0);//from w w w .j ava 2 s. co m } long t1 = System.currentTimeMillis(); try { CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); PropertiesFactory pf = PropertiesFactory.getInstance(); if (cmd.getOptionValue("c") != null) { // First make sure to set the config directory pf.setConfigDir(cmd.getOptionValue("c")); } System.setProperty("PathToConfigDir", pf.getConfigDir()); logger.debug("Starting a new Simulation ..."); // Read in properties from file Configuration simulationProperties; simulationProperties = new PropertiesConfiguration(pf.getConfigDir() + "/simulation.properties"); final String frequency = simulationProperties.getString("simulation.default.frequency", "TICK"); final int quantity = simulationProperties.getInt("simulation.default.quantity", 10); final Double minProfit = simulationProperties.getDouble("simulation.default.minProfit", 2.0); String className = simulationProperties.getString("simulation.default.class", "org.mot.client.sg.mvgAvg.SimpleMvgAvgComparison"); Double txnpct; // Get the transaction percentage if (cmd.getOptionValue("t") != null) { txnpct = Double.valueOf(cmd.getOptionValue("t")); } else { txnpct = simulationProperties.getDouble("simulation.order.txncost.pct", 0.0024); } // Make sure to overwrite the className if provided in the command line if (cmd.getOptionValue("n") != null) { className = cmd.getOptionValue("n"); } String[] symbols; // Array for the list of instruments if (cmd.getOptionValues("l") != null) { symbols = cmd.getOptionValues("l"); } else { symbols = simulationProperties.getStringArray("simulation.default.instruments"); } String startDate = null; String endDate = null; if (cmd.getOptionValue("w") != null) { DateBuilder db = new DateBuilder(); String pattern = "yyyy-MM-dd"; startDate = db.getDateForWeekOfYear(Integer.valueOf(cmd.getOptionValue("w")), pattern); endDate = db.addDaysToDate(startDate, pattern, 5); } else { // Get the start date if (cmd.getOptionValue("s") != null) { startDate = cmd.getOptionValue("s"); } else { startDate = simulationProperties.getString("simulation.default.date.start", "2014-07-01"); } // get the End date if (cmd.getOptionValue("e") != null) { endDate = cmd.getOptionValue("e"); } else { endDate = simulationProperties.getString("simulation.default.date.end", "2014-07-31"); } } System.out.println("*** Loading new values to simulation pipeline: *** "); System.out.println("* Using configuration from: " + pf.getConfigDir()); System.out.println("* for Symbol: " + symbols.toString()); System.out.println("* Start date: " + startDate); System.out.println("* End date: " + endDate); System.out.println("* Transaction costs: " + txnpct); System.out.println("* Using class file: " + className); System.out.println("************************************************** "); PropertyConfigurator.configure(pf.getConfigDir() + "/log4j.properties"); Map<Integer, String> instruments = new Hashtable<Integer, String>(); if (symbols[0].equals("ALL")) { WatchListDAO wld = new WatchListDAO(); instruments = wld.getWatchlistAsTable("STK"); } else { for (int p = 0; p < symbols.length; p++) { instruments.put(p, symbols[p].trim()); } } Iterator<Entry<Integer, String>> it = instruments.entrySet().iterator(); while (it.hasNext()) { final Map.Entry<Integer, String> entry = it.next(); SimulationLoader msa = new SimulationLoader(); //msa.loadSimulationRequests(entry.getValue(), className, frequency, quantity, rangemin, rangemax, maxIncrement, startDate, endDate, txnpct); // (String symbol, String className, String frequency, int quantity, String startDate, String endDate, Double txnPct, Double minProfit ) { msa.loadSimulationRequests(entry.getValue(), className, frequency, quantity, startDate, endDate, txnpct, minProfit); } System.out.println("*** FINISHED *** "); } catch (ConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("runSimulationLoader.sh|.bat", options); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("runSimulationLoader.sh|.bat", options); } long totalTime = (System.currentTimeMillis() - t1); logger.debug("End... Run took: " + totalTime + " msecs"); System.exit(0); }
From source file:org.mot.core.simulation.SimulationRunner.java
public static void main(String[] args) { // Run with -w 1-42 -l TSLA -1 581 -2 730 -d Options options = new Options(); options.addOption("c", true, "Config directory"); options.addOption("l", true, "Single instrument/symbol."); options.addOption("1", true, "Moving Average 1"); options.addOption("2", true, "Moving Average 2"); options.addOption("w", true, "Week of Year to process"); options.addOption("d", false, "Write results to DB (default: false)"); if (args.length == 0) { System.out.println("*** Missing arguments: ***"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("runSimulator.sh|.bat", options); System.exit(0);/* w w w .j av a2 s . c o m*/ } try { // Setting command line options CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); PropertiesFactory pf = PropertiesFactory.getInstance(); if (cmd.hasOption("c")) { // First make sure to set the config directory pf.setConfigDir(cmd.getOptionValue("c")); } else { // Default the configuration directory to <ROOT>/conf pf.setConfigDir("conf"); } System.setProperty("PathToConfigDir", pf.getConfigDir()); // Read in properties from file Configuration simulationProperties; simulationProperties = new PropertiesConfiguration(pf.getConfigDir() + "/simulation.properties"); final String className = simulationProperties.getString("simulation.default.class", "org.mot.core.esper.AdvancedMvgAvgComparisonListenerG4"); Double txnpct; // Get the transaction percentage if (cmd.getOptionValue("t") != null) { txnpct = Double.valueOf(cmd.getOptionValue("t")); } else { txnpct = simulationProperties.getDouble("simulation.order.txncost.pct", 0.0024); } String symbol = null; // Array for the list of instruments if (cmd.getOptionValue("l") != null) { symbol = cmd.getOptionValue("l"); } Configuration genericProperties = new PropertiesConfiguration(pf.getConfigDir() + "/config.properties"); PropertyConfigurator.configure(pf.getConfigDir() + "/log4j.properties"); final int quantity = simulationProperties.getInt("simulation.default.quantity", 10); SimulationRunner rmas = new SimulationRunner(); if (cmd.getOptionValue("w") != null) { String week = cmd.getOptionValue("w"); Boolean writeToDB = false; if (cmd.hasOption("d")) { writeToDB = true; } int m1 = Integer.valueOf(cmd.getOptionValue("1")); int m2 = Integer.valueOf(cmd.getOptionValue("2")); if (week.contains("-")) { String[] weekList = week.split("-"); int start = Integer.valueOf(weekList[0]); int end = Integer.valueOf(weekList[1]); for (int u = start; u < end; u++) { rmas.processSingleRequestByWeek(m1, m2, txnpct, symbol, quantity, u, writeToDB, className); } } else { rmas.processSingleRequestByWeek(m1, m2, txnpct, symbol, quantity, Integer.valueOf(week), writeToDB, className); } System.exit(0); } else { rmas.startThreads(genericProperties); while (true) { Thread.sleep(1000); } } } catch (ParseException e1) { // TODO Auto-generated catch block HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("runMovingAverageSimulator.sh|.bat", options); } catch (ConfigurationException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("runMovingAverageSimulator.sh|.bat", options);// TODO Auto-generated catch block } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.sonar.plugins.qi.AbstractDecoratorTest.java
@Test public void testComputeAxisWeight() { String defaultValue = "2.0"; double otherValue = 2.4; Configuration configuration = mock(Configuration.class); when(configuration.getDouble(anyString(), eq(Double.valueOf(defaultValue)))).thenReturn(otherValue); decorator = new DecoratorImpl(configuration, Double.toString(otherValue), defaultValue); assertThat(decorator.computeAxisWeight(), is(otherValue)); when(configuration.getDouble(null, Double.valueOf(defaultValue))).thenReturn(Double.valueOf(defaultValue)); decorator = new DecoratorImpl(configuration, null, defaultValue); assertThat(decorator.computeAxisWeight(), is(Double.valueOf(defaultValue))); }
From source file:org.sonar.plugins.qi.AbstractDecoratorTest.java
private void mockMeasure(DecoratorContext context, Configuration configuration, String qualifier, Metric metric, double value) { Resource resource = mock(Resource.class); when(context.getResource()).thenReturn(resource); when(resource.getQualifier()).thenReturn(qualifier); when(context.getMeasure(metric)).thenReturn(new Measure(metric, value)); when(configuration.getDouble(anyString(), anyDouble())).thenReturn(1.0); }
From source file:org.sonar.plugins.technicaldebt.axis.CommentDebtCalculatorTest.java
@Before public void setUp() throws Exception { Configuration configuration = mock(Configuration.class); when(configuration.getDouble(anyString(), anyDouble())) .thenReturn(TechnicalDebtPlugin.COST_UNDOCUMENTED_API_DEFVAL); calculator = new CommentDebtCalculator(configuration); context = mock(DecoratorContext.class); }
From source file:org.sonar.plugins.technicaldebt.axis.DesignDebtCalculatorTest.java
@Before public void setUp() throws Exception { Configuration configuration = mock(Configuration.class); when(configuration.getDouble(anyString(), anyDouble())).thenReturn(TechnicalDebtPlugin.COST_CYCLE_DEFVAL); calculator = new DesignDebtCalculator(configuration); context = mock(DecoratorContext.class); }
From source file:org.sonar.plugins.technicaldebt.axis.DuplicationDebtCalculatorTest.java
@Before public void setUp() throws Exception { Configuration configuration = mock(Configuration.class); when(configuration.getDouble(anyString(), anyDouble())) .thenReturn(TechnicalDebtPlugin.COST_DUPLICATED_BLOCKS_DEFVAL); calculator = new DuplicationDebtCalculator(configuration); context = mock(DecoratorContext.class); }
From source file:org.sonar.plugins.technicaldebt.axis.ViolationsDebtCalculatorTest.java
@Before public void setUp() throws Exception { Configuration configuration = mock(Configuration.class); when(configuration.getDouble(anyString(), anyDouble())) .thenReturn(TechnicalDebtPlugin.COST_VIOLATION_DEFVAL); calculator = new ViolationsDebtCalculator(configuration); context = mock(DecoratorContext.class); }
From source file:org.sonar.plugins.technicaldebt.ComplexityDebtDecorator.java
public ComplexityDebtDecorator(Configuration configuration) { String complexityConfiguration = configuration.getString(TechnicalDebtPlugin.COMPLEXITY_THRESHOLDS, TechnicalDebtPlugin.COMPLEXITY_THRESHOLDS_DEFVAL); Map<String, Double> complexityLimits = KeyValueFormat.parse(complexityConfiguration, new KeyValueFormat.StringNumberPairTransformer()); classThreshold = (Double) ObjectUtils.defaultIfNull(complexityLimits.get("CLASS"), Double.MAX_VALUE); methodThreshold = (Double) ObjectUtils.defaultIfNull(complexityLimits.get("METHOD"), Double.MAX_VALUE); classSplitCost = configuration.getDouble(TechnicalDebtPlugin.COST_CLASS_COMPLEXITY, TechnicalDebtPlugin.COST_CLASS_COMPLEXITY_DEFVAL); methodSplitCost = configuration.getDouble(TechnicalDebtPlugin.COST_METHOD_COMPLEXITY, TechnicalDebtPlugin.COST_METHOD_COMPLEXITY_DEFVAL); }