<commit_before>package foodtruck.server.api;


import java.util.Map;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Inject;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import foodtruck.model.DailySchedule;
import foodtruck.model.Location;
import foodtruck.model.Truck;
import foodtruck.model.TruckSchedule;
import foodtruck.model.TruckStop;

/**
 * Writes model objects out to JSON objects.
 * @author <EMAIL>
 * @since 9/14/11
 */
public class JsonWriter {
  private final DateTimeFormatter timeFormatter;

  @Inject
  public JsonWriter(DateTimeZone zone) {
    timeFormatter = DateTimeFormat.forPattern("hh:mm a").withZone(zone);
  }

  public JSONArray writeTrucks(Iterable<Truck> trucks) throws JSONException {
    JSONArray arr = new JSONArray();
    for (Truck truck : trucks) {
      arr.put(writeTruck(truck));
    }
    return arr;
  }

  public JSONObject writeTruck(Truck truck) throws JSONException {
    return new org.codehaus.jettison.json.JSONObject()
        .put("id", truck.getId())
        .put("description", truck.getDescription())
        .put("iconUrl", truck.getIconUrl())
        .put("twitterHandle", truck.getTwitterHandle())
        .put("facebook", truck.getFacebook())
        .put("foursquare", truck.getFoursquareUrl())
        .put("name", truck.getName())
        .put("inactive", truck.isInactive())
        .put("url", truck.getUrl());
  }

  public JSONObject writeLocation(Location location, int id, boolean fullOptions)
      throws JSONException {
    JSONObject obj = new JSONObject()
        .put("latitude", location.getLatitude())
        .put("longitude", location.getLongitude())
        .put("description", location.getDescription())
        .put("url", location.getUrl())
        .put("name", location.getName());
    if (fullOptions) {
      obj.put("valid", location.isValid());
      obj.put("key", location.getKey());
    }
    if (id != 0) {
      obj.put("id", id);
    }
    return obj;
  }

  public JSONObject writeSchedule(TruckSchedule schedule) throws JSONException {
    JSONObject obj = new JSONObject()
        .put("truck", writeTruck(schedule.getTruck()))
        .put("day", schedule.getDate().toString());
    JSONArray arr = new JSONArray();
    for (TruckStop stop : schedule.getStops()) {
      JSONObject truckStop = new JSONObject()
          .put("location", writeLocation(stop.getLocation(), 0, false))
          .put("id", stop.getKey())
          .put("locked", stop.isLocked())
          .put("startTimeMillis", stop.getStartTime().getMillis())
          .put("endTimeMillis", stop.getEndTime().getMillis())
          .put("startTime", timeFormatter.print(stop.getStartTime()))
          .put("endTime", timeFormatter.print(stop.getEndTime()));
      arr.put(truckStop);
    }
    return obj.put("stops", arr);
  }

  public JSONObject writeSchedule(DailySchedule schedule) throws JSONException {
    JSONObject payload = new JSONObject();
    Iterable<Truck> trucks =
        Iterables.transform(schedule.getStops(), new Function<TruckStop, Truck>() {
          @Override public Truck apply(TruckStop input) {
            return input.getTruck();
          }
        });
    Map<Location, Integer> locations = Maps.newHashMap();
    int i = 1;
    for (TruckStop stop : schedule.getStops()) {
      if (locations.containsKey(stop.getLocation())) {
        continue;
      }
      locations.put(stop.getLocation(), i++);
    }
    JSONArray locationArr = new JSONArray();
    for (Map.Entry<Location, Integer> loc : locations.entrySet()) {
      locationArr.put(writeLocation(loc.getKey(), loc.getValue(), false));
    }
    JSONArray schedules = new JSONArray();
    for (TruckStop stop : schedule.getStops()) {
      JSONObject truckStop = new JSONObject()
          .put("location", locations.get(stop.getLocation()))
          .put("truckId", stop.getTruck().getId())
          .put("startTime", timeFormatter.print(stop.getStartTime()))
          .put("startMillis", stop.getStartTime().getMillis())
          .put("endMillis", stop.getEndTime().getMillis())
          .put("endTime", timeFormatter.print(stop.getEndTime()));
      schedules.put(truckStop);
    }
    payload.put("trucks", writeTrucks(ImmutableSet.copyOf(trucks)));
    payload.put("locations", locationArr);
    payload.put("stops", schedules);
    return payload;
  }
}
<commit_msg>Reverted prior compression change<commit_after>package foodtruck.server.api;


