@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    View rowView = inflater.inflate(resourseId, parent, false);
    // initialize
    distance = (TextView) rowView.findViewById(R.id.view_distance);
    duration = (TextView) rowView.findViewById(R.id.view_duration);
    maxSpeed = (TextView) rowView.findViewById(R.id.view_maxspeed);
    averageSpeed = (TextView) rowView.findViewById(R.id.view_avrspeed);
    timePerKm = (TextView) rowView.findViewById(R.id.view_timeperkm);
    createdAt = (TextView) rowView.findViewById(R.id.view_created);
    user = (TextView) rowView.findViewById(R.id.view_user);
    // set text
    distance.setText(String.valueOf(dataList.get(position).getDistance()) + " m");
    duration.setText(
        String.valueOf(
            Calculations.roundToTwoDigitsAfterDecimalPoint(
                    dataList.get(position).getDuration() / 1000 / 60)
                + " min"));
    maxSpeed.setText(String.valueOf(dataList.get(position).getMaxSpeed()) + " kmph");
    averageSpeed.setText(String.valueOf(dataList.get(position).getAverageSpeed()) + " kmph");
    timePerKm.setText(String.valueOf(dataList.get(position).getTimePerKilometer()) + " min/km");
    createdAt.setText(String.valueOf(dataList.get(position).getCreatedAt()));
    user.setText(String.valueOf(dataList.get(position).getUserName()));

    return rowView;
  }
示例#2
0
 @Override
 public boolean activate() {
   int index = 0;
   final Tile[] tiles = GlobalConstant.TILE_ROCKS[Checks.isGold()];
   for (int i = 1; i < tiles.length; i++) {
     if (Calculations.distanceTo(tiles[i]) < Calculations.distanceTo(tiles[index])) index = i;
   }
   if (GlobalConstant.WIELDED_ID != -1
       && (Tabs.getCurrent().equals(Tabs.INVENTORY) || Tabs.getCurrent().equals(Tabs.ATTACK))
       && Settings.get(300) == 1000) {
     if (Checks.getLP() < Skills.getRealLevel(Skills.CONSTITUTION) * 10 - 200) return true;
   }
   return !Banker.isDepositOpen()
       && ((inCombat() /* && Calculations.distanceTo(tiles[index]) < 8 && !Inventory.isFull()*/)
           || Checks.isOutside()
           || (GlobalConstant.KEEP_ALIVE
               && Checks.getLP() < Skills.getRealLevel(Skills.CONSTITUTION) * 0.4f * 10));
 }
示例#3
0
 public void steepestDescentInitialize(int stepMax, double criterion) {
   this.stepMax = stepMax; // 1000
   // The criterion must be in the units of the calculation.
   // However, the user is setting this, so they will be in Minimizer units.
   //
   this.criterion = criterion / toUserUnits(1); // 1e-3
   currentStep = 0;
   clearForces();
   calc.setLoggingEnabled(true);
   calc.setLoggingEnabled(stepMax == 0 || Logger.isActiveLevel(Logger.LEVEL_DEBUGHIGH));
   String s =
       name
           + " "
           + calc.getDebugHeader(-1)
           + "Jmol Minimization Version "
           + Viewer.getJmolVersion()
           + "\n";
   calc.appendLogData(s);
   Logger.info(s);
   calc.getConstraintList();
   if (calc.loggingEnabled)
     calc.appendLogData(calc.getAtomList("S T E E P E S T   D E S C E N T"));
   dE = 0;
   calc.setPreliminary(stepMax > 0);
   e0 = energyFull(false, false);
   s =
       TextFormat.sprintf(
           " Initial "
               + name
               + " E = %10.3f "
               + minimizer.units
               + " criterion = %8.6f max steps = "
               + stepMax,
           new Object[] {Float.valueOf(toUserUnits(e0)), Float.valueOf(toUserUnits(criterion))});
   minimizer.report(s, false);
   calc.appendLogData(s);
 }
