<commit_before>package controllers

import akka.actor.Props
import akka.pattern.ask
import akka.util.Timeout
import com.decodified.scalassh.SSH
import com.typesafe.config.ConfigFactory
import io.rampant.minecraft.ServerInfo
import io.rampant.minestatus._
import play.api.Configuration
import play.api.Play.current
import play.api.cache.Cache
import play.api.libs.concurrent.Akka
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc._

import scala.collection.JavaConverters._
import scala.concurrent.Future
import scala.concurrent.duration._

object Application extends Controller {
	implicit val actorTimeout = Timeout(5 seconds)
	val infoActor = Akka.system.actorOf(Props[StatusWorker], name = "infoActor")

	val sshLOG = play.api.Logger("ssh")

	val serverInfoCacheTimeout = 1.days

	val pageTitle = current.configuration.getString("page.title").get
	val serverDefaults = current.configuration.getConfig("server.defaults").get.underlying
	val configuredServers = ConfigFactory.load().getConfigList("servers").asScala.map({ c => Configuration(c.withFallback(serverDefaults))})

	case class MCServer(id: String, name: String, info: Option[ServerInfo], running: Boolean, cachedInfo: Boolean = false)

	def index = Action.async {
		Future.sequence(configuredServers.map({ s =>
			val host = s.getString("host").get
			val port = s.getInt("query.port").get
			val cacheKey = s"mcserver:$host:$port"
			val serverId = s.getString("id").get
			(infoActor ? QueryRequest(host, port)).map(_.asInstanceOf[QueryResponse]).map({
				case OfflineResponse =>
					val info = Cache.getAs[ServerInfo](cacheKey)
					MCServer(serverId, s.getString("name").getOrElse(serverId), info, running = false, cachedInfo = info.isDefined);
				case info: InfoResponse =>
					Cache.set(cacheKey, info, serverInfoCacheTimeout)
					MCServer(serverId, info.info.name, Some(info.info), running = true);
			})
		})).map({ s => Ok(views.html.index(pageTitle, s))})
	}

	def start(id: String) = Action {
		configuredServers.find(_.getString("id").get.equalsIgnoreCase(id)) match {
			case None => NotFound("Unknown server: " + id)
			case Some(s) =>
				SSH(s.getString("host").get) { client =>
					client.exec(s.getString("command").get) match {
						case Right(v) => sshLOG.debug(v.stdOutAsString())
						case Left(v) => sshLOG.error("SSH Error: " + v)
					}
				}
				Redirect(routes.Application.index)
		}
	}
}<commit_msg>Abstract out a few methods, for the future<commit_after>package controllers

import akka.actor.Props
import akka.pattern.ask
import akka.util.Timeout
import com.decodified.scalassh.SSH
import com.typesafe.config.ConfigFactory
import io.rampant.minecraft.ServerInfo
import io.rampant.minestatus._
import play.api.Configuration
import play.api.Play.current
import play.api.cache.Cache
import play.api.libs.concurrent.Akka
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc._

import scala.collection.JavaConverters._
import scala.concurrent.Future
import scala.concurrent.duration._

object Application extends Controller {
	implicit val actorTimeout = Timeout(5 seconds)
	val infoActor = Akka.system.actorOf(Props[StatusWorker], name = "infoActor")

	val sshLOG = play.api.Logger("ssh")

	val serverInfoCacheTimeout = 1.days

	val pageTitle = current.configuration.getString("page.title").get
	val serverDefaults = current.configuration.getConfig("server.defaults").get.underlying
	val configuredServers = ConfigFactory.load().getConfigList("servers").asScala.map({ c => Configuration(c.withFallback(serverDefaults))})

	case class MCServer(id: String, name: String, info: Option[ServerInfo], running: Boolean, cachedInfo: Boolean = false)

	def serverFromConfig(s: Configuration) = {
		val host = s.getString("host").get
		val port = s.getInt("query.port").get
		val cacheKey = s"mcserver:$host:$port"
		val serverId = s.getString("id").get
		(infoActor ? QueryRequest(host, port)).map(_.asInstanceOf[QueryResponse]).map({
			case OfflineResponse =>
				val info = Cache.getAs[ServerInfo](cacheKey)
				MCServer(serverId, s.getString("name").getOrElse(serverId), info, running = false, cachedInfo = info.isDefined);
			case info: InfoResponse =>
				Cache.set(cacheKey, info, serverInfoCacheTimeout)
				MCServer(serverId, info.info.name, Some(info.info), running = true);
		})
	}

	def findServerConfig(id: String) = configuredServers.find(_.getString("id").get.equalsIgnoreCase(id))

	def index = Action.async {
		Future.sequence(configuredServers.map(serverFromConfig))
			.map({ s => Ok(views.html.index(pageTitle, s))})
	}

	def start(id: String) = Action {
		findServerConfig(id) match {
			case None => NotFound("Unknown server: " + id)
			case Some(s) =>
				SSH(s.getString("host").get) { client =>
					client.exec(s.getString("command").get) match {
						case Right(v) => sshLOG.debug(v.stdOutAsString())
						case Left(v) => sshLOG.error("SSH Error: " + v)
					}
				}
				Redirect(routes.Application.index)
		}
	}
}
{'fraction_non_alphanumeric': 0.13447236180904523, 'fraction_numerical': 0.0008040201005025126, 'mean_word_length': 4.902728351126927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '3846816', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1555, 'n_words': 315}