Search in sources :

Example 1 with CalcAvrSlopeResult

use of course_generator.TrackData.CalcAvrSlopeResult in project Course_Generator by patrovite.

the class JPanelResume method refresh.

/**
 * Refresh the resume grid
 *
 * @param force
 */
public void refresh() {
    // Exit if the tab is not displayed
    // if (TabbedPaneMain.getSelectedIndex() != 4) // Resume
    // return;
    // StatusBar.Items["Message"].Visible = true;
    // StatusBar.Items["Message"].Text = "Mise à jour resumé en cours...";
    // StatusBar.Refresh();
    int i = 0;
    int k = 0;
    int old = 0;
    CgData OldData;
    if (Track == null)
        return;
    if (Track.data.isEmpty())
        return;
    CalcClimbResult ccr = new CalcClimbResult();
    CalcAvrSlopeResult casr = new CalcAvrSlopeResult();
    CalcAvrSpeedResult speedResult = new CalcAvrSpeedResult();
    Resume.data.clear();
    OldData = Track.data.get(0);
    for (CgData src : Track.data) {
        if ((src.getTag() & 32) != 0) {
            k++;
            CgResume dst = new CgResume();
            // ResGrid.Rows.Add();
            dst.setNum(k);
            dst.setName(src.getName());
            dst.setLine(src.getNum());
            dst.setElevation(src.getElevation(CgConst.UNIT_METER));
            ccr = Track.CalcClimb(0, i, ccr);
            dst.setClimbP(ccr.cp);
            dst.setClimbM(ccr.cm);
            dst.setDist(src.getTotal(CgConst.UNIT_METER) / 1000.0);
            dst.setTime(src.getTime());
            dst.setHour(src.getHour());
            dst.setTimeLimit(src.getTimeLimit());
            dst.setStationTime(src.getStation());
            dst.setdTime_f(src.getTime() - OldData.getTime());
            dst.setdDist((src.getTotal(CgConst.UNIT_METER) - OldData.getTotal(CgConst.UNIT_METER)) / 1000.0);
            ccr = Track.CalcClimb(old, i, ccr);
            casr = Track.CalcAvrSlope(old, i, casr);
            speedResult = Track.CalcAvrSpeed(old, i, speedResult);
            dst.setdClimbP(ccr.cp);
            dst.setdClimbM(ccr.cm);
            dst.setSpeedP(ccr.cp * 3600 / Math.abs(ccr.tp));
            dst.setSpeedM(ccr.cm * 3600 / Math.abs(ccr.tm));
            // if ((AvrSlopeP == 0) || (Double.IsNaN(AvrSlopeP) ))
            dst.setAvgSlopeP(casr.AvrSlopeP);
            dst.setAvgSlopeM(casr.AvrSlopeM);
            dst.setAvgSpeed(speedResult.getAvrspeed(CgConst.UNIT_METER));
            dst.setComment(src.getComment());
            Resume.data.add(dst);
            OldData = src;
            old = i;
        }
        i++;
    }
    // -- Refresh the grid
    TableResume.invalidate();
}
Also used : CalcClimbResult(course_generator.TrackData.CalcClimbResult) CgResume(course_generator.CgResume) CalcAvrSpeedResult(course_generator.TrackData.CalcAvrSpeedResult) CalcAvrSlopeResult(course_generator.TrackData.CalcAvrSlopeResult) CgData(course_generator.CgData)

Example 2 with CalcAvrSlopeResult

use of course_generator.TrackData.CalcAvrSlopeResult in project Course_Generator by patrovite.

the class JPanelStatistics method refresh.

/**
 * Refresh the statistic tab
 */
public void refresh() {
    if (track == null)
        return;
    if (track.data.isEmpty())
        return;
    StringBuilder sb = new StringBuilder();
    int unit = settings.Unit;
    // -- Get current language
    String lang = Locale.getDefault().toString();
    InputStream is = getClass().getResourceAsStream("stattemplate_" + lang + ".html");
    // -- File exist?
    if (is == null) {
        // / -- Use default file
        is = getClass().getResourceAsStream("stattemplate_en_US.html");
        CgLog.info("RefreshStat: Statistic file not present! Loading the english statistic file");
    }
    try {
        InputStreamReader isr = new InputStreamReader(is, "UTF-8");
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        br.close();
        isr.close();
        is.close();
    } catch (IOException e) {
        CgLog.error("RefreshStat : Impossible to read the template file from resource");
        e.printStackTrace();
    }
    track.CalcStatElev();
    track.CalcStatSlope();
    track.CalcStatNight();
    CalcAvrSlopeResult casr = new CalcAvrSlopeResult();
    casr = track.CalcAvrSlope(0, track.data.size() - 1, casr);
    CalcAvrSpeedResult speedResult = new CalcAvrSpeedResult();
    speedResult = track.CalcAvrSpeed(0, track.data.size() - 1, speedResult);
    track.CalcRoad();
    sb = Utils.sbReplace(sb, "@500", String.format("%1.3f " + Utils.uLDist2String(unit), track.getTotalDistance(unit) / 1000));
    sb = Utils.sbReplace(sb, "@501", String.format("%1.0f " + Utils.uElev2String(unit), track.getClimbP(unit)));
    sb = Utils.sbReplace(sb, "@502", String.format("%1.0f " + Utils.uElev2String(unit), track.getClimbM(unit)));
    sb = Utils.sbReplace(sb, "@503", String.format("%1.0f " + Utils.uElev2String(unit), track.getMinElev(unit)));
    sb = Utils.sbReplace(sb, "@504", String.format("%1.0f " + Utils.uElev2String(unit), track.getMaxElev(unit)));
    double temp = ((track.getMaxElev(CgConst.UNIT_METER) - track.getMinElev(CgConst.UNIT_METER)) / 100) * 0.6;
    sb = Utils.sbReplace(sb, "@505", String.format("~%1.1f°C / ~%1.1f°F", temp, Utils.C2F(temp) - 32.0));
    sb = Utils.sbReplace(sb, "@506", String.format("%1.1f%%", casr.AvrSlopeP));
    sb = Utils.sbReplace(sb, "@507", String.format("%1.1f%%", casr.AvrSlopeM));
    sb = Utils.sbReplace(sb, "@508", String.format("%1.3f " + Utils.uLDist2String(unit), casr.getTotClimbP(unit) / 1000));
    sb = Utils.sbReplace(sb, "@509", String.format("%1.3f " + Utils.uLDist2String(unit), casr.getTotFlat(unit) / 1000));
    sb = Utils.sbReplace(sb, "@510", String.format("%1.3f " + Utils.uLDist2String(unit), casr.getTotClimbM(unit) / 1000));
    sb = Utils.sbReplace(sb, "@511", String.format("%1.1f " + Utils.uSpeed2String(unit, settings.isPace), speedResult.getAvrspeed(unit)));
    double tmpdbl = (track.getDistRoad(unit) * 100 / track.getTotalDistance(unit));
    sb = Utils.sbReplace(sb, "@512", String.format("%1.0f%% / %1.3f " + Utils.uLDist2String(unit), tmpdbl, track.getDistRoad(unit) / 1000));
    sb = Utils.sbReplace(sb, "@513", String.format("%1.0f%% / %1.3f " + Utils.uLDist2String(unit), 100.0 - tmpdbl, (track.getTotalDistance(unit) - track.getDistRoad(unit)) / 1000));
    sb = Utils.sbReplace(sb, "@514", track.CourseName);
    sb = Utils.sbReplace(sb, "@515", track.Description);
    // -- Speed, distance and time vs slope
    for (int i = 1; i <= 13; i++) sb = Utils.sbReplace(sb, String.format("@%03d", i), CalcVMoy(track.StatSlope[i - 1].getDist(unit), track.StatSlope[i - 1].Time, unit));
    for (int i = 21; i <= 33; i++) sb = Utils.sbReplace(sb, String.format("@%03d", i), String.format("%1.3f " + Utils.uLDist2String(unit), track.StatSlope[i - 21].getDist(unit) / 1000) + ' ' + String.format("(%1.1f%%)", track.StatSlope[i - 21].getDist(unit) / track.getTotalDistance(unit) * 100));
    for (int i = 41; i <= 53; i++) {
        int k = (int) track.StatSlope[i - 41].Time;
        sb = Utils.sbReplace(sb, String.format("@%03d", i), Utils.Second2DateString(k));
    }
    // -- Speed, distance and time vs elevation
    for (int i = 100; i <= 105; i++) sb = Utils.sbReplace(sb, String.format("@%03d", i), CalcVMoy(track.StatElev[i - 100].getDist(unit), track.StatElev[i - 100].Time, unit));
    for (int i = 110; i <= 115; i++) sb = Utils.sbReplace(sb, String.format("@%03d", i), String.format("%1.3f " + Utils.uLDist2String(unit), track.StatElev[i - 110].getDist(unit) / 1000) + ' ' + String.format("(%1.1f%%)", track.StatElev[i - 110].getDist(unit) / track.getTotalDistance(unit) * 100));
    for (int i = 120; i <= 125; i++) {
        int k = (int) track.StatElev[i - 120].Time;
        sb = Utils.sbReplace(sb, String.format("@%03d", i), Utils.Second2DateString(k));
    }
    // -- Speed, distance and track time vs the elevation (day)
    for (int i = 200; i <= 205; i++) sb = Utils.sbReplace(sb, String.format("@%03d", i), CalcVMoy(track.StatElevDay[i - 200].getDist(unit), track.StatElevDay[i - 200].Time, unit));
    for (int i = 210; i <= 215; i++) sb = Utils.sbReplace(sb, String.format("@%03d", i), String.format("%1.3f " + Utils.uLDist2String(unit), track.StatElevDay[i - 210].getDist(unit) / 1000) + ' ' + String.format("(%1.1f%%)", track.StatElevDay[i - 210].getDist(unit) / track.getTotalDistance(unit) * 100));
    for (int i = 220; i <= 225; i++) {
        int k = (int) track.StatElevDay[i - 220].Time;
        sb = Utils.sbReplace(sb, String.format("@%03d", i), Utils.Second2DateString(k));
    }
    // -- Speed, distance and track time vs the elevation (night)
    for (int i = 300; i <= 305; i++) sb = Utils.sbReplace(sb, String.format("@%03d", i), CalcVMoy(track.StatElevNight[i - 300].getDist(unit), track.StatElevNight[i - 300].Time, unit));
    for (int i = 310; i <= 315; i++) sb = Utils.sbReplace(sb, String.format("@%03d", i), String.format("%1.3f " + Utils.uLDist2String(unit), track.StatElevNight[i - 310].getDist(unit) / 1000) + ' ' + String.format("(%1.1f%%)", track.StatElevNight[i - 310].getDist(unit) / track.getTotalDistance(unit) * 100));
    for (int i = 320; i <= 325; i++) {
        int k = (int) track.StatElevNight[i - 320].Time;
        sb = Utils.sbReplace(sb, String.format("@%03d", i), Utils.Second2DateString(k));
    }
    // -- Speed, distance and track time during day and night
    sb = Utils.sbReplace(sb, "@400", CalcVMoy(track.tInDay.getDist(unit), track.tInDay.Time, unit));
    sb = Utils.sbReplace(sb, "@410", String.format("%1.3f " + Utils.uLDist2String(unit), track.tInDay.getDist(unit) / 1000) + ' ' + String.format("(%1.1f%%)", track.tInDay.getDist(unit) / track.getTotalDistance(unit) * 100));
    int k1 = (int) track.tInDay.Time;
    sb = Utils.sbReplace(sb, "@420", Utils.Second2DateString(k1));
    sb = Utils.sbReplace(sb, "@401", CalcVMoy(track.tInNight.getDist(unit), track.tInNight.Time, unit));
    sb = Utils.sbReplace(sb, "@411", String.format("%1.3f " + Utils.uLDist2String(unit), track.tInNight.getDist(unit) / 1000) + ' ' + String.format("(%1.1f%%)", track.tInNight.getDist(unit) / track.getTotalDistance(unit) * 100));
    k1 = (int) track.tInNight.Time;
    sb = Utils.sbReplace(sb, "@421", Utils.Second2DateString(k1));
    /*
		@900=1000m=3280feet
		@901=1500m=4921feet
		@902=2000m=6561feet
		@903=2500m=8202feet
		@904=3000m=9842feet
		 */
    if (unit == CgConst.UNIT_METER) {
        sb = Utils.sbReplace(sb, "@900", "1000m");
        sb = Utils.sbReplace(sb, "@901", "1500m");
        sb = Utils.sbReplace(sb, "@902", "2000m");
        sb = Utils.sbReplace(sb, "@903", "2500m");
        sb = Utils.sbReplace(sb, "@904", "3000m");
    } else {
        sb = Utils.sbReplace(sb, "@900", "3280 feet");
        sb = Utils.sbReplace(sb, "@901", "4921 feet");
        sb = Utils.sbReplace(sb, "@902", "6561 feet");
        sb = Utils.sbReplace(sb, "@903", "8202 feet");
        sb = Utils.sbReplace(sb, "@904", "9842 feet");
    }
    // -- Refresh the view and set the cursor position
    editorStat.setText(sb.toString());
    editorStat.setCaretPosition(0);
}
Also used : CalcAvrSpeedResult(course_generator.TrackData.CalcAvrSpeedResult) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) CalcAvrSlopeResult(course_generator.TrackData.CalcAvrSlopeResult) IOException(java.io.IOException)

Aggregations

CalcAvrSlopeResult (course_generator.TrackData.CalcAvrSlopeResult)2 CalcAvrSpeedResult (course_generator.TrackData.CalcAvrSpeedResult)2 CgData (course_generator.CgData)1 CgResume (course_generator.CgResume)1 CalcClimbResult (course_generator.TrackData.CalcClimbResult)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1