Skip to content

Commit

Permalink
Merge pull request #1349 from ProjectSidewalk/develop
Browse files Browse the repository at this point in the history
v5.0.0
  • Loading branch information
misaugstad authored Nov 29, 2018
2 parents 9805c5e + e30e1b2 commit fa97786
Show file tree
Hide file tree
Showing 325 changed files with 8,447 additions and 10,379 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Set up the development environment for Scala, JavaScript and Postgres. The detai
1. Install JDK 7 (or above), Scala, and `activator` on your computer. See detailed [instructions for installing Scala environment here](https://github.com/ProjectSidewalk/Instructions#java--scala).
2. Install Node.js. See detailed [instructions here](https://github.com/ProjectSidewalk/Instructions#javascript).
3. On the top directory, run `npm install` to install all the JavaScript dependencies.
4. Set up the Postgres database by folloing the tutorial. See detailed [instructions on installing the Postgres database here.](https://github.com/ProjectSidewalk/Instructions#postgresql)
4. Set up the Postgres database by following the tutorial. See detailed [instructions on installing the Postgres database here.](https://github.com/ProjectSidewalk/Instructions#postgresql)

### Running the Application Locally
To run the web server locally,
Expand Down
4 changes: 2 additions & 2 deletions anonymize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def anonymize(sql_filename):


terminate_line = "\."
copy_user_start_line = """COPY "user" (user_id, username, email) FROM stdin;"""
copy_user_start_line = """COPY sidewalk_user (user_id, username, email) FROM stdin;"""
copy_login_info_start_line = """COPY login_info (login_info_id, provider_id, provider_key) FROM stdin;"""


Expand All @@ -39,7 +39,7 @@ def anonymize(sql_filename):

new_line = line

# Substitute lines in the user table
# Substitute lines in the sidewalk_user table
if read_user_table:
line_list = line.split("\t")
if line_list[1] != "anonymous":
Expand Down
106 changes: 12 additions & 94 deletions app/controllers/AdminController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import controllers.headers.ProvidesHeader
import formats.json.TaskFormats._
import formats.json.UserRoleSubmissionFormats._
import models.attribute.{GlobalAttribute, GlobalAttributeTable}
import models.audit.{AuditTaskInteractionTable, AuditTaskTable, InteractionWithLabel}
import models.audit.{AuditTaskInteractionTable, AuditTaskTable, InteractionWithLabel, UserAuditTime}
import models.daos.slick.DBTableDefinitions.UserTable
import models.label.LabelTable.LabelMetadata
import models.label.{LabelPointTable, LabelTable, LabelTypeTable}
Expand Down Expand Up @@ -147,15 +147,15 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth
}

/**
* Gets count of completed missions for each anonymous user (diff users have diff ip addresses)
* Gets count of completed missions for each user.
*
* @return
*/
def getAllAnonUserCompletedMissionCounts = UserAwareAction.async { implicit request =>
def getAllUserCompletedMissionCounts = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {
val counts: List[(Option[String], Int)] = UserDAOImpl.getAnonUserCompletedMissionCounts
val jsonArray = Json.arr(counts.map(x => {
Json.obj("ip_address" -> x._1, "count" -> x._2, "is_researcher" -> false)
val missionCounts: List[(String, String, Int)] = MissionTable.selectMissionCountsPerUser
val jsonArray = Json.arr(missionCounts.map(x => {
Json.obj("user_id" -> x._1, "role" -> x._2, "count" -> x._3)
}))
Future.successful(Ok(jsonArray))
} else {
Expand All @@ -170,10 +170,8 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth
*/
def getAllUserSignInCounts = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {
val counts: List[(String, Int)] = WebpageActivityTable.selectAllSignInCounts
val jsonArray = Json.arr(counts.map(x => {
Json.obj("user_id" -> x._1, "count" -> x._2, "is_researcher" -> UserRoleTable.isResearcher(UUID.fromString(x._1)))
}))
val counts: List[(String, String, Int)] = WebpageActivityTable.selectAllSignInCounts
val jsonArray = Json.arr(counts.map(x => { Json.obj("user_id" -> x._1, "role" -> x._2, "count" -> x._3) }))
Future.successful(Ok(jsonArray))
} else {
Future.successful(Redirect("/"))
Expand Down Expand Up @@ -297,43 +295,13 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth
def getAuditTimes() = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {
val auditTimes = AuditTaskInteractionTable.selectAllAuditTimes().map(auditTime =>
Json.obj("user_id" -> auditTime.userId, "time" -> auditTime.duration, "ip_address" -> auditTime.ipAddress))
Json.obj("user_id" -> auditTime.userId, "role" -> auditTime.role, "time" -> auditTime.duration))
Future.successful(Ok(JsArray(auditTimes)))
} else {
Future.successful(Redirect("/"))
}
}

/**
* Get all auditing times for Turkers
*
* @return
*/
def getTurkerAuditTimes() = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {
val auditTimes = AuditTaskInteractionTable.selectAllTurkerAuditTimes().map(auditTime =>
Json.obj("user_id" -> auditTime.userId, "time" -> auditTime.duration, "ip_address" -> auditTime.ipAddress))
Future.successful(Ok(JsArray(auditTimes)))
} else {
Future.successful(Redirect("/"))
}
}

/**
* Get all anonymous auditing times
*
* @return
*/
def getAnonAuditTimes() = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {
val anonAuditTimes = AuditTaskInteractionTable.selectAllAnonAuditTimes().map(auditTime =>
Json.obj("user_id" -> auditTime.userId, "time" -> auditTime.duration, "ip_address" -> auditTime.ipAddress))
Future.successful(Ok(JsArray(anonAuditTimes)))
} else {
Future.successful(Redirect("/"))
}
}


/**
* This method returns the tasks and labels submitted by the given user.
Expand All @@ -354,27 +322,6 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth
}
}

def getMissionsCompletedByUsers = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {
val missionsCompleted = MissionTable.selectMissionsCompletedByUsers.map(x =>
Json.obj("username" -> x.username, "label" -> x.label, "level" -> x.level, "distance_m" -> x.distance_m,
"distance_ft" -> x.distance_ft, "distance_mi" -> x.distance_mi)
)
Future.successful(Ok(JsArray(missionsCompleted)))
} else {
Future.successful(Redirect("/"))
}
}

def completedTasks = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {

Future.successful(Ok(JsArray()))
} else {
Future.successful(Redirect("/"))
}
}

/**
* Get records of audit task interactions of a user
*
Expand All @@ -394,19 +341,6 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth
}
}

def auditTaskInteractions(taskId: Int) = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {
AuditTaskTable.find(taskId) match {
case Some(user) =>
val interactions = AuditTaskInteractionTable.selectAuditTaskInteractions(taskId).map(x => Json.toJson(x))
Future.successful(Ok(JsArray(interactions)))
case _ => Future.successful(Ok(Json.obj("error" -> "no user found")))
}
} else {
Future.successful(Redirect("/"))
}
}

def getAnAuditTaskPath(taskId: Int) = UserAwareAction.async { implicit request =>
if (isAdmin(request.identity)) {
AuditTaskTable.find(taskId) match {
Expand Down Expand Up @@ -455,26 +389,10 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth
* USER CENTRIC ANALYTICS
*/

def getAllRegisteredUserLabelCounts = UserAwareAction.async { implicit request =>
val labelCounts = LabelTable.getLabelCountsPerRegisteredUser
val json = Json.arr(labelCounts.map(x => Json.obj(
"user_id" -> x._1, "count" -> x._2, "is_researcher" -> UserRoleTable.isResearcher(UUID.fromString(x._1))
)))
Future.successful(Ok(json))
}

def getAllTurkerUserLabelCounts = UserAwareAction.async { implicit request =>
val labelCounts = LabelTable.getLabelCountsPerTurkerUser
val json = Json.arr(labelCounts.map(x => Json.obj(
"user_id" -> x._1, "count" -> x._2, "is_researcher" -> UserRoleTable.isResearcher(UUID.fromString(x._1))
)))
Future.successful(Ok(json))
}

def getAllAnonUserLabelCounts = UserAwareAction.async { implicit request =>
val labelCounts = LabelTable.getLabelCountsPerAnonUser
def getAllUserLabelCounts = UserAwareAction.async { implicit request =>
val labelCounts = LabelTable.getLabelCountsPerUser
val json = Json.arr(labelCounts.map(x => Json.obj(
"ip_address" -> x._1, "count" -> x._2, "is_researcher" -> false
"user_id" -> x._1, "role" -> x._2, "count" -> x._3
)))
Future.successful(Ok(json))
}
Expand Down
Loading

0 comments on commit fa97786

Please sign in to comment.