Added csv dump matching format of existing observations database.
This commit is contained in:
parent
51fbb9a3db
commit
42ce7bd8df
@ -189,6 +189,18 @@ class Controller {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@PostMapping("/observations/csv")
|
||||
fun getObservationsCsvDump(@Valid @RequestBody observationsRequest: ObservationsRequest): String? {
|
||||
val data = getObservations(observationsRequest)
|
||||
if(data.isEmpty()) return null
|
||||
val builder = StringBuilder(data[0].csvHeaderString())
|
||||
data.forEach {
|
||||
builder.append('\n')
|
||||
builder.append(it.toCsvFormat())
|
||||
}
|
||||
return builder.toString()
|
||||
}
|
||||
}
|
||||
|
||||
data class AverageData(
|
||||
|
@ -18,6 +18,7 @@ import javax.persistence.ManyToMany
|
||||
import javax.persistence.ManyToOne
|
||||
import javax.persistence.OneToMany
|
||||
import javax.persistence.Table
|
||||
import kotlin.math.round
|
||||
|
||||
/**
|
||||
* Defines a location at which observations occur.
|
||||
@ -95,7 +96,45 @@ data class Observation(
|
||||
val tutors: Set<Tutor>,
|
||||
@ManyToMany
|
||||
val persons: Set<Person>
|
||||
)
|
||||
) {
|
||||
fun csvHeaderString(): String {
|
||||
return "Ob ID,Observerfull,Observer,obDate,Title,Type,Department,Station,Station Focus,Scores-Monitoring,Scores-Control Procedural," +
|
||||
"Scores-Control,Scores-Conservatism,Scores-Teamwork Comms,Scores-Teamwork Leadership,Scores-Teamwork Workload,\"Scores-Knowledge, Skills and Attitudes\"," +
|
||||
"Strengths-Monitoring,Strengths-Control Procedural,Strengths-Control,Strengths-Conservatism,Strengths-Teamwork Comms," +
|
||||
"Strengths-Teamwork Leadership,Strengths-Teamwork Workload,\"Strengths-Knowledge, Skills and Attitudes\"," +
|
||||
"Develop-Monitoring,Develop-Control Procedural,Develop-Control,Develop-Conservatism,Develop-Teamwork Comms," +
|
||||
"Develop-Teamwork Leadership,Develop-Teamwork Workload,\"Develop-Knowledge, Skills and Attitudes\""
|
||||
}
|
||||
fun toCsvFormat(): String {
|
||||
return ",,${tutors.elementAt(0).name},$date,\"$observed\",\"Training\",\"Performance Improvement - Training\",\"${site.name}\",\"N/A\"," +
|
||||
"${roundScore(monitoring)},${roundScore(controlProcedural)},${roundScore(control)}," +
|
||||
"${roundScore(conservatism)},${roundScore(teamworkCommunications)},${roundScore(teamworkLeadership)}," +
|
||||
"${roundScore(teamworkWorkload)},${roundScore(knowledge)},\"${getStrengths(RatingCategory.MONITORING)}\"," +
|
||||
"\"${getStrengths(RatingCategory.CONTROL_PROCEDURAL)}\",\"${getStrengths(RatingCategory.CONTROL)}\",\"${getStrengths(RatingCategory.CONSERVATISM)}\"," +
|
||||
"\"${getStrengths(RatingCategory.TEAMWORK_COMMUNICATIONS)}\",\"${getStrengths(RatingCategory.TEAMWORK_LEADERSHIP)}\"," +
|
||||
"\"${getStrengths(RatingCategory.TEAMWORK_WORKLOAD)}\",\"${getStrengths(RatingCategory.KNOWLEDGE)}\"," +
|
||||
"\"${getImprovements(RatingCategory.MONITORING)}\",\"${getImprovements(RatingCategory.CONTROL_PROCEDURAL)}\"," +
|
||||
"\"${getImprovements(RatingCategory.CONTROL)}\",\"${getImprovements(RatingCategory.CONSERVATISM)}\"," +
|
||||
"\"${getImprovements(RatingCategory.TEAMWORK_COMMUNICATIONS)}\",\"${getImprovements(RatingCategory.TEAMWORK_LEADERSHIP)}\"," +
|
||||
"\"${getImprovements(RatingCategory.TEAMWORK_WORKLOAD)}\",\"${getImprovements(RatingCategory.KNOWLEDGE)}\""
|
||||
}
|
||||
|
||||
private fun getStrengths(category: RatingCategory): String{
|
||||
return entries.asSequence().filter { it.type == category }.map{ it.strengths }.joinToString()
|
||||
}
|
||||
|
||||
private fun getImprovements(category: RatingCategory): String{
|
||||
return entries.asSequence().filter { it.type == category }.map{ it.improvements }.joinToString()
|
||||
}
|
||||
|
||||
private fun roundScore(input: Double?): String {
|
||||
if (input != null) {
|
||||
return round(input).toString()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Entry giving specific details on observation performance for a tutor defined constraint.
|
||||
|
Loading…
Reference in New Issue
Block a user