<commit_before>package de.wellenvogel.avnav.gps;

import android.location.Location;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.InetSocketAddress;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by andreas on 25.12.14.
 */
public class GpsDataProvider {
    public static final double msToKn=1852.0/3600.0;
    private static final String LOGPRFX="GpsDataProvider";
    public static class SatStatus{
        public int numSat=0;
        public int numUsed=0;
        public boolean gpsEnabled; //for external connections this shows if it is connected
        public String statusText=null;
        public SatStatus(int numSat,int numUsed){
            this.numSat=numSat;
            this.numUsed=numUsed;
            this.gpsEnabled=(numUsed>0)?true:false;
        }
        public String toString(){
            return "Sat num="+numSat+", used="+numUsed;
        }
    }

    SatStatus getSatStatus(){return null;}

    /**
     * stop the service and free all resources
     * afterwards the provider will not be used any more
     */
    public void stop(){}

    /**
     * get the current location if any available or null
     * @return
     */
    public Location getLocation() {return null;}

    /**
     * get the GPS data the same way as we return it in the Json response
     * (i.e. the format used by gpsd)
     * @return
     */
    public JSONObject getGpsData() throws JSONException{ return null;}

    /**
     * will be called from a timer in regular intervals
     * should be used to check (e.g. check if provider enabled or socket can be opened)
     */
    public void check(){}

    /**
     * service function to convert an android location
     * @param curLoc
     * @return
     * @throws JSONException
     */
    JSONObject getGpsData(Location curLoc) throws JSONException{
        if (curLoc == null) {
            Log.d(LOGPRFX, "getGpsData returns empty data");
            return null;
        }
        JSONObject rt=new JSONObject();
        rt.put(G_CLASS, GV_CLASS_TPV);
        rt.put(G_TAG,GV_TAG_RMC);
        rt.put(G_MODE,1);
        rt.put(G_LAT,curLoc.getLatitude());
        rt.put(G_LON,curLoc.getLongitude());
        rt.put(G_COURSE,curLoc.getBearing());
        rt.put(G_SPEED,curLoc.getSpeed()*msToKn);
        rt.put(G_TIME,dateFormat.format(new Date(curLoc.getTime())));
        Log.d(LOGPRFX,"getGpsData: "+rt.toString());
        return rt;
    }

    //GPS position data
    public static final String G_CLASS="class";
    public static final String G_TAG="tag";
    public static final String GV_CLASS_TPV="TPV";<commit_msg>correctly handle gps speed<commit_after>package de.wellenvogel.avnav.gps;

import android.location.Location;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.InetSocketAddress;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by andreas on 25.12.14.
 */
public class GpsDataProvider {
    public static final double msToKn=3600.0/1852.0;
    private static final String LOGPRFX="GpsDataProvider";
    public static class SatStatus{
        public int numSat=0;
        public int numUsed=0;
        public boolean gpsEnabled; //for external connections this shows if it is connected
        public String statusText=null;
        public SatStatus(int numSat,int numUsed){
            this.numSat=numSat;
            this.numUsed=numUsed;
            this.gpsEnabled=(numUsed>0)?true:false;
        }
        public String toString(){
            return "Sat num="+numSat+", used="+numUsed;
        }
    }

    SatStatus getSatStatus(){return null;}

    /**
     * stop the service and free all resources
     * afterwards the provider will not be used any more
     */
    public void stop(){}

    /**
     * get the current location if any available or null
     * @return
     */
    public Location getLocation() {return null;}

    /**
     * get the GPS data the same way as we return it in the Json response
     * (i.e. the format used by gpsd)
     * @return
     */
    public JSONObject getGpsData() throws JSONException{ return null;}

    /**
     * will be called from a timer in regular intervals
     * should be used to check (e.g. check if provider enabled or socket can be opened)
     */
    public void check(){}

    /**
     * service function to convert an android location
     * @param curLoc
     * @return
     * @throws JSONException
     */
    JSONObject getGpsData(Location curLoc) throws JSONException{
        if (curLoc == null) {
            Log.d(LOGPRFX, "getGpsData returns empty data");
            return null;
        }
        JSONObject rt=new JSONObject();
        rt.put(G_CLASS, GV_CLASS_TPV);
        rt.put(G_TAG,GV_TAG_RMC);
        rt.put(G_MODE,1);
        rt.put(G_LAT,curLoc.getLatitude());
        rt.put(G_LON,curLoc.getLongitude());
        rt.put(G_COURSE,curLoc.getBearing());
        rt.put(G_SPEED,curLoc.getSpeed());
        rt.put(G_TIME,dateFormat.format(new Date(curLoc.getTime())));
        Log.d(LOGPRFX,"getGpsData: "+rt.toString());
        return rt;
    }

    //GPS position data
    public static final String G_CLASS="class";
    public static final String G_TAG="tag";
    public static final String GV_CLASS_TPV="TPV";
{'fraction_non_alphanumeric': 0.10334067547723935, 'fraction_numerical': 0.007342143906020558, 'mean_word_length': 2.6038359788359786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5563752', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1630, 'n_words': 466}