<commit_before>package controllers

import models._
import models.JsonHelper._
import play.api.data.Forms._
import play.api.data._
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.json.Json._
import play.api.mvc._
import providers.{LocationProvider, WeatherFetchStrategies, ConcreteProviders}
import scala.concurrent.Future
import views._


object Application extends Controller
with LocationProvider
with WeatherFetchStrategies
with ConcreteProviders {

  /**
   * Describe the computer form (used in both edit and create screens).
   */
  val addressForm = Form(
    mapping(
      "address" -> nonEmptyText
    )(Address.apply)(Address.unapply)
  )


  /**
   * Simple action that displays the index page.
   * @return
   */
  def index = Action.async {
    Future {
      Ok(html.main())
    }
  }


  /**
   * Method that returns the location for an address as JSON.
   * Mapped to the GET verb in routes.
   *
   * @param address
   * @return
   */
  def getLocationForAddress_GET(address: String) = Action.async {
    getLocations(address).map(s => Ok(toJson(s)))
  }


  /**
   * Method that binds an address from the request. Looks up the
   * locations for that address and then gets the weather for the
   * locations according to a defined strategy.
   * Mapped to the POST verb in routes
   *
   * @return
   */
  def getLocationWithWeather_POST = Action.async(parse.json) {
    implicit request =>
      addressForm.bindFromRequest.fold(formWithErrors => Future {
        BadRequest("Unable to parse form")
      },
        address => Future {
          getLocationsWithWeatherAsJson(address.address)
        })
  }


  /**
   * Method that returns a location with weather for an address.
   * Mapped to the GET verb in routes
   *
   * @param address
   * @return
   */
  def getLocationsWithWeather_GET(address: String) = Action.async {
    getLocationsWithWeatherAsJson(address)
  }


  def getLocationsWithWeatherFuture(locations: Seq[Location]): Future[Seq[LocationWithWeather]] =
    Future.sequence(locations.map(location => smhi(location)))


  private def getLocationsWithWeatherAsJson(address: String): Future[SimpleResult] = {
    for {
      locations <- getLocations(address)
      locationsWithWeather <- getLocationsWithWeatherFuture(locations)
    } yield Ok(toJson(locationsWithWeather))
  }


}<commit_msg>make getLocationsWithWeatherFuture private<commit_after>package controllers

import models._
import models.JsonHelper._
import play.api.data.Forms._
import play.api.data._
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.json.Json._
import play.api.mvc._
import providers.{LocationProvider, WeatherFetchStrategies, ConcreteProviders}
import scala.concurrent.Future
import views._


object Application extends Controller
with LocationProvider
with WeatherFetchStrategies
with ConcreteProviders {

  /**
   * Describe the computer form (used in both edit and create screens).
   */
  val addressForm = Form(
    mapping(
      "address" -> nonEmptyText
    )(Address.apply)(Address.unapply)
  )


  /**
   * Simple action that displays the index page.
   * @return
   */
  def index = Action.async {
    Future {
      Ok(html.main())
    }
  }


  /**
   * Method that returns the location for an address as JSON.
   * Mapped to the GET verb in routes.
   *
   * @param address
   * @return
   */
  def getLocationForAddress_GET(address: String) = Action.async {
    getLocations(address).map(s => Ok(toJson(s)))
  }


  /**
   * Method that binds an address from the request. Looks up the
   * locations for that address and then gets the weather for the
   * locations according to a defined strategy.
   * Mapped to the POST verb in routes
   *
   * @return
   */
  def getLocationWithWeather_POST = Action.async(parse.json) {
    implicit request =>
      addressForm.bindFromRequest.fold(formWithErrors => Future {
        BadRequest("Unable to parse form")
      },
        address => Future {
          getLocationsWithWeatherAsJson(address.address)
        })
  }


  /**
   * Method that returns a location with weather for an address.
   * Mapped to the GET verb in routes
   *
   * @param address
   * @return
   */
  def getLocationsWithWeather_GET(address: String) = Action.async {
    getLocationsWithWeatherAsJson(address)
  }


  private def getLocationsWithWeatherFuture(locations: Seq[Location]): Future[Seq[LocationWithWeather]] =
    Future.sequence(locations.map(location => smhi(location)))


  private def getLocationsWithWeatherAsJson(address: String): Future[SimpleResult] = {
    for {
      locations <- getLocations(address)
      locationsWithWeather <- getLocationsWithWeatherFuture(locations)
    } yield Ok(toJson(locationsWithWeather))
  }


}
{'fraction_non_alphanumeric': 0.0931794333683106, 'fraction_numerical': 0.0, 'mean_word_length': 3.3485401459854014, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '4917398', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1360, 'n_words': 371}