import java.util.Map;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Inject;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import foodtruck.model.DailySchedule;
import foodtruck.model.Location;
import foodtruck.model.Truck;
import foodtruck.model.TruckSchedule;
import foodtruck.model.TruckStop;

/**
 * Writes model objects out to JSON objects.
 * @author <EMAIL>
 * @since 9/14/11
 */
public class JsonWriter {
  private final DateTimeFormatter timeFormatter;

  @Inject
  public JsonWriter(DateTimeZone zone) {
    timeFormatter = DateTimeFormat.forPattern("hh:mm a").withZone(zone);
  }

  public JSONArray writeTrucks(Iterable<Truck> trucks) throws JSONException {
    JSONArray arr = new JSONArray();
    for (Truck truck : trucks) {
      arr.put(writeTruck(truck));
    }
    return arr;
  }

  public JSONObject writeTruck(Truck truck) throws JSONException {
    return new org.codehaus.jettison.json.JSONObject()
        .put("id", truck.getId())
        .put("description", truck.getDescription())
        .put("iconUrl", truck.getIconUrl())
        .put("twitterHandle", truck.getTwitterHandle())
        .put("facebook", truck.getFacebook())
        .put("foursquare", truck.getFoursquareUrl())
        .put("name", truck.getName())
        .put("inactive", truck.isInactive())
        .put("url", truck.getUrl());
  }

  public JSONObject writeLocation(Location location, int id, boolean fullOptions)
      throws JSONException {
    JSONObject obj = new JSONObject()
        .put("latitude", location.getLatitude())
        .put("longitude", location.getLongitude())
        .put("description", location.getDescription())
        .put("url", location.getUrl())
        .put("name", location.getName());
    if (fullOptions) {
      obj.put("valid", location.isValid());
      obj.put("key", location.getKey());
    }
    if (id != 0) {
      obj.put("id", id);
    }
    return obj;
  }

  public JSONObject writeSchedule(TruckSchedule schedule) throws JSONException {
    JSONObject obj = new JSONObject()
        .put("truck", writeTruck(schedule.getTruck()))
        .put("day", schedule.getDate().toString());
    JSONArray arr = new JSONArray();
    for (TruckStop stop : schedule.getStops()) {
      JSONObject truckStop = new JSONObject()
          .put("location", writeLocation(stop.getLocation(), 0, false))
          .put("id", stop.getKey())
          .put("locked", stop.isLocked())
          .put("startTimeMillis", stop.getStartTime().getMillis())
          .put("endTimeMillis", stop.getEndTime().getMillis())
          .put("startTime", timeFormatter.print(stop.getStartTime()))
          .put("endTime", timeFormatter.print(stop.getEndTime()));
      arr.put(truckStop);
    }
    return obj.put("stops", arr);
  }

  public JSONObject writeSchedule(DailySchedule schedule) throws JSONException {
    JSONObject payload = new JSONObject();
    Iterable<Truck> trucks =
        Iterables.transform(schedule.getStops(), new Function<TruckStop, Truck>() {
          @Override public Truck apply(TruckStop input) {
            return input.getTruck();
          }
        });
    Map<Location, Integer> locations = Maps.newHashMap();
    JSONArray locationArr = new JSONArray();
    int i = 1;
    for (TruckStop stop : schedule.getStops()) {
      locations.put(stop.getLocation(), i++);
      locationArr.put(writeLocation(stop.getLocation(), i, false));
    }
    JSONArray schedules = new JSONArray();
    for (TruckStop stop : schedule.getStops()) {
      JSONObject truckStop = new JSONObject()
          .put("location", locations.get(stop.getLocation()))
          .put("truckId", stop.getTruck().getId())
          .put("startTime", timeFormatter.print(stop.getStartTime()))
          .put("startMillis", stop.getStartTime().getMillis())
          .put("endMillis", stop.getEndTime().getMillis())
          .put("endTime", timeFormatter.print(stop.getEndTime()));
      schedules.put(truckStop);
    }
    payload.put("trucks", writeTrucks(ImmutableSet.copyOf(trucks)));
    payload.put("locations", locationArr);
    payload.put("stops", schedules);
    return payload;
  }
}

{'fraction_non_alphanumeric': 0.14344262295081966, 'fraction_numerical': 0.001725625539257981, 'mean_word_length': 3.449616122840691, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3827829', 'n_tokens_mistral': 2801, 'n_tokens_neox': 2754, 'n_words': 539}