示例#4
0
  /*
    //
    //          f(x + 2delta) - 2f(x + delta) + f(x)
    // f''(x) = ------------------------------------
    //                        (delta)^2
    //
    void getNumericalSecondDerivative(MinAtom atom, int terms, Vector3d dir) {
      double delta = 1.0e-5;
      double e0 = getEnergy(terms, false);
      double dx = getDx2(atom, terms, 0, e0, delta);
      double dy = getDx2(atom, terms, 1, e0, delta);
      double dz = getDx2(atom, terms, 2, e0, delta);
      dir.set(dx, dy, dz);
    }

    private double getDx2(MinAtom atom, int terms, int i,
                                       double e0, double delta) {
      // calculate f(1)
      atom.coord[i] += delta;
      double e1 = getEnergy(terms, false);
      // calculate f(2)
      atom.coord[i] += delta;
      double e2 = getEnergy(terms, false);
      atom.coord[i] -= 2 * delta;
      return (e2 - 2 * e1 + e0) / (delta * delta);
    }

  */
  public double energyFull(boolean gradients, boolean isSilent) {
    double energy;

    if (gradients) clearForces();

    energy =
        energyBond(gradients)
            + energyAngle(gradients)
            + energyTorsion(gradients)
            + energyStretchBend(gradients)
            + energyOOP(gradients)
            + energyVDW(gradients)
            + energyES(gradients);

    if (!isSilent && calc.loggingEnabled)
      calc.appendLogData(
          TextFormat.sprintf(
              "\nTOTAL %s ENERGY = %8.3f %s/mol\n",
              new Object[] {name, Float.valueOf(toUserUnits(energy)), minimizer.units}));
    return energy;
  }
示例#5
0
文件: Chop.java 项目: phl0w/java
 @Override
 public int execute() {
   final GameObject g = Objects.get(TREE_PREDICATE);
   if (g != null) {
     if (g.isOnScreen()) {
       if (g.applyAction("Chop")) {
         Variables.status = "Chopping";
         Utilities.sleepNoException(500, 700);
         Utilities.sleepUntil(SLEEP, 2000);
       }
     } else {
       Variables.status = "Turning cam";
       Camera.turnTo(g);
       if (!g.isOnScreen()
           && Calculations.distance(Players.getLocal().getLocation(), MAPLE_TREE_TILE) >= 5) {
         Variables.status = "Walking tree";
         Walking.walkTo(MAPLE_TREE_TILE);
         Utilities.sleepNoException(500, 700);
         Utilities.sleepUntil(WALK_SLEEP, 2000);
       }
     }
   }
   return 1000;
 }
示例#6
0
 double energyOOP(boolean gradients) {
   return calc.energyOOP(gradients);
 }
示例#7
0
 public void log(String s) {
   calc.appendLogData(s);
 }
示例#8
0
 public float toUserUnits(double energy) {
   return toUnits(energy, calc.getUnits());
 }
示例#9
0
 public String getLogData() {
   return calc.getLogData();
 }
示例#10
0
 public String getAtomList(String title) {
   return calc.getAtomList(title);
 }
示例#11
0
 double energyES(boolean gradients) {
   return calc.energyES(gradients);
 }
