2 rcs_id('$Id: PreferenceApp.php,v 1.1 2004-07-07 19:46:39 dfrankow Exp $');
\r
7 require_once('lib/PageList.php');
\r
8 require_once('lib/InlineParser.php');
\r
10 require_once('lib/wikilens/Utils.php');
\r
11 require_once('lib/Theme.php');
\r
12 require_once('lib/wikilens/Buddy.php');
\r
13 require_once('lib/wikilens/RatingsDb.php');
\r
17 * PreferenceApp is used to analyze a category of items that a group
\r
18 * of people have rated. A user is grouped to be analyzed in the group by
\r
19 * 1) having rated at least one item in the database and 2) matching the optional
\r
20 * criteria for declaring a budget on their homepage.
\r
22 * An example of a budget decleration would be "TotalSoda: 50" on my homepage.
\r
24 * PreferenceApp will output a matrix style table shows "how much" fractionally
\r
25 * a group of people prefer an item over other items. For example, if my soda
\r
26 * budget is 100 then PreferenceApp might assign 20 units of my budget to Moutain Dew.
\r
28 * Author: mcassano circa April 2004
\r
31 * <?plugin PreferenceApp category="Soda" pageLabel="TotalSoda" roundCalc="true" ?>
\r
34 class WikiPlugin_PreferenceApp
\r
37 function getName () {
\r
38 return _("Preference App");
\r
41 function getDescription () {
\r
42 return _("Analyzes Preferences based on voting budget and ratings.");
\r
45 function getVersion() {
\r
46 return preg_replace("/[Revision: $]/", '',
\r
47 "\$Revision: 1.1 $");
\r
50 function getDefaultArguments() {
\r
53 'lockedBudget' => null,
\r
54 'pageTextLabel' => null,
\r
56 'roundCalc' => "true",
\r
57 'neutralRating' => "3",
\r
58 'declareBudget' => "true");
\r
60 // info arg allows multiple columns
\r
61 // info=mtime,hits,summary,version,author,locked,minor
\r
62 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
\r
65 function run($dbi, $argstr, $request) {
\r
67 extract($this->getArgs($argstr, $request));
\r
68 if($pageTextLabel == null && $category != null && $group == null){
\r
69 $group = $category;
\r
73 if($category == null || $pageTextLabel == null){
\r
74 $html = HTML("PreferencesApp Error: You must declare at least parameters category and pageTextLabel.");
\r
79 $dbi = $request->getDbh();
\r
80 $rdbi = RatingsDb::getTheRatingsDb();
\r
82 $CATEGORY = $category;
\r
83 $PAGE_TEXT_LABEL = $pageTextLabel;
\r
84 $NEUTRAL_RATING = (int)$neutralRating;
\r
86 $active_user = $request->getUser();
\r
87 $active_userid = $active_user->_userid;
\r
89 $html->pushContent("");
\r
91 //Load participating Users
\r
92 $users_array = array();
\r
94 $users_array = getMembers($group, $rdbi);
\r
97 $people_iter = $rdbi->sql_get_users_rated();
\r
98 while($people_array = $people_iter->next()){
\r
99 $users_array[] = $people_array['pagename'];
\r
103 foreach($users_array as $person_indv){
\r
104 if($declareBudget == "true"){
\r
105 $get_array = getPageTextData($person_indv, $dbi, $PAGE_TEXT_LABEL, "cans");
\r
106 if(count($get_array) == 1){
\r
107 $cans_text = $get_array[0];
\r
108 if(is_numeric($cans_text) && $cans_text >= 0){
\r
109 $canBudget[$person_indv] = $cans_text; //Load the persons budget
\r
111 $canBudget[$person_indv] = 0;
\r
113 $people[] = $person_indv;
\r
116 $canBudget[$person_indv] = $lockedBudget;
\r
117 $people[] = $person_indv;
\r
120 if(count($people) < 1){
\r
121 $html = HTML("Nobody has used $PAGE_TEXT_LABEL on their homepage");
\r
124 //Get all pages from Category
\r
125 $pageids = array();
\r
126 $category_page = $dbi->getPage($CATEGORY);
\r
127 $iter = $category_page->getLinks();
\r
128 while($item = $iter->next()){
\r
129 array_push($pageids, $item->getName());
\r
131 $ratingTotals = array();
\r
132 foreach($people as $person){
\r
133 $ratings_iter = $rdbi->sql_get_rating(0, $person, $pageids);
\r
134 $ratingTotals[$person] = 0;
\r
135 while($ratings_array = $ratings_iter->next()){
\r
136 $can_rating = $ratings_array['ratingvalue'];
\r
137 if($can_rating >= $NEUTRAL_RATING){
\r
138 $ratingTotals[$person] += $can_rating;
\r
144 $canTotals = array();
\r
145 $peopleTotals = array();
\r
146 foreach($pageids as $soda){
\r
147 $canTotals[$soda] = 0;
\r
149 foreach($people as $person){
\r
150 foreach($pageids as $soda){
\r
151 $peopleTotals[$person][$soda] = 0;
\r
154 foreach($people as $person){
\r
155 foreach($pageids as $page){
\r
156 $can_rating_iter = $rdbi->sql_get_rating(0, $person, $page);
\r
157 $can_rating_array = $can_rating_iter->next();
\r
158 $can_rating = $can_rating_array['ratingvalue'];
\r
159 if($can_rating >= $NEUTRAL_RATING){
\r
160 $calc = (($can_rating / $ratingTotals[$person]) * $canBudget[$person]);
\r
161 if($roundCalc == "true"){
\r
162 $adjustedCans = round($calc);
\r
164 $adjustedCans = round($calc, 2);
\r
166 $peopleTotals[$person][$page] = $adjustedCans;
\r
168 $canTotals[$page] = $canTotals[$page] + $adjustedCans;
\r
172 $outputArray = array();
\r
173 foreach($people as $person){
\r
174 foreach($pageids as $page){
\r
175 $outputArray[$person][$page] = 0;
\r
179 $table = HTML::table(array('cellpadding' => '5', 'cellspacing' => '1', 'border' => '0'));
\r
181 $td = HTML::td(array('bgcolor' => '#FFFFFF'));
\r
182 $td->pushContent(" ");
\r
183 $tr->pushContent($td);
\r
185 foreach($people as $person){
\r
186 $td = HTML::td(array('bgcolor' => '#FFFFFF'));
\r
187 $td->pushContent(HTML::a(array('href' => WikiURL($person),
\r
190 SplitPagename($person)));
\r
191 //$td->pushContent(WikiLink(" $person "));
\r
192 $tr->pushContent($td);
\r
194 $td = HTML::td(array('bgcolor' => '#FFFFFF'));
\r
195 $td->pushContent("Total Units");
\r
196 $tr->pushContent($td);
\r
197 $td = HTML::td(array('bgcolor' => '#FFFFFF'));
\r
198 $td->pushContent("Total Voters");
\r
199 $tr->pushContent($td);
\r
200 $table->pushContent($tr);
\r
202 for($i = 0; $i < count($pageids); $i++){
\r
204 for($j = 0; $j < count($people); $j++){
\r
205 $td = HTML::td(array('align' => 'right'));
\r
206 $cans_per_soda = $peopleTotals[$people[$j]][$pageids[$i]];
\r
207 $total_cans = $total_cans + $cans_per_soda;
\r
208 $outputArray[$people[$j]][$pageids[$i]] = $cans_per_soda;
\r
213 foreach($people as $person){
\r
215 $min_cans = 9999999; //9 million, serving as "infinity"
\r
217 foreach($pageids as $page){
\r
218 $cur_soda_cans = $outputArray[$person][$page];
\r
219 if($cur_soda_cans < $min_cans && $cur_soda_cans > 0){
\r
220 $min_cans = $cur_soda_cans;
\r
223 $total_cans = $total_cans + $cur_soda_cans;
\r
225 if($total_cans != $canBudget[$person] && $total_cans > 0){
\r
226 $diff = $canBudget[$person] - $total_cans;
\r
227 $outputArray[$person][$min_soda] = $outputArray[$person][$min_soda] + $diff;
\r
230 for($i = 0; $i < count($pageids); $i++){
\r
232 $td = HTML::td(array('align' => 'left', 'bgcolor' => '#f7f7f7'));
\r
233 $td->pushContent(HTML::a(array('href' => WikiURL($pageids[$i]),
\r
236 SplitPagename($pageids[$i])));
\r
237 $tr->pushContent($td);
\r
240 for($j = 0; $j < count($people); $j++){
\r
241 $td = HTML::td(array('align' => 'right', 'bgcolor' => '#f7f7f7'));
\r
242 $output = $outputArray[$people[$j]][$pageids[$i]];
\r
243 $total_cans = $total_cans + $output;
\r
249 $td->pushContent($output);
\r
250 $tr->pushContent($td);
\r
252 if($total_cans == ""){
\r
253 $total_cans = "-";
\r
255 if($total_voters == ""){
\r
256 $total_voters = "-";
\r
258 $td = HTML::td(array('align' => 'right'));
\r
259 $td->pushContent($total_cans);
\r
260 $tr->pushContent($td);
\r
261 $td = HTML::td(array('align' => 'right'));
\r
262 $td->pushContent($total_voters);
\r
263 $tr->pushContent($td);
\r
264 $table->pushContent($tr);
\r
268 $td = HTML::td(array('align' => 'left'));
\r
269 $td->pushContent(HTML::strong("Total Budget"));
\r
270 $tr->pushContent($td);
\r
273 for($i = 0; $i < count($people); $i++){
\r
274 $td = HTML::td(array('align' => 'right'));
\r
275 $cans_for_soda = 0;
\r
276 foreach($pageids as $page){
\r
277 $cans_for_soda = $cans_for_soda + $outputArray[$people[$i]][$page];
\r
279 $cans = $cans_for_soda;
\r
280 $cans_total = $cans_total + $cans;
\r
286 $td->pushContent(HTML::strong($cans));
\r
287 $tr->pushContent($td);
\r
289 $td = HTML::td(array('align' => 'right'));
\r
290 $td->pushContent(HTML::strong($cans_total));
\r
291 $tr->pushContent($td);
\r
292 $td = HTML::td(array('align' => 'right'));
\r
293 $td->pushContent(HTML::strong($total_voters));
\r
294 $tr->pushContent($td);
\r
295 $table->pushContent($tr);
\r
297 $table2 = HTML::table(array('bgcolor' => '#dedfdf'));
\r
298 $table2->pushContent(HTML::tr(HTML::td($table)));
\r
299 $html->pushContent($table2);
\r
306 // Local Variables:
\r
309 // c-basic-offset: 4
\r
310 // c-hanging-comment-ender-p: nil
\r
311 // indent-tabs-mode: nil
\r