-
Notifications
You must be signed in to change notification settings - Fork 109
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 { | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в этом JS я ничего не понимаю, надо будет кого-нибудь позвать сделать review There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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&E: ' + | ||
(talks === 0xff ? '≥' : '') + talks + '\n' : '') + | ||
(tech ? 'Технические разделы: ' + | ||
(tech === 0xff ? '≥' : '') + tech + '\n' : '') + | ||
(news ? 'Новости / Галерея / Опросы: ' + | ||
(news === 0xff ? '≥' : '') + news : ''); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
// suppress automatic redraws | ||
CalHeatMap.prototype.fill = function() {}; | ||
} | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это надо без Await сделать, тут и так на выходе Future