Added comments.
This commit is contained in:
parent
5f4ad72a14
commit
be031b0b32
@ -16,16 +16,25 @@ class Controller {
|
|||||||
@Autowired
|
@Autowired
|
||||||
lateinit var observationRepository: ObservationRepository
|
lateinit var observationRepository: ObservationRepository
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all current sites.
|
||||||
|
*/
|
||||||
@GetMapping("/site")
|
@GetMapping("/site")
|
||||||
fun getAllSites(): List<NameValue> = siteRepository.findAll().map { NameValue(it.name, it.id) }
|
fun getAllSites(): List<NameValue> = siteRepository.findAll().map { NameValue(it.name, it.id) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new Site to the database based on the data provided in [newSite].
|
||||||
|
*/
|
||||||
@PostMapping("/site")
|
@PostMapping("/site")
|
||||||
fun addSite(@Valid @RequestBody newSite: NewSite): NameValue {
|
fun addSite(@Valid @RequestBody newSite: NewSite): NameValue {
|
||||||
val site = siteRepository.save(Site(name = newSite.name))
|
val site = siteRepository.save(Site(name = newSite.name))
|
||||||
return NameValue(site.name, site.id)
|
return NameValue(site.name, site.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the tutors assigned to the site with the given [id].
|
||||||
|
* Returned in a form compatible with a HTML Select element.
|
||||||
|
*/
|
||||||
@GetMapping("/site/{id}/tutors")
|
@GetMapping("/site/{id}/tutors")
|
||||||
fun getTutorsForSite(@PathVariable(value = "id") id: Long): List<NameValue>? {
|
fun getTutorsForSite(@PathVariable(value = "id") id: Long): List<NameValue>? {
|
||||||
val site = siteRepository.findById(id)
|
val site = siteRepository.findById(id)
|
||||||
@ -34,9 +43,16 @@ class Controller {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all known tutors.
|
||||||
|
* Returned in a form compatible with a HTML Select element.
|
||||||
|
*/
|
||||||
@GetMapping("/tutor")
|
@GetMapping("/tutor")
|
||||||
fun getAllTutors(): List<NameValue> = tutorRepository.findAll().map { NameValue(it.name, it.id) }
|
fun getAllTutors(): List<NameValue> = tutorRepository.findAll().map { NameValue(it.name, it.id) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new Tutor to the database based on the data provided in [newTutor].
|
||||||
|
*/
|
||||||
@PostMapping("/tutor")
|
@PostMapping("/tutor")
|
||||||
fun addTutor(@Valid @RequestBody newTutor: NewTutor): NameValue? {
|
fun addTutor(@Valid @RequestBody newTutor: NewTutor): NameValue? {
|
||||||
var nameValue: NameValue? = null
|
var nameValue: NameValue? = null
|
||||||
@ -49,18 +65,24 @@ class Controller {
|
|||||||
return nameValue
|
return nameValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all observations overseen by the tutor with [id].
|
||||||
|
*/
|
||||||
@GetMapping("/tutor/{id}/observations")
|
@GetMapping("/tutor/{id}/observations")
|
||||||
fun getObservationsForTutor(@PathVariable(value = "id") id: Long): List<SimpleObservation> =
|
fun getObservationsForTutor(@PathVariable(value = "id") id: Long): List<SimpleObservation> =
|
||||||
tutorRepository.findById(id).map { tutor ->
|
tutorRepository.findById(id).map { tutor ->
|
||||||
tutor.observations.map { SimpleObservation(it) }
|
tutor.observations.map { SimpleObservation(it) }
|
||||||
}.orElse(listOf())
|
}.orElse(listOf())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new observation to the database using data provided in [newObservation].
|
||||||
|
*/
|
||||||
@PostMapping("/observation")
|
@PostMapping("/observation")
|
||||||
fun addObservation(@Valid @RequestBody newObservation: NewObservation): Long? {
|
fun addObservation(@Valid @RequestBody newObservation: NewObservation): Long? {
|
||||||
val site = siteRepository.findById(newObservation.site)
|
val site = siteRepository.findById(newObservation.site)
|
||||||
val tutors = tutorRepository.findAllById(newObservation.tutors).toSet()
|
val tutors = tutorRepository.findAllById(newObservation.tutors).toSet()
|
||||||
if(!site.isPresent) return null
|
if (!site.isPresent) return null
|
||||||
if(tutors.isEmpty() || tutors.size != newObservation.tutors.size) return null
|
if (tutors.isEmpty() || tutors.size != newObservation.tutors.size) return null
|
||||||
val overallScores = newObservation.entries.asSequence().groupBy { it.type }
|
val overallScores = newObservation.entries.asSequence().groupBy { it.type }
|
||||||
.map { entry -> entry.key to entry.value.asSequence().mapNotNull { it.rating }.average() }
|
.map { entry -> entry.key to entry.value.asSequence().mapNotNull { it.rating }.average() }
|
||||||
.map { it.first to if (it.second > 0) it.second else null }.toList()
|
.map { it.first to if (it.second > 0) it.second else null }.toList()
|
||||||
@ -87,6 +109,9 @@ class Controller {
|
|||||||
return observation.id
|
return observation.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all observations that are within the constraints provided in [observationsRequest].
|
||||||
|
*/
|
||||||
@PostMapping("/observations")
|
@PostMapping("/observations")
|
||||||
fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List<Observation> {
|
fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List<Observation> {
|
||||||
if (observationsRequest.tutor != null) {
|
if (observationsRequest.tutor != null) {
|
||||||
@ -118,10 +143,14 @@ class Controller {
|
|||||||
return listOf()
|
return listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all observations that are within the constraints provided in [observationsRequest]
|
||||||
|
* in a format compatible with ChartJS.
|
||||||
|
*/
|
||||||
@PostMapping("/observations/chartdata")
|
@PostMapping("/observations/chartdata")
|
||||||
fun getObservationsChartData(@Valid @RequestBody observationsRequest: ObservationsRequest): ChartData? {
|
fun getObservationsChartData(@Valid @RequestBody observationsRequest: ObservationsRequest): ChartData? {
|
||||||
val data = getObservations(observationsRequest)
|
val data = getObservations(observationsRequest)
|
||||||
if(data.isEmpty()) return ChartData(listOf(), listOf())
|
if (data.isEmpty()) return ChartData(listOf(), listOf())
|
||||||
val groupedData = data.asSequence().groupBy { it.date }.map { entry ->
|
val groupedData = data.asSequence().groupBy { it.date }.map { entry ->
|
||||||
AverageData(
|
AverageData(
|
||||||
entry.value.asSequence().mapNotNull { it.monitoring }.average(),
|
entry.value.asSequence().mapNotNull { it.monitoring }.average(),
|
||||||
|
@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty
|
|||||||
import org.joda.time.LocalDate
|
import org.joda.time.LocalDate
|
||||||
import javax.persistence.*
|
import javax.persistence.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a location at which observations occur.
|
||||||
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
data class Site(
|
data class Site(
|
||||||
@Id
|
@Id
|
||||||
@ -15,6 +18,9 @@ data class Site(
|
|||||||
val tutors: MutableSet<Tutor> = mutableSetOf()
|
val tutors: MutableSet<Tutor> = mutableSetOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a tutor who can oversee observations.
|
||||||
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
data class Tutor(
|
data class Tutor(
|
||||||
@Id
|
@Id
|
||||||
@ -39,6 +45,9 @@ enum class RatingCategory {
|
|||||||
MONITORING, CONTROL, CONSERVATISM, TEAMWORK, KNOWLEDGE
|
MONITORING, CONTROL, CONSERVATISM, TEAMWORK, KNOWLEDGE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data record for a training observation.
|
||||||
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(indexes = [Index(name = "dateIndex", columnList = "date")])
|
@Table(indexes = [Index(name = "dateIndex", columnList = "date")])
|
||||||
data class Observation(
|
data class Observation(
|
||||||
@ -68,6 +77,9 @@ data class Observation(
|
|||||||
val tutors: Set<Tutor>
|
val tutors: Set<Tutor>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry giving specific details on observation performance for a tutor defined constraint.
|
||||||
|
*/
|
||||||
@Embeddable
|
@Embeddable
|
||||||
data class Entry(
|
data class Entry(
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
Loading…
Reference in New Issue
Block a user