npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vanwei-wcs/device-utils

v0.1.10

Published

wcs device utils

Downloads

9

Readme

wcs-device-utils

🚀 wcs device的一些方法 🌈.

安装

npm i @vanwei-wcs/device-utils

使用

import { CountDeviceNumber } from ' @vanwei-wcs/device-utils'
const count = CountDeviceNumber(data.statistics)
console.log(count)

名词解释

虚拟目录

是wcs虚拟出来的类型,下面代码中的label表示名称、type表示基础类型、abilities表示该类型具有的能力集合

export const VirtualGroups = [
	{ label: '下级域', type: 'port', abilities: []},
	{ label: '区域', type: 'district', abilities: []},
	{ label: '链接', type: 'link', abilities: []}
]

真实设备

能够接入真实的设备类型,下面代码中的label表示名称,type表示基础类型,abilities表示该类型具有的能力集合

export const RealDevices: device[] =  [
	{ label: '网关', type: 'vbox', abilities: ['transcode']},
	{ label: '网络录像机', type: 'NVR', abilities: ['record']},
	{ label: '摄像头', type: 'IPC', abilities: ['video', 'transcode']},
	{ label: '硬盘录像机', type: 'DVR', abilities: ['record']},
	{ label: '门禁', type: 'AccessController', abilities: ['door']},
	{ label: '人证机', type: 'IDCardReader', abilities: ['face']},
	{ label: '一键报警设备', type: 'EmergencyAlarmer', abilities: ['alarm']},
	{ label: '消防网关', type: 'FireGateway', abilities: []},
	{ label: '物联网网关', type: 'IOTBox', abilities: []},
	{ label: '混合硬盘录像机', type: 'HVR', abilities: []},
	{ label: '视频服务器', type: 'DVS', abilities: []},
	{ label: 'NVS设备', type: 'NVS', abilities: []},
	{ label: '智能dvr', type: 'IVR', abilities: []},
	{ label: '车载dvr', type: 'MVR', abilities: []},

	{ label: '云台摄像头', type: 'IPC/IPDome', abilities: ['video', 'ptz']},
	{ label: '红外摄像头', type: 'IPC/TII', abilities: ['video', 'thermal']},
	{ label: '云台红外摄像头', type: 'IPC/TII/IPDome', abilities: ['video', 'ptz', 'thermal']},
	{ label: '智能交通摄像机', type: 'IPC/ITC', abilities: ['video', 'door', 'car']},
	{ label: '智能人脸相机', type: 'IPC/Face', abilities: ['video', 'face']},

	// 兼容性要求,后续版本可能会删除
	{ label: '道闸(弃用)', type: 'ITC', abilities: ['door']},
	{ label: '红外摄像头(弃用)', type: 'TII/IPC', abilities: ['thermal']}
]

设备类型

指设备树中设备的device_type的值,是由下面的DeviceTypePrefix的字段(除了masterText)和设备的基础类型组合而成(用/连接),另外有以下几点需要了解

  • 虚拟目录只能和group组合,其他无限制,
  • 含有group的都称为目录,类似于文件夹
  • 含有device/master的都称为主设备,是表示接入的设备本身,例如group/vbox表示网关目录,它的子级有device/master/vbox和一些其他的目录,这个device/master/vbox就表示网关本身,可以用来执行重启网关等操作
  • 含有device的都成为设备,目前一般情况下只有device/IPC开头的设备(表示摄像头的通道,一般用来播放视频)
// 举例
// group
// group/port
// group/IPC/ITC
// group/AccessController
// device/IPC
// device/IPC/IPDome
// device/master/vbox
// device/master/IPC/Face

组件api

常量 Const

|字段|说明|类型|值| |---|---|---|---| |DeviceTypePrefix|wcs设备类型前缀|Object|{group: 'group',device: 'device',masterText: 'master',master: 'device/master'}| |AllBaseTypes|全部类型数组|Array|打印以查看具体值| |VirtualGroups|虚拟目录|Array|| |RealDevices|真实设备|Array|| |GroupTypes|虚拟目录和group组合之后的设备类型集合|Array|| |DeviceTypes|真实设备和device组合之后的设备类型集合|Array|| |GroupDeviceTypes|GroupTypes和DeviceTypes的合集|Array|| |MasterDeviceTypes|真实设备和device/master组合之后的设备类型集合|Array|| |RealDeviceTypes|等于DeviceTypes|Array|| |RealMasterDeviceTypes|等于MasterDeviceTypes|Array|| |RealGroupDeviceTypes|真实设备和group组合之后的设备类型集合|Array|| |VirtualGroupTypes|等于GroupTypes|Array||

