-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from maniek2332/ft/stats
Stats-related functions, stats_graph utility
- Loading branch information
Showing
9 changed files
with
379 additions
and
1 deletion.
There are no files selected for viewing
Submodule kaacore
updated
15 files
+0 −18 | .travis.yml | |
+1 −0 | CMakeLists.txt | |
+2 −0 | include/kaacore/engine.h | |
+1 −1 | include/kaacore/log.h | |
+1 −0 | include/kaacore/renderer.h | |
+109 −0 | include/kaacore/statistics.h | |
+3 −1 | src/CMakeLists.txt | |
+33 −18 | src/engine.cpp | |
+22 −0 | src/renderer.cpp | |
+6 −0 | src/scenes.cpp | |
+270 −0 | src/statistics.cpp | |
+1 −0 | tests/CMakeLists.txt | |
+135 −0 | tests/test_statistics.cpp | |
+7 −0 | third_party/kissnet/CMakeLists.txt | |
+1,332 −0 | third_party/kissnet/kissnet.hpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from libc.stdint cimport uint32_t | ||
from libcpp.vector cimport vector | ||
from libcpp.pair cimport pair | ||
from libcpp.string cimport string | ||
|
||
from .exceptions cimport raise_py_error | ||
|
||
ctypedef pair[string, double] CPairStatisticLastValue | ||
ctypedef pair[string, CStatisticAnalysis] CPairStatisticAnalysis | ||
|
||
cdef extern from "kaacore/statistics.h" nogil: | ||
cdef cppclass CStatisticAnalysis "kaacore::StatisticAnalysis": | ||
uint32_t samples_count | ||
double last_value | ||
double mean_value | ||
double max_value | ||
double min_value | ||
double standard_deviation | ||
|
||
cdef cppclass CStatisticsManager "kaacore::StatisticsManager": | ||
vector[CPairStatisticLastValue] get_last_all() except +raise_py_error | ||
vector[CPairStatisticAnalysis] get_analysis_all() except +raise_py_error | ||
void push_value(const string& name, const double value) except +raise_py_error | ||
|
||
cdef CStatisticsManager& c_get_global_statistics_manager "kaacore::get_global_statistics_manager"() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from .kaacore.statistics cimport ( | ||
CStatisticsManager, c_get_global_statistics_manager, CPairStatisticLastValue, | ||
CStatisticAnalysis, CPairStatisticAnalysis, | ||
) | ||
|
||
|
||
cdef class StatisticAnalysis: | ||
cdef CStatisticAnalysis c_statistic_analysis | ||
|
||
def __init__(self): | ||
raise RuntimeError(f'{self.__class__} must not be instantiated manually!') | ||
|
||
@staticmethod | ||
cdef create(CStatisticAnalysis c_statistic_analysis): | ||
cdef StatisticAnalysis statistic_analysis = \ | ||
StatisticAnalysis.__new__(StatisticAnalysis) | ||
statistic_analysis.c_statistic_analysis = c_statistic_analysis | ||
return statistic_analysis | ||
|
||
def __repr__(self): | ||
return ( | ||
"<StatisticAnalysis: samples_count:{}, last_value:{}," | ||
" mean_value:{}, max_value:{}, min_value:{}," | ||
" standard_deviation:{}" | ||
).format( | ||
self.samples_count, self.last_value, self.mean_value, | ||
self.max_value, self.min_value, self.standard_deviation | ||
) | ||
|
||
@property | ||
def samples_count(self): | ||
return self.c_statistic_analysis.samples_count | ||
|
||
@property | ||
def last_value(self): | ||
return self.c_statistic_analysis.last_value | ||
|
||
@property | ||
def mean_value(self): | ||
return self.c_statistic_analysis.mean_value | ||
|
||
@property | ||
def max_value(self): | ||
return self.c_statistic_analysis.max_value | ||
|
||
@property | ||
def min_value(self): | ||
return self.c_statistic_analysis.min_value | ||
|
||
@property | ||
def standard_deviation(self): | ||
return self.c_statistic_analysis.standard_deviation | ||
|
||
|
||
cdef class StatisticsManager: | ||
cdef CStatisticsManager* c_statistics_manager | ||
|
||
def __init__(self): | ||
raise RuntimeError(f'{self.__class__} must not be instantiated manually!') | ||
|
||
@staticmethod | ||
cdef create(CStatisticsManager* c_statistics_manager): | ||
assert c_statistics_manager | ||
cdef StatisticsManager statistics_manager = \ | ||
StatisticsManager.__new__(StatisticsManager) | ||
statistics_manager.c_statistics_manager = c_statistics_manager | ||
return statistics_manager | ||
|
||
def get_last_all(self): | ||
cdef list results = [] | ||
cdef CPairStatisticLastValue pair | ||
|
||
for pair in self.c_statistics_manager.get_last_all(): | ||
results.append((pair.first.decode(), pair.second)) | ||
return results | ||
|
||
def get_analysis_all(self): | ||
cdef list results = [] | ||
cdef CPairStatisticAnalysis pair | ||
|
||
for pair in self.c_statistics_manager.get_analysis_all(): | ||
results.append((pair.first.decode(), | ||
StatisticAnalysis.create(pair.second))) | ||
return results | ||
|
||
def push_value(self, str stat_name, double value): | ||
self.c_statistics_manager.push_value(stat_name.encode(), value) | ||
|
||
|
||
cdef StatisticsManager _global_statistics_manager = StatisticsManager.create( | ||
&c_get_global_statistics_manager() | ||
) | ||
|
||
|
||
def get_global_statistics_manager(): | ||
return _global_statistics_manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._kaa import get_global_statistics_manager, StatisticsManager, StatisticAnalysis |
Empty file.
Oops, something went wrong.