1 package org.musicontroller.gui.components;
2
3 import java.util.Date;
4 import java.util.LinkedList;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.apache.tapestry.BaseComponent;
9 import org.musicontroller.core.Event;
10 import org.musicontroller.dao.PlaylistKey;
11 import org.varienaja.util.DateTools;
12
13
14
15
16
17
18 public abstract class Usage extends BaseComponent {
19 public abstract Map<String, Integer> getStatistics();
20
21 public abstract int getKind();
22 public abstract void setKind(int kind);
23 public abstract int getYear();
24 public abstract void setYear(int year);
25 public abstract int getMonth();
26 public abstract void setMonth(int month);
27
28
29
30
31
32 public List<Integer> getYears() {
33 List<Integer> result = new LinkedList<Integer>();
34 String firstKey = null;
35 int year = Integer.MAX_VALUE;
36 if (getStatistics().size() > 0) {
37 firstKey = getStatistics().keySet().iterator().next();
38 if (firstKey != null) {
39 String[] parts = firstKey.split(",");
40 year = Integer.parseInt(parts[0]);
41 }
42 }
43
44 int currentYear = DateTools.currentYear();
45 for (int yr=year; yr<=currentYear; yr++) {
46 result.add(0, yr);
47 }
48
49 return result;
50 }
51
52 public Integer[] getMonths() {
53 return new Integer[]{12,11,10,9,8,7,6,5,4,3,2,1};
54 }
55
56 public String getMonthIndicator() {
57 Date d = DateTools.encodeDate(1, getMonth(), getYear());
58 return DateTools.formatDate(d, "MMMMM").substring(0,1);
59 }
60
61 public String getLongMonthIndicator() {
62 Date d = DateTools.encodeDate(1, getMonth(), getYear());
63 return DateTools.formatDate(d, "MMMMM yyyy");
64 }
65
66 private Integer getAmount(int eventkind) {
67 Integer amount = getStatistics().get(getYear()+","+getMonth()+","+eventkind);
68 if (amount==null) {
69 amount=0;
70 }
71 return amount;
72 }
73
74
75
76
77
78
79
80
81
82
83 private String getImageSize(int eventkind) {
84 return "" + getAmount(eventkind) / 8;
85 }
86
87 private String getAmountDesc(int eventkind) {
88 Date d = DateTools.encodeDate(1, getMonth(), getYear());
89 return getAmount(eventkind).toString() + " songs " + Event.getDescription(eventkind) + " in " + DateTools.formatDate(d, "MMMMM yyyy");
90 }
91
92 public String getPlaysSize() {
93 return getImageSize(Event.played);
94 }
95 public String getPlaysDesc() {
96 return getAmountDesc(Event.played);
97 }
98
99 public String getRequestsSize() {
100 return getImageSize(Event.requested);
101 }
102 public String getRequestsDesc() {
103 return getAmountDesc(Event.requested);
104 }
105
106 public String getDownloadsSize() {
107 return getImageSize(Event.downloaded);
108 }
109 public String getDownloadsDesc() {
110 return getAmountDesc(Event.downloaded);
111 }
112
113 public String getSkipsSize() {
114 return getImageSize(Event.skipped);
115 }
116 public String getSkipsDesc() {
117 return getAmountDesc(Event.skipped);
118 }
119
120
121
122
123
124 public long getTop100IdThisYear() {
125 return (new PlaylistKey(-8,DateTools.encodeDate(1, 1, getYear()))).getId();
126 }
127
128
129
130
131
132 public long getTop25IdThisMonth() {
133 return (new PlaylistKey(-4,DateTools.encodeDate(1, getMonth(), getYear()))).getId();
134 }
135
136
137
138
139
140 public long getRequestTop25IdThisMonth() {
141 return (new PlaylistKey(-5,DateTools.encodeDate(1, getMonth(), getYear()))).getId();
142 }
143
144 }