Browse Source

count courseList requests seperat

pull/18/head
Jannik 2 years ago
parent
commit
2f1f65eba0
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 10
      src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt
  2. 3
      src/main/kotlin/org/mosad/thecitadelofricks/DataTypes.kt
  3. 24
      src/main/kotlin/org/mosad/thecitadelofricks/controller/StatusController.kt

10
src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt

@ -30,9 +30,9 @@ import org.mosad.thecitadelofricks.controller.CacheController.Companion.getTimet
import org.mosad.thecitadelofricks.controller.CacheController.Companion.mensaMenu
import org.mosad.thecitadelofricks.controller.StartupController
import org.mosad.thecitadelofricks.controller.StatusController.Companion.getStatus
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateCourseListRequests
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateMensaMenuRequests
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateTimetableRequests
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateTotalRequests
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.RequestMapping
@ -67,14 +67,13 @@ class APIController {
@RequestMapping("/courseList")
fun courseList(): CoursesList {
logger.info("courseList request at ${LocalDateTime.now()}!")
updateTotalRequests()
updateCourseListRequests()
return courseList
}
@RequestMapping("/mensamenu")
fun mensamenu(): MensaMenu {
logger.info("mensamenu request at ${LocalDateTime.now()}!")
updateTotalRequests()
updateMensaMenuRequests()
return mensaMenu
}
@ -85,7 +84,6 @@ class APIController {
@RequestParam(value = "week", defaultValue = "0") week: Int
): TimetableCourseWeek {
logger.info("timetable request at ${LocalDateTime.now()}!")
updateTotalRequests()
updateTimetableRequests(courseName)
return getTimetable(courseName, week)
}
@ -96,7 +94,7 @@ class APIController {
@RequestParam(value = "week", defaultValue = "0") week: Int
): HashSet<String> {
logger.info("lessonSubjectList request at ${LocalDateTime.now()}!")
updateTotalRequests()
updateTimetableRequests(courseName)
return getLessonSubjectList(courseName, week)
}
@ -107,7 +105,7 @@ class APIController {
@RequestParam(value = "week", defaultValue = "0") week: Int
): ArrayList<Lesson> {
logger.info("lesson request at ${LocalDateTime.now()}!")
updateTotalRequests()
updateTimetableRequests(courseName)
return getLesson(courseName, lessonSubject, week)
}

3
src/main/kotlin/org/mosad/thecitadelofricks/DataTypes.kt

@ -69,8 +69,9 @@ data class Status(
val uptime: String,
val apiVersion: String,
val softwareVersion: String,
val requestCount: Int,
val totalRequests: Int,
val mensaMenuRequests: Int,
val courseListRequests: Int,
val timetableRequests: ArrayList<TimetableCounter>,
val timetableListSize: Int,
val coursesLastUpdate: Date,

24
src/main/kotlin/org/mosad/thecitadelofricks/controller/StatusController.kt

@ -42,27 +42,34 @@ class StatusController {
private var totalRequests = 0
private var mensaMenuRequests = 0
private var courseListRequests = 0
private var timetableRequests = ArrayList<TimetableCounter>()
fun updateTotalRequests() {
/**
* if a mensamenu/courseList/timetable is requested update the specific and total request count
*/
fun updateMensaMenuRequests() {
mensaMenuRequests++
totalRequests++
}
fun updateMensaMenuRequests() {
mensaMenuRequests++
fun updateCourseListRequests() {
courseListRequests++
totalRequests++
}
/**
* if a timetable is requested update the request counter
*/
fun updateTimetableRequests(courseName: String) {
timetableRequests.stream().filter { it.courseName == courseName }.findFirst().ifPresentOrElse({
it.requests++
}, {
timetableRequests.add(TimetableCounter(courseName, 1))
})
totalRequests++
}
/**
* getters and setters
*/
fun getTotalRequests(): Int {
return totalRequests
}
@ -71,6 +78,10 @@ class StatusController {
return mensaMenuRequests
}
fun getCourseListRequests(): Int {
return courseListRequests
}
fun getTimetableRequests(): ArrayList<TimetableCounter> {
return timetableRequests
}
@ -108,6 +119,7 @@ class StatusController {
softwareVersion,
getTotalRequests(),
getMensaMenuRequests(),
getCourseListRequests(),
getTimetableRequests(),
CacheController.timetableList.size,
Date(CacheController.courseList.meta.updateTime * 1000),

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close