示例#12
0
 @Override
 public void execute() {
   if (GlobalConstant.WIELDED_ID != -1
       && Settings.get(300) == 1000
       && Checks.getLP() < Skills.getRealLevel(Skills.CONSTITUTION) * 10 - 200) {
     if (Players.getLocal().getAppearance()[GlobalConstant.WEAPON] != GlobalConstant.EXCALIBUR
         && (Tabs.getCurrent().equals(Tabs.INVENTORY) || Tabs.INVENTORY.open())) {
       final Item excalibur = Inventory.getItem(GlobalConstant.EXCALIBUR);
       if (excalibur != null) {
         excalibur.getWidgetChild().click(true);
         PauseHandler.pause(
             new PauseHandler.Condition() {
               @Override
               public boolean validate() {
                 return Players.getLocal().getAppearance()[GlobalConstant.WEAPON]
                     == GlobalConstant.EXCALIBUR;
               }
             },
             (long) Random.nextInt(750, 1500));
       }
     } else if (Tabs.getCurrent().equals(Tabs.ATTACK) || Tabs.ATTACK.open()) {
       final WidgetChild bar = Widgets.get(884, 4);
       if (bar.validate()) {
         bar.click(true);
         PauseHandler.pause(
             new PauseHandler.Condition() {
               @Override
               public boolean validate() {
                 return Settings.get(300) != 1000;
               }
             },
             (long) Random.nextInt(400, 800));
       }
     }
     return;
   }
   if (GlobalConstant.KEEP_ALIVE
       && Checks.getLP() < Skills.getRealLevel(Skills.CONSTITUTION) * 0.4f * 10) {
     if (Checks.isOutside()) {
       if (Players.getLocal().getAnimation() == -1) {
         final WidgetChild[] widgets = {Widgets.get(750, 2), Widgets.get(750, 6)};
         if (widgets[0].validate() && widgets[1].validate()) {
           if (widgets[Random.nextInt(0, widgets.length)].interact("Rest"))
             PauseHandler.pause(
                 new PauseHandler.Condition() {
                   @Override
                   public boolean validate() {
                     return Players.getLocal().getAnimation() != -1;
                   }
                 },
                 (long) Random.nextInt(750, 1500));
         }
       }
       Task.sleep(400, 800);
     } else {
       if (Calculations.distanceTo(GlobalConstant.TILE_BANK) > 5) {
         if (Traverse.walk(GlobalConstant.TILE_BANK)) {
           PauseHandler.pause(
               new PauseHandler.Condition() {
                 @Override
                 public boolean validate() {
                   return Walking.getDestination() == null
                       || Calculations.distanceTo(Walking.getDestination()) < 8;
                 }
               },
               (long) Random.nextInt(500, 1000));
         }
       }
     }
   } else {
     if (Checks.isOutside()) {
       final SceneObject ladder = SceneEntities.getNearest(GlobalConstant.ROPE_DOWN_ID);
       if (ladder != null && ladder.interact("Climb"))
         PauseHandler.pause(
             new PauseHandler.Condition() {
               @Override
               public boolean validate() {
                 return !Checks.isOutside();
               }
             },
             750l);
       else if (ladder != null && Calculations.distanceTo(ladder) > 5)
         PauseHandler.walk(ladder, (long) Random.nextInt(250, 750));
     } else if (inCombat() || Players.getLocal().isInCombat()) {
       final Tile rockTile = GlobalConstant.TILE_ROCKS[Checks.isGold()][Mine.getCurrent()];
       if (true
           || Calculations.distanceTo(GlobalConstant.TILE_BANK)
               < Calculations.distanceTo(rockTile)) {
         if (Calculations.distanceTo(GlobalConstant.TILE_BANK) > 6
             && Traverse.walk(GlobalConstant.TILE_BANK)) {
           PauseHandler.pause(
               new PauseHandler.Condition() {
                 @Override
                 public boolean validate() {
                   return Walking.getDestination() == null
                       || Calculations.distanceTo(Walking.getDestination()) < 8;
                 }
               },
               (long) Random.nextInt(200, 500));
         }
       } else {
         final SceneObject rock = SceneEntities.getAt(rockTile);
         final NPC npc =
             NPCs.getNearest(
                 new Filter<NPC>() {
                   @Override
                   public boolean accept(final NPC npc) {
                     return npc.getInteracting() != null
                         && npc.getInteracting().equals(Players.getLocal())
                         && Arrays.binarySearch(GlobalConstant.LRC_NPC, npc.getId()) >= 0;
                   }
                 });
         if (rock != null && npc != null) {
           final Tile hardcodedSafe =
               GlobalConstant.MINE_GOLD && Mine.getCurrent() == 0
                   ? GlobalConstant.GOLD_SAFE_SPOT
                   : !GlobalConstant.MINE_GOLD && Mine.getCurrent() == 2
                       ? GlobalConstant.COAL_SAFE_SPOT
                       : null;
           if (hardcodedSafe != null) {
             hardcodedSafe
                 .randomize(0, Mine.getCurrent() == 2 ? 4 : 1, 1, Mine.getCurrent() == 0 ? -4 : 1)
                 .clickOnMap();
           } else {
             final Tile[] bounds = rock.getArea().getBoundingTiles();
             Arrays.sort(
                 bounds,
                 new Comparator<Tile>() {
                   @Override
                   public int compare(final Tile t1, final Tile t2) {
                     return Calculations.distance(t1, npc.getLocation())
                             < Calculations.distance(t2, npc.getLocation())
                         ? 1
                         : -1;
                   }
                 });
             final int[][] flags = Walking.getCollisionFlags(Game.getPlane());
             final Tile colOffset =
                 Walking.getCollisionOffset(Game.getPlane())
                     .derive(Game.getBaseX(), Game.getBaseY());
             Tile toWalk = null;
             for (final int[] offset : new int[][] {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}) {
               final Tile derive = bounds[0].derive(offset[0], offset[1]);
               if (Nodes.walkable(flags, colOffset, derive)) {
                 if (toWalk == null
                     || Calculations.distance(derive, npc) > Calculations.distance(toWalk, npc))
                   toWalk = derive;
               }
             }
             if (toWalk != null) {
               if (!toWalk.isOnScreen()) Camera.turnTo(toWalk);
               toWalk.interact("Walk here");
             }
           }
           Task.sleep(100, 300);
           final int lp = Checks.getLP();
           final Timer timer = new Timer((long) Random.nextInt(7500, 10000));
           while (Players.getLocal().isInCombat()
               && Checks.getLP() >= lp
               && !Context.get().getScriptHandler().isPaused()
               && timer.isRunning()) Task.sleep(200, 800);
         }
       }
     }
   }
 }
示例#13
0
 double energyTorsion(boolean gradients) {
   return calc.energyTorsion(gradients);
 }
示例#14
0
 double energyAngle(boolean gradients) {
   return calc.energyAngle(gradients);
 }
示例#15
0
 double energyBond(boolean gradients) {
   return calc.energyBond(gradients);
 }
示例#16
0
 /**
  * @param gradients
  * @return energy
  */
 double energyStretchBend(boolean gradients) {
   return calc.energyStretchBend(gradients);
 }
示例#17
0
  // Vector3d dir = new Vector3d();
  public boolean steepestDescentTakeNSteps(int n) {
    if (stepMax == 0) return false;
    boolean isPreliminary = true;
    for (int iStep = 1; iStep <= n; iStep++) {
      currentStep++;
      calc.setSilent(true);
      for (int i = 0; i < minAtomCount; i++)
        if (bsFixed == null || !bsFixed.get(i))
          setForcesUsingNumericalDerivative(minAtoms[i], ENERGY);
      linearSearch();
      calc.setSilent(false);

      if (calc.loggingEnabled) calc.appendLogData(calc.getAtomList("S T E P    " + currentStep));

      double e1 = energyFull(false, false);
      dE = e1 - e0;
      boolean done = Util.isNear(e1, e0, criterion);

      if (done || currentStep % 10 == 0 || stepMax <= currentStep) {
        String s =
            TextFormat.sprintf(
                name + " Step %-4d E = %10.6f    dE = %8.6f ",
                new Object[] {
                  new float[] {(float) e1, (float) (dE), (float) criterion},
                  Integer.valueOf(currentStep)
                });
        minimizer.report(s, false);
        calc.appendLogData(s);
      }
      e0 = e1;
      if (done || stepMax <= currentStep) {
        if (calc.loggingEnabled) calc.appendLogData(calc.getAtomList("F I N A L  G E O M E T R Y"));
        if (done) {
          String s =
              TextFormat.formatString(
                  "\n    "
                      + name
                      + " STEEPEST DESCENT HAS CONVERGED: E = %8.5f "
                      + minimizer.units
                      + " after "
                      + currentStep
                      + " steps",
                  "f",
                  toUserUnits(e1));
          calc.appendLogData(s);
          minimizer.report(s, true);
          Logger.info(s);
        }
        return false;
      }
      // System.out.println(isPreliminary + " " + getNormalizedDE() + " " + currentStep);
      if (isPreliminary && getNormalizedDE() >= 2) {
        // looking back at this after some time, I don't exactly see why I wanted
        // this to stay in preliminary mode unless |DE| >= 2 * crit.
        // It's hard to ever have |DE| NOT >= 2 * crit -- that would be very close to the criterion.
        // And when that IS the case, why would you want to STAY in preliminary mode? Hmm.
        calc.setPreliminary(isPreliminary = false);
        e0 = energyFull(false, false);
      }
    }
    return true; // continue
  }
示例#18
0
 double energyVDW(boolean gradients) {
   return calc.energyVDW(gradients);
 }
示例#19
0
 public void setConstraints(Minimizer m) {
   this.bsFixed = m.bsMinFixed;
   calc.setConstraints(m.constraints);
   coordSaved = null;
 }