#MIT License
#Copyright (c) 2017 Tim Wentzlau
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import time
from datetime import datetime
from kervi.values.kervi_value import KerviValue
from kervi.core.utility.component import KerviComponent
from kervi.config import Configuration
class NumberValue(KerviValue):
"""
Value that holds a float value.
If this value is an input it is shown as a slider on dashboards.
If is an output it is possible to specify different kinds of gauges.
"""
def __init__(self, name, **kwargs):
KerviValue.__init__(self, name, "number-value", **kwargs)
#self.spine = Spine()
self._min_value = -100
self._max_value = 100
self._unit = ""
self._type = None
self._display_unit = ""
self._default_value = 0.0
self._value = 0
self._delta = None
self._ui_parameters["type"] = ""
self._ui_parameters["value_icon"] = None
self._ui_parameters["min_integer_digits"] = 1
self._ui_parameters["min_fraction_digits"] = 1
self._ui_parameters["max_fraction_digits"] = 1
self._ui_parameters["show_sparkline"] = False
self._ui_parameters["pad_auto_center"] = False
self._ui_parameters["chart_buttons"] = True
self._ui_parameters["chart_grid"] = True
self._ui_parameters["chart_interval"] = "5min"
self._ui_parameters["chart_fill"] = True
self._ui_parameters["chart_point"] = 0
if Configuration:
unit_system = Configuration.display.unit_systems.default
chart_time_format = Configuration.display.unit_systems.systems[unit_system].datetime.chart
self._ui_parameters["chart_time_format"] = chart_time_format
else:
self._ui_parameters["chart_time_format"] = {
"millisecond": "h:mm:ss.SSS",
"second": "h:mm:ss",
"minute": "h:mm",
"hour": "h",
"day": "MMM D",
"week": "ll",
"month": "MMM YYYY",
"quarter":"[Q]Q - YYYY",
"year": "YYYY",
}
self._ui_parameters["tick"] = 1.0
self._ui_parameters["display_unit"] = True
self._last_reading = None
@property
def delta(self):
"""
Enter how much a the value should change before it triggers changes events and updates links.
:type: ``float``
"""
return self._delta
@delta.setter
def delta(self, value):
self._delta = value
@property
def max(self):
"""
Maximum value.
:type: ``float``
"""
return self._max_value
@max.setter
def max(self, value):
self._max_value = value
@property
def min(self):
"""
Minimum value.
:type: ``float``
"""
return self._min_value
@min.setter
def min(self, value):
self._min_value = value
@property
def unit(self):
"""
Metric Unit of value.
:type: ``str``
"""
return self._unit
@unit.setter
def unit(self, value):
self._unit = value
@property
def type(self):
"""
Value type.
:type: ``str``
"""
return self._type
@type.setter
def type(self, value):
self._type = value
@property
def display_unit(self):
"""
Display unit of value.
:type: ``str``
"""
if self._display_unit:
return self._display_unit
else:
config = Configuration.display.unit_systems
default_system = config.default
units = config.systems[default_system]
display_unit = units.get(self._type, self._unit)
return display_unit
@display_unit.setter
def display_unit(self, value):
self._display_unit = value
def _get_ui_parameters(self, ui_parameters):
ui_parameters["display_unit"] = self.display_unit
return ui_parameters
def _get_info(self, **kwargs):
return {
"isInput":self.is_input,
"unit":self._unit,
"value":self.value,
"maxValue":self._max_value,
"minValue":self._min_value,
"command":self.command,
"ranges":self._event_ranges,
"sparkline":self._sparkline,
}
def __delta_exceeded(self, value):
if self._delta is None:
return True
elif value is None:
return False
elif self._value is None:
return True
elif value >= self._value + self.delta:
return True
elif value <= self._value - self.delta:
return True
else:
return False
def _set_value(self, new_value, allow_persist=True):
if self.__delta_exceeded(new_value):
self.spine.log.debug(
"value change on input:{0} value:{1}",
self.component_id,
new_value
)
old_value = self._value
self._value = new_value
self.value_changed(new_value, old_value)
for observer in self._observers:
if isinstance(observer, tuple):
item, transformation = observer
if transformation:
item.kervi_value_changed(self, transformation(new_value))
else:
item.kervi_value_changed(self, new_value)
else:
observer.kervi_value_changed(self, new_value)
self._check_value_events(new_value, old_value)
if self._persist_value and allow_persist:
self.settings.store_value("value", self.value)
timestamp = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
if len(self._sparkline) == 0:
self._sparkline += [{"timestamp":timestamp, "value":new_value}]
elif len(self._sparkline) >= 10:
self._sparkline.pop(0)
self._sparkline += [{"timestamp":timestamp, "value":new_value}]
self._last_reading = time.clock()
val = {"value_id":self.component_id, "value":new_value, "timestamp":datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")}
self.spine.trigger_event(
"valueChanged",
self.component_id,
{"id":self.component_id, "value":new_value, "timestamp":datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")},
self._log_values,
groups=self.user_groups
)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:kervi-core-0.15.46.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
kervi-core-0.15.46.tar.gz (35个子文件)
kervi-core-0.15.46
PKG-INFO 1KB
kervi
core
utility
kervi_logging.py 3KB
cron.py 85B
thread.py 2KB
__init__.py 1B
settings.py 2KB
superformatter.py 707B
component.py 10KB
module_thread.py 2KB
process.py 5KB
version
__init__.py 22B
config
configuration.py 6KB
__init__.py 1KB
hal
gpio.py 10KB
__init__.py 7KB
one_wire.py 2KB
motor_controller.py 11KB
i2c.py 4KB
displays
__init__.py 11KB
controllers
steering.py 4KB
__init__.py 0B
controller.py 10KB
tasks.py 2KB
values
value_list.py 3KB
__init__.py 20KB
kervi_value.py 15KB
user_input
__init__.py 5KB
dashboards
__init__.py 11KB
sensors
sensor.py 10KB
__init__.py 0B
actions
action.py 19KB
__init__.py 2KB
actions_list.py 1KB
spine
__init__.py 2KB
setup.py 2KB
共 35 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- vs2019 c++20 语法规范 头文件 <ratio> 的源码阅读与注释,处理分数的存储,加减乘除,以及大小比较等运算
- 基于Kotlin语言的Android开发工具类集合源码
- 零延迟 DirectX 11 扩展实用程序.zip
- 基于Java的语音识别系统设计源码
- 基于Java和HTML的yang_home766个人主页设计源码
- 基于Java与前端技术的全国实时疫情信息网站设计源码
- 基于鸿蒙系统的HarmonyHttpClient设计源码,纯Java实现类似OkHttp的HttpNet框架与优雅的Retrofit注解解析
- 基于HTML和JavaScript的廖振宇图书馆前端设计源码
- 基于Java的Android开发工具集合源码
- 通过 DirectX 12 Hook (kiero) 实现通用 ImGui.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功