Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Max Mecklin
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f89a5a71
authored
Dec 16, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Statistics
1 parent
c98a99af
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
186 additions
and
62 deletions
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/StatisticsBeanLocal.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/ProductBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/StatisticsBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceSlotFacade.java
code/moya-web/WebContent/reports/basicStatistics.xhtml
code/moya-web/src/main/java/fi/codecrew/moya/web/reports/BasicStatisticsView.java
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/StatisticsBeanLocal.java
View file @
f89a5a7
...
@@ -18,18 +18,64 @@
...
@@ -18,18 +18,64 @@
*/
*/
package
fi
.
codecrew
.
moya
.
beans
;
package
fi
.
codecrew
.
moya
.
beans
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.ejb.Local
;
import
javax.ejb.Local
;
import
fi.codecrew.moya.beans.StatisticsBeanLocal.ProductSlotcountMover
;
import
fi.codecrew.moya.model.Product
;
@Local
@Local
public
interface
StatisticsBeanLocal
{
public
interface
StatisticsBeanLocal
{
public
Long
getGroupMembershipsEnteredEvent
();
public
Long
getGroupMembershipsEnteredEvent
();
public
Long
getCardDeliveredCount
();
public
Long
getCardDeliveredCount
();
public
Long
getGroupMembershipsTotalCount
();
public
Long
getGroupMembershipsTotalCount
();
public
Map
<
Long
,
Long
>
getHourlyIncomingStatistics
(
long
startingFromMillis
,
int
hourCount
);
public
Map
<
Long
,
Long
>
getHourlyIncomingStatistics
(
long
startingFromMillis
,
int
hourCount
);
public
static
class
ProductSlotcountMover
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
7759706761198824766L
;
private
final
Product
product
;
private
Long
totalSlots
;
private
Long
unusedSlots
;
public
ProductSlotcountMover
(
Product
p
)
{
this
.
product
=
p
;
}
public
Long
getTotalSlots
()
{
return
totalSlots
;
}
public
void
setTotalSlots
(
Long
totalSlots
)
{
this
.
totalSlots
=
totalSlots
;
}
public
Long
getUnusedSlots
()
{
return
unusedSlots
;
}
public
void
setUnusedSlots
(
Long
unusedSlots
)
{
this
.
unusedSlots
=
unusedSlots
;
}
public
Product
getProduct
()
{
return
product
;
}
}
List
<
ProductSlotcountMover
>
getUnusedSlots
(
boolean
onlyPaid
);
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/ProductBean.java
View file @
f89a5a7
...
@@ -217,9 +217,9 @@ public class ProductBean implements ProductBeanLocal {
...
@@ -217,9 +217,9 @@ public class ProductBean implements ProductBeanLocal {
if
(
prod
.
getPlaces
()
!=
null
&&
!
prod
.
getPlaces
().
isEmpty
())
{
if
(
prod
.
getPlaces
()
!=
null
&&
!
prod
.
getPlaces
().
isEmpty
())
{
Long
selectableCount
=
placeFacade
.
countSelectable
(
prod
);
Long
selectableCount
=
placeFacade
.
countSelectable
(
prod
);
Long
unusedSlots
=
slotfacade
.
findUnusedSlotsCount
(
prod
);
Long
unusedSlots
=
slotfacade
.
findUnusedSlotsCount
(
prod
,
false
);
int
freeCount
=
selectableCount
.
intValue
()
-
unusedSlots
.
intValue
();
int
freeCount
=
selectableCount
.
intValue
()
-
unusedSlots
.
intValue
();
logger
.
info
(
"Prodlimit selectable {}, unused {}, free {}, prod {}"
,
selectableCount
,
unusedSlots
,
freeCount
,
prod
);
logger
.
info
(
"Prodlimit selectable {}, unused {}, free {}, prod {}"
,
selectableCount
,
unusedSlots
,
freeCount
,
prod
);
ret
.
put
(
prod
.
getId
(),
BigDecimal
.
valueOf
(
freeCount
));
ret
.
put
(
prod
.
getId
(),
BigDecimal
.
valueOf
(
freeCount
));
}
}
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/StatisticsBean.java
View file @
f89a5a7
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
*/
*/
package
fi
.
codecrew
.
moya
.
beans
;
package
fi
.
codecrew
.
moya
.
beans
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -32,8 +33,10 @@ import org.slf4j.LoggerFactory;
...
@@ -32,8 +33,10 @@ import org.slf4j.LoggerFactory;
import
fi.codecrew.moya.enums.apps.EventPermission
;
import
fi.codecrew.moya.enums.apps.EventPermission
;
import
fi.codecrew.moya.facade.GroupMembershipFacade
;
import
fi.codecrew.moya.facade.GroupMembershipFacade
;
import
fi.codecrew.moya.facade.PlaceSlotFacade
;
import
fi.codecrew.moya.facade.PrintedCardFacade
;
import
fi.codecrew.moya.facade.PrintedCardFacade
;
import
fi.codecrew.moya.model.GroupMembership
;
import
fi.codecrew.moya.model.GroupMembership
;
import
fi.codecrew.moya.model.Product
;
/**
/**
* Session Bean implementation class FoodWaveBean
* Session Bean implementation class FoodWaveBean
...
@@ -43,14 +46,18 @@ import fi.codecrew.moya.model.GroupMembership;
...
@@ -43,14 +46,18 @@ import fi.codecrew.moya.model.GroupMembership;
public
class
StatisticsBean
implements
StatisticsBeanLocal
{
public
class
StatisticsBean
implements
StatisticsBeanLocal
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
StatisticsBean
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
StatisticsBean
.
class
);
@EJB
@EJB
GroupMembershipFacade
groupMembershipFacade
;
GroupMembershipFacade
groupMembershipFacade
;
@EJB
@EJB
PrintedCardFacade
printedCardFacade
;
PrintedCardFacade
printedCardFacade
;
@EJB
private
PlaceSlotFacade
psfacade
;
@EJB
private
ProductBeanLocal
prodbean
;
@Override
@Override
@RolesAllowed
(
EventPermission
.
S_VIEW_STATISTICS
)
@RolesAllowed
(
EventPermission
.
S_VIEW_STATISTICS
)
...
@@ -72,38 +79,44 @@ public class StatisticsBean implements StatisticsBeanLocal {
...
@@ -72,38 +79,44 @@ public class StatisticsBean implements StatisticsBeanLocal {
@Override
@Override
public
Map
<
Long
,
Long
>
getHourlyIncomingStatistics
(
long
startingFromMillis
,
int
hourCount
)
{
public
Map
<
Long
,
Long
>
getHourlyIncomingStatistics
(
long
startingFromMillis
,
int
hourCount
)
{
List
<
GroupMembership
>
groupMemberships
=
groupMembershipFacade
.
findAllEnteredBetween
(
startingFromMillis
,
(
startingFromMillis
+
((
long
)
hourCount
)
*
60
l
*
60
l
*
1000
l
));
List
<
GroupMembership
>
groupMemberships
=
groupMembershipFacade
.
findAllEnteredBetween
(
startingFromMillis
,
(
startingFromMillis
+
((
long
)
hourCount
)
*
60
l
*
60
l
*
1000
l
));
HashMap
<
Long
,
Long
>
retMap
=
new
HashMap
<>();
HashMap
<
Long
,
Long
>
retMap
=
new
HashMap
<>();
long
currentTimestamp
=
startingFromMillis
;
long
currentTimestamp
=
startingFromMillis
;
long
hour
=
(
60
l
*
60
l
*
1000
l
);
long
hour
=
(
60
l
*
60
l
*
1000
l
);
long
hourEntered
=
0
;
long
hourEntered
=
0
;
for
(
GroupMembership
gm
:
groupMemberships
)
{
for
(
GroupMembership
gm
:
groupMemberships
)
{
// find the hour this one belongs to (sometime we need to skip empty hours)
// find the hour this one belongs to (sometime we need to skip empty hours)
while
(
gm
.
getEnteredEvent
().
getTimeInMillis
()
>
currentTimestamp
+
hour
)
{
while
(
gm
.
getEnteredEvent
().
getTimeInMillis
()
>
currentTimestamp
+
hour
)
{
retMap
.
put
(
currentTimestamp
,
hourEntered
);
retMap
.
put
(
currentTimestamp
,
hourEntered
);
hourEntered
=
0
;
hourEntered
=
0
;
currentTimestamp
+=
hour
;
currentTimestamp
+=
hour
;
}
}
hourEntered
++;
hourEntered
++;
}
}
return
retMap
;
return
retMap
;
}
}
}
@Override
public
List
<
ProductSlotcountMover
>
getUnusedSlots
(
boolean
onlyPaid
)
{
List
<
ProductSlotcountMover
>
ret
=
new
ArrayList
<>();
for
(
Product
p
:
prodbean
.
getProducts
())
{
logger
.
info
(
"Products for stats {}"
,
p
);
ProductSlotcountMover
m
=
new
ProductSlotcountMover
(
p
);
m
.
setUnusedSlots
(
psfacade
.
findUnusedSlotsCount
(
p
,
onlyPaid
));
m
.
setTotalSlots
(
psfacade
.
totalSlotcount
(
p
,
onlyPaid
));
if
(
m
.
getTotalSlots
()
>
0
&&
m
.
getUnusedSlots
()
>
0
)
{
ret
.
add
(
m
);
}
}
return
ret
;
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceSlotFacade.java
View file @
f89a5a7
...
@@ -113,37 +113,59 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
...
@@ -113,37 +113,59 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
return
getEm
().
createQuery
(
q
).
getResultList
();
return
getEm
().
createQuery
(
q
).
getResultList
();
}
}
public
Long
findUnusedSlotsCount
(
Product
prod
)
{
public
Long
findUnusedSlotsCount
(
Product
prod
,
boolean
paidOnly
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
Long
>
q
=
cb
.
createQuery
(
Long
.
class
);
CriteriaQuery
<
Long
>
q
=
cb
.
createQuery
(
Long
.
class
);
Root
<
PlaceSlot
>
root
=
q
.
from
(
PlaceSlot
.
class
);
Root
<
PlaceSlot
>
root
=
q
.
from
(
PlaceSlot
.
class
);
q
.
select
(
cb
.
count
(
root
));
q
.
select
(
cb
.
count
(
root
));
Path
<
Bill
>
bill
=
root
.
get
(
PlaceSlot_
.
bill
);
Path
<
Bill
>
bill
=
root
.
get
(
PlaceSlot_
.
bill
);
Path
<
Calendar
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
q
.
where
(
cb
.
equal
(
root
.
get
(
PlaceSlot_
.
product
),
prod
),
List
<
Predicate
>
preds
=
new
ArrayList
<>();
cb
.
or
(
cb
.
isNull
(
billexp
),
preds
.
add
(
cb
.
equal
(
root
.
get
(
PlaceSlot_
.
product
),
prod
));
cb
.
greaterThan
(
billexp
,
Calendar
.
getInstance
())
),
if
(
paidOnly
)
{
cb
.
isNull
(
root
.
get
(
PlaceSlot_
.
place
)),
// Only if bill is paid
cb
.
isNull
(
root
.
get
(
PlaceSlot_
.
used
))
preds
.
add
(
cb
.
isNotNull
(
bill
.
get
(
Bill_
.
paidDate
)));
);
}
else
{
// If expire is null or has not passed, count it
Path
<
Calendar
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
preds
.
add
(
cb
.
or
(
cb
.
isNull
(
billexp
),
cb
.
greaterThan
(
billexp
,
Calendar
.
getInstance
())
));
}
// Check that slot is not used
preds
.
add
(
cb
.
isNull
(
root
.
get
(
PlaceSlot_
.
place
)));
preds
.
add
(
cb
.
isNull
(
root
.
get
(
PlaceSlot_
.
used
)));
q
.
where
(
preds
.
toArray
(
new
Predicate
[
preds
.
size
()]));
Long
count
=
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
q
));
Long
count
=
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
q
));
return
count
;
return
count
;
}
}
public
Long
totalSlotcount
(
Product
prod
)
{
public
Long
totalSlotcount
(
Product
prod
,
boolean
paidOnly
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
Long
>
q
=
cb
.
createQuery
(
Long
.
class
);
CriteriaQuery
<
Long
>
q
=
cb
.
createQuery
(
Long
.
class
);
Root
<
PlaceSlot
>
root
=
q
.
from
(
PlaceSlot
.
class
);
Root
<
PlaceSlot
>
root
=
q
.
from
(
PlaceSlot
.
class
);
q
.
select
(
cb
.
count
(
root
));
q
.
select
(
cb
.
count
(
root
));
Path
<
Bill
>
bill
=
root
.
get
(
PlaceSlot_
.
bill
);
Path
<
Bill
>
bill
=
root
.
get
(
PlaceSlot_
.
bill
);
Path
<
Calendar
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
q
.
where
(
cb
.
equal
(
root
.
get
(
PlaceSlot_
.
product
),
prod
),
List
<
Predicate
>
preds
=
new
ArrayList
<>();
cb
.
or
(
cb
.
isNull
(
billexp
),
preds
.
add
(
cb
.
equal
(
root
.
get
(
PlaceSlot_
.
product
),
prod
));
cb
.
greaterThan
(
billexp
,
Calendar
.
getInstance
())
if
(
paidOnly
)
{
)
preds
.
add
(
cb
.
isNotNull
(
bill
.
get
(
Bill_
.
paidDate
)));
);
}
else
{
Path
<
Calendar
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
preds
.
add
(
cb
.
or
(
cb
.
isNull
(
billexp
),
cb
.
greaterThan
(
billexp
,
Calendar
.
getInstance
())
));
}
q
.
where
(
preds
.
toArray
(
new
Predicate
[
preds
.
size
()]));
Long
count
=
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
q
));
Long
count
=
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
q
));
return
count
;
return
count
;
...
...
code/moya-web/WebContent/reports/basicStatistics.xhtml
View file @
f89a5a7
<!DOCTYPE html
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:products=
"http://java.sun.com/jsf/composite/tools/products"
xmlns:foodwave=
"http://java.sun.com/jsf/composite/tools"
xmlns:p=
"http://primefaces.org/ui"
>
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:products=
"http://java.sun.com/jsf/composite/tools/products"
xmlns:foodwave=
"http://java.sun.com/jsf/composite/tools"
xmlns:p=
"http://primefaces.org/ui"
>
<h:body>
<h:body>
<ui:composition
template=
"#{sessionHandler.template}"
>
<ui:composition
template=
"#{sessionHandler.template}"
>
<ui:define
name=
"content"
>
<ui:define
name=
"content"
>
Sisällä:
<p:outputLabel
value=
"#{basicStatisticsView.groupMembershipsEnteredCount} / #{basicStatisticsView.groupMembershipsTotalCount}"
/><br
/>
Sisällä:
<h:outputText
value=
"#{basicStatisticsView.groupMembershipsEnteredCount} / #{basicStatisticsView.groupMembershipsTotalCount}"
/>
Korttei:
<p:outputLabel
value=
"#{basicStatisticsView.cardDeliveredCount}"
/>
<br
/>
Korttei:
<h:outputText
value=
"#{basicStatisticsView.cardDeliveredCount}"
/>
<br
/>
<h2>
Laskutettuja paikkaslotteja
</h2>
<p:dataTable
var=
"slot"
value=
"#{basicStatisticsView.unusedBilledSlots}"
>
<p:column
headerText=
"Tuote"
>
<h:outputText
value=
"#{slot.product.name}"
/>
</p:column>
<p:column
headerText=
"Paikkaslotteja yhteensä"
>
<h:outputText
value=
"#{slot.totalSlots}"
/>
</p:column>
<p:column
headerText=
"Käyttämättömiä slotteja"
>
<h:outputText
value=
"#{slot.unusedSlots}"
/>
</p:column>
</p:dataTable>
<h2>
Maksettuja paikkaslotteja
</h2>
<p:dataTable
var=
"slot"
value=
"#{basicStatisticsView.unusedPaidSlots}"
>
<p:column
headerText=
"Tuote"
>
<h:outputText
value=
"#{slot.product.name}"
/>
</p:column>
<p:column
headerText=
"Paikkaslotteja yhteensä"
>
<h:outputText
value=
"#{slot.totalSlots}"
/>
</p:column>
<p:column
headerText=
"Käyttämättömiä slotteja"
>
<h:outputText
value=
"#{slot.unusedSlots}"
/>
</p:column>
</p:dataTable>
</ui:define>
</ui:define>
</ui:composition>
</ui:composition>
</h:body>
</h:body>
...
...
code/moya-web/src/main/java/fi/codecrew/moya/web/reports/BasicStatisticsView.java
View file @
f89a5a7
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
*/
*/
package
fi
.
codecrew
.
moya
.
web
.
reports
;
package
fi
.
codecrew
.
moya
.
web
.
reports
;
import
java.util.List
;
import
javax.ejb.EJB
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.ConversationScoped
;
import
javax.enterprise.context.ConversationScoped
;
import
javax.enterprise.context.RequestScoped
;
import
javax.enterprise.context.RequestScoped
;
...
@@ -29,6 +31,7 @@ import javax.inject.Named;
...
@@ -29,6 +31,7 @@ import javax.inject.Named;
import
fi.codecrew.moya.beans.EventBeanLocal
;
import
fi.codecrew.moya.beans.EventBeanLocal
;
import
fi.codecrew.moya.beans.LectureBeanLocal
;
import
fi.codecrew.moya.beans.LectureBeanLocal
;
import
fi.codecrew.moya.beans.StatisticsBeanLocal
;
import
fi.codecrew.moya.beans.StatisticsBeanLocal
;
import
fi.codecrew.moya.beans.StatisticsBeanLocal.ProductSlotcountMover
;
import
fi.codecrew.moya.enums.apps.LecturePermission
;
import
fi.codecrew.moya.enums.apps.LecturePermission
;
import
fi.codecrew.moya.model.Lecture
;
import
fi.codecrew.moya.model.Lecture
;
import
fi.codecrew.moya.model.LectureGroup
;
import
fi.codecrew.moya.model.LectureGroup
;
...
@@ -43,20 +46,36 @@ public class BasicStatisticsView extends GenericCDIView {
...
@@ -43,20 +46,36 @@ public class BasicStatisticsView extends GenericCDIView {
@EJB
@EJB
private
StatisticsBeanLocal
statisticsBean
;
private
StatisticsBeanLocal
statisticsBean
;
private
List
<
ProductSlotcountMover
>
billedslots
;
private
List
<
ProductSlotcountMover
>
paidslots
;
public
Long
getGroupMembershipsEnteredCount
()
{
public
Long
getGroupMembershipsEnteredCount
()
{
return
statisticsBean
.
getGroupMembershipsEnteredEvent
();
return
statisticsBean
.
getGroupMembershipsEnteredEvent
();
}
}
public
Long
getCardDeliveredCount
()
{
public
Long
getCardDeliveredCount
()
{
return
statisticsBean
.
getCardDeliveredCount
();
return
statisticsBean
.
getCardDeliveredCount
();
}
}
public
Long
getGroupMembershipsTotalCount
()
{
public
Long
getGroupMembershipsTotalCount
()
{
return
statisticsBean
.
getGroupMembershipsTotalCount
();
return
statisticsBean
.
getGroupMembershipsTotalCount
();
}
}
public
List
<
ProductSlotcountMover
>
getUnusedBilledSlots
()
{
if
(
billedslots
==
null
)
{
billedslots
=
statisticsBean
.
getUnusedSlots
(
false
);
}
return
billedslots
;
}
public
List
<
ProductSlotcountMover
>
getUnusedPaidSlots
()
{
if
(
paidslots
==
null
)
{
paidslots
=
statisticsBean
.
getUnusedSlots
(
true
);
}
return
paidslots
;
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment