📄 ziliao.pas
字号:
unit ZiLiao;
interface
uses
math,SysUtils,Types,Classes,Dialogs,Graphics;
type
TP = class(TObject) //绘制图片类
public
constructor Create(width:integer;heigh:integer);
destructor Destroy; override;
procedure Init_Data(const Data_Source : boolean;const id_min : integer; const id_max : integer);
procedure Init_Value(const MinValue : Double;const MaxValue : Double;Const AverageValue : Double);
public
TB : TPicture; //绘制的图片
Flag : boolean; //成图标志
DataSource : boolean; //数据源,true时候为原始数据,FALSE为处理后的数据
Index_Begin : Integer; //数据的开始编号
Index_End : Integer; //数据的结束编号
Max_Value : Double; //数据中的最大值
Min_Value : Double; //数据中的最小值
Average_Value : Double; //数据的平均值
Scale_Y : Double; //Y方向的放大倍数
Scale_X : Double; //X方向的放大倍数
B_Width : Integer; //图片的宽度
B_Heigh : Integer; //图片的高度
end;
TData = class(TObject)
constructor Create(const filename:string;const width : integer=1000;const height : integer=300);
destructor Destroy;override;
private
FIndex_Min : Cardinal; //模拟资料数字化后波形数据的最小编号
Findex_Max : Cardinal; //模拟资料数字化后波形数据的最大编号
FAverage_YuanShi : Double; //原始数据的平均值
FAverage_ChuLi : Double; //处理后数据的平均值
public
TP1 : TP;
TP2 : TP;
Data_YuanShi : array of array of Integer; //保存原始数据
Data_ChuLi : array of Double; //保存处理后的数据
function PutOut_Yuanshi(): TStringList;
property Index_Min : Cardinal read FIndex_Min;
property Index_Max : Cardinal read Findex_Max;
property Average_YuanShi : Double read FAverage_YuanShi;
property Average_ChuLi : Double read FAverage_ChuLi;
procedure CreatePicture(const index : byte;const Data_Source : boolean;const index_begin: integer;const index_end : integer);
procedure CreatePicutre_Refresh(const index : byte);
procedure ChuLi(const i : integer=1);
//查找图片坐标x对应的数据 dataindex为1时候为TP1,2时为TP2,
procedure Search_Data(const index : integer;const dataindex : integer; out Data_index : integer;out Data_Value : Double);
//去台阶,从台阶为id1到id2
procedure Data_Clear_Taijie(const id1 : integer; const id2 : integer;const flag : integer=1);
//去平均值得,平均值从id1到id2这些数据平均 flag 为1的时候,采用线性扣去台阶,2的时候直接采用去掉id1~id2之间的数据
procedure Data_Sub_Average(const id1 : integer; const id2 : integer);
end;
procedure fenjie(const s: string;out temp1: integer;out temp2:integer); //分解数据
// 如 12,456,则分解为temp=12, temp2 =456
implementation
{ TData }
procedure TData.ChuLi(const i: integer);
var
j,k,temp,sum : integer;
begin
if i=1 then //取最大值的方法处理数据
begin
setlength(Data_Chuli,length(Data_Yuanshi)); //设置处理后的数据长度与原始长度一致
for j := low(Data_YuanShi) to high(Data_YuanShi) do
begin
Data_Chuli[j] := Data_YuanSHi[j,0];
for k := low(Data_YuanShi[j]) to high(Data_YuanShi[j]) do
if Data_Chuli[j] < Data_YuanSHi[j,k] then
Data_Chuli[j] := Data_YuanSHi[j,k];
end;
end
else if i=2 then //向两边拓展处理
begin
setlength(Data_Chuli,length(Data_Yuanshi)); //设置处理后的数据长度与原始长度一致
sum :=0;
temp := min(5,length(Data_Yuanshi)); //防止数据长度过小
for j := 0 to temp do
sum := sum + Data_Yuanshi[j,0];
temp := round(sum/5);
for j := low(Data_YuanShi) to high(Data_YuanShi) do
begin
Data_Chuli[j] := Data_YuanSHi[j,0];
for k := low(Data_YuanShi[j]) to high(Data_YuanShi[j]) do
if Data_Chuli[j]>temp then
begin
if Data_Chuli[j] < Data_YuanSHi[j,k] then
Data_Chuli[j] := Data_YuanSHi[j,k];
end
else
begin
if Data_Chuli[j] > Data_YuanSHi[j,k] then
Data_Chuli[j] := Data_YuanSHi[j,k];
end;
end;
end;
end;
constructor TData.Create(const filename: string;const width : integer=1000;const height : integer=300);
var
f : TextFile;
i : Integer;
temp1,temp2,l : Integer;
s : string;
T : TStringList;
begin
inherited Create;
if fileexists(filename) then
begin
T := TStringList.Create;
assignfile(f,filename);
reset(f);
for i:=1 to 13 do
readln(f,s); //先读入文件头,最后一个为数据范围内的最前一个
while((trim(s)<>'') and ( not EOF(f))) do
begin
T.Add(s);
readln(f,s);
end;
for I := 0 to T.Count - 1 do
begin
fenjie(T.Strings[i],temp1,temp2);
T.Strings[i] := format('%5d,%6d',[temp1,temp2]);
end;
T.Sort; //排序
fenjie(T.Strings[0],temp1,temp2);
self.FIndex_Min := temp1;
fenjie(T.Strings[T.count-1],temp1,temp2);
self.Findex_Max := temp1;
temp2 := self.Findex_Max - self.FIndex_Min+1;
setlength(Data_Yuanshi,temp2); //设置原始数据的长度
setlength(Data_Chuli,temp2); //设置处理后的数据长度
for i:=0 to temp2-1 do
setlength(Data_Yuanshi[i],0);
for i:=0 to T.Count-1 do
begin
s := T.Strings[i];
fenjie(s,temp1,temp2);
l := length(Data_Yuanshi[temp1-self.FIndex_Min]);
inc(l);
setlength(Data_Yuanshi[temp1-self.FIndex_Min],l);
Data_Yuanshi[temp1-self.FIndex_Min,l-1] := temp2;
end;
T.Free;
closefile(f);
TP1 := TP.Create(width,height);
TP2 := TP.Create(width,height);
end;
end;
procedure fenjie(const s: string;out temp1: integer;out temp2:integer); //分解数据
var
i,l : integer;
begin
l := length(s);
i := Pos(',',s);
temp1 := strtoint(copy(s,0,i-1));
temp2 := strtoint(copy(s,i+1,l-i));
end;
procedure TData.CreatePicture(const index: byte;const Data_Source : boolean; const index_begin,
index_end: integer);
var
temp : TP;
id_min,id_max,i,j :integer;
MaxValue,MinValue,AverageValue,Sum : Double;
begin
id_min := index_begin;
id_max := index_end;
if index=1 then
temp := TP1
else
temp := TP2;
if index_begin<0 then
id_min :=0;
if (index_end=0) or (index_end>(self.Index_Max-self.Index_Min)) then
begin
if index=1 then
id_max := self.Index_Max-self.Index_Min
else if index=2 then
id_max := high(Data_ChuLi);
end;
temp.Init_Data(Data_Source,id_min,id_max); //初始化数据
temp.Flag := true; //成图标志,表明已经成图了
if Data_Source then //原始数据
begin
MaxValue := Data_YuanShi[id_min,0];
MinValue := Data_YuanShi[id_Min,0];
Sum :=0;
for i:= id_min to id_max do
begin
sum :=sum + Data_YuanShi[i,0];
for j:= low(Data_Yuanshi[i]) to high(Data_YuanShi[i]) do //求最大最小值得
begin
if MaxValue<Data_Yuanshi[i,j] then
MaxValue := Data_Yuanshi[i,j];
if MinValue>Data_Yuanshi[i,j] then
MinValue := Data_Yuanshi[i,j];
end;
end;
AverageValue := sum/(id_max-id_min+1); //平均值
end
else //处理后的数据
begin
MaxValue := Data_ChuLi[id_min];
MinValue := Data_ChuLi[id_min];
sum :=0;
for i:= id_min to id_max do
begin
if MaxValue<Data_ChuLi[i] then
MaxValue := Data_ChuLi[i];
if MinValue>Data_ChuLi[i] then
MinValue := Data_ChuLi[i];
sum := sum + Data_ChuLi[i];
end;
AverageValue := sum/(id_max-id_min+1); //平均值
end;
temp.Init_Value(MinValue,MaxValue,AverageValue);
temp := nil; //设置完毕
// 以下
CreatePicutre_Refresh(index); //成图
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -