1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-02-17 11:28:41 +01:00

- Reworked tag weight.

Signed-off-by: 8n-tech <8n-tech@users.noreply.github.com>
This commit is contained in:
8n-tech 2015-04-16 00:35:36 +10:00
parent 0347bf772d
commit 67bab31510
4 changed files with 91 additions and 31 deletions

View File

@ -119,7 +119,6 @@ unset( $boardTags );
/* Activity Fetching */
$boardActivity = fetchBoardActivity( array_keys( $response['boards'] ), $search['time'], true );
$response['tags'] = array();
// Loop through each board and record activity to it.
// We will also be weighing and building a tag list.
@ -141,21 +140,8 @@ foreach ($response['boards'] as $boardUri => &$board) {
unset( $precision );
}
if (isset($board['tags']) && count($board['tags']) > 0) {
foreach ($board['tags'] as $tag) {
if (isset($response['tags'][$tag])) {
$response['tags'][$tag] += $board['active'];
}
else {
$response['tags'][$tag] = $board['active'];
}
}
}
}
unset( $boardActivity );
// Sort boards by their popularity, then by their total posts.
$boardActivityValues = array();
$boardTotalPostsValues = array();
@ -177,16 +163,63 @@ $response['omitted'] = $search['index'] ? 0 : count( $response['boards'] ) - $bo
$response['boards'] = array_splice( $response['boards'], 0, $boardLimit );
$response['order'] = array_keys( $response['boards'] );
// Get the top most popular tags.
if (count($response['tags']) > 0) {
// Sort by most active tags.
arsort( $response['tags'] );
// Get the first n most active tags.
$response['tags'] = array_splice( $response['tags'], 0, 100 );
// $tagLightest = end( array_keys( $response['tag'] ) );
// Loop through the truncated array to compile tags.
$response['tags'] = array();
$tagUsage = array( 'boards' => array(), 'users' => array() );
foreach ($response['boards'] as $boardUri => &$board) {
if (isset($board['tags']) && count($board['tags']) > 0) {
foreach ($board['tags'] as $tag) {
if (!isset($tagUsage['boards'][$tag])) {
$tagUsage['boards'][$tag] = 0;
}
if (!isset($tagUsage['users'][$tag])) {
$tagUsage['users'][$tag] = 0;
}
$response['tags'][$tag] = true;
++$tagUsage['boards'][$tag];
$tagUsage['users'][$tag] += $board['active'];
}
}
}
// Get the top most popular tags.
if (count($response['tags']) > 0) {
arsort( $tagUsage['boards'] );
arsort( $tagUsage['users'] );
array_multisort(
$tagUsage['boards'], SORT_DESC, SORT_NUMERIC,
$tagUsage['users'], SORT_DESC, SORT_NUMERIC,
$response['tags']
);
// Get the first n most active tags.
$response['tags'] = array_splice( $response['tags'], 0, 100 );
$response['tagOrder'] = array_keys( $response['tags'] );
$response['tagWeight'] = array();
$tagsMostUsers = max( $tagUsage['users'] );
$tagsLeastUsers = min( $tagUsage['users'] );
$tagsAvgUsers = array_sum( $tagUsage['users'] ) / count( $tagUsage['users'] );
$weightDepartureFurthest = 0;
foreach ($tagUsage['users'] as $tagUsers) {
$weightDeparture = abs( $tagUsers - $tagsAvgUsers );
if( $weightDeparture > $weightDepartureFurthest ) {
$weightDepartureFurthest = $weightDeparture;
}
}
foreach ($tagUsage['users'] as $tagName => $tagUsers) {
$weightDeparture = abs( $tagUsers - $tagsAvgUsers );
$response['tagWeight'][$tagName] = 75 + round( 100 * ( $weightDeparture / $weightDepartureFurthest ), 0);
}
}
/* Include our interpreted search terms. */
$response['search'] = $search;

View File

@ -19,8 +19,8 @@ if (count($searchJson)) {
if (isset($searchJson['boards'])) {
$boards = $searchJson['boards'];
}
if (isset($searchJson['tags'])) {
$tags = $searchJson['tags'];
if (isset($searchJson['tagWeight'])) {
$tags = $searchJson['tagWeight'];
}
}

View File

@ -1043,6 +1043,15 @@ span.pln {
min-height: 76px;
min-width: 128px;
}
.loading-small {
background: none;
background-color: none;
background-image: url('/static/infinity-small.gif');
background-position: center center;
background-repeat: no-repeat;
min-height: 24px;
min-width: 48px;
}
/* Responsive helpers */
@ -1378,6 +1387,18 @@ table.board-list-table .board-tags {
padding: 0 15px 0 4px;
}
table.board-list-table .board-uri .board-nsfw {
color: rgb(230,0,0);
margin: 0 0 0 0.6em;
float: right;
}
table.board-list-table .board-uri .board-sfw {
/* I'm using blue instead of green to help users with Deuteranopia (most common form of colorblndness). */
color: rgb(0,0,230);
margin: 0 0 0 0.6em;
float: right;
}
table.board-list-table div.board-cell {
max-width: 100%;
overflow: hidden;
@ -1397,9 +1418,7 @@ aside.search-container .box {
}
.board-search {
padding: 0 0 8px 0;
margin: 8px;
border-bottom: 1px solid #000333;
margin: 8px 0;
}
.search-item {
margin: 8px 0;
@ -1427,12 +1446,17 @@ aside.search-container .box {
min-width: 100%;
width: 100%:
}
#search-loading {
display: inline-block;
vertical-align: bottom;
}
ul.tag-list {
display: block;
list-style: none;
padding: 0;
margin: 0 8px;
margin: 8px 8px -9px 8px;
padding: 8px 0 0 0;
border-top: 1px solid #000333;
}
ul.tag-list::after {
content: ' ';
@ -1445,7 +1469,10 @@ li.tag-item {
font-size: 100%;
list-style: none;
margin: 0;
padding: 0 0.6em 0 0;
padding: 0 4px 0 0;
}
li.tag-item:last-child {
padding-bottom: 17px;
}
a.tag-link {
overflow: hidden;

View File

@ -1,5 +1,5 @@
{% for tag, weight in tags %}
<li class="tag-item">
<a class="tag-link" href="#">{{tag}}</a>
<a class="tag-link" href="#" style="font-size: {{weight}}%;">{{tag}}</a>
</li>
{% endfor %}