public void testLabelMiner() throws IOException, JSONException, ParseException {
    LabelHandler handler = new LabelHandler();
    Miner miner = new Miner(handler);

    miner.setStartDate(new FdaDate("20140808"));
    miner.processDay();
  }
  public void testEventMiner() throws IOException, JSONException, ParseException {
    EventHandler handler = new EventHandler();
    Miner miner = new Miner(handler);

    miner.setStartDate(new FdaDate("20140115"));
    miner.processDay();
  }
Esempio n. 3
0
  /**
   * Create a concrete miner to extract the informations of evolution. Each supported system have to
   * have your own miner, IPROJECT, REDMINE, SIGPRoject, etc...
   *
   * @param systemName
   * @return
   */
  public Miner getMiner(
      String minerName,
      String workDirectoryPath,
      MergeSide mergeSide,
      boolean systemOnLineModel,
      boolean repositoryOnlineModel) {

    if (StringUtils.isEmpty(minerName)) return null; // support half side miner

    Properties prop = new Properties();
    try {
      // I think that this also should be in the config file, this is hardcode
      URL url = new URL("platform:/plugin/br.ufrn.spl.ev/src/br/ufrn/spl/ev/miners.properties");
      InputStream inputStream = url.openConnection().getInputStream();

      prop.load(inputStream);
      Miner miner = (Miner) Class.forName(prop.getProperty(minerName)).newInstance();

      // OBSERVATION.: RepositoryConnector is always "true" in the miner, we don't find out a way to
      // do this offline

      if (miner instanceof IprojectMiner) {
        miner.setSystemConnector(
            new ConnectorFactory()
                .getSystemConnector("IPROJECT", workDirectoryPath, mergeSide, systemOnLineModel));
        miner.setRepositoryConnector(
            new ConnectorFactory().getRepositoryConnector(mergeSide, repositoryOnlineModel));
      }

      if (miner instanceof RedmineMiner) {
        miner.setSystemConnector(
            new ConnectorFactory()
                .getSystemConnector("REDMINE", workDirectoryPath, mergeSide, systemOnLineModel));
        miner.setRepositoryConnector(
            new ConnectorFactory().getRepositoryConnector(mergeSide, repositoryOnlineModel));
      }

      if (miner instanceof SIGProjectMiner) {
        miner.setSystemConnector(
            new ConnectorFactory()
                .getSystemConnector("SIGPROJECT", workDirectoryPath, mergeSide, systemOnLineModel));
        miner.setRepositoryConnector(
            new ConnectorFactory().getRepositoryConnector(mergeSide, repositoryOnlineModel));
      }

      if (miner instanceof GithubMiner) {
        miner.setSystemConnector(
            new ConnectorFactory()
                .getSystemConnector("GITHUB", workDirectoryPath, mergeSide, systemOnLineModel));
        miner.setRepositoryConnector(
            new ConnectorFactory().getRepositoryConnector(mergeSide, repositoryOnlineModel));
      }

      return miner;

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
Esempio n. 4
0
  @SuppressWarnings("unused")
  public static void main(String[] args) throws UnknownExpressionException {
    String rootPath = args[0];
    File rootFile = new File(rootPath);

    Miner miner = new Miner();
    miner.mine(rootFile);

    for (Type type : miner.getMinedTypes()) {
      if (!type.toString().equals("HttpRoute")) {
        logger.debug("Skipping type: {}", type);
        continue;
      }

      logger.debug("Analyzing uses of: {}", type);

      Set<ClassDeclaration> decs = miner.getClassDecs(type);
      List<ConcreteUse> concreteUses = new LinkedList<>();

      for (ClassDeclaration dec : decs) {
        List<ConcreteUse> uses = ConcreteUse.extractUses(type, dec);
        /*
         * for(ConcreteUse c: uses){ if(c.getCFG().asList().size() >0)
         * concreteUses.add(c); }
         */
        concreteUses.addAll(uses);
      }

      logger.debug("Analyzing uses of: {} concrete uses", concreteUses.size());

      for (ConcreteUse use : concreteUses) {
        logger.debug("{}", use);
      }

      // if more than n, then cluster them
      List<List<ConcreteUse>> clusters = ConcreteUseClusterer.cluster(concreteUses);

      // abstract each cluster, then print it
      List<AbstractUse> abstractUses = new LinkedList<>();
      for (List<ConcreteUse> cluster : clusters) {
        AbstractUse use = AbstractUse.abstractUse(cluster);
        logger.debug("{}", use);
      }
      return;
    }
  }
Esempio n. 5
0
  private static MinedCounter runStrategy(
      BlockMap blockMap, int mineLength, List<Vector> starts, int branchOffset, int branches) {
    MinedCounter mined = new MinedCounter();

    for (Vector start : starts) {
      Miner miner = new Miner(blockMap.clone());

      for (int x = 0; x < branches; x++) {
        Vector currentStart =
            new Vector(start.getX() + x * branchOffset, start.getY(), start.getZ());

        miner.run(currentStart, new Point(0, 1), mineLength);
      }

      //            System.out.println(String.format("Iteration %d", i + 1));
      //            System.out.println(miner.getMined());

      mined.addAll(miner.getMined());
    }

    mined.average(starts.size());

    return mined;
  }
Esempio n. 6
0
  public void render(Miner miner) {
    Vector adjustedPosition = miner.position().add(viewPoint);
    int x = (int) adjustedPosition.x();
    int y = (int) adjustedPosition.y();

    AffineTransform orig = graphics.getTransform();
    AffineTransform rot =
        AffineTransform.getRotateInstance(miner.heading().x(), miner.heading().y(), x, y);
    graphics.transform(rot);
    graphics.drawRect(
        x - (int) miner.boundingRadius(),
        y - ((int) miner.boundingRadius() / 2),
        (int) miner.boundingRadius() * 2,
        (int) miner.boundingRadius());
    graphics.setTransform(orig);
    renderHealthBar(miner, x, y);
    renderEnergyBar(miner, x, y);
  }
  // @param turns    the amount of turns that the budget was saved up for
  // @param progress the progress that we are in the build order
  public void updateBudgetingForBuildOrderProgress(int turns, int oreMined, int progress)
      throws GameActionException {

    int remainingOre = oreMined;

    // check if we need to take some for the supply depots
    if (progress >= this.civicRatios.length - 1) {

      if (this.broadcaster.budgetForType(RobotType.SUPPLYDEPOT) < 250) {

        this.broadcaster.incrementBudget(RobotType.SUPPLYDEPOT, (int) (remainingOre * 0.1));
        remainingOre *= 0.9;
      }
    }

    // firstly check the beavers
    final int beavers = this.broadcaster.robotCountFor(Beaver.type());
    int beaverOreAllocation = 0;
    if (beavers == 0) {

      beaverOreAllocation = 100;
    }

    // miners
    final int minerFactories = this.broadcaster.robotCountFor(MinerFactory.type());
    int minerOreAllocation = 0;
    if (minerFactories > 0 && this.broadcaster.robotCountFor(Miner.type()) < 30) {

      minerOreAllocation = (60 / (20 / turns));
      if (this.broadcaster.budgetForType(Miner.type()) >= minerFactories * 60)
        minerOreAllocation = 0;
    }

    // launchers
    final int aerospaceLabs = this.broadcaster.robotCountFor(AerospaceLab.type());
    int launcherOreAllocation = aerospaceLabs * (400 / (100 / turns));
    if (this.broadcaster.budgetForType(Launcher.type()) >= aerospaceLabs * 400)
      launcherOreAllocation = 0;

    // drones
    int droneOreAllocation = 0;
    if (Clock.getRoundNum() > 600 && this.broadcaster.robotCountFor(Drone.type()) == 0) {

      droneOreAllocation = 8;
    }

    int total =
        beaverOreAllocation + minerOreAllocation + launcherOreAllocation + droneOreAllocation;
    double multiplier = (total > remainingOre) ? remainingOre / (float) total : 1.0;

    this.broadcaster.incrementBudget(Beaver.type(), (int) (beaverOreAllocation * multiplier));
    this.broadcaster.incrementBudget(Miner.type(), (int) (minerOreAllocation * multiplier));
    this.broadcaster.incrementBudget(Launcher.type(), (int) (launcherOreAllocation * multiplier));
    this.broadcaster.incrementBudget(Drone.type(), (int) (droneOreAllocation * multiplier));

    remainingOre -= total * multiplier;
    if (remainingOre > 40 && oreMined < 500 /* first turn */) {

      beaverOreAllocation = 10;
      this.broadcaster.incrementBudget(Beaver.type(), beaverOreAllocation);
      remainingOre -= beaverOreAllocation;
    }
    this.broadcaster.incrementCivicBudget(remainingOre);
  }
  @Test
  public void test() {
    SessionFactory.initializeForTest();
    LabelHandler handler = new LabelHandler();
    Miner miner = new Miner(handler);

    try {
      ///////////////////////// test miner.query() ///////////////////////////

      // Negative test of query()
      String answer = Miner.query(FAIL_URL);
      assertNull(answer); // Note that query date above must be set to future date.

      // Positive test of query()
      answer = Miner.query(GOOD_URL);
      assertNotNull(answer);

      // get dirty entry
      JSONObject obj = new JSONObject(answer);
      JSONArray results = obj.optJSONArray("results");
      assertNotNull(results);

      JSONObject dirty = results.optJSONObject(0);
      assertNotNull(dirty);

      ///////////////////////// test miner.cleanEntries() ///////////////////////////
      // get clean entry
      JSONArray cleanList = miner.cleanEntries(answer);
      assertNotNull(cleanList);

      JSONObject clean = cleanList.optJSONObject(0);
      assertNotNull(clean);

      boolean fMissing =
          TestLabelHandler.validateRequired(dirty, clean, LabelHandler.REQ_ROOT_KEYS);
      if (fMissing) {
        assertNull(clean);
        return;
      }

      JSONObject fda = dirty.optJSONObject("openfda");
      if (fda == null) {
        assertNull(clean);
        return;
      }

      fMissing = TestLabelHandler.validateRequired(fda, clean, LabelHandler.REQ_FDA_KEYS);
      if (fMissing) {
        assertNull(clean);
        return;
      }

      assertNotNull(clean);

      /*
      ///////////////////////// test miner.saveCleanList() ///////////////////////////
       		long startCount = miner.getCollection().count();
       		miner.saveCleanList( cleanList );
       		long count = miner.getCollection().count();

       		assertTrue( startCount < count );
       		*/

    } catch (IOException e) {
      e.printStackTrace();

    } catch (JSONException e) {
      e.printStackTrace();
    }
  }