<commit_before>package com.example.bot.spring.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.json.JSONObject;

import com.linecorp.bot.model.action.URIAction;
import com.linecorp.bot.model.message.TemplateMessage;
import com.linecorp.bot.model.message.template.CarouselColumn;
import com.linecorp.bot.model.message.template.CarouselTemplate;

import se.walkercrou.places.GooglePlaces;
import se.walkercrou.places.Param;
import se.walkercrou.places.Place;

public class RestaurantService {

  private static RestaurantService instance = new RestaurantService();

  public static RestaurantService getInstance() {
    return instance;
  }

  public RestaurantService() {}

  public TemplateMessage getRestaurant(double lat, double lng) {
    String apiKey = "<KEY>";
    GooglePlaces client = new GooglePlaces(apiKey);
    List<Place> places =
        client.getNearbyPlaces(
            lat,
            lng,
            1000,
            Param.name("type").value("food"),
            Param.name("language").value("zh-TW"));
    List<CarouselColumn> carusels = new ArrayList<CarouselColumn>();
    String photoUrl =
        "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&key="
            + apiKey
            + "&photoreference=";
    places.sort(
        (Place p1, Place p2) ->
            p1.getRating() > p2.getRating() ? -1 : (p1.getRating() < p2.getRating() ? 1 : 0));
    for (Place p : places) {
      JSONObject json = p.getJson();
      if (json.isNull("photos")) continue;
      String imageUrl =
          photoUrl + json.getJSONArray("photos").getJSONObject(0).getString("photo_reference");
      if (carusels.size() == 5) break;
      CarouselColumn temp =
          new CarouselColumn(
              imageUrl,
              p.getName(),
              "評分:"
                  + p.getRating()
                  + "\r\n\"營業狀態: + "
                  + p.getStatus()
                  + "\r\n地址:"
                  + p.getVicinity(),
              Arrays.asList(
                  new URIAction(
                      "map location",
                      "https://www.google.com/maps/search/?api=1&query=%20&query_place_id="
                          + p.getPlaceId())));
      carusels.add(temp);
    }
    TemplateMessage templateMessage = new TemplateMessage("food", new CarouselTemplate(carusels));
    return templateMessage;
  }
}<commit_msg>google place api - final final<commit_after>package com.example.bot.spring.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.json.JSONObject;

import com.linecorp.bot.model.action.URIAction;
import com.linecorp.bot.model.message.TemplateMessage;
import com.linecorp.bot.model.message.template.CarouselColumn;
import com.linecorp.bot.model.message.template.CarouselTemplate;

import se.walkercrou.places.GooglePlaces;
import se.walkercrou.places.Param;
import se.walkercrou.places.Place;

public class RestaurantService {

  private static RestaurantService instance = new RestaurantService();

  public static RestaurantService getInstance() {
    return instance;
  }

  public RestaurantService() {}

  public TemplateMessage getRestaurant(double lat, double lng) {
    String apiKey = "<KEY>";
    GooglePlaces client = new GooglePlaces(apiKey);
    List<Place> places =
        client.getNearbyPlaces(
            lat,
            lng,
            1000,
            Param.name("type").value("food"),
            Param.name("language").value("zh-TW"));
    List<CarouselColumn> carusels = new ArrayList<CarouselColumn>();
    String photoUrl =
        "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&key="
            + apiKey
            + "&photoreference=";
    places.sort(
        (Place p1, Place p2) ->
            p1.getRating() > p2.getRating() ? -1 : (p1.getRating() < p2.getRating() ? 1 : 0));
    for (Place p : places) {
      JSONObject json = p.getJson();
      if (json.isNull("photos")) continue;
      String imageUrl =
          photoUrl + json.getJSONArray("photos").getJSONObject(0).getString("photo_reference");
      if (carusels.size() == 5) break;
      CarouselColumn temp =
          new CarouselColumn(
              imageUrl,
              p.getName(),
              "評分:" + p.getRating() + "\r\n營業狀態:" + p.getStatus() + "\r\n地址:" + p.getVicinity(),
              Arrays.asList(
                  new URIAction(
                      "map location",
                      "https://www.google.com/maps/search/?api=1&query=%20&query_place_id="
                          + p.getPlaceId())));
      carusels.add(temp);
    }
    TemplateMessage templateMessage = new TemplateMessage("food", new CarouselTemplate(carusels));
    return templateMessage;
  }
}
{'fraction_non_alphanumeric': 0.12777545035609553, 'fraction_numerical': 0.008797653958944282, 'mean_word_length': 2.470203488372093, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '424174', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1401, 'n_words': 262}