Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
23d8f843
Commit
23d8f843
authored
Mar 07, 2020
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改取样的滤波方法,使用时间滤波。 界面添加查看原始AD 与滤波后的AD
parent
e6bcbe0b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
339 additions
and
61 deletions
+339
-61
GetSampleServiceClient.cs
...hick.Base/FLY.Thick.Base/Client/GetSampleServiceClient.cs
+40
-3
IGetSampleService.cs
...Y.Thick.Base/FLY.Thick.Base/IService/IGetSampleService.cs
+27
-1
GETSAMPLE_OBJ_INTERFACE.cs
...e/FLY.Thick.Base/OBJ_INTERFACE/GETSAMPLE_OBJ_INTERFACE.cs
+22
-1
GetSample_OBJProxy.cs
...Base/FLY.Thick.Base/Server.OBJProxy/GetSample_OBJProxy.cs
+24
-1
GetSample.cs
Project.FLY.Thick.Base/FLY.Thick.Base/Server/GetSample.cs
+91
-48
TempFilter.cs
Project.FLY.Thick.Base/FLY.Thick.Base/Server/TempFilter.cs
+135
-7
No files found.
Project.FLY.Thick.Base/FLY.Thick.Base/Client/GetSampleServiceClient.cs
View file @
23d8f843
...
...
@@ -146,6 +146,19 @@ namespace FLY.Thick.Base.Client
/// </summary>
public
int
Window
{
get
;
set
;
}
/// <summary>
/// 使用%方式检查异常
/// </summary>
public
bool
IsCheckByPercent
{
get
;
set
;
}
=
true
;
/// <summary>
/// 异常% 单位%
/// </summary>
public
double
ErrPercent
{
get
;
set
;
}
=
2
;
/// <summary>
/// 异常值
/// </summary>
public
int
ErrValue
{
get
;
set
;
}
=
200
;
/// <summary>
/// 样品
/// </summary>
...
...
@@ -179,7 +192,10 @@ namespace FLY.Thick.Base.Client
velocity
=
Velocity
,
range
=
Range
,
window
=
Window
,
samples
=
new
GETSAMPLE_OBJ_INTERFACE
.
Pack_Params_SampleCell
[
Samples
.
Count
()],
IsCheckByPercent
=
IsCheckByPercent
,
ErrPercent
=
ErrPercent
,
ErrValue
=
ErrValue
,
samples
=
new
GETSAMPLE_OBJ_INTERFACE
.
Pack_Params_SampleCell
[
Samples
.
Count
()],
search
=
Search
,
features
=
new
GETSAMPLE_OBJ_INTERFACE
.
Pack_Params_SampleFeature
[
Features
.
Count
()]
};
...
...
@@ -212,11 +228,11 @@ namespace FLY.Thick.Base.Client
p
.
ToBytes
()
);
}
#
endregion
#
region
INotifyPropertyChanged
成员
public
event
PropertyChangedEventHandler
PropertyChanged
;
...
...
@@ -262,6 +278,10 @@ namespace FLY.Thick.Base.Client
Velocity
=
p
.
velocity
;
Range
=
p
.
range
;
Window
=
p
.
window
;
IsCheckByPercent
=
p
.
IsCheckByPercent
;
ErrPercent
=
p
.
ErrPercent
;
ErrValue
=
p
.
ErrValue
;
for
(
int
i
=
0
;
i
<
Samples
.
Count
()
&&
i
<
p
.
samples
.
Count
();
i
++)
{
Samples
[
i
].
Enable
=
p
.
samples
[
i
].
enable
;
...
...
@@ -303,6 +323,23 @@ namespace FLY.Thick.Base.Client
{
PushGetValue
(
from
,
srcid
,
infoid
,
infodata
);
}
public
override
void
PushCallFunction
(
IFConn
from
,
uint
srcid
,
uint
magic
,
ushort
funcid
,
byte
[]
retdata
,
object
AsyncDelegate
,
object
AsyncState
)
{
switch
(
funcid
)
{
case
GETSAMPLE_OBJ_INTERFACE
.
CALL_GET_TEMPDATAS
:
{
string
json
=
Misc
.
Converter
.
BytesToString
(
retdata
);
var
reponse
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
List
<
List
<
TempFilterData
>>>(
json
);
(
AsyncDelegate
as
AsyncCBHandler
)(
AsyncState
,
reponse
);
}
break
;
}
}
public
void
GetTempFilterDatas
(
AsyncCBHandler
asyncCB
,
object
asyncContext
)
{
CurrObjSys
.
CallFunctionEx
(
mConn
,
mServerID
,
ID
,
GETSAMPLE_OBJ_INTERFACE
.
CALL_GET_TEMPDATAS
,
null
,
asyncCB
,
asyncContext
);
}
}
}
Project.FLY.Thick.Base/FLY.Thick.Base/IService/IGetSampleService.cs
View file @
23d8f843
...
...
@@ -4,6 +4,7 @@ using System.Linq;
using
System.Text
;
using
FLY.Thick.Base.Common
;
using
System.ComponentModel
;
using
FObjBase
;
namespace
FLY.Thick.Base.IService
{
...
...
@@ -34,7 +35,18 @@ namespace FLY.Thick.Base.IService
/// </summary>
int
Window
{
get
;
set
;
}
/// <summary>
/// 使用%方式检查异常
/// </summary>
bool
IsCheckByPercent
{
get
;
set
;
}
/// <summary>
/// 异常%
/// </summary>
double
ErrPercent
{
get
;
set
;
}
/// <summary>
/// 异常值
/// </summary>
int
ErrValue
{
get
;
set
;
}
/// <summary>
/// 参数:样品点参数
/// </summary>
...
...
@@ -58,6 +70,20 @@ namespace FLY.Thick.Base.IService
/// 应用
/// </summary>
void
Apply
();
/// <summary>
/// 返回 List(List(TempFilterData))
/// </summary>
/// <param name="asyncCB"></param>
/// <param name="asyncContext"></param>
void
GetTempFilterDatas
(
AsyncCBHandler
asyncCB
,
object
asyncContext
);
}
public
class
TempFilterData
{
public
DateTime
Time
{
get
;
set
;
}
public
int
Ad
{
get
;
set
;
}
public
int
FilterAd
{
get
;
set
;
}
public
bool
IsReset
{
get
;
set
;
}
}
public
interface
ISampleCell
:
INotifyPropertyChanged
{
...
...
Project.FLY.Thick.Base/FLY.Thick.Base/OBJ_INTERFACE/GETSAMPLE_OBJ_INTERFACE.cs
View file @
23d8f843
...
...
@@ -101,6 +101,9 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
public
UInt32
velocity
;
public
int
range
;
public
int
window
;
public
bool
IsCheckByPercent
;
public
double
ErrPercent
;
public
int
ErrValue
;
public
Pack_Params_SampleCell
[]
samples
;
public
int
search
;
public
Pack_Params_SampleFeature
[]
features
;
...
...
@@ -115,6 +118,10 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
buf
.
AddRange
(
BitConverter
.
GetBytes
(
velocity
));
buf
.
AddRange
(
BitConverter
.
GetBytes
(
range
));
buf
.
AddRange
(
BitConverter
.
GetBytes
(
window
));
buf
.
AddRange
(
BitConverter
.
GetBytes
(
IsCheckByPercent
));
buf
.
AddRange
(
BitConverter
.
GetBytes
(
ErrPercent
));
buf
.
AddRange
(
BitConverter
.
GetBytes
(
ErrValue
));
buf
.
AddRange
(
BitConverter
.
GetBytes
(
search
));
buf
.
AddRange
(
BitConverter
.
GetBytes
(
samples
.
Length
));
...
...
@@ -135,7 +142,7 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
public
bool
TryParse
(
byte
[]
value
)
{
int
cnt
=
1
+
4
*
4
+
4
+
4
+
4
;
int
cnt
=
1
+
4
*
4
+
4
+
4
+
4
+
(
1
+
8
+
4
)
;
if
(
value
.
Length
<
cnt
)
return
false
;
int
idx
=
0
;
...
...
@@ -150,6 +157,12 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
window
=
BitConverter
.
ToInt32
(
value
,
idx
);
idx
+=
4
;
IsCheckByPercent
=
BitConverter
.
ToBoolean
(
value
,
idx
);
idx
++;
ErrPercent
=
BitConverter
.
ToDouble
(
value
,
idx
);
idx
+=
8
;
ErrValue
=
BitConverter
.
ToInt32
(
value
,
idx
);
idx
+=
4
;
search
=
BitConverter
.
ToInt32
(
value
,
idx
);
idx
+=
4
;
...
...
@@ -389,5 +402,13 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
public
const
UInt16
PUSH_PARAMS
=
0
;
public
const
UInt16
PUSH_STATE
=
1
;
#
endregion
#
region
CallFunction
/// <summary>
/// request:null
/// reponse:List(List(TempFilterData))
/// </summary>
public
const
UInt16
CALL_GET_TEMPDATAS
=
0
;
#
endregion
}
}
Project.FLY.Thick.Base/FLY.Thick.Base/Server.OBJProxy/GetSample_OBJProxy.cs
View file @
23d8f843
...
...
@@ -99,7 +99,9 @@ namespace FLY.Thick.Base.Server.OBJProxy
(
e
.
PropertyName
==
"Velocity"
)
||
(
e
.
PropertyName
==
"Range"
)
||
(
e
.
PropertyName
==
"Window"
)
||
(
e
.
PropertyName
==
"OnePointIsOffset"
)
||
(
e
.
PropertyName
==
"IsCheckByPercent"
)
||
(
e
.
PropertyName
==
"ErrPercent"
)
||
(
e
.
PropertyName
==
"ErrValue"
)
||
(
e
.
PropertyName
==
"Search"
))
{
push_params
();
...
...
@@ -124,6 +126,9 @@ namespace FLY.Thick.Base.Server.OBJProxy
range
=
mGetSampleService
.
Range
,
velocity
=
mGetSampleService
.
Velocity
,
window
=
mGetSampleService
.
Window
,
IsCheckByPercent
=
mGetSampleService
.
IsCheckByPercent
,
ErrPercent
=
mGetSampleService
.
ErrPercent
,
ErrValue
=
mGetSampleService
.
ErrValue
,
search
=
mGetSampleService
.
Search
};
...
...
@@ -192,6 +197,9 @@ namespace FLY.Thick.Base.Server.OBJProxy
mGetSampleService
.
Range
=
p
.
range
;
mGetSampleService
.
Velocity
=
p
.
velocity
;
mGetSampleService
.
Window
=
p
.
window
;
mGetSampleService
.
IsCheckByPercent
=
p
.
IsCheckByPercent
;
mGetSampleService
.
ErrPercent
=
p
.
ErrPercent
;
mGetSampleService
.
ErrValue
=
p
.
ErrValue
;
mGetSampleService
.
Search
=
p
.
search
;
for
(
int
i
=
0
;
i
<
mGetSampleService
.
Samples
.
Count
()
&&
i
<
p
.
samples
.
Count
();
i
++)
...
...
@@ -212,5 +220,20 @@ namespace FLY.Thick.Base.Server.OBJProxy
}
break
;
}
}
public
override
void
CallFunction
(
IFConn
from
,
uint
srcid
,
uint
magic
,
ushort
funcid
,
byte
[]
infodata
)
{
switch
(
funcid
)
{
case
GETSAMPLE_OBJ_INTERFACE
.
CALL_GET_TEMPDATAS
:
{
mGetSampleService
.
GetTempFilterDatas
((
context
,
retdata
)
=>
{
string
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
retdata
);
CurrObjSys
.
PushCallFunctionEx
(
from
,
srcid
,
ID
,
magic
,
funcid
,
Misc
.
Converter
.
StringToBytes
(
json
));
},
null
);
}
break
;
}
}
}
}
Project.FLY.Thick.Base/FLY.Thick.Base/Server/GetSample.cs
View file @
23d8f843
This diff is collapsed.
Click to expand it.
Project.FLY.Thick.Base/FLY.Thick.Base/Server/TempFilter.cs
View file @
23d8f843
using
System
;
using
FLY.Thick.Base.IService
;
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Text
;
namespace
FLY.Thick.Base.Server
{
/// <summary>
/// 样品修正 滤波
/// </summary>
public
class
TempFilter
{
DateTime
sampleTime
;
int
sampleFailure
;
int
swfilterCnt
;
/// <summary>
/// 滤波器
/// </summary>
class
SWFilter
{
/// <summary>
/// 缓存区
/// </summary>
int
[]
buffer
;
/// <summary>
/// 缓存区大小
/// </summary>
int
bufferSize
;
/// <summary>
/// 队列尾
/// </summary>
int
lastData
;
/// <summary>
/// 默认值
/// </summary>
int
initvalue
;
public
SWFilter
(
int
buffersize
)
...
...
@@ -44,7 +63,7 @@ namespace FLY.Thick.Base.Server
window
--;
}
if
(
cnt
==
0
)
return
initvalue
;
return
(
int
)
(
sum
/
cnt
+
0.5
);
return
(
int
)
Math
.
Round
(
sum
/
cnt
);
}
public
void
Clear
(
int
initvalue
)
...
...
@@ -65,7 +84,7 @@ namespace FLY.Thick.Base.Server
public
void
SetSize
(
int
buffersize
)
{
if
(
buffersize
!=
this
.
bufferS
ize
)
if
(
this
.
bufferSize
!=
buffers
ize
)
{
this
.
bufferSize
=
buffersize
;
...
...
@@ -78,8 +97,14 @@ namespace FLY.Thick.Base.Server
SWFilter
swfilter
;
int
tempBIndex
;
int
[]
tempBuf
=
new
int
[
3
];
/// <summary>
/// 前一个AD值
/// </summary>
int
preValue
;
/// <summary>
///
/// </summary>
public
TempFilter
()
{
sampleFailure
=
0
;
...
...
@@ -90,20 +115,40 @@ namespace FLY.Thick.Base.Server
preValue
=
-
1
;
}
/// <summary>
/// 复位失败次数
/// </summary>
public
void
ResetSampleFailure
()
{
sampleFailure
=
0
;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public
bool
IsSampleFailure
()
{
if
(
sampleFailure
<
0
)
return
true
;
return
false
;
}
/// <summary>
/// 输入原始AD值,输出滤波后AD值
/// </summary>
/// <param name="ad"></param>
/// <returns></returns>
public
int
CalSampleAD
(
int
ad
)
{
int
originAD
;
return
CalSampleAD
(
ad
,
out
originAD
);
return
CalSampleAD
(
ad
,
out
int
originAD
);
}
/// <summary>
/// 输入原始AD值,输出滤波后AD值
/// </summary>
/// <param name="ad"></param>
/// <param name="originAD"></param>
/// <returns></returns>
public
int
CalSampleAD
(
int
ad
,
out
int
originAD
)
{
originAD
=
0
;
...
...
@@ -137,7 +182,7 @@ namespace FLY.Thick.Base.Server
if
(
delta
>
0.01
*
Math
.
Abs
(
preValue
))
//跳到超过 1% ,有问题
{
if
(
tempBIndex
<
1
)
//
Sudden Changed! Need 3 times to confirm.
if
(
tempBIndex
<
1
)
//
突变!! 需要2次确认 因为可能只是很大的噪声
{
tempBIndex
++;
tempBuf
[
tempBIndex
]
=
ad
;
...
...
@@ -173,10 +218,93 @@ namespace FLY.Thick.Base.Server
preValue
=
swfilter
.
CalValue
(
swfilterCnt
);
return
preValue
;
}
/// <summary>
/// 移动滤波窗口大小
/// </summary>
/// <param name="window"></param>
public
void
SetWindow
(
int
window
)
{
if
(
window
<
50
)
swfilterCnt
=
window
;
}
}
/// <summary>
/// 样品修正 滤波, 返回N分钟内数据的均值。
/// 如果波动较大,提示异常
/// </summary>
public
class
TempFilter2
{
List
<
TempFilterData
>
Datas
=
new
List
<
TempFilterData
>();
TimeSpan
keepTime
=
TimeSpan
.
FromMinutes
(
6
);
/// <summary>
///
/// </summary>
public
TempFilter2
()
{
}
/// <summary>
///
/// </summary>
/// <param name="ad">原始AD</param>
/// <param name="filterTime">滤波时间</param>
/// <returns>滤波后Ad</returns>
public
int
CalSampleAD
(
int
ad
,
TimeSpan
filterTime
)
{
if
(
filterTime
.
TotalSeconds
<=
0
)
{
filterTime
=
TimeSpan
.
Zero
;
}
keepTime
=
TimeSpan
.
FromMinutes
(
Math
.
Max
(
6
,
filterTime
.
TotalMinutes
*
3
));
var
now
=
DateTime
.
Now
;
Datas
.
RemoveAll
(
d
=>
d
.
Time
<
now
-
keepTime
);
Datas
.
Add
(
new
TempFilterData
()
{
Ad
=
ad
,
FilterAd
=
ad
,
Time
=
now
});
double
sum
=
0
;
int
cnt
=
0
;
for
(
int
i
=
0
;
i
<
Datas
.
Count
();
i
++)
{
var
d
=
Datas
[
Datas
.
Count
()-
1
-
i
];
if
(
d
.
Time
>=
(
now
-
filterTime
)
&&
d
.
IsReset
==
false
)
{
sum
+=
d
.
Ad
;
cnt
++;
}
else
{
break
;
}
}
if
(
cnt
>
0
)
{
Datas
.
Last
().
FilterAd
=
(
int
)
Math
.
Round
(
sum
/
cnt
);
}
return
Datas
.
Last
().
FilterAd
;
}
/// <summary>
///
/// </summary>
public
void
Reset
()
{
var
now
=
DateTime
.
Now
;
Datas
.
RemoveAll
(
d
=>
d
.
Time
<
now
-
keepTime
);
Datas
.
Add
(
new
TempFilterData
()
{
IsReset
=
true
,
Time
=
DateTime
.
Now
});
}
public
List
<
TempFilterData
>
GetDatas
()
{
return
Datas
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment