<commit_before>/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2014, PlanetMayo Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
package org.mwc.debrief.core.gpx.mappers;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.JAXBIntrospector;
import javax.xml.bind.Unmarshaller;

import org.eclipse.core.runtime.IStatus;
import org.mwc.cmap.core.CorePlugin;
import org.mwc.debrief.core.gpx.TrackExtensionType;
import org.mwc.debrief.core.loaders.DebriefJaxbContextAware;
import org.w3c.dom.Node;

import com.topografix.gpx.v10.Gpx;
import com.topografix.gpx.v10.Gpx.Trk;
import com.topografix.gpx.v10.Gpx.Trk.Trkseg;
import com.topografix.gpx.v10.Gpx.Trk.Trkseg.Trkpt;
import com.topografix.gpx.v10.ObjectFactory;
import com.topografix.gpx.v11.ExtensionsType;
import com.topografix.gpx.v11.GpxType;
import com.topografix.gpx.v11.TrkType;
import com.topografix.gpx.v11.TrksegType;
import com.topografix.gpx.v11.WptType;

import Debrief.ReaderWriter.Replay.ImportReplay;
import Debrief.Wrappers.FixWrapper;
import Debrief.Wrappers.TrackWrapper;
import Debrief.Wrappers.Track.TrackSegment;
import MWC.GUI.Editable;
import MWC.GUI.Layers;
import MWC.GUI.Properties.LocationPropertyEditor;
import junit.framework.TestCase;

/**
 * @author <NAME> <<EMAIL>>
 * @date August 21, 2012
 * @category gpx
 *
 *           <pre>
 * /plot/session/layers/track										/gpx/trk								Debrief.Wrappers.TrackWrapper
 * /plot/session/layers/track/TrackSegment 			/gpx/trk/trkseg 				Debrief.Wrappers.Track.TrackSegment
 * /plot/session/layers/track/TrackSegment/fix 	/gpx/trk/trkseg/trkpt 	Debrief.Wrappers.FixWrapper
 *           </pre>
 */
public class TrackMapper implements DebriefJaxbContextAware
{
  public static class TestGPXExport extends TestCase
  {
    private static TrackWrapper getData(final String name)
        throws FileNotFoundException
    {
      // get our sample data-file
      final ImportReplay importer = new ImportReplay();
      final Layers theLayers = new Layers();
      final String fName =
          "../org.mwc.cmap.combined.feature/root_installs/sample_data/" + name;
      final File inFile = new File(fName);
      assertTrue("input file exists", inFile.exists());
      final FileInputStream is = new FileInputStream(fName);
      importer.importThis(fName, is, theLayers);

      // sort out the sensors
      importer.storePendingSensors();

      // get the sensor track
      final TrackWrapper track = (TrackWrapper) theLayers.elements()
          .nextElement();

      return track;
    }

    public void testTrackExport() throws FileNotFoundException
    {
      final List<TrackWrapper> tracks = new ArrayList<TrackWrapper>();

      final TrackMapper mapper = new TrackMapper();

      List<Trk> res = mapper.toGpx10(tracks);

      assertEquals("empty list", 0, res.size());

      final TrackWrapper trk1 = getData("boat1.rep");

      tracks.add(trk1);

      res = mapper.toGpx10(tracks);

      assertEquals("has track", 1, res.size());

      final TrackWrapper trk2 = getData("boat2.rep");

      tracks.add(trk2);

      res = mapper.toGpx10(tracks);

      assertEquals("has track", 2, res.size());

      // check the data
      final Trk firstTrack = res.get(0);
      final Trkseg seg = firstTrack.getTrkseg().iterator().next();
      final Iterator<Trkpt> tIter = seg.getTrkpt().iterator();
      final Trkpt fix1 = tIter.next();

      assertEquals("correct lat", 22.186286d, fix1.getLat().doubleValue(),
          0.000001);
      assertEquals("correct lon", -21.697880, fix1.getLon().doubleValue(),
          0.000001);
      assertEquals("correct course", 269.7d, MWC.Algorithms.Conversions
          .Rads2Degs(fix1.getCourse().doubleValue()), 0.1);
      assertEquals("correct speed", 2d, MWC.Algorithms.Conversions.Mps2Kts(fix1
          .getSpeed().doubleValue()), 0.001);
      assertEquals("correct time", "1995-12-12T05:00:00Z", fix1.getTime()
          .toString());

      final Trkpt fix2 = tIter.next();

      assertEquals("correct lat", 22.186272d, fix2.getLat().doubleValue(),
          0.000001);
      assertEquals("correct lon", -21.700827, fix2.getLon().doubleValue(),
          0.000001);
      assertEquals("correct course", 269.7d, MWC.Algorithms.Conversions
          .Rads2Degs(fix2.getCourse().doubleValue()), 0.1);
      assertEquals("correct speed", 2d, MWC.Algorithms.Conversions.Mps2Kts(fix2
          .getSpeed().doubleValue()), 0.001);
      assertEquals("correct time", "1995-12-12T05:01:00Z", fix2.getTime()
          .toString());

    }
  }
<commit_msg>course should already be in degrees<commit_after>/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2014, PlanetMayo Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
package org.mwc.debrief.core.gpx.mappers;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.JAXBIntrospector;
import javax.xml.bind.Unmarshaller;

import org.eclipse.core.runtime.IStatus;
import org.mwc.cmap.core.CorePlugin;
import org.mwc.debrief.core.gpx.TrackExtensionType;
import org.mwc.debrief.core.loaders.DebriefJaxbContextAware;
import org.w3c.dom.Node;

import com.topografix.gpx.v10.Gpx;
import com.topografix.gpx.v10.Gpx.Trk;
import com.topografix.gpx.v10.Gpx.Trk.Trkseg;
import com.topografix.gpx.v10.Gpx.Trk.Trkseg.Trkpt;
import com.topografix.gpx.v10.ObjectFactory;
import com.topografix.gpx.v11.ExtensionsType;
import com.topografix.gpx.v11.GpxType;
import com.topografix.gpx.v11.TrkType;
import com.topografix.gpx.v11.TrksegType;
import com.topografix.gpx.v11.WptType;

import Debrief.ReaderWriter.Replay.ImportReplay;
import Debrief.Wrappers.FixWrapper;
import Debrief.Wrappers.TrackWrapper;
import Debrief.Wrappers.Track.TrackSegment;
import MWC.GUI.Editable;
import MWC.GUI.Layers;
import MWC.GUI.Properties.LocationPropertyEditor;
import junit.framework.TestCase;

/**
 * @author <NAME> <<EMAIL>>
 * @date August 21, 2012
 * @category gpx
 *
 *           <pre>
 * /plot/session/layers/track										/gpx/trk								Debrief.Wrappers.TrackWrapper
 * /plot/session/layers/track/TrackSegment 			/gpx/trk/trkseg 				Debrief.Wrappers.Track.TrackSegment
 * /plot/session/layers/track/TrackSegment/fix 	/gpx/trk/trkseg/trkpt 	Debrief.Wrappers.FixWrapper
 *           </pre>
 */
public class TrackMapper implements DebriefJaxbContextAware
{
  public static class TestGPXExport extends TestCase
  {
    private static TrackWrapper getData(final String name)
        throws FileNotFoundException
    {
      // get our sample data-file
      final ImportReplay importer = new ImportReplay();
      final Layers theLayers = new Layers();
      final String fName =
          "../org.mwc.cmap.combined.feature/root_installs/sample_data/" + name;
      final File inFile = new File(fName);
      assertTrue("input file exists", inFile.exists());
      final FileInputStream is = new FileInputStream(fName);
      importer.importThis(fName, is, theLayers);

      // sort out the sensors
      importer.storePendingSensors();

      // get the sensor track
      final TrackWrapper track = (TrackWrapper) theLayers.elements()
          .nextElement();

      return track;
    }

    public void testTrackExport() throws FileNotFoundException
    {
      final List<TrackWrapper> tracks = new ArrayList<TrackWrapper>();

      final TrackMapper mapper = new TrackMapper();

      List<Trk> res = mapper.toGpx10(tracks);

      assertEquals("empty list", 0, res.size());

      final TrackWrapper trk1 = getData("boat1.rep");

      tracks.add(trk1);

      res = mapper.toGpx10(tracks);

      assertEquals("has track", 1, res.size());

      final TrackWrapper trk2 = getData("boat2.rep");

      tracks.add(trk2);

      res = mapper.toGpx10(tracks);

      assertEquals("has track", 2, res.size());

      // check the data
      final Trk firstTrack = res.get(0);
      final Trkseg seg = firstTrack.getTrkseg().iterator().next();
      final Iterator<Trkpt> tIter = seg.getTrkpt().iterator();
      final Trkpt fix1 = tIter.next();

      assertEquals("correct lat", 22.186286d, fix1.getLat().doubleValue(),
          0.000001);
      assertEquals("correct lon", -21.697880, fix1.getLon().doubleValue(),
          0.000001);
      assertEquals("correct course", 269.7d, fix1.getCourse().doubleValue(),
          0.1);
      assertEquals("correct speed", MWC.Algorithms.Conversions.Kts2Mps(2d), fix1
          .getSpeed().doubleValue(), 0.001);
      assertEquals("correct time", "1995-12-12T05:00:00Z", fix1.getTime()
          .toString());

      final Trkpt fix2 = tIter.next();

      assertEquals("correct lat", 22.186272d, fix2.getLat().doubleValue(),
          0.000001);
      assertEquals("correct lon", -21.700827, fix2.getLon().doubleValue(),
          0.000001);
      assertEquals("correct course", 269.7d, fix2.getCourse().doubleValue(),
          0.1);
      assertEquals("correct speed", MWC.Algorithms.Conversions.Kts2Mps(2d), fix2
          .getSpeed().doubleValue(), 0.001);
      assertEquals("correct time", "1995-12-12T05:01:00Z", fix2.getTime()
          .toString());

    }
  }

{'fraction_non_alphanumeric': 0.12314511466563885, 'fraction_numerical': 0.034688764694546154, 'mean_word_length': 3.3499580888516345, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2372599', 'n_tokens_mistral': 3630, 'n_tokens_neox': 3355, 'n_words': 701}