We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit c5925ec9 authored by idflood's avatar idflood

added simple plays by day stats.

parent 2dbe45c1
......@@ -38,8 +38,7 @@ class PlayStats {
if (!is_string($field)) return false;
if (!is_string($table)) return false;
if (!is_integer($limit)) return false;
$sizes = array('xx-large', 'x-large', 'large', 'medium', 'small', 'x-small', 'xx-small');
$query = "SELECT $field, count(*) AS count FROM $table";
$query = "SELECT $field, count(*) AS count FROM $table";
$query .= (!is_null($constraint) || ($table == "Scrobbles")) ? ' WHERE ' : null;
if ($field == "track") {
$query .= (!is_null($constraint)) ? ' artist = ' . $mdb2->quote($constraint, 'text') : null;
......@@ -68,5 +67,39 @@ class PlayStats {
return $data;
}
}
static function generatePlayByDays($table, $limit = 100, $constraint = null, $maxwidth = 100 ) {
global $mdb2;
if (!is_string($table)) return false;
if (!is_integer($limit)) return false;
$query = "SELECT COUNT(*) as count,DATE(FROM_UNIXTIME(time)) as date FROM $table";
$query .= (!is_null($constraint) || ($table == "Scrobbles")) ? ' WHERE ' : null;
$query .= (!is_null($constraint)) ? ' username = ' . $mdb2->quote($constraint, 'text') : null;
$query .= (!is_null($constraint) && ($table == "Scrobbles")) ? ' AND ' : null;
$query .= ($table == "Scrobbles") ? " rating <> 'S' " : null;
$query .= " GROUP BY date ORDER BY date DESC LIMIT $limit";
$res = $mdb2->query($query);
if (PEAR::isError($res)) {
echo("ERROR" . $res->getMessage());
}
if (!$res->numRows()) {
return false;
} else {
$data = $res->fetchAll(MDB2_FETCHMODE_ASSOC);
$max = 0;
foreach($data as &$i){
if( $i['count'] > $max ) $max = $i['count'];
}
foreach($data as &$i){
$i['size'] = $i['count'] / $max * $maxwidth;
}
return $data;
}
}
}
?>
......@@ -56,12 +56,17 @@ if(isset($user->name)) {
$smarty->assign('user_tagcloud',$aUserTagCloud);
}
$smarty->assign('stat_barwidth', 300);
$smarty->assign('stat_barwidth', 320);
$aUserPlayStat = PlayStats::GeneratePlayStats('Scrobbles', 'artist', 40, $user->name, 300);
if (!PEAR::isError ($aUserPlayStat)) {
$smarty->assign('user_playstats',$aUserPlayStat);
}
$aUserDayStat = PlayStats::generatePlayByDays('Scrobbles', 40, $user->name, 300);
if (!PEAR::isError ($aUserDayStat)) {
$smarty->assign('user_daystats',$aUserDayStat);
}
$smarty->assign('isme', ($_SESSION['user']->name == $user->name));
$smarty->assign('stats', true);
......
......@@ -43,7 +43,14 @@
{section name=i loop=$user_playstats}
<tr><td class="counts">{$user_playstats[i].count}</td><td class="bar" style="width: {$stat_barwidth}px"><div style="width:{$user_playstats[i].size}px" class="artist"></div></td><td><a
href="{$user_playstats[i].pageurl|escape:'html':'UTF-8'}" rel="{if $user_playstats[i].size|substr:-5 ==
'large'}foaf:interest {/if}tag">{$user_playstats[i].artist|escape:"html":"UTF-8"}</a></td>
'large'}foaf:interest {/if}tag">{$user_playstats[i].artist|escape:"html":"UTF-8"}</a></td></tr>
{/section}
</table>
<h3>{$user}'{if $user|substr:-1 != 's'}s{/if} plays by day</h3>
<table class="stats_artists" about="{$id}">
{section name=i loop=$user_daystats}
<tr><td class="counts">{$user_daystats[i].count}</td><td class="bar" style="width: {$stat_barwidth}px"><div style="width:{$user_daystats[i].size}px" class="artist"></div></td><td class="date">{$user_daystats[i].date}</td></tr>
{/section}
</table>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment