Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ПІСТРЯВЕНЬКА статистика #972

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/ru/org/linux/user/WhoisController.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public ModelAndView handleUserNotFound() {

@RequestMapping(value="/people/{nick}/profile", method = {RequestMethod.GET, RequestMethod.HEAD}, params="year-stats")
@ResponseBody
public CompletionStage<Map<Object, Object>> yearStats(@PathVariable String nick) {
public CompletionStage<Map<String, Map<Object, Object>>> yearStats(@PathVariable String nick) {
User user = userService.getUser(nick);

user.checkBlocked();
Expand Down
36 changes: 24 additions & 12 deletions src/main/scala/ru/org/linux/user/UserStatisticsService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.concurrent.CompletionStage

import com.sksamuel.elastic4s.http.ElasticClient
import com.sksamuel.elastic4s.http.ElasticDsl._
import com.sksamuel.elastic4s.http.Response
import com.sksamuel.elastic4s.http.search.SearchResponse
import com.sksamuel.elastic4s.searches.DateHistogramInterval
import com.typesafe.scalalogging.StrictLogging
Expand Down Expand Up @@ -84,18 +85,29 @@ class UserStatisticsService(
)
}

def getYearStats(user: User): CompletionStage[java.util.Map[Long, Long]] = {
Future.successful(elastic).flatMap {
_ execute {
val root = boolQuery().filter(termQuery("author", user.getNick), rangeQuery("postdate").gt("now-1y/M"))

search(MessageIndex) size 0 timeout 30.seconds query root aggs
dateHistogramAgg("days", "postdate").interval(DateHistogramInterval.days(1)).minDocCount(1)
} map {
_.result.aggregations.dateHistogram("days").buckets.map { bucket =>
bucket.timestamp/1000 -> bucket.docCount
}.toMap.asJava
}
def getYearStats(user: User): CompletionStage[java.util.Map[String, java.util.Map[Long, Long]]] = {
val queries = Map(
"talks" -> termsQuery("group", Seq("talks", "science", "club")),
"news" -> termsQuery("section", Seq("news", "polls", "gallery")),
"tech" -> filter( termQuery("section", "forum"), not( termsQuery("group", Seq("talks", "science", "club")) ) )
)

Future.successful(elastic).flatMap { el =>
Future.successful(queries.keys.map { key =>
key -> Await.result(el.execute {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это надо без Await сделать, тут и так на выходе Future

val root = boolQuery().filter(
termQuery("author", user.getNick),
rangeQuery("postdate").gt("now-1y/M"),
queries(key))

search(MessageIndex) size 0 timeout 30.seconds query root aggs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо трех запросов это надо запихать в один. Для этого основную выборку нужно сделать по адресу и дате, и в ней сделать три агрегата с фильтрами по разделу

dateHistogramAgg("days", "postdate").interval(DateHistogramInterval.days(1)).minDocCount(1)
} map { sr: Response[SearchResponse] =>
sr.result.aggregations.dateHistogram("days").buckets.map { bucket =>
bucket.timestamp/1000 -> bucket.docCount
}.toMap.asJava
}, 5.seconds)
}.toMap[String, java.util.Map[Long, Long]].asJava)
}.toJava
}

Expand Down
72 changes: 67 additions & 5 deletions src/main/webapp/WEB-INF/jsp/whois.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,83 @@
range: 12,
domainDynamicDimension: false,
displayLegend: false,
legend: [8, 32, 64, 128],
legend: [8],
legendColors: ['#000', '#fff'],
cellSize: size,
start: new Date("<%= DateTime.now().minusMonths(11).toString() %>"),
tooltip: true,
tooltip: false,
domainLabelFormat: function (date) {
return moment(date).format("MMMM");
},
subDomainDateFormat: function (date) {
return moment(date).format("LL");
},
subDomainTitleFormat: {
empty: "{date}",
filled: "{date}<br>сообщений: {count}"
afterLoadData: function(data) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в этом JS я ничего не понимаю, надо будет кого-нибудь позвать сделать review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кого-нибудь позвать

@unclechu?

(сейчас опять кучу ES6 насуёт и понлифиллами обмажет, ага)

var stats = {};
var sections = {
talks: 16,
tech: 8,
news: 0,
};
var curIntTs, ts, addition, curCount;

for (var section in sections) {
if (sections.hasOwnProperty(section) && data[section]) {
for (ts in data[section]) {
curIntTs = parseInt(ts);
if (!isNaN(curIntTs)) {
curCount = data[section][ts];
if (curCount > 0xff) curCount = 0xff; // clamp
addition = curCount << sections[section];
if (stats[curIntTs] !== undefined) {
stats[curIntTs] += addition;
} else {
stats[curIntTs] = addition;
}
}
}
}
}

return stats;
},
onComplete: function() {
var rects = document.getElementById('cal-heatmap').getElementsByTagName('rect');
var rect, value, talks, tech, news, r, g, b;
var PI_0019 = Math.PI * 0.0019;
for (var i = 0; i < rects.length; i ++) {
rect = rects[i];
if (rect.__data__ && rect.__data__.v) {
value = parseInt(rect.__data__.v);
if (!isNaN(value)) {
talks = value >> 16;
tech = (value >> 8) & 0xff;
news = value & 0xff;

// excite
r = talks ? parseInt(180 + 60 * Math.sin(talks * PI_0019)) : 0;
g = tech ? parseInt(180 + 60 * Math.sin(tech * PI_0019)) : 0;
b = news ? parseInt(180 + 60 * Math.sin(news * PI_0019)) : 0;

rect.setAttribute('fill', 'rgb(' + r + ',' + g + ',' + b + ')');
rect.setAttribute('class', '');

if (rect.nextSibling && rect.nextSibling.tagName === 'title') {
rect.nextSibling.innerHTML += '\n' +
(talks ? 'Talks / Клуб / S&amp;E: ' +
(talks === 0xff ? '≥' : '') + talks + '\n' : '') +
(tech ? 'Технические разделы: ' +
(tech === 0xff ? '≥' : '') + tech + '\n' : '') +
(news ? 'Новости / Галерея / Опросы: ' +
(news === 0xff ? '≥' : '') + news : '');
}
}
}
}
}
});
// suppress automatic redraws
CalHeatMap.prototype.fill = function() {};
}
});
});
Expand Down
39 changes: 0 additions & 39 deletions src/main/webapp/sass/_cal-heapmap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,45 +46,6 @@
fill: #999
}

