Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a service for calculating statistics

  • Loading branch information...
commit 53a63dd6ae5b5b1370931e23931d7e55499c576f 1 parent 9423aee
@gardeman gardeman authored
View
6 qanban/application.properties
@@ -1,12 +1,14 @@
#utf-8
-#Fri Jan 15 11:38:29 CET 2010
+#Wed Jan 20 09:46:45 CET 2010
plugins.acegi=0.5.2
app.version=0.1
+plugins.console=0.2.2
plugins.jquery=1.3.2.4
app.servlet.version=2.4
plugins.hibernate=1.1.1
plugins.code-coverage=1.1.7
-app.name=Qanban
plugins.liquibase=1.9.3.0
+app.name=Qanban
app.grails.version=1.1.1
+plugins.joda-time=0.5
plugins.avatar=0.3
View
104 qanban/grails-app/services/se/qbranch/qanban/StatisticsService.groovy
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2010 Qbranch AB
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package se.qbranch.qanban
+
+import org.joda.time.Period
+import org.joda.time.Interval
+
+
+class StatisticsService {
+
+ boolean transactional = true
+
+
+ // Lead Time Calculation
+
+ def calculateLeadTime(board) {
+ def cards = getArchivedCards(board,)
+ getAverageLeadTime(cards)
+ }
+
+ def calculateLeadTime(board,interval){
+ def cards = getArchivedCardsFromInterval(board,interval)
+ getAverageLeadTime(cards)
+ }
+
+ private getAverageLeadTime(cards){
+ def leadTimes = cards.collect{ card ->
+ getLeadTimeInterval(card).toDurationMillis()
+ }
+ new Period((leadTimes == [] ? 0 : leadTimes.sum() / leadTimes.size()).longValue())
+ }
+
+ private getLeadTimeInterval(card){
+ def startTimeStamp = card.dateCreated.time
+ def archivedTimeStamp = CardEventMove.findByDomainIdAndPhaseDomainId(card.domainId,card.phase.board.phases[-1].domainId).dateCreated.time
+ new Interval(startTimeStamp, archivedTimeStamp)
+ }
+
+
+ // Cycle Time Calculation
+
+ def calculateCycleTime(board) {
+ def cards = getArchivedCards(board)
+ getCycleTime(board,cards)
+ }
+
+ def calculateCycleTime(board,interval){
+ def cards = getArchivedCardsFromInterval(board,interval)
+ getCycleTime(board,cards,interval)
+ }
+
+ private getCycleTime(board,cards){
+ def events = getArchivingEvents(board,cards)
+ new Period( (( events[-1].dateCreated.time - events[1].dateCreated.time ) / events.size()).longValue() )
+ }
+
+ private getCycleTime(board,cards,interval){
+ def events = getArchivingEvents(board,cards)
+ new Period( (( interval.endMillis - interval.startMillis ) / events.size()).longValue() )
+ }
+
+ private getArchivingEvents(board,cards){
+ def archive = board.phases[-1]
+ Event.withCriteria {
+ eq('class','se.qbranch.qanban.CardEventMove')
+ eq('phaseDomainId',archive.domainId)
+ 'in'('domainId',cards*.domainId)
+ order('dateCreated','asc')
+ }
+ }
+
+
+ // Shared help methods
+
+ private getArchivedCards(board){
+ board.phases[-1].cards
+ }
+
+ private getArchivedCardsFromInterval(board,interval){
+ def phase = board.phases[-1]
+ def events = Event.withCriteria {
+ eq('class','se.qbranch.qanban.CardEventMove')
+ eq('phaseDomainId',phase.domainId)
+ between('dateCreated',interval.start.toDate(),interval.end.toDate())
+ }
+ def domainIds = events.collect{ event -> event.domainId }
+ Card.findAllByDomainIdInList(domainIds)
+ }
+
+}
View
18 qanban/test/unit/se/qbranch/qanban/StatisticsServiceTests.groovy
@@ -0,0 +1,18 @@
+package se.qbranch.qanban
+
+import grails.test.*
+
+class StatisticsServiceTests extends GrailsUnitTestCase {
+ protected void setUp() {
+ super.setUp()
+
+ }
+
+ protected void tearDown() {
+ super.tearDown()
+ }
+
+ void testSomething() {
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.