Skip to content

Commit

Permalink
Boostrap / refactoring
Browse files Browse the repository at this point in the history
bootstraping
crawl data types
header
  • Loading branch information
DePizzottri committed Jan 26, 2015
1 parent ce59af6 commit 2a9aa5c
Show file tree
Hide file tree
Showing 24 changed files with 9,739 additions and 31 deletions.
8 changes: 6 additions & 2 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import concurrent.{Future}
object Application extends Controller {

def index = Action { request =>
Ok(views.html.index("Feel my power!"))
Ok(views.html.index("IMI table of honor"))
}

def list= Action.async{ request =>
def list = Action.async { request =>
val pairedFutures = CodeforcesAccountsList.getAll.map( handle =>
(handle, CodeForcesWebGetter.get(handle).map{_.solvedCount})
)
Expand All @@ -26,6 +26,10 @@ def list= Action.async{ request =>
p._2 .map((_, p._1))
}

//val l = List((1, "a"), (2, "b"));

//Ok(views.html.list(l));

for(l <- resultFuture) yield Ok(views.html.list(l))
}
}
2 changes: 1 addition & 1 deletion app/model/Codeforces/JsonProtocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ object JsonProtocol extends DefaultJsonProtocol {
implicit val problemFormat = jsonFormat6(Problem)
implicit val partyFormat = jsonFormat8(Party)
implicit val submissionFormat = jsonFormat12(Submission)
implicit val statucResultFormat = jsonFormat2(StatusResponce)
implicit val statucResultFormat = jsonFormat2(StatusResponse)
}
2 changes: 1 addition & 1 deletion app/model/Codeforces/objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ case class Submission(
timeConsumedMillis: Int,
memoryConsumedBytes: Int)

case class StatusResponce(
case class StatusResponse(
status: String,
result: List[Submission])

20 changes: 20 additions & 0 deletions app/model/DataScheme/MineData.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.IMIHOF.MineData

import spray.http.DateTime

abstract class Data {
def raw: String
def solvedCount: Int
}

abstract class SubmitResult {
def date: DateTime

class SubmitStatus extends Enumeration {
type SubmitStatus = Value
val Success, TimeLimit, MemoryLimit, WrongAnswer = Value
}

def status: SubmitStatus
def attempt: Int
}
15 changes: 6 additions & 9 deletions app/model/WebGetter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ import play.api.libs.concurrent.Akka
import com.codeforces.api.objects._
import com.codeforces.api.JsonProtocol._

abstract class Data {
def raw: String
def solvedCount: Int
}
import com.IMIHOF.MineData._

class CodeForcesData(val data: StatusResponce) extends Data {
override def raw = data.toJson.prettyPrint
override def solvedCount = data.result.map(_.problem.name).toSet.size
class CodeForcesData(val data: StatusResponse) extends Data {
override def raw = data.toJson.prettyPrint
override def solvedCount = data.result.map(_.problem.name).toSet.size
}

object CodeForcesData {
def apply(rj: StatusResponce) = new CodeForcesData(rj)
def apply(rj: StatusResponse) = new CodeForcesData(rj)
}

trait WebGetter {
Expand All @@ -37,7 +34,7 @@ object CodeForcesWebGetter extends WebGetter {

import spray.httpx.SprayJsonSupport._

val pipeline = sendReceive ~> unmarshal[StatusResponce]
val pipeline = sendReceive ~> unmarshal[StatusResponse]
val response = pipeline(
Get("http://codeforces.com/api/user.status?handle=" + param + "&from=1&count=10000")
)
Expand Down
9 changes: 9 additions & 0 deletions app/views/header.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@(title:String)

<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<span class="navbar-brand" >@title</span>
</div>
</div>
</nav>
11 changes: 7 additions & 4 deletions app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@(message: String)

@main(message) {

<p><a href="@controllers.routes.Application.list" class="btn">
<i class="icon-plus"></i> "Get list!"</a></p>
@header("Main")

@main(message) {
<p>
<a href="@controllers.routes.Application.list" class="btn">
Get CodeForces list
</a>
</p>
}
27 changes: 18 additions & 9 deletions app/views/list.scala.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
@(list: List[(Int, String)])

@header("CodeForeces table of honor")

@main("Table of Honor") {
<table border='1' style="width:300px">
<tr><td>Handle</td><td>Solved N</td></tr>
@for(d <- list) {
<tr>
<td>@d._2</td>
<td>@d._1</td>
</tr>
}
</table>
<div class="container fluid">
<div class="raw">
<div class="col-md-4 col-md-offset-4">
<table class="table table-bordered table-hover">
<tr><th>Handle</th><th>Solved N</th></tr>
@for(d <- list) {
<tr>
<td>@d._2</td>
<td>@d._1</td>
</tr>
}
</table>
</div>
<div class="col-md-4"></div>
</div>
</div>
}
4 changes: 2 additions & 2 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<html>
<head>
<title>@title</title>
<link rel="stylesheet" type="text/css" media="screen" href='@routes.Assets.at("stylesheets/bootstrap.css")'>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="stylesheet" type="text/css" media="screen" href='@routes.Assets.at("css/bootstrap.css")'/>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"></link>
</head>
<body>
@content
Expand Down
2 changes: 1 addition & 1 deletion project/activator-sbt-echo-play-shim.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-echo-play" % "0.1.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-echo-play" % "0.1.6.2")
Loading

0 comments on commit 2a9aa5c

Please sign in to comment.