mirror of https://github.com/MISP/MISP
new: [statistics] Added organisation activity over time
parent
a8b5da4be2
commit
806f443764
|
@ -1761,6 +1761,7 @@ class UsersController extends AppController
|
|||
foreach ($events as $event) {
|
||||
$orgs[$event['Event']['orgc_id']]['eventCount'] = $event[0]['count(*)'];
|
||||
$orgs[$event['Event']['orgc_id']]['attributeCount'] = $event[0]['attributeCount'];
|
||||
$orgs[$event['Event']['orgc_id']]['orgActivity'] = $this->User->getOrgActivity($event['Event']['orgc_id'], array('event_timestamp' => '365d'));
|
||||
}
|
||||
unset($events);
|
||||
$orgs = Set::combine($orgs, '{n}.name', '{n}');
|
||||
|
|
|
@ -1461,4 +1461,57 @@ class User extends AppModel
|
|||
|
||||
return new Crypt_GPG($options);
|
||||
}
|
||||
|
||||
public function getOrgActivity($orgId, $params=array())
|
||||
{
|
||||
$conditions = array();
|
||||
$options = array();
|
||||
foreach($params as $paramName => $value) {
|
||||
$options['filter'] = $paramName;
|
||||
$filterParam[$paramName] = $value;
|
||||
$conditions = $this->Event->set_filter_timestamp($filterParam, $conditions, $options);
|
||||
}
|
||||
$conditions['Event.orgc_id'] = $orgId;
|
||||
$events = $this->Event->find('all', array(
|
||||
'recursive' => -1,
|
||||
'fields' => array('Event.orgc_id', 'Event.timestamp', 'Event.attribute_count'),
|
||||
'conditions' => $conditions,
|
||||
'order' => 'Event.timestamp'
|
||||
));
|
||||
$sparklineData = array();
|
||||
foreach ($events as $event) {
|
||||
$date = date("Y-m-d", $event['Event']['timestamp']);
|
||||
if (!isset($sparklineData[$event['Event']['attribute_count']][$date])) {
|
||||
$sparklineData[$date] = $event['Event']['attribute_count'];
|
||||
} else {
|
||||
$sparklineData[$date] += $event['Event']['attribute_count'];
|
||||
}
|
||||
}
|
||||
|
||||
// get first and last timestamp
|
||||
if (isset($params['from'])) {
|
||||
$startDate = $params['from'];
|
||||
} else {
|
||||
$startDate = $this->resolveTimeDelta($params['event_timestamp']);
|
||||
}
|
||||
if (isset($params['to'])) {
|
||||
$endDate = $params['to'];
|
||||
} else {
|
||||
$endDate = time();
|
||||
}
|
||||
$dates = array();
|
||||
for ($d=$startDate; $d < $endDate; $d=$d+3600*24) {
|
||||
$dates[] = date('Y-m-d', $d);
|
||||
}
|
||||
$csv = 'Date,Close\n';
|
||||
foreach ($dates as $date) {
|
||||
$csv .= sprintf('%s,%s\n', $date, isset($sparklineData[$date]) ? $sparklineData[$date] : 0);
|
||||
}
|
||||
$data = array(
|
||||
'csv' => $csv,
|
||||
'data' => $sparklineData,
|
||||
'orgId' => $orgId
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
<th><?php echo __('Nationality');?></th>
|
||||
<th><?php echo __('Type');?></th>
|
||||
<th><?php echo __('Sector');?></th>
|
||||
<th><?php echo __('Activity (1 year)');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($orgs as $data):
|
||||
|
@ -52,6 +53,13 @@
|
|||
<td class="shortish"><?php echo isset($data['nationality']) && $data['nationality'] !== 'Not specified' ? h($data['nationality']) : ' '; ?></td>
|
||||
<td class="shortish"><?php echo isset($data['type']) ? h($data['type']) : ' '; ?></td>
|
||||
<td class="shortish"><?php echo isset($data['sector']) ? h($data['sector']) : ' '; ?></td>
|
||||
<td class="shortish">
|
||||
<?php
|
||||
if (isset($data['orgActivity'])) {
|
||||
echo $this->element('sparkline', array('scope' => 'organisation', 'id' => $data['id'], 'csv' => $data['orgActivity']['csv']));
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
|
|
Loading…
Reference in New Issue