owned this note
owned this note
Published
Linked with GitHub
In this release я начал добавлять графики и на примере бенефициарских наград вы можете увидеть как будут выглядеть другие страницы с вознаграждениями.
Так же в этом релизе я добавил загрузку on demand данных в таблицах. Теперь я могу отображать данные за весь период существования аккаунта.
На очереди переделка кураторских вознаграждений.
* вынесение на отдельную страницу
* добавлние графиков
как реализовано получение бенефециарских наград:
так как все данные по аккаунты мы храним в mongoDB то мы можем получить все операции типа:
`comment_benefactor_reward`
Так как данных может быть много, то я решил что данные для графиков будут собиртаься с помощью базы данных и собственно такого запроса:
```
$data_by_monthes = $collection->aggregate([
[
'$match' => [
'type' => ['$eq' => 'comment_benefactor_reward'],
'op.benefactor' => ['$eq' => $acc]
]
],
['$unwind' => '$op'],
[
'$group' => [
'_id' => ['date' => ['M' => ['$month' => '$date'], 'Y' => ['$year' => '$date'],]],
'total' => ['$sum' => '$op.VESTS'],
'count' => ['$sum' => 1]
]
],
]);
```
У нас есть два типа наград:
те кторые получает просматриваемый аккаунт `'op.benefactor' => ['$eq' => $acc]`
те которые отдает из своих постов просматриваемый акканут `'op.benefactor' => ['$ne' => $acc]`
Выборка данных для подрбных таблиц происходит таким запросом
```
$data_by_monthes = $collection->aggregate([
[
'$match' => [
'date' => ['$gte' => $date_start, '$lt' => $date_end],
'type' => ['$eq' => 'comment_benefactor_reward'],
'op.benefactor' => [$typeQ => $acc]
]
]
]);
```
Получаем данные за месяц, а затем перебираем их в цикле и приводим их к нужному виду
```
foreach ($data_by_monthes as $state) {
if ($type == 'In') {
$arr['author'] = $state['op'][1]['author'];
}
if ($type == 'Out') {
$arr['author'] = $state['op'][1]['benefactor'];
}
$arr['permlink'] = $state['op'][1]['permlink'];
$arr['VESTS'] = $state['op'][1]['VESTS'];
$arr['SP'] = BchApi::convertToSg($state['op'][1]['VESTS']);
$arr['timestamp'] = $state['timestamp'];
$res_arr[] = $arr;
}
```
Более подробно можно посмотреть в файле: `app/Http/Controllers/BenefactorRewardsController.php`
Так же в каждом релизи есть изменения для переноса данных из блокчейна в базу данных. Никак не могу найти безошибочный способ. Постоянно чтонить ломается:(
Думаю все же переходить к отдельной библиотке по работе с базой данных. И полноценному изначальному сбору данных из блоков.
ENG
utopian-io development accusta steemit tools
#### Repository
https://github.com/semasping/Accusta
### In 1.0.0 release of [](https://steemit.accusta.tk):
* Add information about Benefactor rewards.
* New structure for pages with rewards with charts and ajax data loading.
* Bugfixes
# Deteled information
### New Features
In this release I started adding of a charts so let’s look at the example of beneficiary reward to see reward pages form.
In current release I also added on demand data download to the tables. Now it is possible to show data over all the time of the account existence.
Redesign of curation rewards will be next in line for development, i.e.:
* transferring to a separate page
* charts adding
### How receiving of beneficial rewards is implemented:
So far as all accounts’ data is stored in the mongoDB we can get all operations of the type:
`comment_benefactor_reward`
As there are cases when we need to handle a lot of data so I solved that the data for charts will be collected using the DB by the following request:
```
$data_by_monthes = $collection->aggregate([
[
'$match' => [
'type' => ['$eq' => 'comment_benefactor_reward'],
'op.benefactor' => ['$eq' => $acc]
]
],
['$unwind' => '$op'],
[
'$group' => [
'_id' => ['date' => ['M' => ['$month' => '$date'], 'Y' => ['$year' => '$date'],]],
'total' => ['$sum' => '$op.VESTS'],
'count' => ['$sum' => 1]
]
],
]);
```
We have two reward types:
those which are received by the account `'op.benefactor' => ['$eq' => $acc]`
those which are given out by the account (i.e.from its posts) `'op.benefactor' => ['$ne' => $acc]`
Data sampling for this kind of tables are proceeded by the request:
```
$data_by_monthes = $collection->aggregate([
[
'$match' => [
'date' => ['$gte' => $date_start, '$lt' => $date_end],
'type' => ['$eq' => 'comment_benefactor_reward'],
'op.benefactor' => [$typeQ => $acc]
]
]
]);
```
So we get monthly data, then handle them in foreach and convert them into desirable form.
```
foreach ($data_by_monthes as $state) {
if ($type == 'In') {
$arr['author'] = $state['op'][1]['author'];
}
if ($type == 'Out') {
$arr['author'] = $state['op'][1]['benefactor'];
}
$arr['permlink'] = $state['op'][1]['permlink'];
$arr['VESTS'] = $state['op'][1]['VESTS'];
$arr['SP'] = BchApi::convertToSg($state['op'][1]['VESTS']);
$arr['timestamp'] = $state['timestamp'];
$res_arr[] = $arr;
}
```
See more details here: `app/Http/Controllers/BenefactorRewardsController.php`
### Bugfixes
Besides each release contains changes for data transfer from blockchain to the DB. I can’t find error-free way so far. Any sort of bugs occurs all the time :(
I suppose it's needed to move on to separate library for work with DB and to implement a full-value initial collection of data from blocks.
## This release it is the beginning of new development stage of the Accusta system.
#### GitHub Account
https://github.com/semasping