Can now get average score stats over all time.
This commit is contained in:
parent
9ceac25393
commit
583e07877d
@ -0,0 +1,33 @@
|
||||
package uk.co.neviyn.Observations.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jdbi.v3.core.mapper.RowMapper;
|
||||
import org.jdbi.v3.core.statement.StatementContext;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class AverageStats {
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
private float monitoring, control, conservatism, teamwork, knowledge;
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
private LocalDate date;
|
||||
|
||||
public static class Mapper implements RowMapper<AverageStats> {
|
||||
public AverageStats map(ResultSet rs, StatementContext ctx) throws SQLException {
|
||||
return new AverageStats(rs.getFloat("monitoring"), rs.getFloat("control"), rs.getFloat("conservatism"),
|
||||
rs.getFloat("teamwork"), rs.getFloat("knowledge"), new LocalDate(rs.getDate("date")));
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.joda.time.DateTime;
|
||||
import uk.co.neviyn.Observations.api.AverageStats;
|
||||
import uk.co.neviyn.Observations.api.NewObservation;
|
||||
import uk.co.neviyn.Observations.core.Observation;
|
||||
|
||||
@ -44,4 +45,9 @@ public interface ObservationDao {
|
||||
"LEFT JOIN tutor ON observation_tutor.tutorId = tutor.id WHERE tutor.id = :tutorId")
|
||||
List<Observation> observationsByTutorBetweenDates(@Bind("tutorId")int tutorId, @Bind("startDate")DateTime startDate,
|
||||
@Bind("endDate")DateTime endDate);
|
||||
|
||||
@SqlQuery("SELECT AVG(monitoring) as monitoring, AVG(control) as control, AVG(conservatism) as conservatism, " +
|
||||
"AVG(teamwork) as teamwork, AVG(knowledge) as knowledge, date FROM observations GROUP BY date")
|
||||
@RegisterRowMapper(AverageStats.Mapper.class)
|
||||
List<AverageStats> averageObservationScoresByDay();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import uk.co.neviyn.Observations.api.AverageStats;
|
||||
import uk.co.neviyn.Observations.api.NewObservation;
|
||||
import uk.co.neviyn.Observations.core.Observation;
|
||||
import uk.co.neviyn.Observations.dao.ObservationDao;
|
||||
@ -42,4 +43,10 @@ public class ObservationResource {
|
||||
public List<Observation> observationsBy(@PathParam("tutorId") int tutorId){
|
||||
return dao.observationsByTutor(tutorId);
|
||||
}
|
||||
|
||||
@Path("/average/all")
|
||||
@GET
|
||||
public List<AverageStats> averageObservationScores(){
|
||||
return dao.averageObservationScoresByDay();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user