Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2c78c6fc
authored
Mar 02, 2014
by
Liv Haapala
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
statistiikan piirtämistä, graafeja yms
1 parent
e6a46dde
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
255 additions
and
4 deletions
code/MoyaDatabase/src/fi/codecrew/moya/model/User.java
code/MoyaWeb/WebContent/useradmin/charts.xhtml
code/MoyaWeb/WebContent/useradmin/list.xhtml
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/user/ChartView.java
code/MoyaDatabase/src/fi/codecrew/moya/model/User.java
View file @
2c78c6f
...
...
@@ -401,9 +401,9 @@ public class User extends GenericEntity implements IUser {
age
=
age
.
add
(
decimalYears
);
age
=
age
.
add
(
decimalDays
);
System
.
out
.
print
(
"Years: "
+
years
+
"\n"
);
System
.
out
.
print
(
"Days: "
+
days
+
"\n"
);
System
.
out
.
print
(
"Fraction of days: "
+
fraction
+
"\n"
);
//
System.out.print("Years: " + years + "\n");
//
System.out.print("Days: " + days + "\n");
//
System.out.print("Fraction of days: " + fraction + "\n");
}
return
age
;
...
...
code/MoyaWeb/WebContent/useradmin/charts.xhtml
0 → 100644
View file @
2c78c6f
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"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"
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:users=
"http://java.sun.com/jsf/composite/cditools/user"
xmlns:p=
"http://primefaces.org/ui"
>
<h:body>
<ui:composition
template=
"#{sessionHandler.template}"
>
<f:metadata>
<f:event
type=
"preRenderView"
listener=
"#{chartView.initCreateView}"
/>
</f:metadata>
<ui:define
name=
"content"
>
<h:panelGrid
columns=
"2"
>
<h:panelGroup>
<h:form>
<h:outputLabel
for=
"rolefilter"
value=
"#{i18n['userlist.rolefilter']}"
/>
<h:selectManyCheckbox
layout=
"pageDirection"
styleClass=
"nowrap"
id=
"rolefilter"
value=
"#{chartView.filterRoles}"
converter=
"#{roleConverter}"
>
<f:selectItems
value=
"#{roleDataView.roles}"
var=
"r"
itemLabel=
"#{r.name}"
/>
</h:selectManyCheckbox>
<h:commandButton
action=
"#{chartView.updateAgesChart()}"
value=
"Päivitä kuvaaja"
></h:commandButton>
</h:form>
</h:panelGroup>
<h:panelGroup>
<p:barChart
id=
"basic"
value=
"#{chartView.agesChart}"
legendPosition=
"ne"
title=
"Käyttäjien Ikäjakauma"
style=
"width:600px"
xaxisAngle=
"-45"
/>
</h:panelGroup>
</h:panelGrid>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
code/MoyaWeb/WebContent/useradmin/list.xhtml
View file @
2c78c6f
...
...
@@ -30,7 +30,8 @@
<f:selectItems
value=
"#{userSearchView.searchQuery.accountCompareValues}"
/>
</h:selectOneMenu>
<h:inputText
value=
"#{userSearchView.searchQuery.accountSaldo}"
>
<f:convertNumber
minFractionDigits=
"0"
maxFractionDigits=
"2"
/>
</h:inputText>
<br
/>
<h:outputLabel
for=
"rolefilter"
value=
"#{i18n['userlist.rolefilter']}"
/>
<h:selectManyCheckbox
layout=
"pageDirection"
styleClass=
"nowrap"
id=
"rolefilter"
</h:inputText>
<br
/>
<h:outputLabel
for=
"rolefilter"
value=
"#{i18n['userlist.rolefilter']}"
/>
<h:selectManyCheckbox
layout=
"pageDirection"
styleClass=
"nowrap"
id=
"rolefilter"
value=
"#{userSearchView.searchQuery.filterRoles}"
converter=
"#{roleConverter}"
>
<f:selectItems
value=
"#{roleDataView.roles}"
var=
"r"
itemLabel=
"#{r.name}"
/>
</h:selectManyCheckbox>
...
...
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/user/ChartView.java
0 → 100644
View file @
2c78c6f
package
fi
.
codecrew
.
moya
.
web
.
cdiview
.
user
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.ConversationScoped
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
org.primefaces.model.chart.CartesianChartModel
;
import
org.primefaces.model.chart.ChartSeries
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.beans.RoleBeanLocal
;
import
fi.codecrew.moya.beans.UserBeanLocal
;
import
fi.codecrew.moya.enums.apps.UserPermission
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Role
;
import
fi.codecrew.moya.model.User
;
import
fi.codecrew.moya.util.UserSearchQuery
;
import
fi.codecrew.moya.web.annotations.SelectedUser
;
import
fi.codecrew.moya.web.cdiview.GenericCDIView
;
import
fi.codecrew.moya.utilities.SearchResult
;
@Named
@ConversationScoped
public
class
ChartView
extends
GenericCDIView
{
/**
*
*/
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ChartView
.
class
);
private
static
final
long
serialVersionUID
=
-
2692873541096663937L
;
@EJB
private
transient
UserBeanLocal
userbean
;
@EJB
private
transient
RoleBeanLocal
rolebean
;
@Inject
@SelectedUser
private
transient
EventUser
selectedUser
;
private
List
<
Role
>
selectedRoles
;
public
ChartView
()
{
createAgesChart
();
}
public
void
initCreateView
()
{
if
(
super
.
requirePermissions
(
UserPermission
.
VIEW_ALL
))
{
createAgesChart
();
super
.
beginConversation
();
}
}
private
CartesianChartModel
agesChart
=
new
CartesianChartModel
();
public
CartesianChartModel
getAgesChart
()
{
if
(
agesChart
==
null
)
agesChart
=
new
CartesianChartModel
();
return
agesChart
;
}
public
void
updateAgesChart
()
{
createAgesChart
();
}
private
void
createAgesChart
()
{
if
(
selectedRoles
!=
null
)
{
//selectedRoles = new ArrayList<Role>();
agesChart
=
new
CartesianChartModel
();
ArrayList
<
ChartSeries
>
series
=
new
ArrayList
<
ChartSeries
>();
for
(
Role
role
:
selectedRoles
)
{
series
.
add
(
new
ChartSeries
(
role
.
getName
()));
}
HashMap
<
Role
,
HashMap
<
Integer
,
Integer
>>
hashMap
=
new
HashMap
<
Role
,
HashMap
<
Integer
,
Integer
>>();
UserSearchQuery
usersearch
=
new
UserSearchQuery
();
int
pagesize
=
usersearch
.
getPagesize
();
int
page
=
usersearch
.
getPage
();
usersearch
.
setPagesize
(
999999999
);
usersearch
.
setPage
(
0
);
//usersearch.setFilterRoles(selectedRoles);
//usersearch.setOnlyThisEvent(true);
ArrayList
<
Integer
>
ageList
=
new
ArrayList
<
Integer
>();
if
(
userbean
!=
null
)
{
//System.out.println("userbean not null");
System
.
out
.
println
(
"Looping eventUsers and roles for data\n\n"
);
SearchResult
<
EventUser
>
users
=
userbean
.
getThisEventsUsers
(
usersearch
);
for
(
Role
role
:
selectedRoles
)
{
System
.
out
.
println
(
"Role: "
+
role
.
getName
());
for
(
EventUser
eventUser
:
users
.
getResults
())
{
//if(eventUser.getEvent() == selectedUser.getEvent()) {
System
.
out
.
println
(
"EventUser: "
+
eventUser
.
getLogin
());
List
<
Role
>
usersRoles
=
userbean
.
findUsersRoles
(
eventUser
);
if
(
usersRoles
!=
null
&&
!
usersRoles
.
isEmpty
()
&&
usersRoles
.
contains
(
role
))
{
System
.
out
.
println
(
"EventUser contains role: "
+
role
.
getName
());
int
age
=
eventUser
.
getUser
().
getAge
().
intValue
();
System
.
out
.
println
(
"Age: "
+
age
);
int
amount
=
0
;
HashMap
<
Integer
,
Integer
>
ages
=
new
HashMap
<
Integer
,
Integer
>();
if
(
hashMap
.
containsKey
(
role
))
{
ages
=
hashMap
.
get
(
role
);
}
if
(
ages
.
containsKey
(
age
))
{
amount
=
ages
.
get
(
age
);
}
if
(!
ageList
.
contains
(
age
))
ageList
.
add
(
age
);
ages
.
put
(
age
,
amount
+
1
);
hashMap
.
put
(
role
,
ages
);
System
.
out
.
println
(
"Amount: "
+
amount
);
//}
}
}
}
Object
[]
sortedAges
=
ageList
.
toArray
();
Arrays
.
sort
(
sortedAges
);
System
.
out
.
println
(
"Data looped. Starting adding data to series..\n\n"
);
Set
set
=
hashMap
.
entrySet
();
Iterator
iterator
=
set
.
iterator
();
//for (Role role : hashMap.keySet()) {
while
(
iterator
.
hasNext
()
)
{
Map
.
Entry
me
=
(
Map
.
Entry
)
iterator
.
next
();
Role
role
=
(
Role
)
me
.
getKey
();
HashMap
<
Integer
,
Integer
>
ages
=
hashMap
.
get
(
role
);
Object
[]
keys
=
ages
.
keySet
().
toArray
();
Arrays
.
sort
(
keys
);
System
.
out
.
println
(
"Role: "
+
role
.
getName
()
+
" keys length: "
+
keys
.
length
+
" ages.length: "
+
ages
.
values
().
size
());
int
i
=
0
;
for
(
Object
obj
:
keys
)
{
int
age
=
(
int
)
obj
;
int
amount
=
ages
.
get
(
age
);
for
(
ChartSeries
serie
:
series
)
{
if
(
serie
.
getLabel
()
==
role
.
getName
())
{
System
.
out
.
println
(
"Int i: "
+
i
+
" sortedAges-length; "
+
sortedAges
.
length
+
" Age: "
+
age
+
", amount: "
+
amount
);
if
(
i
<
sortedAges
.
length
)
{
if
(
age
>
(
int
)
sortedAges
[
i
])
{
while
(
age
>
(
int
)
sortedAges
[
i
])
{
System
.
out
.
println
(
"Age: "
+
age
+
", amount: 0"
);
serie
.
set
(
String
.
valueOf
(
sortedAges
[
i
]),
0
);
if
(
i
<
sortedAges
.
length
)
i
++;
}
}
if
(
age
==
(
int
)
sortedAges
[
i
])
{
if
(
i
<
sortedAges
.
length
)
i
++;
System
.
out
.
println
(
"Age: "
+
age
+
", amount: "
+
amount
);
serie
.
set
(
String
.
valueOf
(
age
),
amount
);
}
}
break
;
}
}
}
}
System
.
out
.
println
(
"Data set to series. Adding serieses to chart.\n\n"
);
for
(
ChartSeries
serie
:
series
)
{
if
(
serie
.
getData
()
!=
null
&&
!
serie
.
getData
().
isEmpty
())
agesChart
.
addSeries
(
serie
);
}
}
//else
// System.out.println("userbean is null");
}
}
public
void
setFilterRoles
(
List
<
Role
>
roles
)
{
this
.
selectedRoles
=
roles
;
}
public
List
<
Role
>
getFilterRoles
()
{
return
this
.
selectedRoles
;
}
}
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