xia_meta.health.Health
- class xia_meta.health.Health(**kwargs)
Bases:
EmbeddedDocument
Define the health situation
- Mathematical Definition:
In the ideal situation, a health object is a series of downtime events. For example, for a one-month-period, your laptop is expected to fail: * Twice because of network issue, downtime of each will be 16 seconds * 1% chance to get you a disk failure(unlucky). Downtime might be 2-3 days for restoration
Each event is considered following Poisson Process and thus could be calculated for event combination. Suppose λ1t1, λ2t2 for event1 and event2. * event for event1 or event2 * event for event1 and event2 occurs at the same time The challenge is that the operation will become complex because the varies downtime introduced. That’s why we defined a standard downtime list frequency[0:27]: * Period is fixed at 2 ** 26 seconds * frequency[i] = downtime of 2^i seconds occurs how many times
For the above example: frequency[4] (16 seconds = 2 ** 4) = 2 * 0.0386 (1 month has 0.0386 * 2 ** 26 seconds) frequency[17] (2-3 days is about 2 ** 17 seconds) = 0.01 * 0.0386
Appendix: predefined overlap probability map
- Pick a simple example:
period = 8s, downtime_1 = 1s and downtime_2 = 2s
two downtime could be placed at any moment in the period thus a point of the surface of 8*8
The overlap means the abs(downtime_1 - downtime_2) < 1.5 (attention, the downtime time point is at the middle)
So the result should be: 1-((64-1.5)/64)² = 4.632%.
- __init__(**kwargs)
Methods
__init__
(**kwargs)from_db
(**kwargs)Transform database data to internal data
from_display
(**kwargs)Transform Display data to internal data
from_mtbf
(hours, downtime)Get Health object with Mean Time Before Failure
get_display_data
([lazy])Get Display data (visualized form of data)
get_error_rate
([max_errors])How much chance that max errors occurs
get_frequency
(total_frequency, downtime)Get Raw data (materialized form of data)
Get Runtime data (calculated from raw data when runtime is activated)
Get a sample document data
set_new_downtime
(downtime)Set a new downtime in the case of specified situation
to_db
([ignore_unknown, no_class])Translate the runtime data into raw data (materialized form of data)
validate
()Validate if all of the component of document follows the predefined rules
Attributes
LENGTH
frequency
overlap_map
period
- classmethod from_db(**kwargs)
Transform database data to internal data
- Parameters
**kwargs (object) – python dict got from system
- Returns
python dict object
- classmethod from_display(**kwargs)
Transform Display data to internal data
- Parameters
**kwargs (object) – display object got from front end
- Returns
python dict object
- classmethod from_mtbf(hours: int, downtime: float)
Get Health object with Mean Time Before Failure
- Parameters
hours – Mean Time Before Failure in Hours
downtime – Downtime in seconds
- get_display_data(lazy: bool = True)
Get Display data (visualized form of data)
- Returns
python dict object
Notes
We will return the detail form if it is possible
- get_error_rate(max_errors: int = 0) float
How much chance that max errors occurs
- Parameters
max_errors – max error number. Attention max supported error number = 170
- Returns
probability in float[0, 1]
- Return type
object
- get_raw_data()
Get Raw data (materialized form of data)
- Returns
python dict object
- get_runtime_data()
Get Runtime data (calculated from raw data when runtime is activated)
- Returns
python dict object
- classmethod get_sample()
Get a sample document data
- set_new_downtime(downtime: float)
Set a new downtime in the case of specified situation
- Parameters
downtime – new downtime in seconds
- to_db(ignore_unknown: bool = False, no_class: bool = False)
Translate the runtime data into raw data (materialized form of data)
- Parameters
no_class (bool) – Don’t save the class name into document
ignore_unknown (bool) – When a field is not defined in the document, should we send it back to the database
- Returns
python dict object
- validate()
Validate if all of the component of document follows the predefined rules
- Returns
Always None. No exception raised means the validation passed