/*
.cal-heatmap-container .q0
{
background-color: grayscale(darken($heatmap_max, 20%));
fill: grayscale(darken($heatmap_max, 20%));
stroke: #ededed
}
*/

.cal-heatmap-container .q1
{
background-color: adjust-color($heatmap_max, $lightness: -20%*$heatmap_scale);
fill: adjust-color($heatmap_max, $lightness: -20%*$heatmap_scale);
}

.cal-heatmap-container .q2
{
background-color: adjust-color($heatmap_max, $lightness: -15%*$heatmap_scale);
fill: adjust-color($heatmap_max, $lightness: -15%*$heatmap_scale);
}

.cal-heatmap-container .q3
{
background-color: adjust-color($heatmap_max, $lightness: -10%*$heatmap_scale);
fill: adjust-color($heatmap_max, $lightness: -10%*$heatmap_scale);
}

.cal-heatmap-container .q4
{
background-color: adjust-color($heatmap_max, $lightness: -5%*$heatmap_scale);
fill: adjust-color($heatmap_max, $lightness: -5%*$heatmap_scale);
}

.cal-heatmap-container .q5
{
background-color: $heatmap_max;
fill: $heatmap_max;
}

.cal-heatmap-container rect.highlight
{
stroke:#444;
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/sass/waltz/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ $tagpage_group_label_background: #E7AF55;
$tagpage_group_label_color: $table_link_color;
$stars_color: #465A48;

$heatmap_max: darken(#8ae234, 15%);
$heatmap_max: #8ae234;
$heatmap_scale: -1.5;
$tracker_tag_color: $table_border_color;
$tracker_tag_color: $table_border_color;
5 changes: 5 additions & 0 deletions src/main/webapp/sass/waltz/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,9 @@ fieldset legend {
color: $stars_color;
}

.cal-heatmap-container .graph-label
{
fill: $text_color;
}

@import "../responsive";
8 changes: 7 additions & 1 deletion src/main/webapp/sass/white2/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,14 @@ textarea {

@import "../responsive";

$heatmap_max: darken(#8ae234, 15%);
$heatmap_max: #8ae234;
$heatmap_scale: -1.5;
@import "../cal-heapmap";

.cal-heatmap-container .graph-label
{
fill: black;
}

@import "../tracker";

2 changes: 1 addition & 1 deletion src/main/webapp/sass/zomg_ponies/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ $stars_color: #400040;

$icon_button_active_color: $stars_color;

$heatmap_max: darken(#8ae234, 15%);
$heatmap_max: #8ae234;
$heatmap_scale: -1.5;
$tracker_tag_color: $tag_even_color;
7 changes: 6 additions & 1 deletion src/main/webapp/sass/zomg_ponies/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ a:hover {
display: none;
}

article, .boxlet, #counter_block, .infoblock, #nav-menu, #p-lang, .messages .msg, #warning-text, #tag-page-forum, fieldset, legend, #tag-page-news, #related-topics, .tags-first-letters{
article, .boxlet, #counter_block, .infoblock, #nav-menu, #p-lang, .messages .msg, #warning-text, #tag-page-forum, fieldset, legend, #tag-page-news, #related-topics, .tags-first-letters, #cal-heatmap{
background-color: $article_background;
border-top-color: white;
border-left-color: white;
Expand Down Expand Up @@ -725,4 +725,9 @@ fieldset legend {
border: 2px solid $targeted_message_border_color;
}

.cal-heatmap-container .graph-label
{
fill: $text_color;
}

@import "../responsive";