<commit_before>package in.tosc.ghumo;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.JsonElement;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * Created by championswimmer on 22/8/15.
 */
public class FareOps {

    public ArrayList<Fare> getFares(Context ctx) {
        ArrayList<Fare> fares = new ArrayList<>();
        String jsonString = getJsonFromAssets("fares.json", ctx);
        try {
            JSONArray fareArr = new JSONArray(jsonString);
            Gson gson = new Gson();
            for (int i = 0; i < fareArr.length(); i++) {
                fares.add(gson.fromJson((fareArr.getJSONObject(i)).toString(), Fare.class));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return fares;
    }

    public String getJsonFromAssets (String assetFileName, Context c) {
        String json = null;
        try {
            InputStream is = c.getAssets().open(assetFileName);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);<commit_msg>calculate far from distance<commit_after>package in.tosc.ghumo;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.JsonElement;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * Created by championswimmer on 22/8/15.
 */
public class FareOps {

    public ArrayList<Fare> getFares(Context ctx) {
        ArrayList<Fare> fares = new ArrayList<>();
        String jsonString = getJsonFromAssets("fares.json", ctx);
        try {
            JSONArray fareArr = new JSONArray(jsonString);
            Gson gson = new Gson();
            for (int i = 0; i < fareArr.length(); i++) {
                fares.add(gson.fromJson((fareArr.getJSONObject(i)).toString(), Fare.class));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return fares;
    }

    public float calcFare(float kiloMeters, Fare fare) {
        float totalFare = 0;
        totalFare += fare.getBooking_fee();
        totalFare += fare.getMin_fare();

        float chargeableKm = kiloMeters - fare.getMin_dist();
        chargeableKm = (chargeableKm>0) ? chargeableKm : 0;

        totalFare += chargeableKm * fare.getFare_per_km();

        return totalFare;
    }

    public String getJsonFromAssets (String assetFileName, Context c) {
        String json = null;
        try {
            InputStream is = c.getAssets().open(assetFileName);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
{'fraction_non_alphanumeric': 0.11584932480454868, 'fraction_numerical': 0.005330490405117271, 'mean_word_length': 2.428745432399513, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, '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': '2969333', 'n_tokens_mistral': 858, 'n_tokens_neox': 835, 'n_words': 196}