方法 Methods

|方法|说明|参数|返回值| |---|---|---|---| |GetBaseTypeByDeviceType|获取设备类型的基础类型,例如 device/IPC -> IPC|deviceType:string|string| |GetLabelByType|根据设备基础类型获取设备label,例如 IPC -> 摄像头|type:string|string| |GetLabelByDeviceType|获取设备类型的label, 例如 device/master/IPC -> 摄像头|deviceType:string|string| |GetLabelByMasterDeviceType|获取设备类型的label,含有主设备标识 "(主)", 例如 device/master/IPC -> 摄像头(主)|deviceType:string|string| |IsGroupType|判断是否是目录|deviceType:string|boolean| |IsDeviceType|判断是真实设备类型,含有device前缀|deviceType:string|boolean| |IsMasterDeviceType|判断是主设备类型,含有device/master前缀|deviceType:string|boolean| |IsIPCDevice|判断是摄像头类型,含有device/IPC|deviceType:string|boolean| |GetDeviceTypesByAbility|获取含有指定能力的真实设备类型集合(含设备类型前缀),参数ability表示能力,prefix表示返回时组合此前缀,默认为device|ability:string,prefix:string|Array| |GetDeviceTypesByAbilities|获取一种或多种能力的真实设备类型集合(含设备类型前缀),参数abilities表示能力字符数组,prefix表示返回时组合此前缀,默认为device|abilities:Array,prefix:string|Array| |GetBaseTypesByAbility|获取含有指定能力的真实设备基础类型集合,参数ability表示能力|ability:string|Array| |GetBaseTypesByAbilities|获取一种或多种能力的真实设备基础类型集合,参数abilities表示能力字符数组|abilities:Array|Array| |CountDeviceNumber|统计设备的子设备在线和总数,参数statistics为设备详情中的statistics字段|statistics|{online,total}| |GetDeviceIcon|获取设备类型的icon字符,参数deviceType为设备类型,status为设备详情中的status字段,具体请参考文末的icon解释|deviceType:string,status:string|string| |HasChildGroup|判断此设备类型的设备是否含有目录类型的子级|deviceType:string|boolean| |GetPathChain|获取一个设备路径path的父级链路数组|path:string|string[]| |GetPathsChain|获取多个设备路径path的父级链路数组|path:string[]|string[]| |IsValidPath|获取多个设备路径path的父级链路数组|path:string[]|string[]| |GetParentPath|判断设备路径是否符合规则|path:string|boolean|

导出定义

export default {
	DeviceTypePrefix,

	AllBaseTypes,

	GroupTypes,
	DeviceTypes,
	MasterDeviceTypes,
	GroupDeviceTypes,

	RealDevices,
	RealDeviceTypes,
	RealMasterDeviceTypes,
	RealGroupDeviceTypes,

	VirtualGroups,
	VirtualGroupTypes,

	GetBaseTypeByDeviceType,
	GetLabelByType,
	GetLabelByDeviceType,
	GetLabelByMasterDeviceType,

	IsGroupType,
	IsDeviceType,
	IsMasterDeviceType,
	IsIPCDevice,

	GetDeviceTypesByAbility,
	GetDeviceTypesByAbilities,
	GetBaseTypesByAbility,
	GetBaseTypesByAbilities,

	CountDeviceNumber,
	GetDeviceIcon,
	HasChildGroup,
	
	IsValidPath,
	GetPathChain,
	GetPathsChain,
	GetParentPath
}

icon解释

通过设备类型和状态来获取一个值,此值可以用来设置这个设备的图片或者图标

/**
 * icon字符列表
 *
 * group	目录
 * device_online	在线设备
 * device_offline	离线设备
 * box_online	在线网关
 * box_offline	离线网关
 * ipc_online	在线摄像头
 * ipc_offline	离线摄像头
 * ball_ipc_online	在线球机
 * ball_ipc_offline	离线球机
 * nvr_online	在线nvr
 * nvr_offline	离线nvr
 * device_master_online	在线主设备
 * device_master_offline	离线主设备
 * link	连接
 * delete	已删除
 *
 */
const icon =  GetDeviceIcon('device/IPC')
const img_url = '/static/device_images/'+ icon + '.png'
// 对应参考图片在device_images文件夹里面,也可以自定义图片