Commit 707b935e by dongshufeng

initial

parent 852654f6
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
apply plugin: 'java'
apply plugin: 'kotlin'
group 'cn.zju'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
credentials { username 'admin'; password 'admin19881109' }
url "http://dsp.sgool.cn:8887/nexus/content/repositories/releases"
}
}
dependencies {
}
// 编码设置
tasks.withType(Javadoc) { options.encoding = "UTF-8" }
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
}
\ No newline at end of file
FLOW ID,是否启用,名称,触发条件,触发条件参数,,
60121,TRUE,简单,Manual,,,
,,,,,,
FLOW ID,节点ID,名称,节点类型,参数,,
60121,1,suffix1,SOURCE_URL,https://pan.zju.edu.cn/share/8ff81c393101990a2c713f4acd,,
60121,2,input1,SOURCE_URL,https://pan.zju.edu.cn/share/6830465b5ffc871477871d365d,,
60121,3,join,Transform,"join(edge1,edge2,[""绞线"",""尺寸""],[""绞线"",""尺寸""],inner)",,
60121,4,sort,Transform,"sort(index, false, false)",,
60121,5,cal_image,TensorEval,"distance = [[0,0.7622,2.1342,1.7247],[0.7622,0,1.372,1.3025],[2.1342,1.372,0,1.5244],[1.7247,1.3025,1.5244,0]];
D = diag(GMR)+distance;
image = 0.0628*(ln(1/D)+8.02517);",,
60121,6,cal_real,SOURCE_URL,https://pan.zju.edu.cn/share/2ddfa2ed5c334b63885e0459f1,,
60121,7,Zabc,Transform,concat(horizontal),,
,,,,,,
FLOW ID,首尾节点,动作名称,DESC,动作类型,动作参数,
60121,1;3,edge1,,None,,
60121,2;3,edge2,,None,,
60121,3;4,rename,,Eval,select,"col(index);col(""绞线"");alias(col(""几何平均半径_m""),mat_4_1);"
60121,4;5,GMR,,Eval,select,col(mat_4_1);
60121,5;7,real,,Eval,select,"alias(col(mat_4_4),Zreal);"
60121,6;7,image,,Eval,select,"alias(col(mat_4_4),Zimag);"
\ No newline at end of file
index,绞线,尺寸
1,"26/7","336/400"
2,"26/7","336/400"
3,"26/7","336/400"
4,"6/1","4/0"
\ No newline at end of file
mat_4_4
0.190
0.0493
0.0493
0.0493
0.0493
0.190
0.0493
0.0493
0.0493
0.0493
0.190
0.0493
0.0493
0.0493
0.0493
0.190
671-692-,650-,684-,633-,611-,680-,646-,645-,634-,652-,632-,675-
,,10,,,11,,,,,9,14
,,,,,,,,,,7,
10,,,,13,,,,,8,,
,,,,,,,,5,,4,
,,13,,,,,,,,,
11,,,,,,,,,,,
,,,,,,,6,,,,
,,,,,,6,,,,3,
,,,5,,,,,,,,
,,8,,,,,,,,,
9,7,,4,,,,3,,,,
14,,,,,,,,,,,
\ No newline at end of file
序号,ID,资源类型,名称,描述,端子数量,属性分组1_名称,属性分组1_描述,属性分组1_属性
1,1,BaseVoltage,BaseVoltage,BaseVoltage,0,ieee,电压等级,1
2,2,ACline,ACLineSegment,交流线路,2,ieee,线路类型-长度,3;4
3,3,Switch,Breaker,Breaker,2,ieee,开关,2
4,4,Load,Load,Load,1,ieee,负荷,
5,5,Transformer,PowerTransformer,Transformer,2,ieee,变压器类型-R-X-原边电压等级,3;9;10;1
6,6,ShuntCompensator,ShuntCompensator,ShuntCompensator,1,ieee,并联补偿,
7,7,Busbar,BusbarSection,母线,1,ieee,母线-源,
\ No newline at end of file
序号,ID,属性标识,属性标题,数据类型,单位
1,1,nominalVoltage,电压等级,U64,V
2,2,normalOpen,normalOpen,Str,UnitOne
3,3,model,config,Str,UnitOne
4,4,length,长度,U64,ft
5,5,crossSectionArea,横截面积,U64,mm2
6,6,nominalVoltage,电压等级,U64,V
7,7,mRID,mRID,Str,UnitOne
8,8,EquipmentContainer,container,Str,UnitOne
9,9,R,电阻,F64,UnitOne
10,10,X,电抗,F64,UnitOne
\ No newline at end of file
Index,ID,Device Define Id,Name,Description,Terminal,Container,Name,ID,Property ID,Property Value,Property ID,Property Value,Property ID,Property Value
1,1,7,Infinite Bus,源,650,,ieee,1,,,,,,
2,2,1,BaseVoltage,电压等级,,,ieee,2,1,10000,,,,
3,3,2,line1,,632;645,,ieee,3,3,603,4,500,,
4,4,2,line2,,632;633,,ieee,4,3,602,4,500,,
5,5,5,transformer,变压器,633;634,,ieee,5,3,4.16-Gr.W 0.48-Gr.W,9,1.1,10,2
6,6,2,line3,,645;646,,ieee,6,3,603,4,300,,
7,7,2,line4,,650;632,,ieee,7,3,601,4,2000,,
8,8,2,line5,,684;652,,ieee,8,3,607,4,800,,
9,9,2,line6,,632;671,,ieee,9,3,601,4,2000,,
10,10,2,line7,,671;684,,ieee,10,3,604,4,300,,
11,11,2,line8,,671;680,,ieee,11,3,601,4,1000,,
12,12,3,switch,开关,671;692,,ieee,12,2,false,,,,
13,13,2,line9,,684;611,,ieee,13,3,605,4,300,,
14,14,2,line10,,692;675,,ieee,14,3,606,4,500,,
15,15,4,Load,负荷,634,,ieee,15,,,,,,
16,16,4,Load,,645,,ieee,16,,,,,,
17,17,4,Load,,646,,ieee,17,,,,,,
18,18,4,Load,,652,,ieee,18,,,,,,
19,19,4,Load,,671,,ieee,19,,,,,,
20,20,4,Load,,675,,ieee,20,,,,,,
21,21,4,Load,,692,,ieee,21,,,,,,
22,22,4,Load,,611,,ieee,22,,,,,,
Index,ID,Point ID,Dev ID,Terminal ID
1,1,1000001,1,10
2,2,1000002,5,634
3,3,1000003,5,634
4,4,1000004,5,634
5,5,1000005,5,634
6,6,1000006,5,634
7,7,1000007,5,634
8,8,1000008,3,645
9,9,1000009,3,645
10,10,1000010,6,646
11,11,1000011,6,646
12,12,1000012,8,652
13,13,1000013,8,652
14,14,1000014,9,671
15,15,1000015,9,671
16,16,1000016,9,671
17,17,1000017,9,671
18,18,1000018,9,671
19,19,1000019,9,671
20,20,1000020,14,675
21,21,1000021,14,675
22,22,1000022,14,675
23,23,1000023,14,675
24,24,1000024,14,675
25,25,1000025,14,675
26,26,1000026,12,692
27,27,1000027,12,692
28,28,1000028,13,611
29,29,1000029,13,611
\ No newline at end of file
Index,Point ID,Value
1,1000001,4160
2,1000002,160
3,1000003,110
4,1000004,120
5,1000005,90
6,1000006,120
7,1000007,90
8,1000008,170
9,1000009,125
10,1000010,230
11,1000011,132
12,1000012,128
13,1000013,86
14,1000014,385
15,1000015,220
16,1000016,385
17,1000017,220
18,1000018,385
19,1000019,220
20,1000020,485
21,1000021,190
22,1000022,68
23,1000023,60
24,1000024,290
25,1000025,212
26,1000026,170
27,1000027,151
28,1000028,170
29,1000029,80
\ No newline at end of file
Index,ID,Name,Alias,Is Discrete,Is Computing,Expression,Trans Expr,Inv Trans Expr,Change Expr,Zero Expr,Unit,Upper Limit,Lower Limit,Alarm 1,Alarm 2,Is Realtime,Is Realtime,Initial,Tags,Description
1,1000001,源电压,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,TotV
2,1000002,A相有功634,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsA
3,1000003,A相无功634,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsA
4,1000004,B相有功634,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsB
5,1000005,B相无功634,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsB
6,1000006,C相有功634,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsC
7,1000007,C相无功634,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsC
8,1000008,B相有功645,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsB
9,1000009,B相无功645,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsB
10,1000010,B相有功646,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsB
11,1000011,B相无功646,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsB
12,1000012,A相有功652,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsA
13,1000013,A相无功652,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsA
14,1000014,A相有功671,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsA
15,1000015,A相无功671,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsA
16,1000016,B相有功671,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsB
17,1000017,B相无功671,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsB
18,1000018,C相有功671,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsC
19,1000019,C相无功671,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsC
20,1000020,A相有功675,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsA
21,1000021,A相无功675,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsA
22,1000022,B相有功675,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsB
23,1000023,B相无功675,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsB
24,1000024,C相有功675,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsC
25,1000025,C相无功675,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsC
26,1000026,C相有功692,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsC
27,1000027,C相无功692,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsC
28,1000028,C相有功611,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhW_phsC
29,1000029,C相无功611,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,PhVAr_phsC
\ No newline at end of file
序号,ID,资源类型,名称,描述,端子数量,属性分组1_名称,属性分组1_描述,属性分组1_属性
1,1,BaseVoltage,BaseVoltage,BaseVoltage,0,ieee,电压等级,1
2,2,ACline,ACLineSegment,交流线路,2,ieee,线路类型-长度,3;4
3,3,Switch,Breaker,Breaker,2,ieee,开关,2
4,4,Load,Load,Load,1,ieee,负荷,
5,5,Transformer,PowerTransformer,Transformer,2,ieee,变压器类型-R-X,3;9;10
6,6,ShuntCompensator,ShuntCompensator,ShuntCompensator,1,ieee,并联补偿,
7,7,Busbar,BusbarSection,母线,1,ieee,母线-源,
序号,ID,属性标识,属性标题,数据类型,单位
1,1,nominalVoltage,电压等级,U64,V
2,2,normalOpen,开关状态,Str,UnitOne
3,3,model,型号,Str,UnitOne
4,4,length,长度,U64,ft
5,5,crossSectionArea,横截面积,U64,mm2
6,6,nominalVoltage,电压等级,U64,V
7,7,mRID,mRID,Str,UnitOne
8,8,EquipmentContainer,container,Str,UnitOne
9,9,R,电阻,F64,UnitOne
10,10,X,电抗,F64,UnitOne
Index,ID,Device Define Id,Name,Description,Terminal,Container,Name,ID,Property ID,Property Value,Property ID,Property Value,Property ID,Property Value
1,1,7,Infinite Bus,源,10,,ieee,1,,,,,,
2,2,2,line1,线路1,21;22,,ieee,2,3,"336,400 26/7",4,,,
3,3,5,transformer,变压器,31;32,,ieee,3,3,Wye-Delta Step Down,9,1.0,10,6.0
4,4,2,line2,线路2,41;42,,ieee,4,3,"336,400 26/7",4,,,
5,5,4,Load,负荷,50,,ieee,5,,,,,,
6,6,1,BaseVoltage,电压等级,60,,ieee,6,1,10000,,,,
\ No newline at end of file
Index,ID,Point ID,Dev ID,Terminal ID
1,1,1000001,1,10
2,2,1000002,5,50
3,3,1000003,5,50
4,4,1000004,5,50
5,5,1000005,5,50
6,6,1000006,5,50
7,7,1000007,5,50
\ No newline at end of file
Index,Point ID,Value
1,1000001,1
2,1000002,5
3,1000003,5
4,1000004,5
5,1000005,5
6,1000006,5
7,1000007,5
\ No newline at end of file
Index,ID,Name,Alias,Is Discrete,Is Computing,Expression,Trans Expr,Inv Trans Expr,Change Expr,Zero Expr,Unit,Upper Limit,Lower Limit,Alarm 1,Alarm 2,Is Realtime,Is Realtime,Initial,Tags,Description
1,1000001,源电压,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,
2,1000002,A相有功,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,
3,1000003,A相无功,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,
4,1000004,B相有功,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,
5,1000005,B相无功,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,
6,1000006,C相有功,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,
7,1000007,C相无功,,FALSE,FALSE,,,,,,,"0","0",,,FALSE,FALSE,0.0,,
\ No newline at end of file
尺寸,绞线,材料,直径_cm,几何平均半径_m,阻值_欧_per_km,容量_A
1,, 钢芯铝绞线,0.9017,0.001274064,0.857494377,200
1,7 STRD,铜,0.83312,0.003023616,0.475350144,270
1,CLASS A,铝合金,0.83312,0.003020568,0.76056023,177
2,6/1,钢芯铝绞线,0.80264,0.001274064,1.050119925,180
2,7 STRD,铜,0.74168,0.002691384,0.599003318,230
2,7/1,钢芯铝绞线,0.8255,0.001536192,1.025265015,180
2,AWG SLD,铜,0.65532,0.002548128,0.587197236,220
2,CLASS A,铝合金,0.74168,0.002691384,0.957535387,156
3,6/1,钢芯铝绞线,0.71374,0.00131064,1.286241565,160
3,AWG SLD,铜,0.58166,0.00227076,0.740676302,190
4,6/1,钢芯铝绞线,0.635,0.001331976,1.596927933,140
4,7/1,钢芯铝绞线,0.65278,0.001377696,1.584500478,140
4,AWG SLD,铜,0.51816,0.002020824,0.933923223,170
4,CLASS A,铝合金,0.58928,0.0021336,1.524227323,90
5,6/1,钢芯铝绞线,0.56642,0.001267968,1.975965303,120
5,AWG SLD,铜,0.462026,0.00179832,1.177501336,140
6,6/1,钢芯铝绞线,0.50292,0.001200912,2.473063492,100
6,AWG SLD,铜,0.41148,0.001603248,1.485080841,120
6,CLASS A,铝合金,0.46736,0.00169164,2.425217791,65
7,AWG SLD,铜,0.366522,0.001426464,1.870331937,110
8,AWG SLD,铜,0.32639,0.001267968,2.361216399,90
9,AWG SLD,铜,0.290576,0.001130808,2.905414642,80
10,AWG SLD,铜,0.258826,0.00100584,3.667714715,75
12,AWG SLD,铜,0.205232,0.000798576,5.825182994,40
14,AWG SLD,铜,0.162814,0.000633984,9.241179614,20
16,AWG SLD,铜,0.129032,0.000499872,14.74281382,10
18,AWG SLD,铜,0.102362,0.00039624,23.40872656,5
19,AWG SLD,铜,0.091186,0.000353568,29.52160513,4
20,AWG SLD,铜,0.08128,0.000313944,37.08601041,3
22,AWG SLD,铜,0.064262,0.000249936,59.3308437,2
24,AWG SLD,铜,0.051054,0.00019812,94.21004884,1
1/0,, 钢芯铝绞线,1.01092,0.001359408,0.695937465,230
1/0,7 STRD,铜,0.93472,0.003392424,0.377173251,310
1/0,CLASS A,铝合金,0.93472,0.00338328,0.602731555,202
2/0,, 钢芯铝绞线,1.13538,0.00155448,0.556128599,270
2/0,7 STRD,铜,1.05156,0.003816096,0.298880286,360
2/0,CLASS A,铝合金,1.05156,0.00381,0.477835634,230
3/0,12 STRD,铜,1.24968,0.004751832,0.237364385,420
3/0,6/1,钢芯铝绞线,1.27508,0.0018288,0.449252489,300
3/0,7 STRD,铜,1.17856,0.004279392,0.237364385,420
3/0,CLASS A,铝合金,1.17856,0.0042672,0.379658742,263
3/8,INCH STE,AAteel,0.9525,0.000003048,2.671902768,150
4/0,12 STRD,铜,1.40208,0.005334,0.188275939,490
4/0,19 STRD,铜,1.34112,0.005084064,0.188275939,480
4/0,6/1,钢芯铝绞线,1.43002,0.002481072,0.36785266,340
4/0,7 STRD,铜,1.32588,0.004812792,0.188275939,480
4/0,CLASS A,铝合金,1.32588,0.00481584,0.300744405,299
250000,12 STRD,铜,1.524,0.005797296,0.159692793,540
250000,19 STRD,铜,1.45796,0.005526024,0.159692793,540
250000,CON LAY,铝合金,1.44018,0.00521208,0.254762822,329
266800,26/7,钢芯铝绞线,1.63068,0.00661416,0.239228504,460
266800,CLASS A,铝合金,1.48844,0.00539496,0.238607131,320
300000,12 STRD,铜,1.66878,0.00633984,0.133595138,610
300000,19 STRD,铜,1.59766,0.006056376,0.133595138,610
300000,26/7,钢芯铝绞线,1.7272,0.0070104,0.212509476,490
300000,30/7,钢芯铝绞线,1.778,0.00734568,0.212509476,500
300000,CON LAY,铝合金,1.59766,0.00603504,0.212509476,350
336/400,26/7,钢芯铝绞线,1.83134,0.00743712,0.190140057,530
336400,30/7,钢芯铝绞线,1.88214,0.0077724,0.190140057,530
336400,CLASS A,铝合金,1.69164,0.0064008,0.189518685,410
350000,12 STRD,铜,1.8034,0.006858,0.11464327,670
350000,19 STRD,铜,1.72466,0.00652272,0.11464327,670
350000,CON LAY,铝合金,1.72466,0.00652272,0.182683585,399
397500,26/7,钢芯铝绞线,1.98882,0.0080772,0.160935539,590
397500,30/7,钢芯铝绞线,2.04724,0.00847344,0.160935539,600
397500,CLASS A,铝合金,1.83896,0.00694944,0.160314166,440
400000,19 STRD,铜,1.84404,0.00697992,0.100600246,730
450000,19 STRD,铜,1.9558,0.00740664,0.089664086,780
450000,CON LAG,铝合金,1.9558,0.00740664,0.142294357,450
477000,26/7,钢芯铝绞线,2.17932,0.0088392,0.134216511,670
477000,30/7,钢芯铝绞线,2.24282,0.00926592,0.134216511,670
477000,CLASS A,铝合金,2.0193,0.00774192,0.134216511,510
500000,19 STRD,铜,2.05994,0.00780288,0.080964868,840
500000,37 STRD,铜,2.06756,0.0079248,0.080964868,840
500000,CON LAY,铝合金,2.06502,0.0079248,0.128002784,483
556500,26/7,钢芯铝绞线,2.35458,0.00954024,0.115513192,730
556500,30/7,钢芯铝绞线,2.42062,0.00999744,0.115513192,730
556500,CLASS A,铝合金,2.17932,0.008382,0.115575329,560
600000,37 STRD,铜,2.26314,0.0086868,0.068040315,940
600000,CON LAY,铝合金,2.26314,0.0086868,0.106876111,520
605000,26/7,钢芯铝绞线,2.45364,0.00996696,0.106876111,760
605000,54/7,钢芯铝绞线,2.42062,0.00978408,0.110293661,750
636000,27/7,钢芯铝绞线,2.5146,0.0102108,0.100538109,780
636000,30/19,钢芯铝绞线,2.58826,0.01069848,0.100538109,780
636000,54/19,钢芯铝绞线,2.48158,0.01002792,0.104887718,770
636000,CLASS A,铝合金,2.33172,0.00896112,0.101283756,620
666600,54/7,钢芯铝绞线,2.54,0.01027176,0.099481775,800
700000,37 STRD,铜,2.44602,0.00938784,0.058843998,1040
700000,CON LAY,铝合金,2.44602,0.00938784,0.091963165,580
715500,26/7,钢芯铝绞线,2.66954,0.0108204,0.089601949,840
715500,30/19,钢芯铝绞线,2.74574,0.01133856,0.089601949,840
715500,54/7,钢芯铝绞线,2.63144,0.01063752,0.09208744,830
715500,CLASS A,铝合金,2.47396,0.00950976,0.090099047,680
750000,37 STRD,铝合金,2.53238,0.00972312,0.055177899,1090
750000,CON LAY,铝合金,2.53238,0.00972312,0.08637081,602
795000,26/7,钢芯铝绞线,2.81432,0.01143,0.080032808,900
795000,30/19,钢芯铝绞线,2.8956,0.01197864,0.080032808,910
795000,54/7,钢芯铝绞线,2.77622,0.01121664,0.085625163,900
795000,CLASS A,铝合金,2.60604,0.00999744,0.081399829,720
\ No newline at end of file
apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'AvailCapMain'
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
dependencies {
compile('cn.zju:alg:2.1.1-rc32') {
transitive = false
}
compile "org.jgrapht:jgrapht-core:1.0.0"
compile "org.xerial:sqlite-jdbc:3.8.11.2"
// https://mvnrepository.com/artifact/com.alibaba/fastjson
compile "com.alibaba:fastjson:1.2.54"
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
jar {
from {
//添加依懒到打包文件
//configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtime.collect{zipTree(it)}
}
manifest {
attributes 'Main-Class': mainClassName
}
}
package com.jinyun.cap;//package availCap;
import zju.devmodel.MapObject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class AvailCapMain {
static String allFeederNameTable = "所有馈线名称";
static String allPsWarnTable = "所有馈线预警设备";
static String allPsLineWarnTable = "所有馈线线路预警设备";
static String allPsTfWarnTable = "所有馈线公变预警设备";
static String maxMinAvailCapTable = "最大最小可开放容量线路";
static String lineITableName = "电流";
static String switchTableName = "开关";
static String lineParamTableName = "参数";
static String oneLineParamTableName = "单线参数";
static String transformerTableName = "公变";
static String tfParamTableName = "公变参数";
static String availCapTableName = "可接入容量";
static String swToLineTableName = "开关线路对应";
static String swToTfTableName = "开关公变对应";
static String tfToLineTableName = "公变线路对应";
static String lineWarnTableName = "线路预警";
static String tfWarnTableName = "公变预警";
static String substationTableName = "变电站";
static String tfMonthUbTableName = "公变月不平衡度";
static String linePassRateTableName = "线路合格率";
static String tfOverLoadRateTableName = "公变越限率";
static String feederTableName = "馈线名称";
static String loadPosTable = "负荷接入位置";
public static void main(String[] args) {
// args[0]选择调用的方法
switch (args[0]) {
case "parseData":
// parseData为解析数据文件和存库操作,args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为线路电流历史数据文件夹的路径
// args[4]为开关历史数据文件夹的路径,args[5]为线路参数.csv格式文件数据,args[6]为公变历史数据文件夹的路径,
// args[7]为公变参数文件的路径,args[8]为存储所有馈线数据的数据库文件的路径,args[9]为变电站名称,args[10]为.xml文件的路径
// 馈线名称和id
JyPowerSystem ps = new JyPowerSystem();
try {
ps.loadFromCimXML(new FileInputStream(new File(args[10])));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
List<MapObject> feederObjs = ps.getResourceByClassId("FEEDER");
String feederMRID = null;
String feederName = null;
for (MapObject feeder: feederObjs) {
if (feeder.getProperty("ISCURRENTFEEDER").equals("true")) {
feederMRID = feeder.getProperty("MRID");
feederName = feeder.getProperty("NAME");
}
}
HistoryData.createLineCurrentTable(args[1] + "\\" + args[2] + ".db", args[2] + lineITableName);
HistoryData.parseLineCurrent(args[2] + lineITableName, args[3], args[1] + "\\" + args[2] + ".db");
HistoryData.createSwitchTable(args[1] + "\\" + args[2] + ".db", args[2] + switchTableName);
HistoryData.parseSwitch(args[2] + switchTableName, args[4], args[1] + "\\" + args[2] + ".db");
HistoryData.createLineParamTable(args[1] + "\\" + args[2] + ".db", args[2] + lineParamTableName);
HistoryData.parseLineParam(args[2] + lineParamTableName, args[5], args[1] + "\\" + args[2] + ".db");
HistoryData.createTFTable(args[1] + "\\" + args[2] + ".db", args[2] + transformerTableName);
HistoryData.parseTF(args[2] + transformerTableName, args[6], args[1] + "\\" + args[2] + ".db");
HistoryData.createTFParamTable(args[1] + "\\" + args[2] + ".db", args[2] + tfParamTableName);
HistoryData.parseTFParam(args[2] + tfParamTableName, args[7], args[1] + "\\" + args[2] + ".db");
HistoryData.parseTFMRID(args[2] + tfParamTableName,
args[2] + transformerTableName, args[1] + "\\" + args[2] + ".db");
HistoryData historyData = new HistoryData();
// 历史数据处理
historyData.lineCurrentDataAnalysis(args[2] + lineITableName, args[1] + "\\" + args[2] + ".db");
historyData.switchDataAnalysis(args[2] + switchTableName, args[1] + "\\" + args[2] + ".db");
historyData.switchDataSeasonCluster(args[2] + switchTableName, args[1] + "\\" + args[2] + ".db");
historyData.switchDataPsCluster(args[2] + switchTableName, args[1] + "\\" + args[2] + ".db");
historyData.tfDataAnalysis(args[2] + transformerTableName, args[1] + "\\" + args[2] + ".db");
historyData.tfDataSeasonCluster(args[2] + transformerTableName, args[1] + "\\" + args[2] + ".db");
historyData.tfDataPsCluster(args[2] + transformerTableName, args[1] + "\\" + args[2] + ".db");
historyData.tfAvailCap(args[2] + transformerTableName + HistoryData.seasonTable,
args[2] + tfParamTableName, args[2] + transformerTableName, args[1] + "\\" + args[2] + ".db");
// 存储馈线名称
historyData.createFeederNameTable(args[1] + "\\" + args[2] + ".db", args[2] + feederTableName);
historyData.saveFeederName(args[2] + feederTableName, args[1] + "\\" + args[2] + ".db", args[2]);
// 存储所有馈线名称
AvailCapModel availCapModel = new AvailCapModel();
availCapModel.createAllFeederNameTable(args[8], allFeederNameTable);
availCapModel.saveAllFeederNameTable(args[8], allFeederNameTable, feederMRID, feederName);
// 存储变电站名称
availCapModel.createSubStationNameTable(args[1] + "\\" + args[2] + ".db", args[2] + substationTableName);
availCapModel.saveSubstationName(args[2] + substationTableName,
args[1] + "\\" + args[2] + ".db", args[9]);
break;
case "calAvailCap": {
// calAvailCap为计算可接入容量操作,args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为.xml文件的路径
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
String[] sourceStationNames = new String[]{sqliteDb.querySubstationName(args[2] + substationTableName)};
ps = new JyPowerSystem(sourceStationNames);
try {
ps.loadFromCimXML(new FileInputStream(new File(args[3])));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ps.createActiveIslands();
availCapModel = new AvailCapModel(ps);
availCapModel.buildPaths();
// availCapModel.setEdgeLimI(args[2] + lineParamTableName, args[1] + "\\" + args[2] + ".db");
// 设置单线限额并存库
availCapModel.createOneLineParamTable(args[1] + "\\" + args[2] + ".db", args[2] + oneLineParamTableName);
availCapModel.setEdgeLimI(args[2] + lineParamTableName,
args[1] + "\\" + args[2] + ".db", args[2] + oneLineParamTableName);
availCapModel.setEdgeAvailCap(args[2] + lineITableName + HistoryData.seasonTable,
args[2] + switchTableName + HistoryData.seasonTable, args[1] + "\\" + args[2] + ".db");
availCapModel.createAvailCapTable(args[1] + "\\" + args[2] + ".db", args[2] + availCapTableName);
availCapModel.calAvailCap(args[2] + availCapTableName,
args[2] + switchTableName, args[1] + "\\" + args[2] + ".db");
break;
}
case "warnDev": {
// warnDev为设备预警分析。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为.xml文件的路径
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
String[] sourceStationNames = new String[]{sqliteDb.querySubstationName(args[2] + substationTableName)};
ps = new JyPowerSystem(sourceStationNames);
try {
ps.loadFromCimXML(new FileInputStream(new File(args[3])));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ps.createActiveIslands();
availCapModel = new AvailCapModel(ps);
availCapModel.buildPaths();
availCapModel.createSwToLineTable(args[1] + "\\" + args[2] + ".db", args[2] + swToLineTableName);
availCapModel.createSwToTfTable(args[1] + "\\" + args[2] + ".db", args[2] + swToTfTableName);
availCapModel.createTfToLineTable(args[1] + "\\" + args[2] + ".db", args[2] + tfToLineTableName);
availCapModel.createLineWarnTable(args[1] + "\\" + args[2] + ".db", args[2] + lineWarnTableName);
availCapModel.createTfWarnTable(args[1] + "\\" + args[2] + ".db", args[2] + tfWarnTableName);
availCapModel.switchToLine(args[2] + switchTableName,
args[1] + "\\" + args[2] + ".db", args[2] + swToLineTableName);
availCapModel.switchToTf(args[2] + switchTableName, args[1] + "\\" + args[2] + ".db",
args[2] + swToTfTableName, args[2] + tfToLineTableName);
availCapModel.warnDevAnalysis(args[1] + "\\" + args[2] + ".db", args[2] + substationTableName,
args[2] + tfWarnTableName, args[2] + transformerTableName,
args[2] + tfParamTableName, args[2] + transformerTableName + HistoryData.seasonTable,
args[2] + tfToLineTableName, args[2] + switchTableName,args[2] + swToLineTableName,
args[2] + oneLineParamTableName, args[2] + switchTableName + HistoryData.seasonTable,
args[2] + lineWarnTableName);
// List<WarnTf> warnTfs = sqliteDb.queryWarnTf(args[2] + tfWarnTableName);
// List<WarnLine> warnLines = sqliteDb.queryWarnLine(args[2] + lineWarnTableName);
// System.out.println(warnTfs.size() + ", " + warnLines.size());
break;
}
case "loadPos": {
// loadPos为分析负荷接入位置,args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为.xml文件夹的路径
// args[4]为负荷容量,args[5]为负荷特征(1为峰用电,2为谷用电,3为峰谷用电),args[6]为存储所有馈线数据的数据库文件的路径
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
String[] sourceStationNames = new String[]{sqliteDb.querySubstationName(args[2] + substationTableName)};
ps = new JyPowerSystem(sourceStationNames);
try {
ps.loadFromCimXML(new FileInputStream(new File(args[3] + "\\" + args[2] + "单线图.sln.xml")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ps.createActiveIslands();
availCapModel = new AvailCapModel(ps);
availCapModel.buildPaths();
availCapModel.createLoadPosTable(args[6], loadPosTable);
double loadCap = Double.parseDouble(args[4]);
int loadType = Integer.parseInt(args[5]);
// 生成负荷曲线
double[] load = new double[96];
double peakAvg = 0.75 * loadCap;
double valleyAvg = 0.4 * loadCap;
double pvAvg = 0.7 * loadCap;
double minLoad = 0.2 * loadCap;
if (loadType == 1) {
load[0] = valleyAvg;
for (int i = 1; i < 32; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[32] = peakAvg;
for (int i = 33; i < 88; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[88] = valleyAvg;
for (int i = 89; i < 96; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
} else if (loadType == 2) {
load[0] = peakAvg;
for (int i = 1; i < 32; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[32] = valleyAvg;
for (int i = 33; i < 88; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[88] = peakAvg;
for (int i = 89; i < 96; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
} else if (loadType == 3) {
load[0] = pvAvg;
for (int i = 1; i < 32; i++) {
double r = 0.08 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[32] = pvAvg;
for (int i = 33; i < 88; i++) {
double r = 0.05 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[88] = pvAvg;
for (int i = 89; i < 96; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
}
for (int i = 0; i < 96; i++) {
System.out.println(load[i] + ",");
}
// 负荷接入分析
LoadPos loadPos = availCapModel.loadPosOpt(load, args[2] + switchTableName,
args[2] + availCapTableName, args[1] + "\\" + args[2] + ".db",
args[2] + substationTableName, args[2] + feederTableName,
args[2] + oneLineParamTableName, args[2] + switchTableName + HistoryData.seasonClusterTable,
args[2] + swToTfTableName, args[2] + tfParamTableName,
args[2] + transformerTableName + HistoryData.tfAvailCapTable,
args[2] + transformerTableName + HistoryData.seasonClusterTable,
args[2] + transformerTableName + HistoryData.minITable, args[6], loadPosTable);
break;
}
case "mouseOverSw": {
// mouseOverSw为鼠标放置在开关上,查询线路限额,最大电流,可开放容量。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为线路mRID
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(args[2] + oneLineParamTableName, args[3]);
double lineMaxI = sqliteDb.queryMaxSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], -1);
double[] cap1 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 1, 96);
double[] cap2 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 2, 96);
double[] cap3 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 3, 96);
double[] cap4 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 4, 96);
break;
}
case "mouseOverTF": {
// mouseOverTF为鼠标放置在公变上,查询公变容量,最大负荷,三相不平衡度。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为公变mRID
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
double tFRatedCap = sqliteDb.queryTFCap(args[2] + tfParamTableName, args[3]);
double tFMaxP = sqliteDb.queryMaxTFP(args[2] + transformerTableName + HistoryData.seasonTable, args[3], -1);
double[] ub = sqliteDb.queryTFUb(args[2] + transformerTableName + HistoryData.unbalanceTable, args[3], -1);
// 低压负荷接入相别
String phase = sqliteDb.queryMinIPhase(args[2] + transformerTableName + HistoryData.minITable, args[3], -1);
System.out.println(tFRatedCap + " " + tFMaxP + " " + ub[0] + " " + ub[1] + " " + phase);
break;
}
case "mouseClickSw": {
// mouseClickSw为鼠标点击开关上,查询线路限额,最大电流,可开放容量。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为开关mRID
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(args[2] + oneLineParamTableName, args[3]);
double lineMaxI = sqliteDb.queryMaxSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], -1);
double lineAvgI = sqliteDb.queryMaxSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], -2);
double[] cap1 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 1, 96);
double[] cap2 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 2, 96);
double[] cap3 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 3, 96);
double[] cap4 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 4, 96);
double[] seasonCluster1 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonClusterTable, args[3], 1, 96);
double[] seasonCluster2 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonClusterTable, args[3], 2, 96);
double[] seasonCluster3 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonClusterTable, args[3], 3, 96);
double[] seasonCluster4 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonClusterTable, args[3], 4, 96);
double[] psCluster1 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.psClusterTable, args[3], 1, 96);
double[] psCluster2 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.psClusterTable, args[3], 2, 96);
double[] psCluster3 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.psClusterTable, args[3], 3, 96);
double[] psCluster4 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.psClusterTable, args[3], 4, 96);
double[] seasonMax1 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], 1, 96);
double[] seasonMax2 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], 2, 96);
double[] seasonMax3 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], 3, 96);
double[] seasonMax4 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], 4, 96);
for (int i = 0; i < 96; i++) {
System.out.println(lineRatedI + "," + seasonCluster1[i] + "," + seasonMax1[i] + "," + seasonCluster2[i] + "," + seasonMax2[i] + "," +
seasonCluster3[i] + "," + seasonMax3[i] + "," + seasonCluster4[i] + "," + seasonMax4[i]);
}
System.out.println();
for (int i = 0; i < 96; i++) {
System.out.println(lineRatedI + "," + psCluster1[i] + "," + seasonMax1[i] + "," + psCluster2[i] + "," + seasonMax2[i] + "," +
psCluster3[i] + "," + seasonMax3[i] + "," + psCluster4[i] + "," + seasonMax4[i]);
}
break;
}
case "mouseClickTF": {
// mouseClickTF为鼠标点击公变上,查询公变容量,最大负荷,三相不平衡度。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为公变mRID
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
double tFRatedCap = sqliteDb.queryTFCap(args[2] + tfParamTableName, args[3]);
double tFMaxI = sqliteDb.queryMaxTFP(args[2] + transformerTableName + HistoryData.seasonTable, args[3], -2);
double[] ub = sqliteDb.queryTFUb(args[2] + transformerTableName + HistoryData.unbalanceTable, args[3], -1);
// 负荷
double[] seasonMax1 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.seasonTable, args[3], 1, 96);
double[] seasonMax2 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.seasonTable, args[3], 2, 96);
double[] seasonMax3 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.seasonTable, args[3], 3, 96);
double[] seasonMax4 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.seasonTable, args[3], 4, 96);
double[] seasonCluster1 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.seasonClusterTable, args[3], 1, 96);
double[] seasonCluster2 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.seasonClusterTable, args[3], 2, 96);
double[] seasonCluster3 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.seasonClusterTable, args[3], 3, 96);
double[] seasonCluster4 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.seasonClusterTable, args[3], 4, 96);
double[] psCluster1 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.psClusterTable, args[3], 1, 96);
double[] psCluster2 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.psClusterTable, args[3], 2, 96);
double[] psCluster3 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.psClusterTable, args[3], 3, 96);
double[] psCluster4 = sqliteDb.querySeasonTFP(args[2] + transformerTableName + HistoryData.psClusterTable, args[3], 4, 96);
// 三相不平衡度
double[] seasonMaxUb1 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.ubMaxTable, args[3], 1, 96);
double[] seasonMaxUb2 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.ubMaxTable, args[3], 2, 96);
double[] seasonMaxUb3 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.ubMaxTable, args[3], 3, 96);
double[] seasonMaxUb4 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.ubMaxTable, args[3], 4, 96);
double[] seasonClusterUb1 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.seasonClusterTable, args[3], 1, 96);
double[] seasonClusterUb2 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.seasonClusterTable, args[3], 2, 96);
double[] seasonClusterUb3 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.seasonClusterTable, args[3], 3, 96);
double[] seasonClusterUb4 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.seasonClusterTable, args[3], 4, 96);
double[] psClusterUb1 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.psClusterTable, args[3], 1, 96);
double[] psClusterUb2 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.psClusterTable, args[3], 2, 96);
double[] psClusterUb3 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.psClusterTable, args[3], 3, 96);
double[] psClusterUb4 = sqliteDb.querySeasonTFUb(args[2] + transformerTableName + HistoryData.psClusterTable, args[3], 4, 96);
// 公变可开放容量
double[] cap1 = sqliteDb.queryAvailCap(args[2] + transformerTableName + HistoryData.tfAvailCapTable, args[3], 1, 96);
double[] cap2 = sqliteDb.queryAvailCap(args[2] + transformerTableName + HistoryData.tfAvailCapTable, args[3], 2, 96);
double[] cap3 = sqliteDb.queryAvailCap(args[2] + transformerTableName + HistoryData.tfAvailCapTable, args[3], 3, 96);
double[] cap4 = sqliteDb.queryAvailCap(args[2] + transformerTableName + HistoryData.tfAvailCapTable, args[3], 4, 96);
System.out.println(tFRatedCap + " " + tFMaxI + " " + ub[0] + " " + ub[1]);
break;
}
case "calAllPsWarnDev": {
// calAllPsWarnDev为统计所有馈线设备预警数量。args[1]为存储所有馈线数据的数据库文件的路径,args[2]为馈线数据库文件夹路径
availCapModel = new AvailCapModel();
availCapModel.createAllPsWarnTable(args[1], allPsWarnTable);
availCapModel.createAllPsLineWarnTable(args[1], allPsLineWarnTable);
availCapModel.createAllPsTfWarnTable(args[1], allPsTfWarnTable);
availCapModel.allPsWarnDev(args[1], allFeederNameTable, args[2], allPsWarnTable, allPsLineWarnTable, allPsTfWarnTable);
System.out.println();
break;
}
case "calTfUb": {
// tfUb为公变月三相不平衡度分析。args[1]为馈线数据库文件夹路径,args[2]为馈线名称
historyData = new HistoryData();
HistoryData.createTfMonthUbTable(args[1] + "\\" + args[2] + ".db", args[2] + tfMonthUbTableName);
historyData.tfMonthUb(args[2] + transformerTableName, args[1] + "\\" + args[2] + ".db",
args[2] + tfMonthUbTableName, args[2] + substationTableName,
args[2] + tfParamTableName, args[2] + transformerTableName + HistoryData.seasonTable,
args[2] + tfToLineTableName);
break;
}
case "calLinePassRate": {
// linePassRate为线路合格率分析。args[1]为馈线数据库文件夹路径,args[2]为馈线名称
historyData = new HistoryData();
historyData.createLinePassRateTable(args[1] + "\\" + args[2] + ".db", args[2] + linePassRateTableName);
historyData.linePassRate(args[1] + "\\" + args[2] + ".db", args[2] + feederTableName,
args[2] + substationTableName, args[2] + switchTableName,
args[2] + swToLineTableName, args[2] + oneLineParamTableName,
args[2] + linePassRateTableName);
break;
}
case "calTfOverLoadRate": {
// tfOverLoadRate为公变越限分析。args[1]为馈线数据库文件夹路径,args[2]为馈线名称
historyData = new HistoryData();
historyData.createTfOverLoadTable(args[1] + "\\" + args[2] + ".db", args[2] + tfOverLoadRateTableName);
historyData.tfOverLoad(args[1] + "\\" + args[2] + ".db", args[2] + feederTableName,
args[2] + substationTableName, args[2] + tfOverLoadRateTableName,
args[2] + transformerTableName, args[2] + tfParamTableName,
args[2] + transformerTableName + HistoryData.seasonTable, args[2] + tfToLineTableName);
break;
}
case "calMaxMinAvailCap": {
// calMaxMinAvailCap为分析可开放容量最大和最小两条线路。args[1]为存储所有馈线数据的数据库文件的路径,args[2]为馈线数据库文件夹路径
availCapModel = new AvailCapModel();
availCapModel.createMaxMinAvailCap(args[1], maxMinAvailCapTable);
availCapModel.maxMinAvailCap(args[1], allFeederNameTable, args[2], maxMinAvailCapTable);
System.out.println();
break;
}
case "allFeederName": {
// allFeederName为查询所有馈线名称。args[1]为存储所有馈线数据的数据库文件的路径
// feederNames为馈线名称列表
SqliteDb sqliteDb = new SqliteDb(args[1]);
List<String> feederNames = sqliteDb.queryAllFeederName(allFeederNameTable);
System.out.println(feederNames.size());
break;
}
case "allFeederNameId": {
// allFeederNameId为查询所有馈线名称和id对应关系。args[1]为存储所有馈线数据的数据库文件的路径
// feederIdToName为馈线id到名称的映射,feederNameToId为馈线名称到id的映射
SqliteDb sqliteDb = new SqliteDb(args[1]);
FeederNameId feederNameId = sqliteDb.queryAllFeederNameId(allFeederNameTable);
Map<String, String> feederIdToName = feederNameId.getFeederIdToName();
Map<String, String> feederNameToId = feederNameId.getFeederNameToId();
System.out.println(feederIdToName.size() + "," + feederNameToId.size());
break;
}
case "allPsWarnDev": {
// allPsWarnDev为查询所有馈线设备预警数量。args[1]为存储所有馈线数据的数据库文件的路径
// hardLineNum为重载线路数量,overLineNum为超载线路数量,hardTfNum为重载配变数量,overTfNum为超载配变数量
SqliteDb sqliteDb = new SqliteDb(args[1]);
int hardLineNum = sqliteDb.queryWarnDevNum(allPsWarnTable, 1, 1);
int overLineNum = sqliteDb.queryWarnDevNum(allPsWarnTable, 2, 1);
int hardTfNum = sqliteDb.queryWarnDevNum(allPsWarnTable, 1, 2);
int overTfNum = sqliteDb.queryWarnDevNum(allPsWarnTable, 2, 2);
System.out.println(hardLineNum + " " + overLineNum + " " + hardTfNum + " " + overTfNum);
break;
}
case "allPsHardLine": {
// allPsHardLine为查询所有馈线重载线路。args[1]为存储所有馈线数据的数据库文件的路径
// hardLine为重载线路列表数据,属性devName;substation;maxI;switchName;ratedCurrent对应界面表格中
// 线路名、所属变电站、最大电流、智能开关、限额
SqliteDb sqliteDb = new SqliteDb(args[1]);
List<WarnLine> hardLine = sqliteDb.queryWarnLine(allPsLineWarnTable, 1,-1,-1);
System.out.println(hardLine.size());
break;
}
case "allPsOverLine": {
// allPsHardLine为查询所有馈线超载线路。args[1]为存储所有馈线数据的数据库文件的路径
// overLine为超载线路列表数据,属性devName;substation;maxI;switchName;ratedCurrent对应界面表格中
// 线路名、所属变电站、最大电流、智能开关、限额
SqliteDb sqliteDb = new SqliteDb(args[1]);
List<WarnLine> overLine = sqliteDb.queryWarnLine(allPsLineWarnTable, 2,-1,-1);
System.out.println(overLine.size());
break;
}
case "allPsHardTf": {
// allPsHardTf为查询所有馈线重载公变。args[1]为存储所有馈线数据的数据库文件的路径
// hardTf为重载公变列表数据,属性devName;lineName;substation;maxLoad;ratedCap对应界面表格中
// 配变名、线路、变电站、最大负荷、容量
SqliteDb sqliteDb = new SqliteDb(args[1]);
List<WarnTf> hardTf = sqliteDb.queryWarnTf(allPsTfWarnTable, 1,-1,-1);
System.out.println(hardTf.size());
break;
}
case "allPsOverTf": {
// allPsOverTf为查询所有馈线超载公变。args[1]为存储所有馈线数据的数据库文件的路径
// overTf为超载公变列表数据,属性devName;lineName;substation;maxLoad;ratedCap对应界面表格中配变名、线路、变电站、最大负荷、容量
SqliteDb sqliteDb = new SqliteDb(args[1]);
List<WarnTf> overTf = sqliteDb.queryWarnTf(allPsTfWarnTable, 2,-1,-1);
System.out.println(overTf.size());
break;
}
case "tfUb": {
// tfUb为公变月三相不平衡度查询。args[1]为存储所有馈线数据的数据库文件的路径,args[2]为馈线数据库文件夹路径
// tfUbs公变月三相不平衡度列表,属性devName为配变名称,ub为三项不平衡度数值
SqliteDb allPsDb = new SqliteDb(args[1]);
List<String> feeders = allPsDb.queryAllFeederName(allFeederNameTable); // 查询馈线名称
List<TfUb> tfUbs = new LinkedList<>();
for (String feeder : feeders) {
SqliteDb sqliteDb = new SqliteDb(args[2] + "\\" + feeder + ".db");
tfUbs.addAll(sqliteDb.queryTfMonthUb(feeder + tfMonthUbTableName));
}
System.out.println(tfUbs.size());
break;
}
case "tfUbDetail": {
// tfUb为公变月三相不平衡度点击显示具体查询。args[1]为存储所有馈线数据的数据库文件的路径,args[2]为馈线数据库文件夹路径
// tfUbs公变月三相不平衡度列表,属性devName;lineName;substation;maxLoad;ratedCap;monthUb对应界面表格中
// 配变名、线路、变电站、最大负荷、容量、一个月的三相不平衡度数值
SqliteDb allPsDb = new SqliteDb(args[1]);
List<String> feeders = allPsDb.queryAllFeederName(allFeederNameTable); // 查询馈线名称
List<TfUb> tfUbs = new LinkedList<>();
for (String feeder : feeders) {
SqliteDb sqliteDb = new SqliteDb(args[2] + "\\" + feeder + ".db");
tfUbs.addAll(sqliteDb.queryTfMonthUb(feeder + tfMonthUbTableName));
}
System.out.println(tfUbs.size());
// TfUb tfUb = tfUbs.get(4);
// System.out.println(tfUb.devName);
// for (int i = 0; i < 30; i++) {
// System.out.println(tfUb.monthUb[i] + ",");
// }
break;
}
case "linePassRate": {
// linePassRate为查询线路电流合格率。args[1]为馈线数据库文件夹路径,args[2]为查询的馈线名称
// LinePassRates为线路电流合格率结果列表,属性passRate为春夏秋冬的合格率数组
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
List<LinePassRate> linePassRates = sqliteDb.queryLinePassRate(args[2] + linePassRateTableName);
System.out.println(linePassRates.size());
break;
}
case "tfOverLoadRate": {
// tfOverLoadRate为查询公变越限分析结果。args[1]为存储所有馈线数据的数据库文件的路径,args[2]为馈线数据库文件夹路径
// tfOverLoadRates为公变越限分析结果列表,属性overLoadRate为春夏秋冬的越限率数组
SqliteDb allPsDb = new SqliteDb(args[1]);
List<String> feeders = allPsDb.queryAllFeederName(allFeederNameTable); // 查询馈线名称
List<TfOverLoadRate> tfOverLoadRates = new LinkedList<>();
for (String feeder : feeders) {
SqliteDb sqliteDb = new SqliteDb(args[2] + "\\" + feeder + ".db");
tfOverLoadRates.addAll(sqliteDb.queryTfOverLoadRate(feeder + tfOverLoadRateTableName));
}
System.out.println(tfOverLoadRates.size());
break;
}
case "maxMinAvailCap": {
// maxMinAvailCap为查询可开放容量最大和最小两条线路。args[1]为存储所有馈线数据的数据库文件的路径
// maxFeeder为可开放容量最大线路,minFeeder为可开放容量最小线路,属性feederName为线路名称、availCap为可开放容量数值
SqliteDb sqliteDb = new SqliteDb(args[1]);
MaxMinAvailCap maxFeeder = sqliteDb.queryMaxMinAvailCap(maxMinAvailCapTable, 1);
MaxMinAvailCap minFeeder = sqliteDb.queryMaxMinAvailCap(maxMinAvailCapTable, 2);
System.out.println(maxFeeder.feederName + " " + maxFeeder.availCap);
System.out.println(minFeeder.feederName + " " + minFeeder.availCap);
break;
}
case "baseInfo": {
// baseInfo为开关基础信息,查询线路限额,最大电流,平均电流。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为开关mRID
// lineRatedI为最大限额,lineMaxI为最大电流,avgI为平均电流
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(args[2] + oneLineParamTableName, args[3]);
double lineMaxI = sqliteDb.queryMaxSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], -1);
double avgI = sqliteDb.queryMaxSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], -2);
System.out.println(lineRatedI + " " + lineMaxI + " " + avgI);
break;
}
case "lineSummer": {
// lineSummer为线路夏季分析。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为开关mRID
// lineRatedICv为线路限额,seasonCluster2为负荷聚类曲线,seasonMax2为最大负荷曲线,cap2为可开放容量
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
double lineRatedI = sqliteDb.queryOneLineSeasonParam(args[2] + oneLineParamTableName, args[3], 1);
double[] lineRatedICv = new double[96];
for (int i = 0; i < 96; i++) {
lineRatedICv[i] = lineRatedI;
}
double[] seasonCluster2 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonClusterTable, args[3], 3, 96);
double[] seasonMax2 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], 3, 96);
double[] cap2 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 3, 96);
// System.out.println("时段,1,2,3,4");
// for (int i = 0; i < 24; i++) {
// System.out.println(i + "," + cap1[4 * i] + "," + cap2[4 * i] + "," + cap3[4 * i] + "," + cap4[4 * i]);
// }
// System.out.println();
break;
}
case "lineWinter": {
// lineWinter为线路冬季分析。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为开关mRID
// lineRatedICv为线路限额,seasonCluster4为负荷聚类曲线,seasonMax4为最大负荷曲线,cap4为可开放容量
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
double lineRatedI = sqliteDb.queryOneLineSeasonParam(args[2] + oneLineParamTableName, args[3], 2);
double[] lineRatedICv = new double[96];
for (int i = 0; i < 96; i++) {
lineRatedICv[i] = lineRatedI;
}
double[] seasonCluster4 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonClusterTable, args[3], 1, 96);
double[] seasonMax4 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], 1, 96);
double[] cap4 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 1, 96);
System.out.println();
break;
}
case "linePs": {
// linePs为线路峰谷分析。args[1]为馈线数据库文件夹的路径,args[2]为馈线名称,args[3]为开关mRID
// lineRatedICv为线路限额,psCluster2为负荷聚类曲线,seasonMax2为最大负荷曲线,cap2为可开放容量
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(args[2] + oneLineParamTableName, args[3]);
double[] lineRatedICv = new double[96];
for (int i = 0; i < 96; i++) {
lineRatedICv[i] = lineRatedI;
}
double[] psCluster2 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.psClusterTable, args[3], 2, 96);
double[] seasonMax2 = sqliteDb.querySeasonSwitchI(args[2] + switchTableName + HistoryData.seasonTable, args[3], 2, 96);
double[] cap2 = sqliteDb.queryAvailCap(args[2] + availCapTableName, args[3], 2, 96);
System.out.println();
break;
}
case "loadPosSeason": {
// loadPosSeason为查询负荷接入分析结果。args[1]为存储所有馈线数据的数据库文件的路径
// loadPosSeason为负荷接入分析结果列表,属性substation;feederName;canIn;tfName;phase;time对应界面表格的
// 变电站、线路名称、能否接入、接入点、接入相别、分析时间
SqliteDb sqliteDb = new SqliteDb(args[1]);
List<LoadPosSeason> loadPosSeason = sqliteDb.queryLoadPosSeason(loadPosTable, 1,-1,-1);
System.out.println(loadPosSeason.size());
break;
}
case "loadPosSw": {
// loadPosSw为查询高压情况负荷接入分析结果。args[1]为存储所有馈线数据的数据库文件的路径,args[2]为loadId(从loadPosSeason属性获取)
// loadPosSw为高压情况负荷接入分析结果,属性canIn为是否能接入,swName为接入点智能开关名称,newLoadI为接入负荷电流曲线,
// swOrgLoad为接入前接入点负荷电流曲线,swNewLoad为接入后负荷电流曲线,swRateI为限额
SqliteDb sqliteDb = new SqliteDb(args[1]);
LoadPosSw loadPosSw = sqliteDb.queryLoadPosSw(loadPosTable, Integer.parseInt(args[2]), 1);
System.out.println();
break;
}
case "loadPosTf": {
// loadPosTf为查询低压情况负荷接入分析结果。args[1]为数据库文件的路径,args[2]为loadId(从loadPosSeason属性获取)
// loadPosTf为低压情况负荷接入分析结果,属性canIn为是否能接入,tfName为接入点,phase为接入相别,newLoad为接入负荷电流曲线,
// tfOrgLoad为接入前接入点负荷电流曲线,tfNewLoad为接入后负荷电流曲线,tfRateCap为限额
SqliteDb sqliteDb = new SqliteDb(args[1]);
LoadPosTf loadPosTf = sqliteDb.queryLoadPosTf(loadPosTable, Integer.parseInt(args[2]), 1);
System.out.println();
break;
}
case "feederWarnDev": {
// feederWarnDev为查询预警元件颜色。args[1]为馈线数据库文件夹路径,args[2]为查询的馈线名称
// yellowTfs为显示黄色的公变列表,redTfs为显示红色的公变列表,yellowLines为显示黄色的线路列表,redLines为显示红色的线路列表,
// 属性loadState为1表示黄色,为2表示红色,属性mRID为设备mRID
SqliteDb sqliteDb = new SqliteDb(args[1] + "\\" + args[2] + ".db");
List<WarnTf> warnTfs = sqliteDb.queryWarnTf(args[2] + tfWarnTableName);
List<WarnLine> warnLines = sqliteDb.queryWarnLine(args[2] + lineWarnTableName);
List<WarnTf> yellowTfs = new LinkedList<>(); // 显示黄色的公变
List<WarnTf> redTfs = new LinkedList<>(); // 显示红色的公变
List<WarnLine> yellowLines = new LinkedList<>(); // 显示黄色的线路
List<WarnLine> redLines = new LinkedList<>(); // 显示红色的线路
for (WarnTf warnTf : warnTfs) {
if (warnTf.loadState == 1)
yellowTfs.add(warnTf);
else
redTfs.add(warnTf);
}
for (WarnLine warnLine : warnLines) {
if (warnLine.loadState == 1)
yellowLines.add(warnLine);
else
redLines.add(warnLine);
}
System.out.println(yellowTfs.size() + ", " + redTfs.size() + ", " + yellowLines.size() + ", " + redLines.size());
break;
}
}
}
}
package com.jinyun.cap;
import org.jgrapht.UndirectedGraph;
import zju.devmodel.MapObject;
import java.util.*;
import static java.lang.Math.sqrt;
public class AvailCapModel {
JyPowerSystem ps;
Map<Edge, double[][]> edgeAvailCap = new HashMap<>();
List<Edge> edges;
Map<String, Edge> idToEdge = new HashMap<>();
Map<String, Integer> edgeDist = new HashMap<>();
Map<String, int[]> cnsPath = new HashMap<>();
String[] loadPos = new String[4];
int T = 15; // 采点时间间隔
int pointNum = 24 * 60 / T;
double JKsm = 1.09;
double JKwin = 1.52;
double LGJsm = 0.88;
double LGJwin = 1.15;
public AvailCapModel(JyPowerSystem ps) {
this.ps = ps;
}
public AvailCapModel() {};
/**
* 创建变电站名称表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createSubStationNameTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" substation varchar(200) NOT NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 存储变电站名称
*/
public void saveSubstationName(String substationNameTable, String dbFile, String substationName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + substationNameTable + " values(" +
"'" + substationName + "')";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
/**
* 创建线路限额表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createOneLineParamTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName varchar(200) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" ratedCurrent decimal(6,2) NULL," +
" smRatedI decimal(6,2) NULL," +
" winRatedI decimal(6,2) NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建可装容量分析结果表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createAvailCapTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName varchar(50) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" availCap decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建负荷接入分析结果表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createLoadPosTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
if (!sqliteDb.existTable(tableName)) {
String initSql = "CREATE TABLE " + tableName + " (" +
" loadId INTEGER NOT NULL," +
" substation varchar(20) NOT NULL," +
" feederName varchar(20) NOT NULL," +
" season INTEGER NULL," +
" canIn varchar(8) NOT NULL," +
" tfName varchar(50) NOT NULL," +
" tfMRID varchar(50) NOT NULL," +
" phase varchar(8) NOT NULL," +
" time varchar(20) NOT NULL," +
" swName varchar(50) NOT NULL," +
" swMRID varchar(50) NOT NULL," +
" newLoadI varchar(1000) NULL, " +
" swOrgLoad varchar(1000) NULL, " +
" swNewLoad varchar(1000) NULL, " +
" swRateI decimal(6,2) NULL, " +
" newLoad varchar(1000) NULL, " +
" tfOrgLoad varchar(1000) NULL, " +
" tfNewLoad varchar(1000) NULL, " +
" tfRateCap decimal(6,2) NULL " +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
}
/**
* 创建开关对应公变、公变对应开关的表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createSwToTfTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName1 varchar(50) NOT NULL," +
" mRID1 varchar(50) NOT NULL," +
" devName2 varchar(50) NOT NULL," +
" mRID2 varchar(50) NOT NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建公变对应线路的表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createTfToLineTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName1 varchar(50) NOT NULL," +
" mRID1 varchar(50) NOT NULL," +
" devName2 varchar(50) NOT NULL," +
" mRID2 varchar(50) NOT NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建开关对应线路、线路对应开关的表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createSwToLineTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName1 varchar(50) NOT NULL," +
" mRID1 varchar(50) NOT NULL," +
" devName2 varchar(50) NOT NULL," +
" mRID2 varchar(50) NOT NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建线路预警表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createLineWarnTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" loadState INTEGER NULL," + // 1为重载,2为超载
" devName varchar(200) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" substation varchar(20) NOT NULL," +
" switchName varchar(200) NOT NULL," +
" switchMRID varchar(50) NOT NULL," +
" maxI decimal(6,2) NULL," +
" ratedCurrent decimal(6,2) NULL," +
" loadRate decimal(4,5) NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建公变预警表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createTfWarnTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" loadState INTEGER NULL," + // 1为重载,2为超载
" devName varchar(200) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" lineName varchar(200) NOT NULL," +
" lineMRID varchar(50) NOT NULL," +
" substation varchar(20) NOT NULL," +
" maxLoad decimal(8,4) NULL," +
" ratedCap decimal(4,0) NULL," +
" loadRate decimal(4,5) NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建所有馈线名称表格
* @param allPsDbFile 数据库路径
* @param tableName 表名
*/
public void createAllFeederNameTable(String allPsDbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
if (!sqliteDb.existTable(tableName)) {
String initSql = "CREATE TABLE " + tableName + " (" +
" feederId varchar(200) NOT NULL," +
" feederName varchar(200) NOT NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
}
/**
* 存储所有馈线名称表格
* @param allPsDbFile 数据库路径
* @param tableName 表名
*/
public void saveAllFeederNameTable(String allPsDbFile, String tableName, String feederMRID, String feederName) {
SqliteDb allPsDb = new SqliteDb(allPsDbFile);
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + tableName + " values(" +
"'" + feederMRID + "','" + feederName + "')";
sqls.add(insertSql);
allPsDb.executeSqls(sqls);
sqls.clear();
}
/**
* 创建所有馈线预警表格
* @param allPsDbFile 数据库路径
* @param tableName 表名
*/
public void createAllPsWarnTable(String allPsDbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" loadState INTEGER NULL," + // 1为重载,2为超载
" type INTEGER NULL," + // 1为线路,2为配变
" number INTEGER NULL" + // 数量
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建所有馈线线路预警表格
* @param allPsDbFile 数据库路径
* @param tableName 表名
*/
public void createAllPsLineWarnTable(String allPsDbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" loadState INTEGER NULL," + // 1为重载,2为超载
" devName varchar(200) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" substation varchar(20) NOT NULL," +
" switchName varchar(200) NOT NULL," +
" switchMRID varchar(50) NOT NULL," +
" maxI decimal(6,2) NULL," +
" ratedCurrent decimal(6,2) NULL," +
" loadRate decimal(4,5) NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建所有馈线公变预警表格
* @param allPsDbFile 所有馈线数据库路径
* @param tableName 表名
*/
public void createAllPsTfWarnTable(String allPsDbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" loadState INTEGER NULL," + // 1为重载,2为超载
" devName varchar(200) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" lineName varchar(200) NOT NULL," +
" lineMRID varchar(50) NOT NULL," +
" substation varchar(20) NOT NULL," +
" maxLoad decimal(8,4) NULL," +
" ratedCap decimal(4,0) NULL," +
" loadRate decimal(4,5) NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建线路可开放容量最大和最小两条表格
* @param allPsDbFile 所有馈线数据库路径
* @param tableName 表名
*/
public void createMaxMinAvailCap(String allPsDbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" maxOrMin INTEGER NULL," + // 1为最大,2为最小
" feederName varchar(200) NOT NULL," +
" availCap decimal(8,4) NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
public void buildPaths() {
if (ps.getSourceCns().isEmpty()) {
System.out.println("No source find while build paths");
return;
}
String supplyCn = ps.getSourceCns().get(0);
UndirectedGraph<String, Edge> g = ps.getActiveIslands().get(0);
edges = new ArrayList<>(g.edgeSet());
for (Edge edge : edges) {
idToEdge.put(edge.getEquips().get(0), edge);
}
// 初始化节点为未访问状态
HashMap<String, Boolean> visited = new HashMap<>(g.vertexSet().size());
for (String cn : g.vertexSet()) {
visited.put(cn, false);
}
//用于深度优先搜索的栈
Deque<String> stack = new ArrayDeque<>();
Deque<Edge> edgeStack = new ArrayDeque<>();
stack.push(supplyCn); // 将电源节点压入栈内
while (!stack.isEmpty()) {
boolean noPush = true;
String cn = stack.peek();
for (Edge e: g.edgesOf(cn)) {
if (!edgeStack.isEmpty() && edgeStack.peek().equals(e))
continue;
edgeDist.put(e.getEquips().getFirst().substring(3), edgeStack.size());
String neighbor = g.getEdgeTarget(e);
if (neighbor.equals(cn))
neighbor = g.getEdgeSource(e);
// 如果顶点已经被遍历过,则不进行处理
if (visited.get(neighbor))
continue;
// 未遍历过的节点
stack.push(neighbor);
noPush = false;
edgeStack.push(e);
int[] path = new int[edges.size()];
for (Edge edge : edgeStack) {
for (int i = 0; i < edges.size(); i++) {
if (edges.get(i).equals(edge)) {
path[i] = 1;
break;
}
}
}
cnsPath.put(neighbor, path);
break;
}
if (noPush) {
visited.put(stack.pop(), true);
if (!edgeStack.isEmpty()) {
edgeStack.pop();
}
}
}
}
/**
* 存储智能开关对应的公变,公变对应的智能开关,公变对应的线路
*/
public void switchToTf(String switchTableName, String dbFile, String swToTfTableName, String tfToLineTableName) {
// 获取开关的mRId
SqliteDb sqliteDb = new SqliteDb(dbFile);
List<String> mRIDs = sqliteDb.queryMRIds(switchTableName);
if (ps.getSourceCns().isEmpty()) {
System.out.println("No source find while build paths");
return;
}
String supplyCn = ps.getSourceCns().get(0);
UndirectedGraph<String, Edge> g = ps.getActiveIslands().get(0);
// 初始化节点为未访问状态
HashMap<String, Boolean> visited = new HashMap<>(g.vertexSet().size());
for (String cn : g.vertexSet()) {
visited.put(cn, false);
}
//用于深度优先搜索的栈
Deque<String> stack = new ArrayDeque<>();
Deque<Edge> edgeStack = new ArrayDeque<>();
Deque<String> switchStack = new ArrayDeque<>(); // 存储开关的栈
Deque<String> lineStack = new ArrayDeque<>(); // 存储线路的栈
stack.push(supplyCn); // 将电源节点压入栈内
while (!stack.isEmpty()) {
boolean noPush = true;
String cn = stack.peek();
for (Edge e: g.edgesOf(cn)) {
if (!edgeStack.isEmpty() && edgeStack.peek().equals(e))
continue;
String neighbor = g.getEdgeTarget(e);
if (neighbor.equals(cn))
neighbor = g.getEdgeSource(e);
// 如果顶点已经被遍历过,则不进行处理
if (visited.get(neighbor))
continue;
// 未遍历过的节点
stack.push(neighbor);
noPush = false;
edgeStack.push(e);
// 智能开关数据库中查找
String eId = e.getEquips().getFirst();
if (ps.isSwitch(eId) && mRIDs.contains(eId.substring(3))) {
switchStack.push(eId);
}
// 线路入栈
if (ps.getResource(eId).getType().equals("ACLINESEGMENT")) {
lineStack.push(eId);
}
break;
}
if (noPush) {
visited.put(stack.pop(), true);
if (!edgeStack.isEmpty()) {
Edge e = edgeStack.pop();
String eId = e.getEquips().getFirst();
if (ps.getResource(eId).getType().equals("POWERTRANSFORMER")) {
String tfName = ps.getResource(eId).getProperty("NAME");
// 存开关和公变对应数据
if (switchStack.size() > 0) {
String swId = switchStack.peek();
String swName = ps.getResource(swId).getProperty("NAME");
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + swToTfTableName + " values(" +
"'" + swName + "','" + swId.substring(3) +
"','" + tfName + "','" + eId.substring(3) + "')";
sqls.add(insertSql);
insertSql = "insert into " + swToTfTableName + " values(" +
"'" + tfName + "','" + eId.substring(3) +
"','" + swName + "','" + swId.substring(3) + "')";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
// 存公变和线路对应数据
if (lineStack.size() > 0 ) {
String lineId = lineStack.peek();
String lineName = ps.getResource(lineId).getProperty("NAME");
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + tfToLineTableName + " values(" +
"'" + tfName + "','" + eId.substring(3) +
"','" + lineName + "','" + lineId.substring(3) + "')";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
// 智能开关数据库中查找
if (ps.isSwitch(eId) && mRIDs.contains(eId.substring(3))) {
switchStack.pop();
}
// 线路
if (ps.getResource(eId).getType().equals("ACLINESEGMENT")) {
lineStack.pop();
}
}
}
}
}
/**
* 存储智能开关对应的线路,线路对应的智能开关
*/
public void switchToLine(String switchTableName, String dbFile, String swToLineTableName) {
// 获取开关的mRId
SqliteDb sqliteDb = new SqliteDb(dbFile);
List<String> mRIDs = sqliteDb.queryMRIds(switchTableName);
if (ps.getSourceCns().isEmpty()) {
System.out.println("No source find while build paths");
return;
}
String supplyCn = ps.getSourceCns().get(0);
UndirectedGraph<String, Edge> g = ps.getActiveIslands().get(0);
// 初始化节点为未访问状态
HashMap<String, Boolean> visited = new HashMap<>(g.vertexSet().size());
for (String cn : g.vertexSet()) {
visited.put(cn, false);
}
//用于深度优先搜索的栈
Deque<String> stack = new ArrayDeque<>();
Deque<Edge> edgeStack = new ArrayDeque<>();
String switchEdge = null; // 线路段开关
List<String> lines = new LinkedList<>(); // 线路段
stack.push(supplyCn); // 将电源节点压入栈内
while (!stack.isEmpty()) {
boolean noPush = true;
String cn = stack.peek();
for (Edge e: g.edgesOf(cn)) {
if (!edgeStack.isEmpty() && edgeStack.peek().equals(e))
continue;
String neighbor = g.getEdgeTarget(e);
if (neighbor.equals(cn))
neighbor = g.getEdgeSource(e);
// 如果顶点已经被遍历过,则不进行处理
if (visited.get(neighbor))
continue;
// 未遍历过的节点
stack.push(neighbor);
noPush = false;
edgeStack.push(e);
String eId = e.getEquips().getFirst();
if (stack.size() > 2 && g.edgesOf(cn).size() > 2) {
// 存库
if (switchEdge != null) {
List<String> sqls = new LinkedList<>();
for (String line : lines) {
String swName = ps.getResource(switchEdge).getProperty("NAME");
String lineName = ps.getResource(line).getProperty("NAME");
String insertSql = "insert into " + swToLineTableName + " values(" +
"'" + swName + "','" + switchEdge.substring(3) +
"','" + lineName + "','" + line.substring(3) + "')";
sqls.add(insertSql);
insertSql = "insert into " + swToLineTableName + " values(" +
"'" + lineName + "','" + line.substring(3) +
"','" + swName + "','" + switchEdge.substring(3) + "')";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
lines.clear();
switchEdge = null;
}
if (ps.getResource(eId).getType().equals("ACLINESEGMENT")) {
lines.add(eId);
}
// 智能开关数据库中查找
if (ps.isSwitch(eId) && mRIDs.contains(eId.substring(3))) {
switchEdge = eId;
}
break;
}
if (noPush) {
visited.put(stack.pop(), true);
if (!edgeStack.isEmpty()) {
edgeStack.pop();
}
}
}
}
public void calAvailCap(String resultTableName, String switchTableName, String dbFile) {
if (ps.getSourceCns().isEmpty()) {
System.out.println("No source find while calculate avail capacity");
return;
}
String supplyCn = ps.getSourceCns().get(0);
UndirectedGraph<String, Edge> g = ps.getActiveIslands().get(0);
// 初始化节点为未访问状态
HashMap<String, Boolean> visited = new HashMap<>(g.vertexSet().size());
for (String cn : g.vertexSet()) {
visited.put(cn, false);
}
//用于深度优先搜索的栈
Deque<String> stack = new ArrayDeque<>();
Deque<Edge> edgeStack = new ArrayDeque<>();
stack.push(supplyCn); // 将电源节点压入栈内
while (!stack.isEmpty()) {
boolean noPush = true;
String cn = stack.peek();
for (Edge e: g.edgesOf(cn)) {
if (!edgeStack.isEmpty() && edgeStack.peek().equals(e))
continue;
String neighbor = g.getEdgeTarget(e);
if (neighbor.equals(cn))
neighbor = g.getEdgeSource(e);
// 如果顶点已经被遍历过,则不进行处理
if (visited.get(neighbor))
continue;
// 未遍历过的节点
stack.push(neighbor);
noPush = false;
double[][] availCap = edgeAvailCap.get(e);
// if (e.getEquips().getFirst().equals("PD_11100000_10584371")) {
// for (int i = 0; i < pointNum; i++) {
// System.out.println(availCap[0][i] + "," + availCap[1][i] + "," + availCap[2][i] + "," + availCap[3][i]);
// }
// System.out.println();
// }
for (Edge edge : edgeStack) {
if (!ps.getResource(edge.getEquips().getFirst()).getType().toUpperCase().equals("BREAKER"))
continue;
double[][] pathAvailCap = edgeAvailCap.get(edge);
for (int season = 0; season < 4; season++) {
for (int j = 0; j < pointNum; j++) {
if (availCap[season][j] > pathAvailCap[season][j]) {
availCap[season][j] = pathAvailCap[season][j];
if (availCap[season][j] < 0) {
if (j > 0)
availCap[season][j] = availCap[season][j - 1];
else
availCap[season][j] = 0;
}
}
}
}
}
// if (e.getEquips().getFirst().equals("PD_11100000_10584371")) {
// for (int i = 0; i < pointNum; i++) {
// System.out.println(availCap[0][i] + "," + availCap[1][i] + "," + availCap[2][i] + "," + availCap[3][i]);
// }
// }
edgeAvailCap.put(e, availCap);
edgeStack.push(e);
break;
}
if (noPush) {
visited.put(stack.pop(), true);
if (!edgeStack.isEmpty()) {
edgeStack.pop();
}
}
}
// 存储可接入容量数据
SqliteDb sqliteDb = new SqliteDb(dbFile);
List<String> mRIDs = sqliteDb.queryMRIds(switchTableName);
for (String mRID : mRIDs) {
Edge edge = idToEdge.get("PD_" + mRID);
if (edge != null) {
double[][] availCap = edgeAvailCap.get(edge);
for (int season = 1; season < 5; season++) {
List<String> sqls = new LinkedList<>();
for (int j = 0; j < pointNum; j++) {
// 电流不转成容量
if (availCap[season - 1][j] < 0) {
availCap[season - 1][j] = 0;
}
String insertSql = "insert into " + resultTableName + " values(" +
"'" + ps.getResource(edge.getEquips().get(0)).getProperty("NAME") + "','" + mRID +
"'," + season + "," + availCap[season - 1][j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
}
}
public LoadPos loadPosOpt(double[] load, String swTableName, String availCapTableName, String dbFile,
String substationTable, String feederTable, String oneLineParamTable, String swClusterTable,
String swToTfTable, String tfParamTable, String tfAvailCapTable, String tfClusterTable,
String tfMinITable, String allPsdbFile, String loadPosTable) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
// 查询变电站名称
String substation = sqliteDb.querySubstationName(substationTable);
// 查询馈线名称
String feeder = sqliteDb.queryFeederName(feederTable);
double[] loadI = new double[pointNum];
loadI[0] = load[0] / 10 / sqrt(3);
StringBuilder newLoad = new StringBuilder(String.valueOf(load[0]));
StringBuilder newLoadI = new StringBuilder(String.valueOf(loadI[0]));
for (int i = 1; i < pointNum; i++) {
loadI[i] = load[i] / 10 / sqrt(3);
newLoad.append(";").append(load[i]);
newLoadI.append(";").append(loadI[i]);
}
LoadPos loadPos = new LoadPos();
loadPos.setNewLoad(load);
loadPos.setNewLoadI(loadI);
List<String> mRIDs = sqliteDb.queryMRIds(swTableName);
// 最优开关
String[] optEdge = new String[]{mRIDs.get(0), mRIDs.get(0), mRIDs.get(0), mRIDs.get(0)};
double[] seasonAvgCap = new double[4]; // 负荷接入后裕度平均值
double[] seasonMinCap = new double[4]; // 负荷接入后裕度最小值
// 次优的开关
String[] optEdge2 = new String[]{mRIDs.get(0), mRIDs.get(0), mRIDs.get(0), mRIDs.get(0)};
double[] seasonAvgCap2 = new double[4];
double[] seasonMinCap2 = new double[4];
// 存储是否存在最优和次优的开关
boolean[] hasFirst = new boolean[]{false, false, false, false};
boolean[] hasSecond = new boolean[]{false, false, false, false};
for (int season = 0; season < 4; season++) {
for (String mRID : mRIDs) {
double[] cap = sqliteDb.queryAvailCap(availCapTableName, mRID, season + 1, pointNum);
double avgCap = 0;
double minCap = Double.MAX_VALUE;
boolean hasNag = false;
for (int i = 0; i < pointNum; i++) {
double resCap = cap[i] - loadI[i];
if (resCap < 0) {
hasNag = true;
break;
}
avgCap += resCap;
if (minCap > resCap) {
minCap = resCap;
}
}
if (hasNag)
break;
avgCap = avgCap / pointNum;
if (avgCap + minCap > seasonAvgCap[season] + seasonMinCap[season]) {
// 存储次优数据
optEdge2[season] = optEdge[season];
seasonAvgCap2[season] = seasonAvgCap[season];
seasonMinCap2[season] = seasonMinCap[season];
if (hasFirst[season])
hasSecond[season] = true;
// 存储最优数据
optEdge[season] = mRID;
seasonAvgCap[season] = avgCap;
seasonMinCap[season] = minCap;
hasFirst[season] = true;
} else if (avgCap + minCap == seasonAvgCap[season] + seasonMinCap[season]) {
// 优先接在离主线近的位置
// 存储次优数据
seasonAvgCap2[season] = seasonAvgCap[season];
seasonMinCap2[season] = seasonMinCap[season];
if (hasFirst[season])
hasSecond[season] = true;
// 存储最优数据
if (hasFirst[season]) {
if (edgeDist.get(mRID) < edgeDist.get(optEdge[season])) {
optEdge2[season] = optEdge[season];
optEdge[season] = mRID;
} else {
if (hasSecond[season]) {
if (edgeDist.get(mRID) < edgeDist.get(optEdge2[season])) {
optEdge2[season] = mRID;
}
} else {
optEdge2[season] = mRID;
}
}
}
}
}
// 时间
long t = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(t);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
String time = year + "." + month + "." + day + " " + hour + ":" + minutes;
SqliteDb allPsDb = new SqliteDb(allPsdbFile);
int loadId = allPsDb.queryMaxLoadId(loadPosTable) + 1;
if (hasFirst[season]) {
MapObject edge = ps.getResource("PD_" + optEdge[season]);
if (edge != null) {
loadPos.addLoadPos(season, optEdge[season], edge.getProperty("NAME"), seasonAvgCap[season], seasonMinCap[season]);
} else {
loadPos.addLoadPos(season, optEdge[season], "", seasonAvgCap[season], seasonMinCap[season]);
}
// System.out.println(season + " " + optEdge[season] + " " + seasonAvgCap[season] + " " + seasonMinCap[season]);
// 查询开关的限额
double swRatedI = sqliteDb.queryOneLineParam(oneLineParamTable, optEdge[season]);
loadPos.getSwRateI()[season] = swRatedI;
// 查询开关聚类电流
double[] swCluster = sqliteDb.querySeasonSwitchI(swClusterTable, optEdge[season], season + 1, pointNum);
loadPos.setSwOrgLoad(season, swCluster);
loadPos.calSwNewLoad(season);
// 查询开关对应的公变
List<String[]> tfs = sqliteDb.querySwToDev(swToTfTable, optEdge[season]);
boolean tfCanIn = false;
double optTfRateCap = 400;
String optTf = null;
String optTfName = null;
double maxSumAvailCap = 0;
for (String[] tf : tfs) {
// 查询公变可开放容量
double[] tfAvailCap = sqliteDb.queryAvailCap(tfAvailCapTable, tf[1], season + 1, pointNum);
boolean canIn = true;
double sumAvailCap = 0;
for (int i = 0; i < pointNum; i++) {
sumAvailCap += tfAvailCap[i];
if (tfAvailCap[i] < load[i]) {
canIn = false;
break;
}
}
if (!canIn)
continue;
tfCanIn = true;
optTfRateCap = sqliteDb.queryTFCap(tfParamTable, tf[1]);
if (sumAvailCap > maxSumAvailCap) {
maxSumAvailCap = sumAvailCap;
optTf = tf[1];
optTfName = tf[0];
}
}
loadPos.getCanIn()[season] = tfCanIn;
if (tfCanIn) {
loadPos.getTfRateCap()[season] = optTfRateCap;
loadPos.getOptTfs()[season] = optTf;
loadPos.getOptTfNames()[season] = optTfName;
// 查询公变聚类负荷
double[] tfCluster = sqliteDb.querySeasonTFP(tfClusterTable, optTf, season + 1, pointNum);
for (int i = 0; i < pointNum; i++) {
tfCluster[i] /= 1000;
}
loadPos.setTfOrgLoad(season, tfCluster);
loadPos.calTfNewLoad(season);
// 查询公变接入相别
String phase = sqliteDb.queryMinIPhase(tfMinITable, optTf, season + 1);
loadPos.getOptPhase()[season] = phase;
StringBuilder swOrgLoad = new StringBuilder(String.valueOf(loadPos.getSwOrgLoad()[season][0]));
StringBuilder swNewLoad = new StringBuilder(String.valueOf(loadPos.getSwNewLoad()[season][0]));
StringBuilder tfOrgLoad = new StringBuilder(String.valueOf(loadPos.getTfOrgLoad()[season][0]));
StringBuilder tfNewLoad = new StringBuilder(String.valueOf(loadPos.getTfNewLoad()[season][0]));
for (int i = 1; i < pointNum; i++) {
swOrgLoad.append(";").append(loadPos.getSwOrgLoad()[season][i]);
swNewLoad.append(";").append(loadPos.getSwNewLoad()[season][i]);
tfOrgLoad.append(";").append(loadPos.getTfOrgLoad()[season][i]);
tfNewLoad.append(";").append(loadPos.getTfNewLoad()[season][i]);
}
List<String> sqls = new LinkedList<>();
// 开关电流,公变容量kW
String insertSql = "insert into " + loadPosTable + " values(" +
loadId + ",'" + substation + "','" + feeder + "'," + (season + 1) + ",'是','" + optTfName +
"','" + optTf + "','" + phase + "相','" + time + "','" + optEdge[season] + "','" + edge.getProperty("NAME") +
"','" + newLoadI + "','" + swOrgLoad + "','" + swNewLoad + "'," + loadPos.getSwRateI()[season] +
",'" + newLoad + "','" + tfOrgLoad + "','" + tfNewLoad + "'," + optTfRateCap + ")";
sqls.add(insertSql);
allPsDb.executeSqls(sqls);
sqls.clear();
} else {
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + loadPosTable + " values(" +
loadId + ",'" + substation + "','" + feeder + "'," + (season + 1) + ",'否','" + "" +
"','" + "" + "','" + "" + "','" + time + "','" + "" + "','" + "" +
"','" + newLoad + "','" + "" + "','" + "" + "'," + 0 +
",'" + newLoadI + "','" + "" + "','" + "" + "'," + 0 + ")";
sqls.add(insertSql);
allPsDb.executeSqls(sqls);
sqls.clear();
}
} else {
loadPos.getCanIn()[season] = false;
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + loadPosTable + " values(" +
loadId + ",'" + substation + "','" + feeder + "'," + (season + 1) + ",'否','" + " " +
"','" + "" + "','" + "" + "','" + time + "','" + "" + "','" + "" +
"','" + newLoad + "','" + "" + "','" + "" + "'," + 0 +
",'" + newLoadI + "','" + "" + "','" + "" + "'," + 0 + ")";
sqls.add(insertSql);
allPsDb.executeSqls(sqls);
sqls.clear();
}
if (hasSecond[season]) {
MapObject edge = ps.getResource("PD_" + optEdge2[season]);
if (edge != null) {
loadPos.addLoadPos2(season, optEdge2[season], edge.getProperty("NAME"), seasonAvgCap2[season], seasonMinCap2[season]);
} else {
loadPos.addLoadPos2(season, optEdge2[season], "", seasonAvgCap2[season], seasonMinCap2[season]);
}
// System.out.println(season + " " + optEdge2[season] + " " + seasonAvgCap2[season] + " " + seasonMinCap2[season]);
}
}
return loadPos;
}
/**
* 设置支路电流限值
* @param tableName 表名
* @param dbFile 数据库名
*/
public void setEdgeLimI(String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
// 读取两个杆的名称
List<LineParamData> lineParamDatas = sqliteDb.queryLineParam(tableName);
for (LineParamData lineParamData : lineParamDatas) {
String cn1 = ps.getPoleNameToCn().get(lineParamData.getPole1());
String cn2 = ps.getPoleNameToCn().get(lineParamData.getPole2());
if (cn1 != null && cn2 != null) {
double limI = lineParamData.getRatedI();
int[] path1 = cnsPath.get(cn1);
int[] path2 = cnsPath.get(cn2);
for (int i = 0; i < edges.size(); i++) {
if (path1[i] + path2[i] == 1) {
Edge e = edges.get(i);
e.setType(lineParamData.getType());
if (e.getLimI() > limI) {
e.setLimI(limI);
}
}
}
}
}
}
/**
* 设置支路电流限值并存库
* @param tableName 表名
* @param dbFile 数据库名
* @param oneLineTableName 单线参数表名
*/
public void setEdgeLimI(String tableName, String dbFile, String oneLineTableName) {
setEdgeLimI(tableName, dbFile);
SqliteDb sqliteDb = new SqliteDb(dbFile);
List<String> sqls = new LinkedList<>();
for (Edge e : edges) {
double smLimI = e.getLimI();
double winLimI = e.getLimI();
if (e.getType() == 1) {
smLimI = e.getLimI() * JKsm;
winLimI = e.getLimI() * JKwin;
} else if (e.getType() == 2) {
smLimI = e.getLimI() * LGJsm;
winLimI = e.getLimI() * LGJwin;
}
String insertSql = "insert into " + oneLineTableName + " values(" +
"'" + ps.getResource(e.getEquips().get(0)).getProperty("NAME") +
"','" + e.getEquips().get(0).substring(3) + "'," + e.getLimI() + "," + smLimI + "," + winLimI + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
/**
* 根据支路电流历史季度电流最大值,设置单支路电流裕度
* @param lineISeasontableName 线路电流按季度分析结果表名
* @param swISeasontableName 开关电流按季度分析结果表名
* @param dbFile 数据库名
*/
public void setEdgeAvailCap(String lineISeasontableName, String swISeasontableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
// 查询主线电流数据
double[][] mainLineI = new double[4][pointNum];
for (int season = 1; season < 5; season++) {
int pNTimes = 3;
double[] I = sqliteDb.querySeasonLineI(lineISeasontableName, season, pNTimes * pointNum);
for (int i = 0; i < pointNum; i++) {
mainLineI[season - 1][i] = I[pNTimes * i];
if (mainLineI[season - 1][i] < I[pNTimes * i + 1]) {
mainLineI[season - 1][i] = I[pNTimes * i + 1];
}
if (mainLineI[season - 1][i] < I[pNTimes * i + 2]) {
mainLineI[season - 1][i] = I[pNTimes * i + 2];
}
}
}
// 主线电流裕度,按第一条有额定电流的线路算
String supplyCn = ps.getSourceCns().get(0);
UndirectedGraph<String, Edge> g = ps.getActiveIslands().get(0);
Edge mainLine = g.edgesOf(supplyCn).iterator().next();
// 初始化节点为未访问状态
HashMap<String, Boolean> visited = new HashMap<>(g.vertexSet().size());
for (String cn : g.vertexSet()) {
visited.put(cn, false);
}
//用于深度优先搜索的栈
Deque<String> stack = new ArrayDeque<>();
Deque<Edge> edgeStack = new ArrayDeque<>();
stack.push(supplyCn); // 将电源节点压入栈内
while (!stack.isEmpty()) {
boolean noPush = true;
String cn = stack.peek();
for (Edge e: g.edgesOf(cn)) {
if (!edgeStack.isEmpty() && edgeStack.peek().equals(e))
continue;
if (e.getLimI() < 10000) {
mainLine = e;
stack.clear();
break;
}
String neighbor = g.getEdgeTarget(e);
if (neighbor.equals(cn))
neighbor = g.getEdgeSource(e);
// 如果顶点已经被遍历过,则不进行处理
if (visited.get(neighbor))
continue;
// 未遍历过的节点
stack.push(neighbor);
noPush = false;
edgeStack.push(e);
break;
}
if (noPush) {
if (!stack.isEmpty()) {
visited.put(stack.pop(), true);
}
if (!edgeStack.isEmpty()) {
edgeStack.pop();
}
}
}
double mainLineLimI = mainLine.getLimI();
double mainLineType = mainLine.getType();
double[][] mainLineAvailCap = new double[4][pointNum];
for (int season = 0; season < 4; season++) {
for (int j = 0; j < pointNum; j++) {
if (season == 1 || season == 2) {
if (mainLineType == 1) {
mainLineAvailCap[season][j] = mainLineLimI * JKsm - mainLineI[season][j];
} else if (mainLineType == 2) {
mainLineAvailCap[season][j] = mainLineLimI * LGJsm - mainLineI[season][j];
}
} else {
if (mainLineType == 1) {
mainLineAvailCap[season][j] = mainLineLimI * JKwin - mainLineI[season][j];
} else if (mainLineType == 2) {
mainLineAvailCap[season][j] = mainLineLimI * LGJwin - mainLineI[season][j];
}
}
}
}
// for (UndirectedGraph<String, Edge> g : ps.getActiveIslands()) {
for (Edge e : g.edgeSet()) {
double[][] availCap = new double[4][pointNum];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < pointNum; j++) {
availCap[i][j] = mainLineAvailCap[i][j];
}
}
// if (e.getEquips().getFirst().equals("PD_11100000_10584371")) {
// for (int i = 0; i < pointNum; i++) {
// System.out.println(availCap[0][i] + "," + availCap[1][i] + "," + availCap[2][i] + "," + availCap[3][i]);
// }
// System.out.println();
// }
for (int season = 1; season < 5; season++) {
for (String equip : e.getEquips()) {
String mRID = equip.substring(3);
double[] I = sqliteDb.querySeasonSwitchI(swISeasontableName, mRID, season, pointNum);
double limI = e.getLimI();
int type = e.getType();
for (int i = 0; i < pointNum; i++) {
if (season == 2 || season == 3) {
if (type == 1) {
if (availCap[season - 1][i] > limI * JKsm - I[i]) {
availCap[season - 1][i] = limI * JKsm - I[i];
}
} else if (type == 2) {
if (availCap[season - 1][i] > limI * LGJsm - I[i]) {
availCap[season - 1][i] = limI * LGJsm - I[i];
}
}
} else {
if (type == 1) {
if (availCap[season - 1][i] > limI * JKwin - I[i]) {
availCap[season - 1][i] = limI * JKwin - I[i];
}
} else if (type == 2) {
if (availCap[season - 1][i] > limI * LGJwin - I[i]) {
availCap[season - 1][i] = limI * LGJwin - I[i];
}
}
}
}
}
}
// if (e.getEquips().getFirst().equals("PD_11100000_10584371")) {
// for (int i = 0; i < pointNum; i++) {
// System.out.println(availCap[0][i] + "," + availCap[1][i] + "," + availCap[2][i] + "," + availCap[3][i]);
// }
// }
edgeAvailCap.put(e, availCap);
}
// }
}
/**
* 查询主线电流和参数
* @param lineISeasontableName 线路电流按季度分析结果表名
* @param swISeasontableName 开关电流按季度分析结果表名
* @param dbFile 数据库名
*/
public void mainLineI(String lineISeasontableName, String swISeasontableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
// 查询主线电流数据
double[][] mainLineI = new double[4][pointNum];
for (int season = 1; season < 5; season++) {
int pNTimes = 3;
double[] I = sqliteDb.querySeasonLineI(lineISeasontableName, season, pNTimes * pointNum);
for (int i = 0; i < pointNum; i++) {
mainLineI[season - 1][i] = I[pNTimes * i];
if (mainLineI[season - 1][i] < I[pNTimes * i + 1]) {
mainLineI[season - 1][i] = I[pNTimes * i + 1];
}
if (mainLineI[season - 1][i] < I[pNTimes * i + 2]) {
mainLineI[season - 1][i] = I[pNTimes * i + 2];
}
}
}
// 主线电流裕度,按第一条有额定电流的线路算
String supplyCn = ps.getSourceCns().get(0);
UndirectedGraph<String, Edge> g = ps.getActiveIslands().get(0);
Edge mainLine = g.edgesOf(supplyCn).iterator().next();
// 初始化节点为未访问状态
HashMap<String, Boolean> visited = new HashMap<>(g.vertexSet().size());
for (String cn : g.vertexSet()) {
visited.put(cn, false);
}
//用于深度优先搜索的栈
Deque<String> stack = new ArrayDeque<>();
Deque<Edge> edgeStack = new ArrayDeque<>();
stack.push(supplyCn); // 将电源节点压入栈内
while (!stack.isEmpty()) {
boolean noPush = true;
String cn = stack.peek();
for (Edge e: g.edgesOf(cn)) {
if (!edgeStack.isEmpty() && edgeStack.peek().equals(e))
continue;
if (e.getLimI() < 10000) {
mainLine = e;
stack.clear();
break;
}
String neighbor = g.getEdgeTarget(e);
if (neighbor.equals(cn))
neighbor = g.getEdgeSource(e);
// 如果顶点已经被遍历过,则不进行处理
if (visited.get(neighbor))
continue;
// 未遍历过的节点
stack.push(neighbor);
noPush = false;
edgeStack.push(e);
break;
}
if (noPush) {
if (!stack.isEmpty()) {
visited.put(stack.pop(), true);
}
if (!edgeStack.isEmpty()) {
edgeStack.pop();
}
}
}
double mainLineLimI = mainLine.getLimI();
double mainLineType = mainLine.getType();
double[][] mainLineAvailCap = new double[4][pointNum];
for (int season = 0; season < 4; season++) {
for (int j = 0; j < pointNum; j++) {
if (season == 1 || season == 2) {
if (mainLineType == 1) {
mainLineAvailCap[season][j] = mainLineLimI * JKsm - mainLineI[season][j];
} else if (mainLineType == 2) {
mainLineAvailCap[season][j] = mainLineLimI * LGJsm - mainLineI[season][j];
}
} else {
if (mainLineType == 1) {
mainLineAvailCap[season][j] = mainLineLimI * JKwin - mainLineI[season][j];
} else if (mainLineType == 2) {
mainLineAvailCap[season][j] = mainLineLimI * LGJwin - mainLineI[season][j];
}
}
}
}
System.out.println("夏季额定电流,夏季最大电流,夏季可开放容量,夏季差值,冬季额定电流,冬季最大电流,冬季可开放容量,冬季差值");
for (int i = 0; i < pointNum; i++) {
if (mainLineType == 1) {
System.out.println(mainLineLimI * JKsm + "," + mainLineI[1][i] + "," + mainLineAvailCap[1][i] + "," +
(mainLineLimI * JKsm - mainLineI[1][i] - mainLineAvailCap[1][i]) + "," + mainLineLimI * JKwin + "," +
mainLineI[3][i] + "," + mainLineAvailCap[3][i] + "," +
(mainLineLimI * JKwin - mainLineI[3][i] - mainLineAvailCap[3][i]));
} else if (mainLineType == 2) {
System.out.println(mainLineLimI * LGJsm + "," + mainLineI[1][i] + "," + mainLineAvailCap[1][i] + "," +
(mainLineLimI * LGJsm - mainLineI[1][i] - mainLineAvailCap[1][i]) + "," + mainLineLimI * LGJwin + "," +
mainLineI[3][i] + "," + mainLineAvailCap[3][i] + "," +
(mainLineLimI * LGJwin - mainLineI[3][i] - mainLineAvailCap[3][i]));
}
}
}
/**
* 设备预警分析
*/
public void warnDevAnalysis(String dbFile, String substationTable, String tfWarnTable, String tfTable, String tfParamTable, String tfSeasonTable,
String tfToLineTable, String swTable, String swToLineTable, String oneLineParamTable,
String swSeasonTable, String lineWarnTable) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
// 查询变电站名称
String substation = sqliteDb.querySubstationName(substationTable);
// 分析公变
Map<String, String> tfNameToMRID = sqliteDb.queryNameToMRID(tfTable);
List<String> sqls = new LinkedList<>();
for (String name : tfNameToMRID.keySet()) {
String mRID = tfNameToMRID.get(name);
double tfRatedCap = sqliteDb.queryTFCap(tfParamTable, mRID);
double tfMaxP = sqliteDb.queryMaxTFP(tfSeasonTable, mRID, -1) / 1000;
double loadRate = tfMaxP / tfRatedCap;
// 公变对应的线路名称
List<String[]> lines = sqliteDb.querySwToDev(tfToLineTable, mRID);
if (lines.size() > 0) {
String[] line = lines.get(0);
if (loadRate < 2 && loadRate > 1) {
String insertSql = "insert into " + tfWarnTable + " values(" +
"2,'" + name + "','" + mRID + "','" + line[0] + "','" + line[1] + "','" + substation + "'," +
tfMaxP + "," + tfRatedCap + "," + loadRate + ")";
sqls.add(insertSql);
} else if (loadRate < 1 && loadRate > 0.8) {
String insertSql = "insert into " + tfWarnTable + " values(" +
"1,'" + name + "','" + mRID + "','" + line[0] + "','" + line[1] + "','" + substation + "'," +
tfMaxP + "," + tfRatedCap + "," + loadRate + ")";
sqls.add(insertSql);
}
}
}
sqliteDb.executeSqls(sqls);
sqls.clear();
// 分析线路(开关对应的线路)
Map<String, String> swNameToMRID = sqliteDb.queryNameToMRID(swTable);
for (String name : swNameToMRID.keySet()) {
String mRID = swNameToMRID.get(name);
List<String[]> lines = sqliteDb.querySwToDev(swToLineTable, mRID);
for (String[] line : lines) {
double lineRatedI = sqliteDb.queryOneLineParam(oneLineParamTable, line[1]);
double lineMaxI = sqliteDb.queryMaxSwitchI(swSeasonTable, mRID, -1);
double loadRate = lineMaxI / lineRatedI;
if (loadRate < 2 && loadRate > 1) {
String insertSql = "insert into " + lineWarnTable + " values(" +
"2,'" + line[0] + "','" + line[1] + "','" + substation + "','" + name + "','" + mRID +
"'," + lineMaxI + "," + lineRatedI + "," + loadRate + ")";
sqls.add(insertSql);
} else if (loadRate < 1 && loadRate > 0.8) {
String insertSql = "insert into " + lineWarnTable + " values(" +
"1,'" + line[0] + "','" + line[1] + "','" + substation + "','" + name + "','" + mRID +
"'," + lineMaxI + "," + lineRatedI + "," + loadRate + ")";
sqls.add(insertSql);
}
}
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
/**
* 所有馈线预警设备数量统计,详细信息存库
*/
public void allPsWarnDev(String allPsdbFile, String allFeederNameTable, String dbFilePath, String allPsWarnTable,
String allPsLineWarnTable, String allPsTfWarnTable) {
SqliteDb allPsDb = new SqliteDb(allPsdbFile);
// 查询馈线名称
List<String> feeders = allPsDb.queryAllFeederName(allFeederNameTable);
int[] warnLineNum = new int[2];
int[] warnTfNum = new int[2];
// 处理馈线数据库文件
for (String feeder : feeders) {
SqliteDb sqliteDb = new SqliteDb(dbFilePath + "\\" + feeder + ".db");
List<WarnLine> warnLines = sqliteDb.queryWarnLine(feeder + AvailCapMain.lineWarnTableName);
List<String> sqls = new LinkedList<>();
for (WarnLine warnLine : warnLines) {
if (warnLine.loadState == 1) {
warnLineNum[0]++;
} else {
warnLineNum[1]++;
}
String insertSql = "insert into " + allPsLineWarnTable + " values(" +
warnLine.loadState + ",'" + warnLine.devName + "','" + warnLine.mRID + "','" + warnLine.substation +
"','" + warnLine.switchName + "','" + warnLine.switchMRID + "'," + warnLine.maxI +
"," + warnLine.ratedCurrent + "," + warnLine.loadRate + ")";
sqls.add(insertSql);
}
allPsDb.executeSqls(sqls);
sqls.clear();
List<WarnTf> warnTfs = sqliteDb.queryWarnTf(feeder + AvailCapMain.tfWarnTableName);
for (WarnTf warnTf : warnTfs) {
if (warnTf.loadState == 1) {
warnTfNum[0]++;
} else {
warnTfNum[1]++;
}
String insertSql = "insert into " + allPsTfWarnTable + " values(" +
warnTf.loadState + ",'" + warnTf.devName + "','" + warnTf.mRID + "','" + warnTf.lineName + "','" +
warnTf.lineMRID + "','" + warnTf.substation + "'," + warnTf.maxLoad + "," + warnTf.ratedCap + "," + warnTf.loadRate + ")";
sqls.add(insertSql);
}
allPsDb.executeSqls(sqls);
sqls.clear();
}
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + allPsWarnTable + " values(" +
1 + "," + 1 + "," + warnLineNum[0] + ")";
sqls.add(insertSql);
insertSql = "insert into " + allPsWarnTable + " values(" +
2 + "," + 1 + "," + warnLineNum[1] + ")";
sqls.add(insertSql);
insertSql = "insert into " + allPsWarnTable + " values(" +
1 + "," + 2 + "," + warnTfNum[0] + ")";
sqls.add(insertSql);
insertSql = "insert into " + allPsWarnTable + " values(" +
2 + "," + 2 + "," + warnTfNum[1] + ")";
sqls.add(insertSql);
allPsDb.executeSqls(sqls);
sqls.clear();
}
/**
* 线路可开放容量最大和最小两条
*/
public void maxMinAvailCap(String allPsdbFile, String allFeederNameTable, String dbFilePath, String maxMinAvailCapTable) {
SqliteDb allPsDb = new SqliteDb(allPsdbFile);
// 查询馈线名称
List<String> feeders = allPsDb.queryAllFeederName(allFeederNameTable);
String maxFeederName = null;
double maxFeederAvailCap = 0;
String minFeederName = null;
double minFeederAvailCap = 1e8;
// 处理馈线数据库文件
for (String feeder : feeders) {
SqliteDb sqliteDb = new SqliteDb(dbFilePath + "\\" + feeder + ".db");
// 查询所有开关的mRID
List<String> mRIDs = sqliteDb.queryMRIds(feeder + AvailCapMain.switchTableName);
double maxLineAvailCap = 0;
for (String mRID : mRIDs) {
double avgAvailCap = 0;
int count = 0;
for (int season = 1; season < 5; season++) {
double[] availCap = sqliteDb.queryAvailCap(feeder + AvailCapMain.availCapTableName, mRID, season, pointNum);
for (int i = 0; i < pointNum; i++) {
avgAvailCap += availCap[i];
count++;
}
}
avgAvailCap /= count;
if (avgAvailCap > maxLineAvailCap) {
maxLineAvailCap = avgAvailCap;
}
}
if (maxLineAvailCap > maxFeederAvailCap) {
maxFeederAvailCap = maxLineAvailCap;
maxFeederName = feeder;
}
if (maxLineAvailCap < minFeederAvailCap) {
minFeederAvailCap = maxLineAvailCap;
minFeederName = feeder;
}
}
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + maxMinAvailCapTable + " values(" +
"1,'" + maxFeederName + "'," + maxFeederAvailCap + ")";
sqls.add(insertSql);
insertSql = "insert into " + maxMinAvailCapTable + " values(" +
"2,'" + minFeederName + "'," + minFeederAvailCap + ")";
sqls.add(insertSql);
allPsDb.executeSqls(sqls);
sqls.clear();
}
}
package com.jinyun.cap;
public interface CimConstants {
//measurement value sources:
public static final String MEASURE_VALUE_SOURCE_SCADA = "SCADA";
//the following is not used usually
public static final String MEASURE_VALUE_SOURCE_PMU = "PMU";
public static final String MEASURE_VALUE_SOURCE_SE = "SE";//todo:
}
package com.jinyun.cap;
import java.util.HashMap;
import java.util.Map;
public class FeederNameId {
Map<String, String> feederIdToName = new HashMap<>();
Map<String, String> feederNameToId = new HashMap<>();
public Map<String, String> getFeederIdToName() {
return feederIdToName;
}
public void setFeederIdToName(Map<String, String> feederIdToName) {
this.feederIdToName = feederIdToName;
}
public Map<String, String> getFeederNameToId() {
return feederNameToId;
}
public void setFeederNameToId(Map<String, String> feederNameToId) {
this.feederNameToId = feederNameToId;
}
}
package com.jinyun.cap;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import zju.matrix.Complex;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import static java.lang.Math.sqrt;
public class HistoryData {
public static String seasonTable = "_season";
public static String unbalanceTable = "_ub";
public static String minITable = "_minI";
public static String seasonClusterTable = "_seasonCluster";
public static String psClusterTable = "_psCluster";
public static String ubMaxTable = "_ubMax";
public static String tfAvailCapTable = "_availCap";
static Map<String, Double> ratedIJK = new HashMap<String, Double>(){{
put("35", 150.);
put("50", 180.);
put("70", 225.);
put("95", 275.);
put("120", 320.);
put("150", 365.);
put("185", 420.);
put("240", 500.);
put("300", 580.);
}};
static Map<String, Double> ratedILGJ = new HashMap<String, Double>(){{
put("35", 170.);
put("50", 220.);
put("70", 275.);
put("95", 335.);
put("120", 380.);
put("150", 445.);
put("185", 515.);
put("240", 610.);
put("300", 754.);
}};
Complex a = new Complex(-1.0 / 2,sqrt(3) / 2);
Complex a2 = Complex.multiply(a, a);
Complex aThird = new Complex(1.0 / 3, 0);
/**
* 创建线路电流表格和按季度分析结果表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public static void createLineCurrentTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" date datetime NULL," +
" current decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
initSql = "CREATE TABLE " + tableName + seasonTable + " (" +
" season INTEGER NULL," +
" current decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + seasonTable;
sqliteDb.executeSql(sql);
}
/**
* 创建公变数据表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public static void createTFTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName varchar(50) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" date datetime NULL," +
" Ia decimal(8,4) NULL, " +
" Ib decimal(8,4) NULL, " +
" Ic decimal(8,4) NULL, " +
" Ua decimal(8,4) NULL, " +
" Ub decimal(8,4) NULL, " +
" Uc decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
initSql = "CREATE TABLE " + tableName + seasonTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" P decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
// 公变三相不平衡度分析结果表,season=-1为年平均不平衡度
initSql = "CREATE TABLE " + tableName + unbalanceTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" ubI2 decimal(2,7) NULL, " +
" ubI0 decimal(2,7) NULL, " +
" ubV2 decimal(2,7) NULL, " +
" ubV0 decimal(2,7) NULL " +
")";
sqliteDb.initDb(initSql);
// 公变最小相电流分析结果表,season=-1为年平均最小电流
initSql = "CREATE TABLE " + tableName + minITable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" phase INTEGER NULL," +
" minI decimal(6,4) NULL " +
")";
sqliteDb.initDb(initSql);
// 公变三相不平衡度最大值表
initSql = "CREATE TABLE " + tableName + ubMaxTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" ubI2 decimal(2,7) NULL, " +
" ubV2 decimal(2,7) NULL " +
")";
sqliteDb.initDb(initSql);
// 公变按季节聚类结果表
initSql = "CREATE TABLE " + tableName + seasonClusterTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" P decimal(2,7) NULL, " +
" ubI2 decimal(2,7) NULL " +
")";
sqliteDb.initDb(initSql);
// 公变按峰谷聚类结果表
initSql = "CREATE TABLE " + tableName + psClusterTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" P decimal(2,7) NULL, " +
" ubI2 decimal(2,7) NULL " +
")";
sqliteDb.initDb(initSql);
// 公变可开放容量结果表
initSql = "CREATE TABLE " + tableName + tfAvailCapTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" availCap decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + seasonTable;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + unbalanceTable;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + minITable;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + ubMaxTable;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + seasonClusterTable;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + psClusterTable;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + tfAvailCapTable;
sqliteDb.executeSql(sql);
}
/**
* 创建公变月三相不平衡度表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public static void createTfMonthUbTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName varchar(200) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" lineName varchar(200) NOT NULL," +
" lineMRID varchar(50) NOT NULL," +
" substation varchar(20) NOT NULL," +
" maxLoad decimal(8,4) NULL," +
" ratedCap decimal(4,0) NULL," +
" ub decimal(2,7) NULL, " +
" monthUb1 decimal(2,7) NULL, " +
" monthUb2 decimal(2,7) NULL, " +
" monthUb3 decimal(2,7) NULL, " +
" monthUb4 decimal(2,7) NULL, " +
" monthUb5 decimal(2,7) NULL, " +
" monthUb6 decimal(2,7) NULL, " +
" monthUb7 decimal(2,7) NULL, " +
" monthUb8 decimal(2,7) NULL, " +
" monthUb9 decimal(2,7) NULL, " +
" monthUb10 decimal(2,7) NULL, " +
" monthUb11 decimal(2,7) NULL, " +
" monthUb12 decimal(2,7) NULL, " +
" monthUb13 decimal(2,7) NULL, " +
" monthUb14 decimal(2,7) NULL, " +
" monthUb15 decimal(2,7) NULL, " +
" monthUb16 decimal(2,7) NULL, " +
" monthUb17 decimal(2,7) NULL, " +
" monthUb18 decimal(2,7) NULL, " +
" monthUb19 decimal(2,7) NULL, " +
" monthUb20 decimal(2,7) NULL, " +
" monthUb21 decimal(2,7) NULL, " +
" monthUb22 decimal(2,7) NULL, " +
" monthUb23 decimal(2,7) NULL, " +
" monthUb24 decimal(2,7) NULL, " +
" monthUb25 decimal(2,7) NULL, " +
" monthUb26 decimal(2,7) NULL, " +
" monthUb27 decimal(2,7) NULL, " +
" monthUb28 decimal(2,7) NULL, " +
" monthUb29 decimal(2,7) NULL, " +
" monthUb30 decimal(2,7) NULL, " +
" monthUb31 decimal(2,7) NULL " +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建公变参数表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public static void createTFParamTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName varchar(50) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" blLine varchar(50) NOT NULL," +
" ratedCap decimal(4,0) NULL " +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建智能开关数据表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public static void createSwitchTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName varchar(50) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" date datetime NULL," +
" Ia decimal(8,4) NULL, " +
" Ib decimal(8,4) NULL, " +
" Ic decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
initSql = "CREATE TABLE " + tableName + seasonTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" Ia decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
initSql = "CREATE TABLE " + tableName + seasonClusterTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" Ia decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
initSql = "CREATE TABLE " + tableName + psClusterTable + " (" +
" mRID varchar(50) NOT NULL," +
" season INTEGER NULL," +
" Ia decimal(8,4) NULL " +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + seasonTable;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + seasonClusterTable;
sqliteDb.executeSql(sql);
sql = "delete from " + tableName + psClusterTable;
sqliteDb.executeSql(sql);
}
/**
* 创建线路参数表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public static void createLineParamTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" devName varchar(200) NOT NULL," +
" pole1 varchar(100) NOT NULL," +
" pole2 varchar(100) NOT NULL," +
" ratedCurrent decimal(6,2) NULL, " +
" type INTEGER NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建馈线名称表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createFeederNameTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" feeder varchar(200) NOT NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 存储馈线名称
*/
public void saveFeederName(String feederNameTable, String dbFile, String feederName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + feederNameTable + " values('" + feederName + "')";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
/**
* 创建线路合格率表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createLinePassRateTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" feederName varchar(200) NOT NULL," +
" substation varchar(20) NOT NULL," +
" passRate1 decimal(1,6) NULL," +
" passRate2 decimal(1,6) NULL," +
" passRate3 decimal(1,6) NULL," +
" passRate4 decimal(1,6) NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 创建公变越限表格
* @param dbFile 数据库路径
* @param tableName 表名
*/
public void createTfOverLoadTable(String dbFile, String tableName) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
String initSql = "CREATE TABLE " + tableName + " (" +
" feederName varchar(200) NOT NULL," +
" devName varchar(200) NOT NULL," +
" mRID varchar(50) NOT NULL," +
" lineName varchar(200) NOT NULL," +
" lineMRID varchar(50) NOT NULL," +
" substation varchar(20) NOT NULL," +
" overLoadRate1 decimal(1,6) NULL," +
" overLoadRate2 decimal(1,6) NULL," +
" overLoadRate3 decimal(1,6) NULL," +
" overLoadRate4 decimal(1,6) NULL" +
")";
sqliteDb.initDb(initSql);
// 清空表格
String sql = "delete from " + tableName;
sqliteDb.executeSql(sql);
}
/**
* 解析线路电流文件并存库
* @param tableName 表名
* @param filesPath 文件路径
* @param dbFile 数据库路径
*/
public static void parseLineCurrent(String tableName, String filesPath, String dbFile) {
// 获取所有txt文件路径
LinkedList<String> filePathList = new LinkedList<>();
File[] fileList = new File(filesPath).listFiles();
for(File file : fileList) {
if(file.isFile()) {
if (file.getName().endsWith(".txt")) {
filePathList.add(filesPath + "\\" + file.getName());
}
}
}
// 逐个解析文件
for (String filePath : filePathList) {
try {
parseLineCurrent(tableName, new FileInputStream(new File(filePath)), dbFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
public static void parseLineCurrent(String tableName, InputStream in, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "GBK"));
List<String> sqls = new LinkedList<>();
String strLine = reader.readLine();
String[] lastContent = new String[]{"0", "0"};
while ((strLine = reader.readLine()) != null) {
String[] contents = strLine.split("\t");
if (contents.length == 1)
contents = new String[]{contents[0], lastContent[1]};
// 处理datetime数据
DateFormat simpleDateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //创建一个格式化日期对象
Date date = null;
try {
date = simpleDateFormat.parse(contents[0]);
} catch (ParseException e) {
e.printStackTrace();
}
Timestamp timeStamp = new Timestamp(date.getTime()); // 让日期时间转换为数据库中的timestamp类型
String insertSql = "insert into " + tableName + " values(" +
"'" + timeStamp + "'," + contents[1] + ")";
sqls.add(insertSql);
lastContent = contents;
}
sqliteDb.executeSqls(sqls);
sqls.clear();
reader.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 解析公变参数文件并存库
* @param tableName 表名
* @param filePath 文件路径
* @param dbFile 数据库路径
*/
public static void parseTFParam(String tableName, String filePath, String dbFile) {
try {
InputStream in = new FileInputStream(new File(filePath));
SqliteDb sqliteDb = new SqliteDb(dbFile);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
List<String> sqls = new LinkedList<>();
String strLine = reader.readLine();
reader.readLine();
while ((strLine = reader.readLine()) != null) {
String[] contents = strLine.split(",");
double ratedCap = 400;
String insertSql = "insert into " + tableName + " values(" +
"'" + contents[1] + "','" + "0" + "','" + contents[3] + "'," + contents[5] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
reader.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
/**
* 解析公变数据文件并存库
* @param tableName 表名
* @param filesPath 文件路径
* @param dbFile 数据库路径
*/
public static void parseTF(String tableName, String filesPath, String dbFile) {
// 获取所有txt文件路径
LinkedList<String> filePathList = new LinkedList<>();
File[] fileList = new File(filesPath).listFiles();
for(File file : fileList) {
if(file.isFile()) {
if (file.getName().endsWith(".txt")) {
filePathList.add(filesPath + "\\" + file.getName());
}
}
}
// 逐个解析文件
SqliteDb sqliteDb = new SqliteDb(dbFile);
for (String filePath : filePathList) {
List<String> sqls = new LinkedList<>();
String s = readJsonFile(filePath);
JSONObject jobj = JSON.parseObject(s);
String devName = (String)jobj.get("devName");
JSONArray tfs = jobj.getJSONArray("root"); //构建JSONArray数组
for (int i = 0; i < tfs.size(); i++) {
JSONObject tf = (JSONObject) tfs.get(i);
// 处理datetime数据
DateFormat simpleDateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //创建一个格式化日期对象
Date date = null;
try {
date = simpleDateFormat.parse((String)tf.get("SJSJ"));
} catch (ParseException e) {
e.printStackTrace();
}
Timestamp timeStamp = new Timestamp(date.getTime()); // 让日期时间转换为数据库中的timestamp类型
String insertSql = "insert into " + tableName + " values(" +
"'" + devName + "','" + (((String)tf.get("zybh")).replace('-','_')) + "','" +
timeStamp + "'," + tf.get("Ia") + "," + tf.get("Ib") + "," + tf.get("Ic") + "," +
tf.get("Ua") + "," + tf.get("Ub") + "," + tf.get("Uc") + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
/**
* 解析公变参数文件并存库
* @param tfParamTableName 公变参数表名
* @param tfTableName 公变表名
* @param dbFile 数据库路径
*/
public static void parseTFMRID(String tfParamTableName, String tfTableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
Map<String, String> nameToMRID = sqliteDb.queryNameToMRID(tfTableName);
List<String> sqls = new LinkedList<>();
for (String name : nameToMRID.keySet()) {
String updateSql = "update " + tfParamTableName + " set mRID = '" + nameToMRID.get(name) + "' where devName = '" + name + "'";
sqls.add(updateSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
/**
* 解析开关数据文件并存库
* @param tableName 表名
* @param filesPath 文件路径
* @param dbFile 数据库路径
*/
public static void parseSwitch(String tableName, String filesPath, String dbFile) {
// 获取所有txt文件路径
LinkedList<String> filePathList = new LinkedList<>();
File[] fileList = new File(filesPath).listFiles();
for(File file : fileList) {
if(file.isFile()) {
if (file.getName().endsWith(".txt")) {
filePathList.add(filesPath + "\\" + file.getName());
}
}
}
// 逐个解析文件
SqliteDb sqliteDb = new SqliteDb(dbFile);
for (String filePath : filePathList) {
List<String> sqls = new LinkedList<>();
String s = readJsonFile(filePath);
JSONObject jobj = JSON.parseObject(s);
String devName = (String)jobj.get("devName");
JSONArray sws = jobj.getJSONArray("root"); //构建JSONArray数组
for (int i = 0; i < sws.size(); i++) {
JSONObject sw = (JSONObject) sws.get(i);
// 处理datetime数据
DateFormat simpleDateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //创建一个格式化日期对象
Date date = null;
try {
date = simpleDateFormat.parse((String)sw.get("SJSJ"));
} catch (ParseException e) {
e.printStackTrace();
}
Timestamp timeStamp = new Timestamp(date.getTime()); // 让日期时间转换为数据库中的timestamp类型
String insertSql = "insert into " + tableName + " values(" +
"'" + devName + "','" + (((String)sw.get("zybh")).replace('-','_')) + "','" +
timeStamp + "'," + sw.get("Iax") + "," + sw.get("Ibx") + "," + sw.get("Icx") + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
//读取json文件
public static String readJsonFile(String fileName) {
String jsonStr = "";
try {
File jsonFile = new File(fileName);
FileReader fileReader = new FileReader(jsonFile);
Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
return jsonStr;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
/**
* 解析线路参数文件并存库
* @param tableName 表名
* @param filePath 文件路径
* @param dbFile 数据库路径
*/
public static void parseLineParam(String tableName, String filePath, String dbFile) {
try {
InputStream in = new FileInputStream(new File(filePath));
SqliteDb sqliteDb = new SqliteDb(dbFile);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
List<String> sqls = new LinkedList<>();
String strLine = reader.readLine();
while ((strLine = reader.readLine()) != null) {
String[] contents = strLine.split(",");
double ratedCurrent = 1000;
String[] type = contents[6].split("-");
int tp = 1;
if (type[0].startsWith("JKLYJ") || type[0].equals("JKLGYJ") || type[0].equals("JLYJ") || type[0].equals("JKYJ")) {
if (type.length == 3) {
if (ratedIJK.get(type[2]) != null) {
ratedCurrent = ratedIJK.get(type[2]);
}
} else if (type.length == 2) {
if (type[1].split("/").length > 1) {
if (ratedIJK.get(type[1].split("/")[1]) != null) {
ratedCurrent = ratedIJK.get(type[1].split("/")[1]);
}
} else {
if (ratedIJK.get(type[1]) != null) {
ratedCurrent = ratedIJK.get(type[1]);
}
}
}
} else if (type[0].startsWith("JL/")) {
if (type.length > 1) {
if (ratedIJK.get(type[1].split("/")[0]) != null) {
ratedCurrent = ratedIJK.get(type[1].split("/")[0]);
}
}
} else if (type[0].equals("LGJ")) {
tp = 2;
if (type.length > 1) {
if (ratedILGJ.get(type[1].split("/")[0]) != null) {
ratedCurrent = ratedILGJ.get(type[1].split("/")[0]);
}
}
} else {
System.out.println(contents[6]);
}
String insertSql = "insert into " + tableName + " values(" +
"'" + contents[0] + "','" + contents[7] + "','" + contents[8] + "'," + ratedCurrent + "," + tp + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
reader.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
/**
* 按季节处理线电流历史数据,每个时段电流取该季节的最大值
* @param tableName 表名
* @param dbFile 数据库路径
*/
public void lineCurrentDataAnalysis(String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
int T = 5; // 采点时间间隔
int pointNum = 24 * 60 / T;
for (int season = 1; season < 5; season++) {
double[] maxCurrent = new double[pointNum];
List<LineCurrentData> lineCurrentDatas = sqliteDb.queryLineCurrentData(tableName, season);
Iterator<LineCurrentData> iterator = lineCurrentDatas.iterator();
while (iterator.hasNext()) {
LineCurrentData lineCurrentData = iterator.next();
long time = lineCurrentData.getData().getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int tNum = (60 * hour + minutes) / T;
if (maxCurrent[tNum] < lineCurrentData.getCurrent())
maxCurrent[tNum] = lineCurrentData.getCurrent();
}
List<String> sqls = new LinkedList<>();
for (int i = 0; i < maxCurrent.length; i++) {
String insertSql = "insert into " + tableName + seasonTable + " values(" +
season + "," + maxCurrent[i] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
/**
* 按季节处理开关历史数据,每个时段电流取该季节的最大值
* @param tableName 表名
* @param dbFile 数据库路径
*/
public void switchDataAnalysis(String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
int T = 15; // 采点时间间隔
int pointNum = 24 * 60 / T;
List<String> mRIDs = sqliteDb.queryMRIds(tableName);
for (int i = 0; i < mRIDs.size(); i++) {
double yMaxI = 0;
double avgI = 0;
int count = 0;
for (int season = 1; season < 5; season++) {
double[] maxCurrent = new double[pointNum];
List<SwitchData> swDatas = sqliteDb.querySwitchData(tableName, mRIDs.get(i), season);
Iterator<SwitchData> iterator = swDatas.iterator();
while (iterator.hasNext()) {
SwitchData swData = iterator.next();
long time = swData.getData().getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int tNum = (60 * hour + minutes) / T;
if (maxCurrent[tNum] < swData.getIa())
maxCurrent[tNum] = swData.getIa();
if (yMaxI < swData.getIa())
yMaxI = swData.getIa();
avgI += swData.getIa();
count++;
}
List<String> sqls = new LinkedList<>();
for (int j = 0; j < pointNum; j++) {
String insertSql = "insert into " + tableName + seasonTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + maxCurrent[j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + tableName + seasonTable + " values(" +
"'" + mRIDs.get(i) + "'," + (-1) + "," + yMaxI + ")";
sqls.add(insertSql);
avgI /= count;
insertSql = "insert into " + tableName + seasonTable + " values(" +
"'" + mRIDs.get(i) + "'," + (-2) + "," + avgI + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
/**
* 按季节聚类开关历史数据
* @param tableName 表名
* @param dbFile 数据库路径
*/
public void switchDataSeasonCluster(String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
int T = 15; // 采点时间间隔
int pointNum = 24 * 60 / T;
List<String> mRIDs = sqliteDb.queryMRIds(tableName);
for (int i = 0; i < mRIDs.size(); i++) {
for (int season = 1; season < 5; season++) {
double[] center = new double[pointNum];
int[] count = new int[pointNum];
List<SwitchData> swDatas = sqliteDb.querySwitchData(tableName, mRIDs.get(i), season);
Iterator<SwitchData> iterator = swDatas.iterator();
while (iterator.hasNext()) {
SwitchData swData = iterator.next();
long time = swData.getData().getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int tNum = (60 * hour + minutes) / T;
center[tNum] += swData.getIa();
count[tNum]++;
}
for (int j = 0; j < pointNum; j++) {
if (count[j] > 0)
center[j] /= count[j];
}
List<String> sqls = new LinkedList<>();
for (int j = 0; j < pointNum; j++) {
String insertSql = "insert into " + tableName + seasonClusterTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + center[j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
}
/**
* 按峰谷聚类开关历史数据
* @param tableName 表名
* @param dbFile 数据库路径
*/
public void switchDataPsCluster(String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
int T = 15; // 采点时间间隔
int pointNum = 24 * 60 / T;
List<String> mRIDs = sqliteDb.queryMRIds(tableName);
for (int i = 0; i < mRIDs.size(); i++) {
for (int season = 1; season < 5; season++) {
double[] center = new double[pointNum];
int[] count = new int[pointNum];
for (int month = season * 3 - 2; month < season * 3 + 1; month++) {
List<SwitchData> swDatas = sqliteDb.querySwDataByMonth(tableName, mRIDs.get(i), month);
Iterator<SwitchData> iterator = swDatas.iterator();
while (iterator.hasNext()) {
SwitchData swData = iterator.next();
long time = swData.getData().getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int tNum = (60 * hour + minutes) / T;
center[tNum] += swData.getIa();
count[tNum]++;
}
boolean hasData = true;
for (int j = 0; j < pointNum; j++) {
if (count[j] == 0)
hasData = false;
}
if (hasData)
break;
}
for (int j = 0; j < pointNum; j++) {
if (count[j] > 0)
center[j] /= count[j];
}
List<String> sqls = new LinkedList<>();
for (int j = 0; j < pointNum; j++) {
String insertSql = "insert into " + tableName + psClusterTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + center[j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
}
/**
* 按季节处理公变历史数据,每个时段负荷取该季节的最大值,按季节和年计算平均三相不平衡度
* @param tableName 表名
* @param dbFile 数据库路径
*/
public void tfDataAnalysis(String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
int T = 15; // 采点时间间隔
int pointNum = 24 * 60 / T;
List<String> mRIDs = sqliteDb.queryMRIds(tableName);
for (int i = 0; i < mRIDs.size(); i++) {
double[][] mAvgUbI = new double[4][2]; // 季度平均三相电流不平衡度
double[][] mAvgUbV = new double[4][2]; // 季度平均三相电压不平衡度
double[][] mAvgI = new double[4][3]; // 季度平均三相电流
int[] mMinIPhase = new int[4];
double[] mMinI = new double[4];
double maxI = 0;
double avgI = 0;
int count = 0;
int seasonNum = 4; // 存在季度数据空缺的情况
double yMaxP = 0;
for (int season = 1; season < 5; season++) {
double[] maxP = new double[pointNum]; // 公变最大负荷
double[] maxUbI = new double[pointNum]; // 公变电流最大三相不平衡度
double[] maxUbV = new double[pointNum]; // 公变电压最大三相不平衡度
List<TFData> tfDatas = sqliteDb.queryTFData(tableName, mRIDs.get(i), season);
Iterator<TFData> iterator = tfDatas.iterator();
while (iterator.hasNext()) {
TFData tfData = iterator.next();
long time = tfData.getDate().getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int tNum = (60 * hour + minutes) / T;
double P = tfData.getIa() * tfData.getUa() + tfData.getIb() * tfData.getUb() + tfData.getIc() * tfData.getUc();
if (maxP[tNum] < P)
maxP[tNum] = P;
if (yMaxP < P)
yMaxP = P;
if (maxI < tfData.getIa())
maxI = tfData.getIa();
if (maxI < tfData.getIb())
maxI = tfData.getIb();
if (maxI < tfData.getIc())
maxI = tfData.getIc();
avgI += tfData.getIa() + tfData.getIb() + tfData.getIc();
count += 3;
// 计算三相不平衡度
double[] ubI = unbalance(new Complex(tfData.getIa(), 0),
Complex.multiply(new Complex(tfData.getIb(), 0), a2),
Complex.multiply(new Complex(tfData.getIc(), 0), a));
mAvgUbI[season - 1][0] += ubI[0];
mAvgUbI[season - 1][1] += ubI[1];
double[] ubV = unbalance(new Complex(tfData.getUa(), 0),
Complex.multiply(new Complex(tfData.getUb(), 0), a2),
Complex.multiply(new Complex(tfData.getUc(), 0), a));
mAvgUbV[season - 1][0] += ubV[0];
mAvgUbV[season - 1][1] += ubV[1];
// 更新三相不平衡度最大值
if (maxUbI[tNum] < ubI[0])
maxUbI[tNum] = ubI[0];
if (maxUbV[tNum] < ubV[0])
maxUbV[tNum] = ubV[0];
// 计算季度平均三相电流
mAvgI[season - 1][0] += tfData.getIa();
mAvgI[season - 1][1] += tfData.getIb();
mAvgI[season - 1][2] += tfData.getIc();
}
if (tfDatas.size() == 0) {
seasonNum--;
} else {
mAvgUbI[season - 1][0] /= tfDatas.size();
mAvgUbI[season - 1][1] /= tfDatas.size();
mAvgUbV[season - 1][0] /= tfDatas.size();
mAvgUbV[season - 1][1] /= tfDatas.size();
mAvgI[season - 1][0] /= tfDatas.size();
mAvgI[season - 1][1] /= tfDatas.size();
mAvgI[season - 1][2] /= tfDatas.size();
// 分析季度平均电流最小相
mMinI[season - 1] = mAvgI[season - 1][0];
mMinIPhase[season - 1] = 0;
if (mMinI[season - 1] > mAvgI[season - 1][1]) {
mMinI[season - 1] = mAvgI[season - 1][1];
mMinIPhase[season - 1] = 1;
}
if (mMinI[season - 1] > mAvgI[season - 1][2]) {
mMinI[season - 1] = mAvgI[season - 1][2];
mMinIPhase[season - 1] = 2;
}
}
// 公变负荷数据存库
List<String> sqls = new LinkedList<>();
for (int j = 0; j < pointNum; j++) {
String insertSql = "insert into " + tableName + seasonTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + maxP[j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
// 最大三相不平衡度存库
for (int j = 0; j < pointNum; j++) {
String insertSql = "insert into " + tableName + ubMaxTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + maxUbI[j] + "," + maxUbV[j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
// 公变年最大负荷存库
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + tableName + seasonTable + " values(" +
"'" + mRIDs.get(i) + "'," + (-1) + "," + yMaxP + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
// 公变最大电流存库
insertSql = "insert into " + tableName + seasonTable + " values(" +
"'" + mRIDs.get(i) + "'," + (-2) + "," + maxI + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
// 公变平均电流存库
avgI /= count;
insertSql = "insert into " + tableName + seasonTable + " values(" +
"'" + mRIDs.get(i) + "'," + (-3) + "," + avgI + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
// 年平均三相不平衡度
double[] yAvgUbI = new double[2];
double[] yAvgUbV = new double[2];
for (int season = 0; season < 4; season++) {
yAvgUbI[0] += mAvgUbI[season][0];
yAvgUbI[1] += mAvgUbI[season][1];
yAvgUbV[0] += mAvgUbV[season][0];
yAvgUbV[1] += mAvgUbV[season][1];
}
yAvgUbI[0] /= seasonNum;
yAvgUbI[1] /= seasonNum;
yAvgUbV[0] /= seasonNum;
yAvgUbV[1] /= seasonNum;
// 三相不平衡度分析结果存库
sqls = new LinkedList<>();
for (int season = 1; season < 5; season++) {
insertSql = "insert into " + tableName + unbalanceTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + mAvgUbI[season - 1][0] + "," + mAvgUbI[season - 1][1] +
"," + mAvgUbV[season - 1][0] + "," + mAvgUbV[season - 1][1] + ")";
sqls.add(insertSql);
}
insertSql = "insert into " + tableName + unbalanceTable + " values(" +
"'" + mRIDs.get(i) + "'," + (-1) + "," + yAvgUbI[0] + "," + yAvgUbI[1] + "," + yAvgUbV[0] + "," + yAvgUbV[1] + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
// 计算年平均三相电流
double[] yAvgI = new double[3];
for (int season = 0; season < 4; season++) {
yAvgI[0] += mAvgI[season][0];
yAvgI[1] += mAvgI[season][1];
yAvgI[2] += mAvgI[season][2];
}
yAvgI[0] /= seasonNum;
yAvgI[1] /= seasonNum;
yAvgI[2] /= seasonNum;
// 分析年平均电流最小相
int yMinIPhase = 0;
double yMinI = yAvgI[0];
if (yMinI > yAvgI[1]) {
yMinI = yAvgI[1];
yMinIPhase = 1;
}
if (yMinI > yAvgI[2]) {
yMinI = yAvgI[2];
yMinIPhase = 2;
}
// 平均最小相电流分析结果存库
for (int season = 1; season < 5; season++) {
insertSql = "insert into " + tableName + minITable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + mMinIPhase[season - 1] + "," + mMinI[season - 1] + ")";
sqls.add(insertSql);
}
insertSql = "insert into " + tableName + minITable + " values(" +
"'" + mRIDs.get(i) + "'," + (-1) + "," + yMinIPhase + "," + yMinI + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
/**
* 公变月三相不平衡度
* @param tfTable 表名
* @param dbFile 数据库路径
*/
public void tfMonthUb(String tfTable, String dbFile, String tfMonthUbTable, String substationTable, String tfParamTable,
String tfSeasonTable, String tfToLineTable) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
// 查询变电站名称
String substation = sqliteDb.querySubstationName(substationTable);
Map<String, String> tfNameToMRID = sqliteDb.queryNameToMRID(tfTable);
for (String name : tfNameToMRID.keySet()) {
String mRID = tfNameToMRID.get(name);
double tfRatedCap = sqliteDb.queryTFCap(tfParamTable, mRID);
double tfMaxP = sqliteDb.queryMaxTFP(tfSeasonTable, mRID, -1) / 1000;
double ub = 0; // 年平均三相不平衡度
int ubCount = 0;
double[] monthUb = new double[31]; // 月三相不平衡度
int[] count = new int[31];
for (int season = 1; season < 5; season++) {
List<TFData> tfDatas = sqliteDb.queryTFData(tfTable, mRID, season);
Iterator<TFData> iterator = tfDatas.iterator();
while (iterator.hasNext()) {
TFData tfData = iterator.next();
long time = tfData.getDate().getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
int day = calendar.get(Calendar.DAY_OF_MONTH);
// 计算三相不平衡度
double[] ubI = unbalance(new Complex(tfData.getIa(), 0),
Complex.multiply(new Complex(tfData.getIb(), 0), a2),
Complex.multiply(new Complex(tfData.getIc(), 0), a));
ub += ubI[0];
ubCount++;
monthUb[day - 1] += ubI[0];
count[day - 1]++;
}
}
ub /= ubCount;
for (int j = 0; j < 31; j++) {
if (count[j] > 0) {
monthUb[j] /= count[j];
}
}
// 公变对应的线路名称
List<String[]> lines = sqliteDb.querySwToDev(tfToLineTable, mRID);
if (lines.size() > 0) {
String[] line = lines.get(0);
// 公变月三相不平衡度存库
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + tfMonthUbTable + " values(" +
"'" + name + "','" + mRID + "','" + line[0] + "','" + line[1] + "','" + substation + "'," +
tfMaxP + "," + tfRatedCap + "," + ub + "," + monthUb[0] + "," + monthUb[1] + "," + monthUb[2] + "," +
monthUb[3] + "," + monthUb[4] + "," + monthUb[5] + "," + monthUb[6] + "," + monthUb[7] + "," +
monthUb[8] + "," + monthUb[9] + "," + monthUb[10] + "," + monthUb[11] + "," + monthUb[12] + "," +
monthUb[13] + "," + monthUb[14] + "," + monthUb[15] + "," + monthUb[16] + "," + monthUb[17] + "," +
monthUb[18] + "," + monthUb[19] + "," + monthUb[20] + "," + monthUb[21] + "," + monthUb[22] + "," +
monthUb[23] + "," + monthUb[24] + "," + monthUb[25] + "," + monthUb[26] + "," + monthUb[27] + "," +
monthUb[28] + "," + monthUb[29] + "," + monthUb[30] + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
}
/**
* 按季节聚类公变负荷历史数据和三相最大不平衡度
* @param tableName 表名
* @param dbFile 数据库路径
*/
public void tfDataSeasonCluster(String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
int T = 15; // 采点时间间隔
int pointNum = 24 * 60 / T;
List<String> mRIDs = sqliteDb.queryMRIds(tableName);
for (int i = 0; i < mRIDs.size(); i++) {
int seasonNum = 4; // 存在季度数据空缺的情况
for (int season = 1; season < 5; season++) {
double[] centerP = new double[pointNum]; // 负荷聚类中心
double[] centerUb = new double[pointNum]; // 不平衡度聚类中心
int[] count = new int[pointNum];
List<TFData> tfDatas = sqliteDb.queryTFData(tableName, mRIDs.get(i), season);
Iterator<TFData> iterator = tfDatas.iterator();
while (iterator.hasNext()) {
TFData tfData = iterator.next();
long time = tfData.getDate().getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int tNum = (60 * hour + minutes) / T;
double P = tfData.getIa() * tfData.getUa() + tfData.getIb() * tfData.getUb() + tfData.getIc() * tfData.getUc();
centerP[tNum] += P;
// 计算三相不平衡度
double[] ubI = unbalance(new Complex(tfData.getIa(), 0),
Complex.multiply(new Complex(tfData.getIb(), 0), a2),
Complex.multiply(new Complex(tfData.getIc(), 0), a));
centerUb[tNum] += ubI[0];
count[tNum]++;
}
for (int j = 0; j < pointNum; j++) {
if (count[j] > 0) {
centerP[j] /= count[j];
centerUb[j] /= count[j];
}
}
// 公变按季节聚类结果存库
List<String> sqls = new LinkedList<>();
for (int j = 0; j < pointNum; j++) {
String insertSql = "insert into " + tableName + seasonClusterTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + centerP[j] + "," + centerUb[j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
}
/**
* 按峰谷聚类公变负荷历史数据和三相最大不平衡度
* @param tableName 表名
* @param dbFile 数据库路径
*/
public void tfDataPsCluster(String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
int T = 15; // 采点时间间隔
int pointNum = 24 * 60 / T;
List<String> mRIDs = sqliteDb.queryMRIds(tableName);
for (int i = 0; i < mRIDs.size(); i++) {
int seasonNum = 4; // 存在季度数据空缺的情况
for (int season = 1; season < 5; season++) {
double[] centerP = new double[pointNum]; // 负荷聚类中心
double[] centerUb = new double[pointNum]; // 不平衡度聚类中心
int[] count = new int[pointNum];
for (int month = season * 3 - 2; month < season * 3 + 1; month++) {
List<TFData> tfDatas = sqliteDb.queryTFDataByMonth(tableName, mRIDs.get(i), month);
Iterator<TFData> iterator = tfDatas.iterator();
while (iterator.hasNext()) {
TFData tfData = iterator.next();
long time = tfData.getDate().getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int tNum = (60 * hour + minutes) / T;
double P = tfData.getIa() * tfData.getUa() + tfData.getIb() * tfData.getUb() + tfData.getIc() * tfData.getUc();
centerP[tNum] += P;
// 计算三相不平衡度
double[] ubI = unbalance(new Complex(tfData.getIa(), 0),
Complex.multiply(new Complex(tfData.getIb(), 0), a2),
Complex.multiply(new Complex(tfData.getIc(), 0), a));
centerUb[tNum] += ubI[0];
count[tNum]++;
}
boolean hasData = true;
for (int j = 0; j < pointNum; j++) {
if (count[j] == 0)
hasData = false;
}
if (hasData)
break;
}
for (int j = 0; j < pointNum; j++) {
if (count[j] > 0) {
centerP[j] /= count[j];
centerUb[j] /= count[j];
}
}
// 公变按季节聚类结果存库
List<String> sqls = new LinkedList<>();
for (int j = 0; j < pointNum; j++) {
String insertSql = "insert into " + tableName + psClusterTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + centerP[j] + "," + centerUb[j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
}
/**
* 按季节计算公变可开放容量
* @param tableName 表名
* @param dbFile 数据库路径
*/
public void tfAvailCap(String tfSeasonTable, String tfParamTable, String tableName, String dbFile) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
int T = 15; // 采点时间间隔
int pointNum = 24 * 60 / T;
List<String> mRIDs = sqliteDb.queryMRIds(tfSeasonTable);
for (int i = 0; i < mRIDs.size(); i++) {
double tFRatedCap = sqliteDb.queryTFCap(tfParamTable, mRIDs.get(i));
for (int season = 1; season < 5; season++) {
double[] seasonP = sqliteDb.querySeasonTFP(tfSeasonTable, mRIDs.get(i), season, 96);
double[] availCap = new double[pointNum];
for (int j = 0; j < pointNum; j++) {
availCap[j] = tFRatedCap - seasonP[j] / 1000;
}
// 公变可接入容量存库
List<String> sqls = new LinkedList<>();
for (int j = 0; j < pointNum; j++) {
String insertSql = "insert into " + tableName + tfAvailCapTable + " values(" +
"'" + mRIDs.get(i) + "'," + season + "," + availCap[j] + ")";
sqls.add(insertSql);
}
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
}
/**
* 公变越限分析
*/
public void tfOverLoad(String dbFile, String feederTable, String substationTable, String tfOverLoadTable, String tfTable, String tfParamTable,
String tfSeasonTable, String tfToLineTable) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
// 查询馈线名称
String feeder = sqliteDb.queryFeederName(feederTable);
// 查询变电站名称
String substation = sqliteDb.querySubstationName(substationTable);
// 分析公变
Map<String, String> tfNameToMRID = sqliteDb.queryNameToMRID(tfTable);
List<String> sqls = new LinkedList<>();
for (String name : tfNameToMRID.keySet()) {
String mRID = tfNameToMRID.get(name);
double tfRatedCap = sqliteDb.queryTFCap(tfParamTable, mRID);
// 公变对应的线路名称
List<String[]> lines = sqliteDb.querySwToDev(tfToLineTable, mRID);
if (lines.size() > 0) {
String[] line = lines.get(0);
double[] overLoadRate = new double[4];
for (int season = 1; season < 5; season++) {
int count = 0;
List<TFData> tfDatas = sqliteDb.queryTFData(tfTable, mRID, season);
Iterator<TFData> iterator = tfDatas.iterator();
while (iterator.hasNext()) {
TFData tfData = iterator.next();
double P = tfData.getIa() * tfData.getUa() + tfData.getIb() * tfData.getUb() + tfData.getIc() * tfData.getUc();
double loadRate = P / tfRatedCap;
if (loadRate < 2 && loadRate > 1) {
overLoadRate[season - 1]++;
}
count++;
}
overLoadRate[season - 1] /= count;
}
String insertSql = "insert into " + tfOverLoadTable + " values(" +
"'" + feeder + "','" + name + "','" + mRID + "','" + line[0] + "','" + line[1] + "','" + substation + "'," +
overLoadRate[0] + "," + overLoadRate[1] + "," + overLoadRate[2] + "," + overLoadRate[3] + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
}
}
/**
* 四季线路电流合格率
*/
public void linePassRate(String dbFile, String feederTable, String substationTable, String swTable, String swToLineTable,
String oneLineParamTable, String linePassRateTable) {
SqliteDb sqliteDb = new SqliteDb(dbFile);
// 查询馈线名称
String feeder = sqliteDb.queryFeederName(feederTable);
// 查询变电站名称
String substation = sqliteDb.querySubstationName(substationTable);
// 分析线路(开关对应的线路)
Map<String, String> swNameToMRID = sqliteDb.queryNameToMRID(swTable);
double[] passRate = new double[4];
for (int season = 1; season < 5; season++) {
int count = 0;
for (String name : swNameToMRID.keySet()) {
String mRID = swNameToMRID.get(name);
List<String[]> lines = sqliteDb.querySwToDev(swToLineTable, mRID); // 开关对应的线路
List<SwitchData> swDatas = sqliteDb.querySwitchData(swTable, mRID, season);
Iterator<SwitchData> iterator = swDatas.iterator();
while (iterator.hasNext()) {
SwitchData swData = iterator.next();
double I = swData.getIa();
boolean pass = true;
for (String[] line : lines) {
double lineRatedI = sqliteDb.queryOneLineParam(oneLineParamTable, line[1]);
double loadRate = I / lineRatedI;
if (loadRate < 2 && loadRate > 1) {
pass = false;
break;
}
}
if (pass) {
passRate[season - 1]++;
}
count++;
}
}
passRate[season - 1] /= count;
}
List<String> sqls = new LinkedList<>();
String insertSql = "insert into " + linePassRateTable + " values(" +
"'" + feeder + "','" + substation + "'," + passRate[0] + "," + passRate[1] + "," + passRate[2] + "," + passRate[3] + ")";
sqls.add(insertSql);
sqliteDb.executeSqls(sqls);
sqls.clear();
}
/**
* 计算三相相量不平衡度
* @param Fa a相相量
* @param Fb b相相量
* @param Fc c相相量
* @return 负序和零序不平衡度
*/
public double[] unbalance(Complex Fa, Complex Fb, Complex Fc) {
// 处理三相量为0的情况
if (Fa.mod() + Fb.mod() + Fc.mod() < 1e-8)
return new double[]{0, 0};
double modFa1 = Complex.multiply(aThird, Complex.add(Complex.add(Fa, Complex.multiply(a, Fb)), Complex.multiply(a2, Fc))).mod();
double modFa2 = Complex.multiply(aThird, Complex.add(Complex.add(Fa, Complex.multiply(a2, Fb)), Complex.multiply(a, Fc))).mod();
double modFa0 = Complex.multiply(aThird, Complex.add(Complex.add(Fa, Fb), Fc)).mod();
return new double[]{modFa2 / modFa1, modFa0 / modFa1};
}
}
package com.jinyun.cap;
import java.sql.Timestamp;
public class LineCurrentData {
Timestamp data;
double current;
public void setData(Timestamp data) {
this.data = data;
}
public Timestamp getData() {
return data;
}
public void setCurrent(double current) {
this.current = current;
}
public double getCurrent() {
return current;
}
}
package com.jinyun.cap;
public class LineParamData {
String devName;
String pole1;
String pole2;
double ratedI;
int type; // 1为JK,2为LGJ
public void setDevName(String devName) {
this.devName = devName;
}
public String getDevName() {
return devName;
}
public void setPole1(String pole1) {
this.pole1 = pole1;
}
public String getPole1() {
return pole1;
}
public void setPole2(String pole2) {
this.pole2 = pole2;
}
public String getPole2() {
return pole2;
}
public void setRatedI(double ratedI) {
this.ratedI = ratedI;
}
public double getRatedI() {
return ratedI;
}
public void setType(int type) {
this.type = type;
}
public int getType() {
return type;
}
}
package com.jinyun.cap;
public class LinePassRate {
String feederName;
String substation;
double[] passRate;
public String getFeederName() {
return feederName;
}
public void setFeederName(String feederName) {
this.feederName = feederName;
}
public String getSubstation() {
return substation;
}
public void setSubstation(String substation) {
this.substation = substation;
}
public double[] getPassRate() {
return passRate;
}
public void setPassRate(double[] passRate) {
this.passRate = passRate;
}
}
package com.jinyun.cap;
import java.util.ArrayList;
import java.util.List;
public class LoadPos {
double[] newLoad; // 接入的负荷
double[] newLoadI; // 接入负荷的电流
boolean[] canIn = new boolean[4];
double[][] swOrgLoad = new double[4][]; // 接入点开关原始负荷
double[][] swNewLoad = new double[4][96]; // 接入后开关电流
double[] swRateI = new double[4]; // 接入点开关限额
double[][] tfOrgLoad = new double[4][]; // 接入点公变原始负荷
double[][] tfNewLoad = new double[4][96]; // 接入后公变负荷
double[] tfRateCap = new double[4]; // 接入点公变额定容量
List<Integer> seasons = new ArrayList<>(4); // 季节
List<String> optEdges = new ArrayList<>(4); // 最优接入位置智能开关的mRID
List<String> optEdgeNames = new ArrayList<>(4); // 最优接入位置智能开关的名称
List<Double> seasonAvgCaps = new ArrayList<>(4); // 负荷接入后,线路剩余可接入容量(电流)的日平均值
List<Double> seasonMinCaps = new ArrayList<>(4); // 负荷接入后,线路剩余可接入容量(电流)的日最小值
List<Integer> seasons2 = new ArrayList<>(4);
List<String> optEdges2 = new ArrayList<>(4);
List<String> optEdgeNames2 = new ArrayList<>(4);
List<Double> seasonAvgCaps2 = new ArrayList<>(4);
List<Double> seasonMinCaps2 = new ArrayList<>(4);
String[] optTfs = new String[4]; // 最优接入位置公变的mRID
String[] optTfNames = new String[4]; // 最优接入位置公变的名称
String[] optPhase = new String[4]; // 公变接入相别
// season从0开始
public void calSwNewLoad(int season) {
for (int i = 0; i < 96; i++) {
swNewLoad[season][i] = newLoadI[i] + swOrgLoad[season][i];
}
}
public void calTfNewLoad(int season) {
for (int i = 0; i < 96; i++) {
tfNewLoad[season][i] = newLoad[i] + tfOrgLoad[season][i];
}
}
public void setSwOrgLoad(int season, double[] swOrgSeasonLoad) {
swOrgLoad[season] = swOrgSeasonLoad;
}
public void setSwNewLoad(int season, double[] swNewSeasonLoad) {
swNewLoad[season] = swNewSeasonLoad;
}
public void setTfOrgLoad(int season, double[] tfOrgSeasonLoad) {
tfOrgLoad[season] = tfOrgSeasonLoad;
}
public void setTfNewLoad(int season, double[] tfNewSeasonLoad) {
tfNewLoad[season] = tfNewSeasonLoad;
}
public void setOptTf(int season, String optTf) {
}
public double[] getNewLoad() {
return newLoad;
}
public void setNewLoad(double[] newLoad) {
this.newLoad = newLoad;
}
public double[] getNewLoadI() {
return newLoadI;
}
public void setNewLoadI(double[] newLoadI) {
this.newLoadI = newLoadI;
}
public boolean[] getCanIn() {
return canIn;
}
public void setCanIn(boolean[] canIn) {
this.canIn = canIn;
}
public double[][] getSwOrgLoad() {
return swOrgLoad;
}
public void setSwOrgLoad(double[][] swOrgLoad) {
this.swOrgLoad = swOrgLoad;
}
public double[][] getSwNewLoad() {
return swNewLoad;
}
public void setSwNewLoad(double[][] swNewLoad) {
this.swNewLoad = swNewLoad;
}
public double[] getSwRateI() {
return swRateI;
}
public void setSwRateI(double[] swRateI) {
this.swRateI = swRateI;
}
public double[][] getTfOrgLoad() {
return tfOrgLoad;
}
public void setTfOrgLoad(double[][] tfOrgLoad) {
this.tfOrgLoad = tfOrgLoad;
}
public double[][] getTfNewLoad() {
return tfNewLoad;
}
public void setTfNewLoad(double[][] tfNewLoad) {
this.tfNewLoad = tfNewLoad;
}
public double[] getTfRateCap() {
return tfRateCap;
}
public void setTfRateCap(double[] tfRateCap) {
this.tfRateCap = tfRateCap;
}
public void addLoadPos(int season, String optEdge, String optEdgeName, double seasonAvgCap, double seasonMinCap) {
this.seasons.add(season);
this.optEdges.add(optEdge);
this.optEdgeNames.add(optEdgeName);
this.seasonAvgCaps.add(seasonAvgCap);
this.seasonMinCaps.add(seasonMinCap);
}
public void addLoadPos2(int season, String optEdge, String optEdgeName, double seasonAvgCap, double seasonMinCap) {
this.seasons2.add(season);
this.optEdges2.add(optEdge);
this.optEdgeNames2.add(optEdgeName);
this.seasonAvgCaps2.add(seasonAvgCap);
this.seasonMinCaps2.add(seasonMinCap);
}
public List<Integer> getSeasons() {
return seasons;
}
public void setSeasons(List<Integer> seasons) {
this.seasons = seasons;
}
public List<String> getOptEdges() {
return optEdges;
}
public void setOptEdges(List<String> optEdges) {
this.optEdges = optEdges;
}
public List<String> getOptEdgeNames() {
return optEdgeNames;
}
public void setOptEdgeNames(List<String> optEdgeNames) {
this.optEdgeNames = optEdgeNames;
}
public List<Double> getSeasonAvgCaps() {
return seasonAvgCaps;
}
public void setSeasonAvgCaps(List<Double> seasonAvgCaps) {
this.seasonAvgCaps = seasonAvgCaps;
}
public List<Double> getSeasonMinCaps() {
return seasonMinCaps;
}
public void setSeasonMinCaps(List<Double> seasonMinCaps) {
this.seasonMinCaps = seasonMinCaps;
}
public List<Integer> getSeasons2() {
return seasons2;
}
public void setSeasons2(List<Integer> seasons2) {
this.seasons2 = seasons2;
}
public List<String> getOptEdges2() {
return optEdges2;
}
public void setOptEdges2(List<String> optEdges2) {
this.optEdges2 = optEdges2;
}
public List<String> getOptEdgeNames2() {
return optEdgeNames2;
}
public void setOptEdgeNames2(List<String> optEdgeNames2) {
this.optEdgeNames2 = optEdgeNames2;
}
public List<Double> getSeasonAvgCaps2() {
return seasonAvgCaps2;
}
public void setSeasonAvgCaps2(List<Double> seasonAvgCaps2) {
this.seasonAvgCaps2 = seasonAvgCaps2;
}
public List<Double> getSeasonMinCaps2() {
return seasonMinCaps2;
}
public void setSeasonMinCaps2(List<Double> seasonMinCaps2) {
this.seasonMinCaps2 = seasonMinCaps2;
}
public String[] getOptTfs() {
return optTfs;
}
public void setOptTfs(String[] optTfs) {
this.optTfs = optTfs;
}
public String[] getOptTfNames() {
return optTfNames;
}
public void setOptTfNames(String[] optTfNames) {
this.optTfNames = optTfNames;
}
public String[] getOptPhase() {
return optPhase;
}
public void setOptPhase(String[] optPhase) {
this.optPhase = optPhase;
}
}
package com.jinyun.cap;
public class LoadPosSeason {
int loadId;
String substation;
String feederName;
String canIn;
String tfName; // 最优接入位置公变的mRID
String tfMRID; // 最优接入位置公变的名称
String phase; // 公变接入相别
String time;
public int getLoadId() {
return loadId;
}
public void setLoadId(int loadId) {
this.loadId = loadId;
}
public String getSubstation() {
return substation;
}
public void setSubstation(String substation) {
this.substation = substation;
}
public String getFeederName() {
return feederName;
}
public void setFeederName(String feederName) {
this.feederName = feederName;
}
public String getCanIn() {
return canIn;
}
public void setCanIn(String canIn) {
this.canIn = canIn;
}
public String getTfName() {
return tfName;
}
public void setTfName(String tfName) {
this.tfName = tfName;
}
public String getTfMRID() {
return tfMRID;
}
public void setTfMRID(String tfMRID) {
this.tfMRID = tfMRID;
}
public String getPhase() {
return phase;
}
public void setPhase(String phase) {
this.phase = phase;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
package com.jinyun.cap;
public class LoadPosSw {
String canIn;
String swName;
String swMRID;
double[] newLoadI; // 接入的负荷电流
double[] swOrgLoad; // 接入点开关原始负荷
double[] swNewLoad; // 接入后开关电流
double[] swRateI; // 接入点开关限额
public String getCanIn() {
return canIn;
}
public void setCanIn(String canIn) {
this.canIn = canIn;
}
public String getSwName() {
return swName;
}
public void setSwName(String swName) {
this.swName = swName;
}
public String getSwMRID() {
return swMRID;
}
public void setSwMRID(String swMRID) {
this.swMRID = swMRID;
}
public double[] getNewLoadI() {
return newLoadI;
}
public void setNewLoadI(double[] newLoadI) {
this.newLoadI = newLoadI;
}
public double[] getSwOrgLoad() {
return swOrgLoad;
}
public void setSwOrgLoad(double[] swOrgLoad) {
this.swOrgLoad = swOrgLoad;
}
public double[] getSwNewLoad() {
return swNewLoad;
}
public void setSwNewLoad(double[] swNewLoad) {
this.swNewLoad = swNewLoad;
}
public double[] getSwRateI() {
return swRateI;
}
public void setSwRateI(double[] swRateI) {
this.swRateI = swRateI;
}
}
package com.jinyun.cap;
public class LoadPosTf {
String canIn;
String tfName; // 最优接入位置公变的mRID
String tfMRID; // 最优接入位置公变的名称
String phase; // 公变接入相别
double[] newLoad; // 接入的负荷
double[] tfOrgLoad; // 接入点公变原始负荷
double[] tfNewLoad; // 接入后公变负荷
double[] tfRateCap; // 接入点公变额定容量
public String getCanIn() {
return canIn;
}
public void setCanIn(String canIn) {
this.canIn = canIn;
}
public String getTfName() {
return tfName;
}
public void setTfName(String tfName) {
this.tfName = tfName;
}
public String getTfMRID() {
return tfMRID;
}
public void setTfMRID(String tfMRID) {
this.tfMRID = tfMRID;
}
public String getPhase() {
return phase;
}
public void setPhase(String phase) {
this.phase = phase;
}
public double[] getNewLoad() {
return newLoad;
}
public void setNewLoad(double[] newLoad) {
this.newLoad = newLoad;
}
public double[] getTfOrgLoad() {
return tfOrgLoad;
}
public void setTfOrgLoad(double[] tfOrgLoad) {
this.tfOrgLoad = tfOrgLoad;
}
public double[] getTfNewLoad() {
return tfNewLoad;
}
public void setTfNewLoad(double[] tfNewLoad) {
this.tfNewLoad = tfNewLoad;
}
public double[] getTfRateCap() {
return tfRateCap;
}
public void setTfRateCap(double[] tfRateCap) {
this.tfRateCap = tfRateCap;
}
}
package com.jinyun.cap;
public class MaxMinAvailCap {
String feederName;
double availCap;
public String getFeederName() {
return feederName;
}
public void setFeederName(String feederName) {
this.feederName = feederName;
}
public double getAvailCap() {
return availCap;
}
public void setAvailCap(double availCap) {
this.availCap = availCap;
}
}
package com.jinyun.cap;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class SqliteDb {
String dbFile;
public SqliteDb(String dbFile) {
this.dbFile = dbFile;
}
private Connection createConn() {
File f = new File(dbFile);
if(!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
Connection conn;
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:"+dbFile);
} catch (Exception e) {
StringWriter w = new StringWriter();
e.printStackTrace(new PrintWriter(w, true));
System.out.println("111"+e.getMessage());
return null;
}
return conn;
}
public Boolean executeSql(String sql) {
Connection conn = createConn();
if(conn == null) return false;
Statement stmt = null;
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.addBatch(sql);
stmt.executeBatch();
conn.commit();
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
System.out.println(e1.getMessage());
}
StringWriter w =new StringWriter();
e.printStackTrace(new PrintWriter(w, true));
System.out.println(e.getMessage());
return false;
} finally {
try {
stmt.close();
conn.setAutoCommit(true);
conn.close();
} catch (SQLException e) {
}
}
return true;
}
public Boolean executeSqls(List<String> sqls) {
Connection conn = createConn();
if(conn == null) return false;
Statement stmt = null;
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
for (String obj : sqls)
stmt.addBatch(obj);
stmt.executeBatch();
conn.commit();
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
System.out.println(e1.getMessage());
}
StringWriter w =new StringWriter();
e.printStackTrace(new PrintWriter(w, true));
System.out.println(e.getMessage());
return false;
} finally {
try {
stmt.close();
conn.setAutoCommit(true);
conn.close();
} catch (SQLException e) {
}
}
return true;
}
public void initDb(String initSql) {
Connection conn = createConn();
if (conn == null) {
System.out.println("Can't connect to sqlite !!!");
return;
}
Statement stmt= null;
try {
stmt = conn.createStatement();
stmt.executeUpdate(initSql);
} catch (SQLException e ) {
if (e.getMessage().contains("table $tableName already exists")) {
System.out.println("Table $tableName already exists");
} else {
StringWriter w = new StringWriter();
e.printStackTrace(new PrintWriter(w, true));
System.out.println(e.getMessage());
}
} finally {
try {
stmt.close();
conn.close();
} catch (SQLException e) {
}
}
}
public List<String> getTableNames() {
Connection conn = createConn();
String sql = "select name from sqlite_master where type='table'";
Statement stmt = null;
ResultSet rs = null;
List<String> tableNames = new LinkedList<>();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
tableNames.add(rs.getString("name"));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return tableNames;
}
public boolean existTable(String table) {
Connection conn = createConn();
String sql = "select count(*) as tableNum from sqlite_master where type='table' and name='" + table + "'";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
if (rs.getInt("tableNum") > 0)
return true;
else
return false;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return false;
}
public List<String> queryMRIds(String tableName) {
List<String> mRIDs = new LinkedList<>();
Connection conn = createConn();
String sql = "select mRID from " + tableName + " group by mRId";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
mRIDs.add(rs.getString("mRID"));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return mRIDs;
}
/**
* 查询开关对应的设备,或设备对应的开关,或公变对应的线路
* @param tableName
* @return
*/
public List<String[]> querySwToDev(String tableName, String mRID) {
List<String[]> mRIDNames = new LinkedList<>();
Connection conn = createConn();
String sql = "select devName2,mRID2 from " + tableName + " where mRID1='" + mRID + "'";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
String[] mRIDName = new String[2];
mRIDName[0] = rs.getString("devName2");
mRIDName[1] = rs.getString("mRID2");
mRIDNames.add(mRIDName);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return mRIDNames;
}
/**
* 查询变电站名称
* @param tableName 表名
* @return
*/
public String queryFeederName(String tableName) {
String feeder = null;
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
feeder = rs.getString("feeder");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return feeder;
}
/**
* 查询变电站名称
* @param tableName 表名
* @return
*/
public String querySubstationName(String tableName) {
String substation = null;
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
substation = rs.getString("substation");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return substation;
}
/**
* 按季节查询主线电流数据
* @param tableName 表名
* @param season 季节
* @return
*/
public List<LineCurrentData> queryLineCurrentData(String tableName, int season) {
List<LineCurrentData> lineCurrentDatas = new LinkedList<>();
Connection conn = createConn();
String sql;
if (season == 1)
sql = "select * from " + tableName + " where strftime('%m',date) >= '01' and strftime('%m',date) <= '03'";
else if (season == 2)
sql = "select * from " + tableName + " where strftime('%m',date) >= '04' and strftime('%m',date) <= '06'";
else if (season == 3)
sql = "select * from " + tableName + " where strftime('%m',date) >= '07' and strftime('%m',date) <= '09'";
else if (season == 4)
sql = "select * from " + tableName + " where strftime('%m',date) >= '10' and strftime('%m',date) <= '12'";
else
return lineCurrentDatas;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
LineCurrentData lineCurrentData = new LineCurrentData();
lineCurrentData.setData(rs.getTimestamp("date"));
lineCurrentData.setCurrent(rs.getDouble("current"));
lineCurrentDatas.add(lineCurrentData);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return lineCurrentDatas;
}
/**
* 按季节查询主线最大电流数据
* @param tableName 表名
* @param season 季节
* @param pointNum 一天的点数
* @return 一天的电流数据
*/
public double[] querySeasonLineI(String tableName, int season, int pointNum) {
double[] seasonLineI = new double[pointNum];
Connection conn = createConn();
String sql = "select * from " + tableName + " where season=" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
int count = 0;
while (rs.next() && count < pointNum) {
seasonLineI[count] = rs.getDouble("current");
count++;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return seasonLineI;
}
/**
* 按mRID和季节查询开关数据
* @param tableName 表名
* @param mRID
* @param season 季节
* @return
*/
public List<SwitchData> querySwitchData(String tableName, String mRID, int season) {
List<SwitchData> swDatas = new LinkedList<>();
Connection conn = createConn();
String sql;
if (season == 1)
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) >= '01' and strftime('%m',date) <= '03'";
else if (season == 2)
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) >= '04' and strftime('%m',date) <= '06'";
else if (season == 3)
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) >= '07' and strftime('%m',date) <= '09'";
else if (season == 4)
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) >= '10' and strftime('%m',date) <= '12'";
else
return swDatas;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
SwitchData swData = new SwitchData();
swData.setDevName(rs.getString("devName"));
swData.setmRID(mRID);
swData.setData(rs.getTimestamp("date"));
swData.setIa(rs.getDouble("Ia"));
swData.setIb(rs.getDouble("Ib"));
swData.setIc(rs.getDouble("Ic"));
swDatas.add(swData);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return swDatas;
}
/**
* 按mRID和月份查询开关数据
* @param tableName 表名
* @param mRID
* @param month 月份
* @return
*/
public List<SwitchData> querySwDataByMonth(String tableName, String mRID, int month) {
List<SwitchData> swDatas = new LinkedList<>();
Connection conn = createConn();
String sql;
if (month >= 1 && month <= 12) {
String monthStr = String.format("%02d", month);
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) = '" + monthStr + "'";
} else
return swDatas;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
SwitchData swData = new SwitchData();
swData.setDevName(rs.getString("devName"));
swData.setmRID(mRID);
swData.setData(rs.getTimestamp("date"));
swData.setIa(rs.getDouble("Ia"));
swData.setIb(rs.getDouble("Ib"));
swData.setIc(rs.getDouble("Ic"));
swDatas.add(swData);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return swDatas;
}
/**
* 按mRID和季节查询开关最大电流或聚类结果
* @param tableName 表名
* @param mRID mRID
* @param season 季节
* @return
*/
public double[] querySeasonSwitchI(String tableName, String mRID, int season, int pointNum) {
double[] seasonSwI = new double[pointNum];
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "' and season =" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
int count = 0;
while (rs.next() && count < pointNum) {
seasonSwI[count] = rs.getDouble("Ia");
count++;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
stmt.close();
} catch (SQLException e) {
}
}
return seasonSwI;
}
/**
* 按mRID查询开关最大电流
* @param tableName 表名
* @param mRID mRID
* @return
*/
public double queryMaxSwitchI(String tableName, String mRID, int season) {
double maxSwI = 10;
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "' and season =" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
int count = 0;
while (rs.next()) {
maxSwI = rs.getDouble("Ia");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
stmt.close();
} catch (SQLException e) {
}
}
return maxSwI;
}
/**
* 按mRID和季节查询公变数据
* @param tableName 表名
* @param mRID
* @param season 季节
* @return
*/
public List<TFData> queryTFData(String tableName, String mRID, int season) {
List<TFData> tfDatas = new LinkedList<>();
Connection conn = createConn();
String sql;
if (season == 1)
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) >= '01' and strftime('%m',date) <= '03'";
else if (season == 2)
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) >= '04' and strftime('%m',date) <= '06'";
else if (season == 3)
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) >= '07' and strftime('%m',date) <= '09'";
else if (season == 4)
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) >= '10' and strftime('%m',date) <= '12'";
else
return tfDatas;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
TFData tfData = new TFData();
tfData.setDevName(rs.getString("devName"));
tfData.setmRID(mRID);
tfData.setDate(rs.getTimestamp("date"));
tfData.setIa(rs.getDouble("Ia"));
tfData.setIb(rs.getDouble("Ib"));
tfData.setIc(rs.getDouble("Ic"));
tfData.setUa(rs.getDouble("Ua"));
tfData.setUb(rs.getDouble("Ub"));
tfData.setUc(rs.getDouble("Uc"));
tfDatas.add(tfData);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return tfDatas;
}
/**
* 按mRID和月份查询公变数据
* @param tableName 表名
* @param mRID
* @param month 季节
* @return
*/
public List<TFData> queryTFDataByMonth(String tableName, String mRID, int month) {
List<TFData> tfDatas = new LinkedList<>();
Connection conn = createConn();
String sql;
if (month >= 1 && month <= 12) {
String monthStr = String.format("%02d", month);
sql = "select * from " + tableName + " where mRID='" + mRID + "' and strftime('%m',date) = '" + monthStr + "'";
} else
return tfDatas;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
TFData tfData = new TFData();
tfData.setDevName(rs.getString("devName"));
tfData.setmRID(mRID);
tfData.setDate(rs.getTimestamp("date"));
tfData.setIa(rs.getDouble("Ia"));
tfData.setIb(rs.getDouble("Ib"));
tfData.setIc(rs.getDouble("Ic"));
tfData.setUa(rs.getDouble("Ua"));
tfData.setUb(rs.getDouble("Ub"));
tfData.setUc(rs.getDouble("Uc"));
tfDatas.add(tfData);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return tfDatas;
}
/**
* 按mRID查询公变最大负荷、最大电流
* @param tableName 表名
* @param mRID mRID
* @return
*/
public double queryMaxTFP(String tableName, String mRID, int season) {
double maxTFP = 50000;
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "' and season =" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
maxTFP = rs.getDouble("P");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
stmt.close();
} catch (SQLException e) {
}
}
return maxTFP;
}
/**
* 按mRID查询公变三相不平衡度
* @param tableName 表名
* @param mRID mRID
* @param season 季节
* @return
*/
public double[] queryTFUb(String tableName, String mRID, int season) {
double[] ubIU = new double[2];
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "' and season =" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
ubIU[0] = rs.getDouble("ubI2");
ubIU[1] = rs.getDouble("ubV2");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
stmt.close();
} catch (SQLException e) {
}
}
return ubIU;
}
/**
* 按mRID查询公变负荷接入相别
* @param tableName 表名
* @param mRID mRID
* @param season 季节
* @return
*/
public String queryMinIPhase(String tableName, String mRID, int season) {
int phaseInt = 0;
String phase = "a";
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "' and season =" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
phaseInt = rs.getInt("phase");
}
if (phaseInt == 1)
phase = "b";
if (phaseInt == 2)
phase = "c";
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
stmt.close();
} catch (SQLException e) {
}
}
return phase;
}
/**
* 查询设备名称、mRID
* @param tableName 表名
* @return
*/
public Map<String, String> queryNameToMRID(String tableName) {
Map<String, String> nameToMRID = new HashMap<>();
Connection conn = createConn();
String sql = "select devName, mRID from " + tableName + " group by devName";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
nameToMRID.put(rs.getString("devName"), rs.getString("mRID"));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return nameToMRID;
}
/**
* 查询公变容量
* @param tableName 表名
* @return
*/
public double queryTFCap(String tableName, String mRID) {
double cap = 400;
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "'";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
cap = rs.getDouble("ratedCap");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return cap;
}
/**
* 按mRID和季节查询公变最大负荷或聚类结果
* @param tableName 表名
* @param mRID mRID
* @param season 季节
* @return
*/
public double[] querySeasonTFP(String tableName, String mRID, int season, int pointNum) {
double[] seasonSwI = new double[pointNum];
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "' and season =" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
int count = 0;
while (rs.next() && count < pointNum) {
seasonSwI[count] = rs.getDouble("P");
count++;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
stmt.close();
} catch (SQLException e) {
}
}
return seasonSwI;
}
/**
* 按mRID和季节查询公变最大三相不平衡度或聚类结果
* @param tableName 表名
* @param mRID mRID
* @param season 季节
* @return
*/
public double[] querySeasonTFUb(String tableName, String mRID, int season, int pointNum) {
double[] seasonSwI = new double[pointNum];
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "' and season =" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
int count = 0;
while (rs.next() && count < pointNum) {
seasonSwI[count] = rs.getDouble("ubI2");
count++;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
stmt.close();
} catch (SQLException e) {
}
}
return seasonSwI;
}
/**
* 查询线路电流限值
* @param tableName 表名
* @return
*/
public List<LineParamData> queryLineParam(String tableName) {
List<LineParamData> lineParamDatas = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
LineParamData lineParamData = new LineParamData();
lineParamData.setDevName(rs.getString("devName"));
lineParamData.setPole1(rs.getString("pole1"));
lineParamData.setPole2(rs.getString("pole2"));
lineParamData.setRatedI(rs.getDouble("ratedCurrent"));
lineParamData.setType(rs.getInt("type"));
lineParamDatas.add(lineParamData);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return lineParamDatas;
}
/**
* 查询单线电流限值
* @param tableName 表名
* @return
*/
public double queryOneLineParam(String tableName, String mRID) {
double oneLineParam = 754;
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "'";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
oneLineParam = rs.getDouble("ratedCurrent");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return oneLineParam;
}
/**
* 查询单线夏季、冬季电流限值
* @param tableName 表名
* @return
*/
public double queryOneLineSeasonParam(String tableName, String mRID, int season) {
double oneLineParam = 754;
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "'";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
if (season == 1) {
oneLineParam = rs.getDouble("smRatedI");
} else {
oneLineParam = rs.getDouble("winRatedI");
}
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return oneLineParam;
}
/**
* 按mRID和季节查询开关或公变可接入容量
* @param tableName 表名
* @param mRID mRID
* @param season 季节
* @return
*/
public double[] queryAvailCap(String tableName, String mRID, int season, int pointNum) {
double[] availCap = new double[pointNum];
Connection conn = createConn();
String sql = "select * from " + tableName + " where mRID='" + mRID + "' and season =" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
int count = 0;
while (rs.next() && count < pointNum) {
availCap[count] = rs.getDouble("availCap");
count++;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
stmt.close();
} catch (SQLException e) {
}
}
return availCap;
}
/**
* 查询预警线路
* @param tableName 表名
* @return
*/
public List<WarnLine> queryWarnLine(String tableName) {
List<WarnLine> warnLines = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
WarnLine warnLine = new WarnLine();
warnLine.setLoadState(rs.getInt("loadState"));
warnLine.setDevName(rs.getString("devName"));
warnLine.setmRID(rs.getString("mRID"));
warnLine.setSubstation(rs.getString("substation"));
warnLine.setSwitchName(rs.getString("switchName"));
warnLine.setSwitchMRID(rs.getString("switchMRID"));
warnLine.setMaxI(rs.getDouble("maxI"));
warnLine.setRatedCurrent(rs.getDouble("ratedCurrent"));
warnLine.setLoadRate(rs.getDouble("loadRate"));
warnLines.add(warnLine);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return warnLines;
}
/**
* 查询按过载情况查询预警线路
* @param tableName 表名
* @return
*/
public int queryWarnLineCount(String tableName, int loadState) {
List<WarnLine> warnLines = new LinkedList<>();
Connection conn = createConn();
String sql = "select count(*) from " + tableName + " where loadState=" + loadState;
Statement stmt = null;
ResultSet rs = null;
int count=0;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
rs.next();
count = rs.getInt(1);
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return count;
}
/**
* 查询按过载情况查询预警线路
* @param tableName 表名
* @return
*/
public List<WarnLine> queryWarnLine(String tableName, int loadState,int page,int rows) {
List<WarnLine> warnLines = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName + " where loadState=" + loadState;
if(page>0 && rows>0){
sql +=" limit " + (page-1)*rows + "," + rows;
}
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
WarnLine warnLine = new WarnLine();
warnLine.setLoadState(rs.getInt("loadState"));
warnLine.setDevName(rs.getString("devName"));
warnLine.setmRID(rs.getString("mRID"));
warnLine.setSubstation(rs.getString("substation"));
warnLine.setSwitchName(rs.getString("switchName"));
warnLine.setSwitchMRID(rs.getString("switchMRID"));
warnLine.setMaxI(rs.getDouble("maxI"));
warnLine.setRatedCurrent(rs.getDouble("ratedCurrent"));
warnLine.setLoadRate(rs.getDouble("loadRate"));
warnLines.add(warnLine);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return warnLines;
}
/**
* 查询预警公变
* @param tableName 表名
* @return
*/
public List<WarnTf> queryWarnTf(String tableName) {
List<WarnTf> warnTfs = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
WarnTf warnTf = new WarnTf();
warnTf.setLoadState(rs.getInt("loadState"));
warnTf.setDevName(rs.getString("devName"));
warnTf.setmRID(rs.getString("mRID"));
warnTf.setLineName(rs.getString("lineName"));
warnTf.setLineMRID(rs.getString("lineMRID"));
warnTf.setSubstation(rs.getString("substation"));
warnTf.setMaxLoad(rs.getDouble("maxLoad"));
warnTf.setRatedCap(rs.getDouble("ratedCap"));
warnTf.setLoadRate(rs.getDouble("loadRate"));
warnTfs.add(warnTf);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return warnTfs;
}
/**
* 查询预警公变
* @param tableName 表名
* @return
*/
public int queryWarnTfCount(String tableName, int loadState) {
Connection conn = createConn();
String sql = "select count(*) from " + tableName + " where loadState=" + loadState;
Statement stmt = null;
ResultSet rs = null;
int count = 0;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
rs.next();
count = rs.getInt(1);
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return count;
}
/**
* 查询预警公变
* @param tableName 表名
* @return
*/
public List<WarnTf> queryWarnTf(String tableName, int loadState,int page,int rows) {
List<WarnTf> warnTfs = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName + " where loadState=" + loadState;
if(page>0 && rows>0){
sql +=" limit " + (page-1)*rows + "," + rows;
}
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
WarnTf warnTf = new WarnTf();
warnTf.setLoadState(rs.getInt("loadState"));
warnTf.setDevName(rs.getString("devName"));
warnTf.setmRID(rs.getString("mRID"));
warnTf.setLineName(rs.getString("lineName"));
warnTf.setLineMRID(rs.getString("lineMRID"));
warnTf.setSubstation(rs.getString("substation"));
warnTf.setMaxLoad(rs.getDouble("maxLoad"));
warnTf.setRatedCap(rs.getDouble("ratedCap"));
warnTf.setLoadRate(rs.getDouble("loadRate"));
warnTfs.add(warnTf);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return warnTfs;
}
/**
* 查询公变月三相不平衡度
* @param tableName 表名
* @return
*/
public List<TfUb> queryTfMonthUb(String tableName) {
List<TfUb> tfUbs = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
TfUb tfUb = new TfUb();
tfUb.setDevName(rs.getString("devName"));
tfUb.setmRID(rs.getString("mRID"));
tfUb.setLineName(rs.getString("lineName"));
tfUb.setLineMRID(rs.getString("lineMRID"));
tfUb.setSubstation(rs.getString("substation"));
tfUb.setMaxLoad(rs.getDouble("maxLoad"));
tfUb.setRatedCap(rs.getDouble("ratedCap"));
tfUb.setUb(rs.getDouble("ub"));
double[] monthUb = new double[30];
for (int i = 0; i < 30; i++) {
monthUb[i] = rs.getDouble("monthUb" + (i + 1));
}
tfUb.setMonthUb(monthUb);
tfUbs.add(tfUb);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return tfUbs;
}
/**
* 查询线路合格率
* @param tableName 表名
* @return
*/
public List<LinePassRate> queryLinePassRate(String tableName) {
List<LinePassRate> linePassRates = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
LinePassRate linePassRate = new LinePassRate();
linePassRate.setFeederName(rs.getString("feederName"));
linePassRate.setSubstation(rs.getString("substation"));
double[] passRate = new double[4];
passRate[0] = rs.getDouble("passRate1");
passRate[1] = rs.getDouble("passRate2");
passRate[2] = rs.getDouble("passRate3");
passRate[3] = rs.getDouble("passRate4");
linePassRate.setPassRate(passRate);
linePassRates.add(linePassRate);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return linePassRates;
}
/**
* 查询公变越限率
* @param tableName 表名
* @return
*/
public List<TfOverLoadRate> queryTfOverLoadRate(String tableName) {
List<TfOverLoadRate> tfOverLoadRates = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
TfOverLoadRate tfOverLoadRate = new TfOverLoadRate();
tfOverLoadRate.setFeederName(rs.getString("feederName"));
tfOverLoadRate.setDevName(rs.getString("devName"));
tfOverLoadRate.setmRID(rs.getString("mRID"));
tfOverLoadRate.setLineName(rs.getString("lineName"));
tfOverLoadRate.setLineMRID(rs.getString("lineMRID"));
tfOverLoadRate.setSubstation(rs.getString("substation"));
double[] overLoadRate = new double[4];
overLoadRate[0] = rs.getDouble("overLoadRate1");
overLoadRate[1] = rs.getDouble("overLoadRate2");
overLoadRate[2] = rs.getDouble("overLoadRate3");
overLoadRate[3] = rs.getDouble("overLoadRate4");
tfOverLoadRate.setOverLoadRate(overLoadRate);
tfOverLoadRates.add(tfOverLoadRate);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return tfOverLoadRates;
}
/**
* 按季节查询负荷接入分析结果总数
* @param tableName 表名
* @param season 季节
* @return
*/
public int queryLoadPosSeasonCount(String tableName, int season) {
Connection conn = createConn();
String sql;
sql = "select count(*) from " + tableName + " where season=" + season;
Statement stmt = null;
ResultSet rs = null;
int count = 0;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
rs.next();
count = rs.getInt(1);
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return count;
}
/**
* 按季节查询负荷接入分析结果总表
* @param tableName 表名
* @param season 季节
* @return
*/
public List<LoadPosSeason> queryLoadPosSeason(String tableName, int season,int page,int rows) {
List<LoadPosSeason> loadPosSeasons = new LinkedList<>();
Connection conn = createConn();
String sql;
sql = "select * from " + tableName + " where season=" + season;
if(page>0 && rows>0){
sql +=" limit " + (page-1)*rows + "," + rows;
}
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
LoadPosSeason loadPosSeason = new LoadPosSeason();
loadPosSeason.setLoadId(rs.getInt("loadId"));
loadPosSeason.setSubstation(rs.getString("substation"));
loadPosSeason.setFeederName(rs.getString("feederName"));
loadPosSeason.setCanIn(rs.getString("canIn"));
loadPosSeason.setTfName(rs.getString("tfName"));
loadPosSeason.setTfMRID(rs.getString("tfMRID"));
loadPosSeason.setPhase(rs.getString("phase"));
loadPosSeason.setTime(rs.getString("time"));
loadPosSeasons.add(loadPosSeason);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return loadPosSeasons;
}
/**
* 查询负荷接入分析结果总表中最大负荷Id
* @param tableName 表名
* @return
*/
public int queryMaxLoadId(String tableName) {
int maxLoadId = 0;
Connection conn = createConn();
String sql;
sql = "select max(loadId) as maxLoadId from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
maxLoadId = rs.getInt("maxLoadId");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return maxLoadId;
}
/**
* 按loadId和季节查询负荷接入开关分析结果
* @param tableName 表名
* @param loadId
* @param season 季节
* @return
*/
public LoadPosSw queryLoadPosSw(String tableName, int loadId, int season) {
LoadPosSw loadPosSw = new LoadPosSw();
Connection conn = createConn();
String sql;
sql = "select * from " + tableName + " where loadId='" + loadId + "' and season=" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
loadPosSw.setCanIn(rs.getString("canIn"));
loadPosSw.setSwName(rs.getString("swName"));
loadPosSw.setSwMRID(rs.getString("swMRID"));
double[] newLoadI = new double[96]; // 接入的负荷电流
double[] swOrgLoad = new double[96]; // 接入点开关原始负荷
double[] swNewLoad = new double[96]; // 接入后开关电流
double[] swRateI = new double[96]; // 接入点开关限额
String[] newLoadIStr = rs.getString("newLoadI").split(";");
String[] swOrgLoadStr = rs.getString("swOrgLoad").split(";");
String[] swNewLoadStr = rs.getString("swNewLoad").split(";");
double swRateIDouble = rs.getDouble("swRateI");
for (int i = 0; i < 96; i++) {
newLoadI[i] = Double.parseDouble(newLoadIStr[i]);
swOrgLoad[i] = Double.parseDouble(swOrgLoadStr[i]);
swNewLoad[i] = Double.parseDouble(swNewLoadStr[i]);
swRateI[i] = swRateIDouble;
}
loadPosSw.setNewLoadI(newLoadI);
loadPosSw.setSwOrgLoad(swOrgLoad);
loadPosSw.setSwNewLoad(swNewLoad);
loadPosSw.setSwRateI(swRateI);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return loadPosSw;
}
/**
* 按loadId和季节查询负荷接入公变分析结果
* @param tableName 表名
* @param loadId
* @param season 季节
* @return
*/
public LoadPosTf queryLoadPosTf(String tableName, int loadId, int season) {
LoadPosTf loadPosTf = new LoadPosTf();
Connection conn = createConn();
String sql;
sql = "select * from " + tableName + " where loadId='" + loadId + "' and season=" + season;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
loadPosTf.setCanIn(rs.getString("canIn"));
loadPosTf.setTfName(rs.getString("tfName"));
loadPosTf.setTfMRID(rs.getString("tfMRID"));
loadPosTf.setPhase(rs.getString("phase"));
double[] newLoad = new double[96]; // 接入的负荷电流
double[] tfOrgLoad = new double[96]; // 接入点开关原始负荷
double[] tfNewLoad = new double[96]; // 接入后开关电流
double[] tfRateCap = new double[96]; // 接入点开关限额
String[] newLoadStr = rs.getString("newLoad").split(";");
String[] tfOrgLoadStr = rs.getString("tfOrgLoad").split(";");
String[] tfNewLoadStr = rs.getString("tfNewLoad").split(";");
double tfRateCapDouble = rs.getDouble("tfRateCap");
for (int i = 0; i < 96; i++) {
newLoad[i] = Double.parseDouble(newLoadStr[i]);
tfOrgLoad[i] = Double.parseDouble(tfOrgLoadStr[i]);
tfNewLoad[i] = Double.parseDouble(tfNewLoadStr[i]);
tfRateCap[i] = tfRateCapDouble;
}
loadPosTf.setNewLoad(newLoad);
loadPosTf.setTfOrgLoad(tfOrgLoad);
loadPosTf.setTfNewLoad(tfNewLoad);
loadPosTf.setTfRateCap(tfRateCap);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return loadPosTf;
}
/**
* 查询所有馈线名称
* @param tableName 表名
* @return
*/
public List<String> queryAllFeederName(String tableName) {
List<String> feederNames = new LinkedList<>();
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
feederNames.add(rs.getString("feederName"));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return feederNames;
}
/**
* 查询所有馈线id和名称对应关系
* @param tableName 表名
* @return
*/
public FeederNameId queryAllFeederNameId(String tableName) {
FeederNameId feederNameId = new FeederNameId();
Connection conn = createConn();
String sql = "select * from " + tableName;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
String id = rs.getString("feederId");
String name = rs.getString("feederName");
feederNameId.feederIdToName.put(id, name);
feederNameId.feederNameToId.put(name, id);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return feederNameId;
}
/**
* 按照过载类型和设备类型,查询预警设备数量
* @param tableName 表名
* @return
*/
public int queryWarnDevNum(String tableName, int loadState, int devType) {
int warnDevNum = 0;
Connection conn = createConn();
String sql = "select * from " + tableName + " where loadState='" + loadState + "' and type=" + devType;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
warnDevNum = rs.getInt("number");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return warnDevNum;
}
/**
* 查询可开放容量最大和最小两条线路
* @param tableName 表名
* @return
*/
public MaxMinAvailCap queryMaxMinAvailCap(String tableName, int maxOrMin) {
MaxMinAvailCap maxMinAvailCap = new MaxMinAvailCap();
Connection conn = createConn();
String sql = "select * from " + tableName + " where maxOrMin=" + maxOrMin;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
maxMinAvailCap.feederName = rs.getString("feederName");
maxMinAvailCap.availCap = rs.getDouble("availCap");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
} catch (SQLException e) {
}
}
return maxMinAvailCap;
}
}
package com.jinyun.cap;
import java.sql.Timestamp;
public class SwitchData {
String devName;
String mRID;
Timestamp data;
double Ia;
double Ib;
double Ic;
public void setDevName(String devName) {
this.devName = devName;
}
public String getDevName() {
return devName;
}
public void setmRID(String mRID) {
this.mRID = mRID;
}
public String getmRID() {
return mRID;
}
public void setData(Timestamp data) {
this.data = data;
}
public Timestamp getData() {
return data;
}
public void setIa(double ia) {
Ia = ia;
}
public double getIa() {
return Ia;
}
public void setIb(double ib) {
Ib = ib;
}
public double getIb() {
return Ib;
}
public void setIc(double ic) {
Ic = ic;
}
public double getIc() {
return Ic;
}
}
package com.jinyun.cap;
import java.sql.Timestamp;
public class TFData {
String devName;
String mRID;
Timestamp date;
double Ia;
double Ib;
double Ic;
double Ua;
double Ub;
double Uc;
public void setDevName(String devName) {
this.devName = devName;
}
public String getDevName() {
return devName;
}
public void setmRID(String mRID) {
this.mRID = mRID;
}
public String getmRID() {
return mRID;
}
public void setDate(Timestamp date) {
this.date = date;
}
public Timestamp getDate() {
return date;
}
public void setIa(double ia) {
Ia = ia;
}
public double getIa() {
return Ia;
}
public void setIb(double ib) {
Ib = ib;
}
public double getIb() {
return Ib;
}
public void setIc(double ic) {
Ic = ic;
}
public double getIc() {
return Ic;
}
public void setUa(double ua) {
Ua = ua;
}
public double getUa() {
return Ua;
}
public void setUb(double ub) {
Ub = ub;
}
public double getUb() {
return Ub;
}
public void setUc(double uc) {
Uc = uc;
}
public double getUc() {
return Uc;
}
}
package com.jinyun.cap;
public class TfOverLoadRate {
String feederName;
String devName;
String mRID;
String lineName;
String lineMRID;
String substation;
double[] overLoadRate;
public String getFeederName() {
return feederName;
}
public void setFeederName(String feederName) {
this.feederName = feederName;
}
public String getDevName() {
return devName;
}
public void setDevName(String devName) {
this.devName = devName;
}
public String getmRID() {
return mRID;
}
public void setmRID(String mRID) {
this.mRID = mRID;
}
public String getSubstation() {
return substation;
}
public void setSubstation(String substation) {
this.substation = substation;
}
public String getLineName() {
return lineName;
}
public void setLineName(String lineName) {
this.lineName = lineName;
}
public String getLineMRID() {
return lineMRID;
}
public void setLineMRID(String lineMRID) {
this.lineMRID = lineMRID;
}
public double[] getOverLoadRate() {
return overLoadRate;
}
public void setOverLoadRate(double[] overLoadRate) {
this.overLoadRate = overLoadRate;
}
}
package com.jinyun.cap;
public class TfUb {
int loadState;
String devName;
String mRID;
String lineName;
String lineMRID;
String substation;
double maxLoad;
double ratedCap;
double ub;
double[] monthUb;
public int getLoadState() {
return loadState;
}
public void setLoadState(int loadState) {
this.loadState = loadState;
}
public String getDevName() {
return devName;
}
public void setDevName(String devName) {
this.devName = devName;
}
public String getmRID() {
return mRID;
}
public void setmRID(String mRID) {
this.mRID = mRID;
}
public String getSubstation() {
return substation;
}
public void setSubstation(String substation) {
this.substation = substation;
}
public String getLineName() {
return lineName;
}
public void setLineName(String lineName) {
this.lineName = lineName;
}
public String getLineMRID() {
return lineMRID;
}
public void setLineMRID(String lineMRID) {
this.lineMRID = lineMRID;
}
public double getMaxLoad() {
return maxLoad;
}
public void setMaxLoad(double maxLoad) {
this.maxLoad = maxLoad;
}
public double getRatedCap() {
return ratedCap;
}
public void setRatedCap(double ratedCap) {
this.ratedCap = ratedCap;
}
public double getUb() {
return ub;
}
public void setUb(double ub) {
this.ub = ub;
}
public double[] getMonthUb() {
return monthUb;
}
public void setMonthUb(double[] monthUb) {
this.monthUb = monthUb;
}
}
package com.jinyun.cap;
public class WarnLine {
int loadState;
String devName;
String mRID;
String substation;
String switchName;
String switchMRID;
double maxI;
double ratedCurrent;
double loadRate;
public int getLoadState() {
return loadState;
}
public void setLoadState(int loadState) {
this.loadState = loadState;
}
public String getDevName() {
return devName;
}
public void setDevName(String devName) {
this.devName = devName;
}
public String getmRID() {
return mRID;
}
public void setmRID(String mRID) {
this.mRID = mRID;
}
public String getSubstation() {
return substation;
}
public void setSubstation(String substation) {
this.substation = substation;
}
public String getSwitchName() {
return switchName;
}
public void setSwitchName(String switchName) {
this.switchName = switchName;
}
public String getSwitchMRID() {
return switchMRID;
}
public void setSwitchMRID(String switchMRID) {
this.switchMRID = switchMRID;
}
public double getMaxI() {
return maxI;
}
public void setMaxI(double maxI) {
this.maxI = maxI;
}
public double getRatedCurrent() {
return ratedCurrent;
}
public void setRatedCurrent(double ratedCurrent) {
this.ratedCurrent = ratedCurrent;
}
public double getLoadRate() {
return loadRate;
}
public void setLoadRate(double loadRate) {
this.loadRate = loadRate;
}
}
package com.jinyun.cap;
public class WarnTf {
int loadState;
String devName;
String mRID;
String lineName;
String lineMRID;
String substation;
double maxLoad;
double ratedCap;
double loadRate;
public int getLoadState() {
return loadState;
}
public void setLoadState(int loadState) {
this.loadState = loadState;
}
public String getDevName() {
return devName;
}
public void setDevName(String devName) {
this.devName = devName;
}
public String getmRID() {
return mRID;
}
public void setmRID(String mRID) {
this.mRID = mRID;
}
public String getSubstation() {
return substation;
}
public void setSubstation(String substation) {
this.substation = substation;
}
public String getLineName() {
return lineName;
}
public void setLineName(String lineName) {
this.lineName = lineName;
}
public String getLineMRID() {
return lineMRID;
}
public void setLineMRID(String lineMRID) {
this.lineMRID = lineMRID;
}
public double getMaxLoad() {
return maxLoad;
}
public void setMaxLoad(double maxLoad) {
this.maxLoad = maxLoad;
}
public double getRatedCap() {
return ratedCap;
}
public void setRatedCap(double ratedCap) {
this.ratedCap = ratedCap;
}
public double getLoadRate() {
return loadRate;
}
public void setLoadRate(double loadRate) {
this.loadRate = loadRate;
}
}
package com.jinyun.cap;
import org.jgrapht.UndirectedGraph
import org.jgrapht.graph.SimpleGraph
import org.jgrapht.graph.Subgraph
import zju.devmodel.MapObject
import zju.dsmodel.DistriSys
import zju.dsmodel.DsDevices
import zju.dsmodel.DsModelCons
import zju.dsmodel.DsTopoNode
import zju.measure.DiscreteInfo
import zju.measure.MeasureInfo
import java.util.*
/**
* 缙云电网的cim文件有以下几个问题:
* 1. 没有TransformerWinding,而PowerTransformer被看成是ConductingEquipment,具有两个端子
* 2. 没有发电机,在判断是否是有源是通过是否有变压器设备代替
* 3. 电源点无法确定
* @date 2021/6/30.
*/
class JyPowerSystem(val sourceStationNames : Array<String>) : PowerSystem() {
var passed : Boolean = true
var errorId : String? = null
inner class JyMeasureProvider : MeasureProvider {
override fun getAnalogValue(measId: String, dataSource: String): Double? {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getDiscreteValue(measId: String, dataSource: String): Int? {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getAnalogsOfEquip(equip: String, dataSource: String): List<MeasureInfo> {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getDiscreteOfEquip(equip: String, dataSource: String): DiscreteInfo {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun setResourceManager(resourceManager: PowerSystem) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getSwitchStatus(switchId: String, dataSource: String): Boolean {
val dev = getResource(switchId)
val r = dev?.getProperty("NORMALOPEN")?.toBoolean()
if (r == null)
return true
else
return r
}
}
init {
this.measureProvider = JyMeasureProvider()
}
constructor() : this(emptyArray())
fun getNodeType(v: TN): Int {
var nodeType = DsTopoNode.TYPE_LINK
for (cn in v.cns) {
if (sourceCns.contains(cn))
return DsTopoNode.TYPE_SUB
val shuntEquips = getShuntEquips(cn)
if (!shuntEquips.isEmpty()) {
assert(shuntEquips.size == 1 && (shuntEquips[0].type == "ENERGYCONSUMER" || shuntEquips[0].type == "POWERTRANSFORMER"))
nodeType = DsTopoNode.TYPE_PQ
}
}
return nodeType
}
val simpledIslands = LinkedList<UndirectedGraph<TN, Edge>>()
val activeIslands = LinkedList<UndirectedGraph<String, Edge>>()
override fun filterDevices() {
try {
if (sourceCns.size == 0) {
// 搜索电源相关的CN
val substations = classToList["SUBSTATION"]?.filter { it.getProperty("NAME") != null && sourceStationNames.contains(it.getProperty("NAME").substringAfter("kV")) }
assert(substations?.size == sourceStationNames.size)
val substationIds = LinkedList<String>()
substations!!.forEach { substationIds.add(it.id) }
// val sourceBus = classToList["BUSBARSECTION"]?.filter { substationIds.contains(it.getProperty("MEMBEROF_EQUIPMENTCONTAINER")) }
val sourceBus = classToList["BUSBARSECTION"]?.filter { substationIds.contains(it.getProperty("EQUIPMENTCONTAINER")) }
sourceBus!!.forEach {
if (getTerminalsOfEquip(it).isEmpty()) {
passed = false
errorId = it.id
return
}
val cn = getCNOfTerminal(getTerminalsOfEquip(it)[0])!!.id
if (!sourceCns.contains(cn))
sourceCns.add(cn)
}
}
super.filterDevices()
} catch (e : Exception) {
e.printStackTrace()
return
}
}
override fun extraFilterDevices(graphes : MutableList<Subgraph<String, Edge, *>>) {
var aclineNum = 0
var switchNum = 0
var transformerNum = 0
var i = 1
for (g in graphes) {
var aclineNum2 = 0
var switchNum2 = 0
var transformerNum2 = 0
val cnInGraph = g.vertexSet().filterNot { it.endsWith(suffixOfAddedCn) }
cnInGraph.forEach { obj -> getTerminalsOfCN(getResource(obj)!!).map { getEquipOfTerminal(it) }.forEach {
if (it?.type == "ACLINESEGMENT") {
if (getTerminalsOfEquip(it!!).size == 1) {
aclineNum2 += 2
} else {
aclineNum2++
}
} else if (it?.type == "POWERTRANSFORMER") {
if (getTerminalsOfEquip(it!!).size == 1) {
transformerNum2 += 2
} else {
transformerNum2++
}
} else if (it != null && isSwitch(it)) {
if(getTerminalsOfEquip(it).size == 1) {
switchNum2 += 6
} else if(getTerminalsOfEquip(it).size == 3) {
switchNum2 += 2
} else {
switchNum2 += 3
}
}
}}
aclineNum2 /= 2
switchNum2 /= 6
transformerNum2 /= 2
aclineNum += aclineNum2
switchNum += switchNum2
transformerNum += transformerNum2
println("====================== " + i++ + " th island information =======================")
println("There are $aclineNum2 ac lines.")
println("There are $switchNum2 switches.")
println("There are $transformerNum2 transformers.")
}
aclines = HashMap<String, MapObject>(aclineNum)
switches = HashMap<String, MapObject>(switchNum)
transformers = HashMap<String, MapObject>(transformerNum)
for (g in graphes)
g.vertexSet().filterNot { it.endsWith(suffixOfAddedCn) }.forEach { cn -> getTerminalsOfCN(getResource(cn)!!)
.mapNotNull { getEquipOfTerminal(it) }
.forEach {
if(it.type == "ACLINESEGMENT") {
if (!aclines!!.containsKey(it.id))
aclines!!.put(it.id, it)
} else if(it.type == "POWERTRANSFORMER") {
if (!transformers!!.containsKey(it.id))
transformers!!.put(it.id, it)
} else if (isSwitch(it)) {
if (!switches!!.containsKey(it.id))
switches!!.put(it.id, it)
}
}
}
}
fun createActiveIslands() {
for (island in activeSubgraphes) {
val g = SimpleGraph<String, Edge>(Edge::class.java)
island.vertexSet().forEach {
g.addVertex(it)
}
island.edgeSet().forEach {
g.addEdge(island.getEdgeSource(it), island.getEdgeTarget(it), it)
}
activeIslands.add(g)
}
}
/**
* 生成计算模型
*/
fun createCalMode(): List<DistriSys> {
val result = ArrayList<DistriSys>(simpledIslands.size)
try {
var j = 1
// 网络简化之后的结果
for (island in simpledIslands) {
val devices = DsDevices()
devices.initialLists()
val vertexSet = island.vertexSet().toList()
for (i in 1..vertexSet.size) {
val v = vertexSet[i - 1]
if (getNodeType(v) == DsTopoNode.TYPE_PQ) {
v.id = "Load_$i" // 设置id
// 开始填充设备
val load = MapObject()
load.id = v.cns[0]
load.setProperty(DsModelCons.KEY_CONNECTED_NODE, v.id)
devices.spotLoads.add(load)
} else if (getNodeType(v) == DsTopoNode.TYPE_SUB) {
v.id = "SRC_$i" // 设置id
} else
v.id = "LINK_$i" // 设置id
}
// 处理边
island.edgeSet().forEach {
val tn1 = island.getEdgeSource(it)
val tn2 = island.getEdgeTarget(it)
// 支路只有开关类型
val sw = MapObject()
sw.id = tn1.id + "-" + tn2.id
sw.setProperty(DsModelCons.KEY_RESOURCE_TYPE, DsModelCons.RESOURCE_SWITCH)
sw.setProperty(DsModelCons.KEY_CONNECTED_NODE, tn1.id + ";" + tn2.id)
devices.switches.add(sw)
}
val r = DistriSys()
r.buildOrigTopo(devices)
result.add(r)
j++
}
} catch (e : Exception) {
e.printStackTrace()
}
return result
}
/**
* 简化网络
*/
fun doSimplification() {
try {
transformers!!.values.forEach { assert(getTerminalsOfEquip(it).size == 2) }
// origGraph.edgeSet().forEach {
// if(it.equips.size != 1)
// print("hh")
// assert(it.equips.size == 1)
// }
origGraph.edgeSet().forEach {
if (getResource(it.equips[0]) != null)
assert(isSwitch(getResource(it.equips[0])!!) || isConnEquip(getResource(it.equips[0])))
else
assert(isSwitch(getResource(it.equips[0].substring(0, it.equips[0].length - 3))!!))
}
for (island in activeSubgraphes) {
val cnToTN = HashMap<String, TN>(island.vertexSet().size)
val g = SimpleGraph<TN, Edge>(Edge::class.java)
island.vertexSet().forEach {
val tn = TN()
tn.cns.add(it)
cnToTN[it] = tn
g.addVertex(tn)
}
island.edgeSet().forEach {
val edge = Edge()
edge.equips.addAll(it.equips)
g.addEdge(cnToTN[island.getEdgeSource(it)], cnToTN[island.getEdgeTarget(it)], edge)
}
// todo: 去除没有电源的负荷
// 合并所有连在一起的AclineSegment
val feederEdges = g.edgeSet().filter { it.equips.all { isConnEquip(getResource(it)) } }
feederEdges.forEach {
if (g.edgeSet().contains(it)) {
val v1 = g.getEdgeSource(it)
val v2 = g.getEdgeTarget(it)
mergeTwoVertex(g, v1, v2)
}
}
//找出来开关对应的支路
// val switchEdges = g.edgeSet().filter {
// it.equips.size == 1 && (isSwitch(it.equips[0])
// || isSwitch(it.equips[0].substring(0, it.equips[0].length - 3)))
// }
// for (e in switchEdges) {
// if (!g.containsEdge(e))
// continue
// val v1 = g.getEdgeSource(e)
// val v2 = g.getEdgeTarget(e)
// if (v1 == null || v2 == null)
// continue
// g.removeEdge(e)
// val inspector = ConnectivityInspector(g)
// val graphs = inspector.connectedSets() //获得连通子图
// // 如果网络没有分裂
// if (graphs.size != 2) {
// g.addEdge(v1, v2, e)
// continue
// }
// // 网络分裂成两个, 下面两种情况需要处理
// // 1. 其中之一是无源的包含负荷的子网,合并节点
// // 2. 其中之一是无源的不包含负荷的子网,删除即可
// var needAdd = true
// for (subV in graphs) {
// var isNoSource = true
// var isNoLoad = true
// subV.map { getNodeType(it) }.forEach {
// if (it == DsTopoNode.TYPE_DG || it == DsTopoNode.TYPE_SUB) {
// isNoSource = false
// return@forEach
// } else if (it == DsTopoNode.TYPE_PQ) {
// isNoLoad = false
// }
// }
// if (isNoSource) {
// if (!isNoLoad) {//需要合并
// g.addEdge(v1, v2, e)
// mergeTwoVertex(g, v1, v2)
// needAdd = false
// break
// } else {//删除子图
//// subV.forEach { g.removeVertex(it) }
//// needAdd = false
//// break
// }
// }
// }
// if (needAdd)
// g.addEdge(v1, v2, e)
// }
// 删除只和两条支路连接的LinkNode
var isFinish = false
while (!isFinish) {
isFinish = true
val linkNodes = g.vertexSet().filter { getNodeType(it) == DsTopoNode.TYPE_LINK && g.edgesOf(it).size == 2 }
linkNodes.forEach {
val edges = g.edgesOf(it).toList()
val v1: TN
val v2: TN
v1 = if (g.getEdgeSource(edges[0]) == it)
g.getEdgeTarget(edges[0])
else
g.getEdgeSource(edges[0])
v2 = if (g.getEdgeSource(edges[1]) == it)
g.getEdgeTarget(edges[1])
else
g.getEdgeSource(edges[1])
g.removeVertex(it)
val edge = Edge()
// 将所有设备都与该边联系在一起
edge.equips.addAll(edges[0].equips)
edge.equips.addAll(edges[1].equips)
g.addEdge(v1, v2, edge)
isFinish = false
}
}
simpledIslands.add(g)
}
} catch (e : Exception) {
e.printStackTrace()
}
}
private fun mergeTwoVertex(g: SimpleGraph<TN, Edge>, v1: TN, v2: TN) {
val edgesOfV2 = g.edgesOf(v2).toList()
edgesOfV2.forEach {
val anotherV: TN = if (v2 == g.getEdgeSource(it)) {
g.getEdgeTarget(it)
} else
g.getEdgeSource(it)
g.removeEdge(it)
if (v1 == anotherV)
return@forEach
val e = g.getEdge(v1, anotherV)
if (e != null) {
if(it.equips.all { isConnEquip(getResource(it)) })
return@forEach
else
e.equips.addAll(it.equips)
} else
g.addEdge(v1, anotherV, it)
}
v1.cns.addAll(v2.cns)
g.removeVertex(v2)
}
override fun getShuntEquips(cn: MapObject): List<MapObject> {
val l = LinkedList<MapObject>()
getTerminalsOfCN(cn).forEach {
val equip = getEquipOfTerminal(it)
if (equip != null) {
if (shuntEquipTypes.contains(equip.type) || equip.type == "POWERTRANSFORMER")
l.add(equip)
}
}
return l
}
fun clearSimpledIslands() {
simpledIslands.clear()
}
fun isConnEquip(obj : MapObject?) : Boolean {
return obj?.type == "ACLINESEGMENT" || obj?.type == "CONNLINE" || obj?.type == "POWERTRANSFORMER"
}
}
package com.jinyun.cap;
import zju.measure.DiscreteInfo
import zju.measure.MeasureInfo
/**
* 提供量测数据的接口
* @date 17-1-8.
*/
interface MeasureProvider {
fun getAnalogValue(measId: String, dataSource: String): Double?
fun getDiscreteValue(measId: String, dataSource: String): Int?
fun getAnalogsOfEquip(equip: String, dataSource: String): List<MeasureInfo>
fun getDiscreteOfEquip(equip: String, dataSource: String): DiscreteInfo?
fun setResourceManager(resourceManager: PowerSystem)
fun getSwitchStatus(switchId: String, dataSource: String): Boolean
}
\ No newline at end of file
package com.jinyun.cap;
import org.jgrapht.UndirectedGraph
import org.jgrapht.alg.ConnectivityInspector
import org.jgrapht.graph.SimpleGraph
import org.jgrapht.graph.Subgraph
import org.xml.sax.Attributes
import org.xml.sax.SAXException
import org.xml.sax.helpers.DefaultHandler
import zju.devmodel.MapObject
import zju.measure.MeasureInfo
import java.io.InputStream
import java.util.*
import javax.xml.parsers.SAXParserFactory
class TN(var id : String = "", val cns : LinkedList<String> = LinkedList())
class Edge(val equips : LinkedList<String> = LinkedList(), var limI : Double = 754.0, var type : Int = 1)
/**
* 该类用于管理电网资源(MapObject)的方法
* @date 17-1-8.
*/
open class PowerSystem {
companion object {
val switchTypes = arrayOf("BREAKER", "DISCONNECTOR", "FUSE", "GROUNDDISCONNECTOR", "COMPOSITESWITCH",
"JUMPER", "LOADBREAKSWITCH")
val conductingEquipTypes = arrayOf("ACLINESEGMENT", "TRANSFORMERWINDING", "BUSBARSECTION", "ENERGYCONSUMER",
"SYNCHRONOUSMACHINE", "SERIESCOMPENSATOR", "SHUNTCOMPENSATOR", "DCLINESEGMENT", "JUNCTION", "CONNLINE",
"POWERTRANSFORMER")
val shuntEquipTypes = arrayOf("ENERGYCONSUMER", "SYNCHRONOUSMACHINE", "SHUNTCOMPENSATOR")
val suffixOfAddedCn = "-neutral"
val minIslandSize = 5
}
val classToList = HashMap<String, MutableList<MapObject>>()
private var idToObject: MutableMap<String, MapObject> = HashMap()
// val assetIdToObject: MutableMap<String, MapObject> = HashMap()
val poleNameToCn: MutableMap<String, String> = HashMap()
// 主要的电力系统资源
var generators: MutableMap<String, MapObject>? = null
var loads: MutableMap<String, MapObject>? = null
var busbars: MutableMap<String, MapObject>? = null
var shuntCompensators: MutableMap<String, MapObject>? = null
var seriesCompensators: MutableMap<String, MapObject>? = null
var aclines: MutableMap<String, MapObject>? = null
var connlines: MutableMap<String, MapObject>? = null
var windings: MutableMap<String, MapObject>? = null
var switches: MutableMap<String, MapObject>? = null
var transformers: MutableMap<String, MapObject>? = null
// 需要的CN
var cns: MutableMap<String, MapObject>? = null
// 量测
var analogs: MutableMap<String, MapObject>? = null
var discretes: MutableMap<String, MapObject>? = null
var equipMeasurements: MutableMap<String, List<MeasureInfo>>? = null
//过滤量测和拓扑分析时需要用到该类
var measureProvider : MeasureProvider? = null
//量测来源
var dataSource = CimConstants.MEASURE_VALUE_SOURCE_SCADA
// 表明电力系统资源是否添加完毕,一旦完毕无法在添加
var isInitial = false
// 原始的有源拓扑岛
val origGraph = SimpleGraph<String, Edge>(Edge::class.java)
val activeSubgraphes: MutableList<Subgraph<String, Edge, *>> = LinkedList()
// 电源所在的ConnectivityNode
var sourceCns = LinkedList<String>()
fun getResourceByClassId(aClass: String): List<MapObject> {
classToList.putIfAbsent(aClass, ArrayList<MapObject>(0))
return classToList[aClass]!!
}
fun getResource(obj: String): MapObject? {
return idToObject[obj]
}
/**
* 从CIM XML中导入电网资源
*/
fun loadFromCimXML(input : InputStream) {
// step 1: 获得SAX解析器工厂实例
val factory = SAXParserFactory.newInstance()
// step 2: 获得SAX解析器实例
val parser = factory.newSAXParser()
// step 3: 开始进行解析
// 传入待解析的文档的处理器
parser.parse(input, CimXmlHandler())
}
/**
* 添加设备,所有设备添加结束之后应该调用endAddPSR方法
*/
fun addPSR(obj : MapObject) {
if(isInitial)
throw Exception("Power system is already initialed, new resource can not be added anymore.")
if(obj.id == null || obj.id.trim() == "") {
System.err.println("Illegal id of power system resource, id can not be null, this obj will not be added.")
System.err.println(obj.toString())
return
}
val isExist = idToObject.containsKey(obj.id)
if(!isExist) { // 同一个对象不能addPSR两次,否则这里添加不进去
idToObject.put(obj.id, obj)
if (obj.type == null || obj.type.trim() == "") {
print("!!No type is found for power system resource whose id is ${obj.id}")
return
}
if (!classToList.containsKey(obj.type))
classToList.put(obj.type, LinkedList<MapObject>())
classToList[obj.type]!!.add(obj)
// if (obj.getProperty("ASSETS") != null)
// assetIdToObject[obj.getProperty("ASSETS")] = obj
}
}
open fun endAddPSR() {
if(isInitial)
throw Exception("Power system is already initialed.")
isInitial = true
// 处理容器
idToObject.values.forEach {
val keys = it.properties.keys.filter { it.startsWith("MEMBEROF_") }
if(keys.size == 1) {
val r = idToObject[it.properties[keys[0]]]
if(r != null)
it.containerId = r.id
}
}
// 处理Terminal和ConnectivityNode之间的关系
val keys = arrayOf("CONDUCTINGEQUIPMENT","CONNECTIVITYNODE")
classToList["TERMINAL"]?.forEach {
// 处理1对多的关系
for(key in keys) {
val r = idToObject[it.properties[key]]
if (r != null) {
val s = r.properties[it.type]
if (s == null)
r.properties[it.type] = it.id
else
r.properties[it.type] = s + ";" + it.id
}
}
}
// 处理TransformerWinding与PowerTransformer之间的关系
classToList["TRANSFORMERWINDING"]?.forEach {
// 处理1对多的关系
val r = idToObject[it.properties["MEMBEROF_POWERTRANSFORMER"]]
if (r != null) {
val s = r.properties[it.type]
if (s == null)
r.properties[it.type] = it.id
else
r.properties[it.type] = s + ";" + it.id
}
}
// 结束之后开始过滤没有必要分析的设备
filterDevices()
}
private fun getObjectList(obj : MapObject, propertyName : String) : List<MapObject> {
val terminals = obj.properties[propertyName]
val l = LinkedList<MapObject>()
if(terminals != null) {
terminals.split(";").forEach {
val t = idToObject[it]
if(t != null)
l.add(t)
}
}
return l
}
fun getShuntEquips(cn : String) : List<MapObject> {
val node = getResource(cn)
if(node == null) return LinkedList()
else return getShuntEquips(node)
}
open fun getShuntEquips(cn : MapObject) : List<MapObject> {
val l = LinkedList<MapObject>()
getTerminalsOfCN(cn).forEach {
val equip = getEquipOfTerminal(it)
if(equip != null) {
if(shuntEquipTypes.contains(equip.type))
l.add(equip)
}
}
return l
}
fun getTerminalsOfEquip(obj : MapObject) : List<MapObject> {
return getObjectList(obj, "TERMINAL")
}
fun getCNOfTerminal(t: MapObject) : MapObject? {
val cnId = t.getProperty("CONNECTIVITYNODE")
if(cnId == null) {
println("!!No connectivy id of terminal ${t.id} is found.")
return null
} else
return getResource(cnId)
}
fun getTerminalsOfCN(cn : MapObject) : List<MapObject> {
return getObjectList(cn, "TERMINAL")
}
fun getEquipOfTerminal(t : MapObject) : MapObject? {
return getResource(t.getProperty("CONDUCTINGEQUIPMENT"))
}
fun getWindingsOfTf(transformer: MapObject) : List<MapObject> {
return getObjectList(transformer, "TRANSFORMERWINDING")
}
fun getTfOfWinding(winding : MapObject) : MapObject? {
return getResource(winding.getProperty("MEMBEROF_POWERTRANSFORMER"))
}
fun isSwitch(id : String) : Boolean {
val sw = getResource(id)
return sw != null && isSwitch(sw)
}
fun isSwitch(obj : MapObject) : Boolean {
return switchTypes.any { obj.type.toUpperCase() == it.toUpperCase() }
}
fun getAllSwitch() : List<MapObject> {
val r = LinkedList<MapObject>()
switchTypes.mapNotNull { classToList[it] }.forEach { r.addAll(it) }
return r
}
open fun getConductingEquips() : MutableList<MapObject> {
val r = LinkedList<MapObject>()
switchTypes.mapNotNull { classToList[it] }.forEach { r.addAll(it) }
conductingEquipTypes.mapNotNull { classToList[it] }.forEach { r.addAll(it) }
return r
}
fun isActiveCn(cn : String) : Boolean {
if(cn.endsWith(suffixOfAddedCn))
return false
getTerminalsOfCN(getResource(cn)!!)
// 判断是否是有电源的
.filter { getEquipOfTerminal(it)?.type == "SYNCHRONOUSMACHINE" }
.forEach { return true }
return false
}
fun isActive(subVertexes : Set<String>) : Boolean {
if(subVertexes.size < minIslandSize)
return false
@Suppress("LoopToCallChain")
for (cn in subVertexes) {
if(sourceCns.contains(cn))
return true
}
return false
}
open fun buildGraph() : MutableList<Subgraph<String, Edge, *>> {
try {
// 清空所有定点
origGraph.vertexSet().toList().forEach { origGraph.removeVertex(it) }
for (obj in getResourceByClassId("CONNECTIVITYNODE"))
origGraph.addVertex(obj.id)
for (obj in getConductingEquips()) {
val terminals = getTerminalsOfEquip(obj)
if (terminals.size != 2)
continue
if (isSwitch(obj) and (obj.getProperty("OPEN") == "true"))
continue
val cn1 = getCNOfTerminal(terminals[0])
val cn2 = getCNOfTerminal(terminals[1])
if (cn1 == null || cn2 == null || cn1.id == cn2.id)
continue
addEdge(cn1.id, cn2.id, obj.id, origGraph)
}
// 处理杆和cn的关系
for (obj in getResourceByClassId("POLECODE")) {
val terminals = getTerminalsOfEquip(obj)
if (terminals.size != 1)
continue
val cn = getCNOfTerminal(terminals[0]) ?: continue
if (obj.getProperty("NAME") != null)
poleNameToCn[obj.getProperty("NAME")] = cn.id
}
for (obj in getResourceByClassId("POWERTRANSFORMER")) {
val windings = getWindingsOfTf(obj)
if (windings.size < 2)
continue
val magneticCn = MapObject() // 中性点对应的CN
magneticCn.id = obj.id + suffixOfAddedCn
magneticCn.type = "CONNECTIVITYNODE"
origGraph.addVertex(magneticCn.id)
windings.forEach {
val cn = getCNOfTerminal(getTerminalsOfEquip(it)[0])
addEdge(magneticCn.id, cn!!.id, it.id, origGraph)
}
}
extraBuildGraph()
// 连通性分析
val inspector = ConnectivityInspector(origGraph)
val graphs = inspector.connectedSets() //获得连通子图
// 找出有电源的CN
graphs.forEach({
it.filter { isActiveCn(it) }.forEach({ sourceCns.add(it) })
})
// 找出有源的电气岛
graphs.filter { isActive(it) }
.mapTo(activeSubgraphes) { Subgraph<String, Edge, UndirectedGraph<String, Edge>>(origGraph, it) }
println("========== There are " + graphs.size + " islands totally. ============")
println("========== There are " + activeSubgraphes.size + " active islands. ============")
for (i in 1..activeSubgraphes.size) {
val vertexNum = activeSubgraphes[i - 1].vertexSet().size
val edgeNum = activeSubgraphes[i - 1].edgeSet().size
println("========== There are $vertexNum vertexes in sub island $i.============")
println("========== There are $edgeNum edges in sub island $i.============")
}
} catch (e: Exception) {
e.printStackTrace();
}
return activeSubgraphes
}
open fun extraBuildGraph() {}
fun addEdge(cn1: String, cn2: String, obj: String, g: SimpleGraph<String, Edge>) {
val e = g.getEdge(cn1, cn2)
if (e == null) {
val edge = Edge()
edge.equips.add(obj)
g.addEdge(cn1, cn2, edge)
} else
e.equips.add(obj)
}
/**
* 形成原始的拓扑图(node-brake),并过滤掉无源的拓扑岛
*/
open fun filterDevices() {
val graphs = buildGraph() //先分析原始的拓扑图
filterDevices(graphs)
}
open fun filterDevices(graphs: MutableList<Subgraph<String, Edge, *>>) {
// val graphs = activeSubgraphes //先分析原始的拓扑图
// 统计ConnectivityNode的数量
val cnNum = graphs.sumBy { it.vertexSet().size }
cns = HashMap(cnNum)
for(g in graphs)
g.vertexSet().forEach {
if(!it.endsWith(suffixOfAddedCn))
cns!!.put(it, getResource(it)!!)
}
var generatorNum = 0
var loadNum = 0
var busbarNum = 0
var shuntCompensatorNum = 0
var seriesCompensatorNum = 0
var aclineNum = 0
var connlineNum = 0
var windingNum = 0
var switchNum = 0
var i = 1
for (g in graphs) {
var generatorNum2 = 0
var loadNum2 = 0
var busbarNum2 = 0
var shuntCompensatorNum2 = 0
var seriesCompensatorNum2 = 0
var aclineNum2 = 0
var connlineNum2 = 0
var windingNum2 = 0
var switchNum2 = 0
val cnInGraph = g.vertexSet().filterNot { it.endsWith(suffixOfAddedCn) }
cnInGraph.forEach { obj -> getTerminalsOfCN(getResource(obj)!!).map { getEquipOfTerminal(it) }.forEach {
if (it?.type == "SYNCHRONOUSMACHINE")
generatorNum2++
else if (it?.type == "ENERGYCONSUMER")
loadNum2++
else if (it?.type == "BUSBARSECTION")
busbarNum2++
else if (it?.type == "SHUNTCOMPENSATOR")
shuntCompensatorNum2++
else if (it?.type == "SERIESCOMPENSATOR")
seriesCompensatorNum2++
else if (it?.type == "ACLINESEGMENT")
aclineNum2++
else if (it?.type == "CONNLINE")
connlineNum2++
else if (it?.type == "TRANSFORMERWINDING")
windingNum2++
else if (it != null && isSwitch(it))
switchNum2++
}}
aclineNum2 /= 2
connlineNum2 /= 2
seriesCompensatorNum2 /= 2
switchNum2 /= 2
generatorNum += generatorNum2
loadNum += loadNum2
busbarNum += busbarNum2
shuntCompensatorNum += shuntCompensatorNum2
seriesCompensatorNum += seriesCompensatorNum2
aclineNum += aclineNum2
connlineNum += connlineNum2
windingNum += windingNum2
switchNum += switchNum2
println("====================== " + i++ + " th island information =======================")
println("There are $generatorNum2 generators.")
println("There are $loadNum2 loads.")
println("There are $busbarNum2 bus bar sections.")
println("There are $shuntCompensatorNum2 shunt compensators.")
println("There are $seriesCompensatorNum2 series compensators.")
println("There are $aclineNum2 ac lines.")
println("There are $connlineNum2 conn lines.")
println("There are $windingNum2 transformer winding.")
println("There are $switchNum2 switches.")
}
generators = HashMap<String, MapObject>(generatorNum)
loads = HashMap<String, MapObject>(loadNum)
busbars = HashMap<String, MapObject>(busbarNum)
shuntCompensators = HashMap<String, MapObject>(shuntCompensatorNum)
seriesCompensators = HashMap<String, MapObject>(seriesCompensatorNum)
aclines = HashMap<String, MapObject>(aclineNum)
connlines = HashMap<String, MapObject>(connlineNum)
windings = HashMap<String, MapObject>(windingNum)
transformers = HashMap<String, MapObject>(windingNum / 2)
switches = HashMap<String, MapObject>(switchNum)
for (g in graphs)
g.vertexSet().filterNot { it.endsWith(suffixOfAddedCn) }.forEach { cn -> getTerminalsOfCN(getResource(cn)!!)
.mapNotNull { getEquipOfTerminal(it) }
.forEach {
if (it.type == "SYNCHRONOUSMACHINE")
generators!!.put(it.id, it)
else if (it.type == "ENERGYCONSUMER")
loads!!.put(it.id, it)
else if (it.type == "BUSBARSECTION")
busbars!!.put(it.id, it)
else if (it.type == "SHUNTCOMPENSATOR")
shuntCompensators!!.put(it.id, it)
else if (it.type == "TRANSFORMERWINDING") {
windings!!.put(it.id, it)
val transformer = getTfOfWinding(it)
if (transformer == null) {
System.err.println("Transformer winding does not belong to any transformer, id:" + it.id + " name:" + it.name)
} else if (!transformers!!.containsKey(transformer.id))
transformers!!.put(transformer.id, transformer)
} else if (it.type == "SERIESCOMPENSATOR") {
if (!seriesCompensators!!.containsKey(it.id))
seriesCompensators!!.put(it.id, it)
} else if (it.type == "ACLINESEGMENT") {
if (!aclines!!.containsKey(it.id))
aclines!!.put(it.id, it)
} else if (it.type == "CONNLINE") {
if (!connlines!!.containsKey(it.id))
connlines!!.put(it.id, it)
} else if (isSwitch(it)) {
if (!switches!!.containsKey(it.id))
switches!!.put(it.id, it)
}
}
}
extraFilterDevices(graphs)
println("=========== needed generators num: " + generators!!.size)
println("=========== needed load num: " + loads!!.size)
println("=========== needed bus bar num: " + busbars!!.size)
println("=========== needed shunt compensator num: " + shuntCompensators!!.size)
println("=========== needed series compensator num: " + seriesCompensators!!.size)
println("=========== needed ac line num: " + aclines!!.size)
println("=========== needed conn line num: " + connlines!!.size)
println("=========== needed winding num: " + windings!!.size)
println("=========== needed transformer num: " + transformers!!.size)
println("=========== needed switch num: " + switches!!.size)
println("=========== needed connectivity node num: " + cnNum)
}
open fun extraFilterDevices(graphes : MutableList<Subgraph<String, Edge, *>>) {}
/**
* 分析需要的量测信息
*/
open fun filterMeasure() {
println("Checking measurement start..")
val start = System.currentTimeMillis()
analogs = HashMap(6000)//todo:size is not good
discretes = HashMap(switches!!.size)
equipMeasurements = HashMap()
findAnalogs(generators!!.values)
findAnalogs(loads!!.values)
findAnalogs(busbars!!.values)
findAnalogs(shuntCompensators!!.values)
findAnalogs(seriesCompensators!!.values)
findAnalogs(aclines!!.values)
findAnalogs(connlines!!.values)
findAnalogs(windings!!.values)
findDiscretes(switches!!.values)
println("=========== needed analog measurement num: " + analogs!!.size)
println("=========== needed discrete measurement num: " + discretes!!.size)
println("Checking measurement end, and time used: " + (System.currentTimeMillis() - start) + "ms")
}
//todo:支只处理了开关位置,变压器档位等量测没有处理
private fun findDiscretes(switches: Collection<MapObject>) {
switches.mapNotNull { measureProvider?.getDiscreteOfEquip(it.id, dataSource) }
.mapNotNull { getResource(it.id) }
.forEach { discretes!!.put(it.id, it) }
}
private fun findAnalogs(equips: Collection<MapObject>) {
for (obj in equips) {
val measurements = measureProvider?.getAnalogsOfEquip(obj.id, dataSource) ?: continue
equipMeasurements!!.put(obj.id, measurements)
measurements.mapNotNull { getResource(it.id) }
.forEach { analogs!!.put(it.id, it) }
}
}
// ---------------------------- 拓扑分析开始 -------------------------------
/**
* 根据开关状态分析网络拓扑
*/
fun buildDynamicTopo() : List<Subgraph<TN, Edge, UndirectedGraph<TN, Edge>>> {
var size = 0
activeSubgraphes.forEach { size += it.vertexSet().size }
val cnToTn: MutableMap<String, TN> = HashMap(size)
// 将闭合开关连在一起的CN都合并在一个TN里
getAllSwitch().filter { measureProvider!!.getSwitchStatus(it.id, dataSource) }.forEach {
val terminals = getTerminalsOfEquip(it)
val cn1 = terminals[0].getProperty("CONNECTIVITYNODE")
val cn2 = terminals[1].getProperty("CONNECTIVITYNODE")
@Suppress("LoopToCallChain")
for(g in activeSubgraphes) {
if(g.containsEdge(cn1, cn2)) {
val tn : TN
if(cnToTn.containsKey(cn1)) {
if(cnToTn.containsKey(cn2))
break
tn = cnToTn[cn1]!!
tn.cns.add(cn2)
cnToTn[cn2] = tn
} else if(cnToTn.containsKey(cn2)) {
if (cnToTn.containsKey(cn1))
break
tn = cnToTn[cn2]!!
tn.cns.add(cn1)
cnToTn[cn1] = tn
} else {
tn = TN()
cnToTn[cn1] = tn
cnToTn[cn2] = tn
tn.cns.add(cn1)
tn.cns.add(cn2)
}
break
}
}
}
val tnToGraph = HashMap<TN, UndirectedGraph<TN, Edge>>()
val islands = LinkedList<Subgraph<TN, Edge, UndirectedGraph<TN, Edge>>>()
// 开始构建TN与SimpleGraph之间的关系
for(g in activeSubgraphes) {
val largeG = SimpleGraph<TN, Edge>(Edge::class.java)
g.vertexSet().forEach {
if(!cnToTn.containsKey(it)) {
val tn = TN()
cnToTn[it] = tn
tn.cns.add(it)
largeG.addVertex(tn)
tnToGraph[tn] = largeG
} else {
val tn = cnToTn[it]!!
if(!tnToGraph.containsKey(tn)) {
largeG.addVertex(tn)
tnToGraph[tn] = largeG
}
}
}
g.edgeSet().forEach {
//如果支路是断开的开关则不加入到图
if(it.equips.size == 1 && measureProvider!!.getSwitchStatus(it.equips[0], dataSource))
return@forEach
val cn1 = g.getEdgeSource(it)
val cn2 = g.getEdgeTarget(it)
val tn1 = cnToTn[cn1]
val tn2 = cnToTn[cn2]
if(tn1 != tn2) {
val e = largeG.getEdge(tn1, tn2)
if (e == null) {//如果不存在边
val edge = Edge()
edge.equips.addAll(it.equips)
largeG.addEdge(tn1, tn2, edge)
} else //两条Edge合并
e.equips.addAll(it.equips)
}
}
// 连通性分析
val inspector = ConnectivityInspector(largeG)
val graphs = inspector.connectedSets() //获得连通子图
// 开始建立
graphs.mapTo(islands) { Subgraph<TN, Edge, UndirectedGraph<TN, Edge>>(largeG, it) }
}
return islands
}
inner class CimXmlHandler : DefaultHandler() {
// 使用栈这个数据结构来保存
private val stack = Stack<String>()
private var obj: MapObject? = null
private var obj_constructing = false
private var obj_type: String? = null
private var startTime : Long = 0
@Throws(SAXException::class)
override fun startDocument() {
println("start document -> parse begin")
startTime = System.currentTimeMillis()
}
@Throws(SAXException::class)
override fun endDocument() {
println("end document -> parse finished, time used ${System.currentTimeMillis() - startTime} ms.")
// 文档结束之后建立对象之间的关系
endAddPSR()
}
@Throws(SAXException::class)
override fun startElement(uri: String?, localName: String?, qName: String?,
attributes: Attributes?) {
// 将标签名压入栈
stack.push(qName)
// 处理属性
if (attributes!!.length >= 1) {
if (attributes.getQName(0) == "rdf:ID") {//判断是否遇见带有id的元素,即二级元素
obj = MapObject() //生成一个新的obj空间
obj_constructing = true //构造开始
val index = qName!!.indexOf(":")
//记录当前obj_type,用以确认obj构造结束时刻,去掉前缀
obj_type = qName.substring(index + 1).toUpperCase()
obj!!.id = attributes.getValue(0) //obj初始化
obj!!.type = obj_type
}
if (attributes.getQName(0) == "rdf:resource") {
var tag: String = qName!! // 取出标签名
if (tag.indexOf('.') >= 0) {//tag的简单处理
tag = tag.substring(tag.indexOf('.') + 1, tag.length) //取出原tag中的.后子字符串
}
var value = attributes.getValue(0)
value = value.substring(1, value.length) //去除#后的sub值,end值需要大1
if (value.trim { it <= ' ' } != "") {
obj!!.setProperty(tag.toUpperCase(), value)//存入characters
}
}
}
}
@Throws(SAXException::class)
override fun characters(ch: CharArray?, start: Int, length: Int) {
val value = String(ch!!, start, length)
// 取出标签名
var tag = stack.peek()
//空白值不保存
if ((value.trim { it <= ' ' } != "") and (tag != obj_type)) {
if (obj_constructing) {
if (tag.indexOf('.') >= 0) {
//取出原tag中的.后子字符串,end值需要大1
tag = tag.substring(tag.indexOf('.') + 1, tag.length)
}
obj!!.setProperty(tag.toUpperCase(), value)//存入characters
}
}
}
@Throws(SAXException::class)
override fun endElement(uri: String?, localName: String?, qName: String?) {
//表示该元素解析完毕,需要从栈中弹出标签
stack.pop()
val index = qName!!.indexOf(":")
if (obj_type == qName.substring(index + 1).toUpperCase()) {//判断obj构造是否结束
addPSR(obj!!)
obj_constructing = false//构造结束
}
}
}
}
\ No newline at end of file
###=====================================================================================
### appenders
###=====================================================================================
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct log messages to daily file ###
log4j.appender.DailyFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DailyFile.File=c:/logs/aems.log
log4j.appender.DailyFile.DatePattern='.'yyyy-MM-dd
log4j.appender.DailyFile.layout=org.apache.log4j.PatternLayout
log4j.appender.DailyFile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{2} %x %m%n
###=====================================================================================
### log level
###=====================================================================================
### the root
log4j.rootLogger=debug,stdout
#log4j.logger.org.mule=warn,stdout
log4j.logger.com.danga.MemCached.MemCachedClient=warn,stdout
log4j.logger.org.quartz=warn,stdout
#log4j.logger.zju.common.NewtonSolver=debug,stdout
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<File name="FileAppender" fileName="log/test.log" append="false">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="FileAppender"/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
apply plugin: 'application'
mainClassName = 'com.jinyun.web.DemoApplication'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
compile project(':jinyun:availCap')
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
implementation group: 'com.auth0', name: 'java-jwt', version: '3.18.2'
compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '2.2.0'
compile group: 'org.projectlombok', name: 'lombok', version: '1.16.22'
compile 'com.alibaba:fastjson:1.2.4'
runtimeOnly 'org.xerial:sqlite-jdbc:3.28.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
package com.jinyun.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
package com.jinyun.web;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
@Configuration
@MapperScan("com.jinyun.**.dao") // 扫描DAO
public class MybatisConfig {
@Autowired
private DataSource dataSource;
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setTypeAliasesPackage("com.jinyun.**.model"); // 扫描Model
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sessionFactory.setMapperLocations(resolver.getResources("classpath*:**/sqlmap/*.xml")); // 扫描映射文件
return sessionFactory.getObject();
}
}
package com.jinyun.web;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi(){
// 添加请求参数,我们这里把token作为请求头部参数传入后端
ParameterBuilder parameterBuilder = new ParameterBuilder();
List<Parameter> parameters = new ArrayList<Parameter>();
parameterBuilder.name("token").description("令牌")
.modelRef(new ModelRef("string")).parameterType("header").required(false).build();
parameters.add(parameterBuilder.build());
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.any()).paths(PathSelectors.any())
.build().globalOperationParameters(parameters);
// return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
// .select()
// .apis(RequestHandlerSelectors.any())
// .paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("SpringBoot API Doc")
.description("This is a restful api document of Spring Boot.")
.version("1.0")
.build();
}
}
package com.jinyun.web.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface PassToken {
boolean required() default true;
}
\ No newline at end of file
package com.jinyun.web.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface UserLoginToken {
boolean required() default true;
}
package com.jinyun.web.config;
import com.jinyun.web.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authenticationInterceptor())
.addPathPatterns("/**"); // 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录
}
@Bean
public AuthenticationInterceptor authenticationInterceptor() {
return new AuthenticationInterceptor();
}
}
package com.jinyun.web.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.maxAge(3600)
.allowCredentials(true);
}
}
package com.jinyun.web.controller;
import com.alibaba.fastjson.JSONObject;
import com.jinyun.web.annotation.UserLoginToken;
import com.jinyun.web.entity.User;
import com.jinyun.web.service.CapService;
import com.jinyun.web.service.TokenService;
import com.jinyun.web.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Api(value = "desc of class", tags="DataImport",description = "数据导入")
//@RestController
@RequestMapping("import")
public class DataImportController {
@Autowired
CapService capService;
@ApiOperation("数据导入")
@PostMapping("/upload")
public String upload(@RequestBody MultipartFile file) throws IOException {
// for(MultipartFile file:files){
// String fileName = file.getOriginalFilename();
// String target = "d:/";
// File dest = new File(target+fileName);
// try {
// file.transferTo(dest);
// System.out.println( "上传成功");;
// } catch (IOException e) {
// e.printStackTrace();
// } catch (IllegalStateException e) {
// e.printStackTrace();
// }
// System.out.println( "上传失败");;
// }
String fileName = file.getOriginalFilename();
String target = "d:/";
File dest = new File(target+fileName);
try {
file.transferTo(dest);
return "上传成功";
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
return "上传成功";
}
@ApiOperation(value = "数据导入列表", notes = "")
@RequestMapping(value = "/dataImportList",method = RequestMethod.GET)
public Object transformerInfoDetail() {
List result = capService.dataImportList();
return result;
}
}
package com.jinyun.web.controller;
import com.jinyun.web.annotation.UserLoginToken;
import com.jinyun.web.service.CapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@Api(value = "desc of class", tags="LineBase",description = "线路台区")
@RestController
@RequestMapping("lineBase")
public class LineBaseController {
@Autowired
CapService capService;
@ApiOperation(value = "基础信息", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "mRID", value = "开关ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/baseInfo",method = RequestMethod.GET)
@UserLoginToken
public Object baseInfo(@RequestParam("mRID") String mRID) {
Map<String,Object> result = capService.baseInfo(mRID);
return result;
}
@ApiOperation(value = "夏季分析", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "mRID", value = "开关ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/lineSummer",method = RequestMethod.GET)
@UserLoginToken
public Object lineSummer(@RequestParam("mRID") String mRID) {
Map<String,Object> result = capService.lineSummer(mRID);
return result;
}
@ApiOperation(value = "冬季分析", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "mRID", value = "开关ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/lineWinter",method = RequestMethod.GET)
@UserLoginToken
public Object lineWinter(@RequestParam("mRID") String mRID) {
Map<String,Object> result = capService.lineWinter(mRID);
return result;
}
@ApiOperation(value = "峰谷分析", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "mRID", value = "开关ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/linePs",method = RequestMethod.GET)
@UserLoginToken
public Object linePs(@RequestParam("mRID") String mRID) {
Map<String,Object> result = capService.linePs(mRID);
return result;
}
@ApiOperation(value = "开关线路信息", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "mRID", value = "线路ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/lineInfo",method = RequestMethod.GET)
@UserLoginToken
public Object lineInfo(@RequestParam("mRID") String mRID) {
Map<String,Object> result = capService.lineInfo(mRID);
return result;
}
@ApiOperation(value = "公变信息", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "mRID", value = "公变ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/transformerInfo",method = RequestMethod.GET)
@UserLoginToken
public Object transformerInfo(@RequestParam("mRID") String mRID) {
Map<String,Object> result = capService.transformerInfo(mRID);
return result;
}
@ApiOperation(value = "线路信息明细", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "mRID", value = "线路ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/lineInfoDetail",method = RequestMethod.GET)
@UserLoginToken
public Object lineInfoDetail(@RequestParam("mRID") String mRID) {
Map<String,Object> result = capService.lineInfoDetail(mRID);
return result;
}
@ApiOperation(value = "公变信息明细", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "mRID", value = "公变ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/transformerInfoDetail",method = RequestMethod.GET)
@UserLoginToken
public Object transformerInfoDetail(@RequestParam("mRID") String mRID) {
Map<String,Object> result = capService.transformerInfoDetail(mRID);
return result;
}
}
package com.jinyun.web.controller;
import com.jinyun.web.annotation.UserLoginToken;
import com.jinyun.web.service.CapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Api(value = "desc of class", tags="LoadPos",description = "负荷接入分析")
@RestController
@RequestMapping("loadPos")
public class LoadPosController {
@Autowired
CapService capService;
@ApiOperation(value = "分析结果列表", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
@ApiImplicitParam(name = "rows", value = "行数", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
})
@RequestMapping(value = "/loadPosList",method = RequestMethod.GET)
@UserLoginToken
public Object loadPosSeason(@RequestParam("page") int page,@RequestParam("rows") int rows) {
int total = capService.loadPosListCout();
List loadPosList = new ArrayList();
if(total>0){
loadPosList = capService.loadPosList(page,rows);
}
Map<String,Object> result = new HashMap<>();
result.put("total",total);
result.put("rows",loadPosList);
return result;
}
@ApiOperation(value = "线路名称列表", notes = "")
@RequestMapping(value = "/lineNameList",method = RequestMethod.GET)
@UserLoginToken
public Object lineNameList() {
List result = capService.lineNameList();
return result;
}
@ApiOperation(value = "负荷接入分析", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "lineName", value = "线路名称", dataType = "string", paramType = "query",required = true),
@ApiImplicitParam(name = "cap", value = "负荷容量", dataType = "int", paramType = "query",example = "0",required = true),
@ApiImplicitParam(name = "type", value = "负荷特征(1为峰用电,2为谷用电,3为峰谷用电)", dataType = "int", paramType = "query",example = "0",required = true),
})
@RequestMapping(value = "/loadPosAnalysis",method = RequestMethod.GET)
@UserLoginToken
public Object loadPosAnalysis(@RequestParam("lineName") String lineName,@RequestParam("cap") int cap,@RequestParam("type") int type) {
Object result = capService.loadPosAnalysis(lineName, cap, type);
if(result != null)
return "分析完成";
else return "分析失败";
}
@ApiOperation(value = "高压负荷接入分析结果", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "loadId", value = "负荷ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/loadPosSw",method = RequestMethod.GET)
@UserLoginToken
public Object loadPosSw(@RequestParam("loadId") String loadId) {
Object result = capService.loadPosSw(loadId);
return result;
}
@ApiOperation(value = "低压负荷接入分析结果", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "loadId", value = "负荷ID", dataType = "string", paramType = "query",required = true),
})
@RequestMapping(value = "/loadPosTf",method = RequestMethod.GET)
@UserLoginToken
public Object loadPosTf(@RequestParam("loadId") String loadId) {
Object result = capService.loadPosTf(loadId);
return result;
}
}
package com.jinyun.web.controller;
import com.alibaba.fastjson.JSONObject;
import com.jinyun.web.annotation.UserLoginToken;
import com.jinyun.web.entity.User;
import com.jinyun.web.service.TokenService;
import com.jinyun.web.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
@Api(value = "desc of class", tags="Login",description = "登录")
@RestController
@RequestMapping("login")
public class LoginController {
@Autowired
UserService userService;
@Autowired
TokenService tokenService;
//登录
@PostMapping("/login")
public Object login(@RequestBody User user){
JSONObject jsonObject=new JSONObject();
User userForBase=userService.findByUsername(user);
if(userForBase==null){
jsonObject.put("message","登录失败,用户不存在");
return jsonObject;
}else {
if (!userForBase.getPassword().equals(user.getPassword())){
jsonObject.put("message","登录失败,密码错误");
return jsonObject;
}else {
String token = tokenService.getToken(userForBase);
jsonObject.put("token", token);
jsonObject.put("user", userForBase);
return jsonObject;
}
}
}
@UserLoginToken
@GetMapping("/getMessage")
public String getMessage(){
return "你已通过验证";
}
}
package com.jinyun.web.controller;
import com.jinyun.web.annotation.UserLoginToken;
import com.jinyun.web.service.CapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Api(value = "desc of class", tags="LowMarginWarn",description = "低裕度预警分析")
@RestController
@RequestMapping("lowMarginWarn")
public class LowMarginWarnController {
@Autowired
CapService capService;
@ApiOperation(value = "lowMarginAnalysis", notes = "")
@RequestMapping(value = "/lowMarginAnalysis",method = RequestMethod.GET)
@UserLoginToken
public Object lowMarginAnalysis() {
Map<String, Object> result = capService.lowMarginAnalysis();
return result;
}
}
package com.jinyun.web.controller;
import com.jinyun.web.annotation.UserLoginToken;
import com.jinyun.web.service.CapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Api(value = "desc of class", tags="MainPage",description = "首页")
@RestController
@RequestMapping("mainPage")
public class MainPageController {
@Autowired
CapService capService;
@ApiOperation(value = "电网统计字段", notes = "")
@RequestMapping(value = "/gridStatistics",method = RequestMethod.GET)
@UserLoginToken
public Object gridStatistics() {
Map<String,Object> result = capService.gridStatistics();
return result;
}
@ApiOperation(value = "低裕度预警统计", notes = "")
@RequestMapping(value = "/lowMarginWarnStatistics",method = RequestMethod.GET)
@UserLoginToken
public Object lowMarginWarnStatistics() {
Map<String,Object> result = capService.lowMarginWarnStatistics();
return result;
}
@ApiOperation(value = "重载线路列表", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
@ApiImplicitParam(name = "rows", value = "行数", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
})
@RequestMapping(value = "/hardLineList",method = RequestMethod.GET)
@UserLoginToken
public Object hardLineList(@RequestParam("page") int page,@RequestParam("rows") int rows) {
int total = capService.hardLineListCount();
List hardLineList = new ArrayList();
if(total>0){
hardLineList = capService.hardLineList(page,rows);
}
Map<String,Object> result = new HashMap<>();
result.put("total",total);
result.put("rows",hardLineList);
return result;
}
@ApiOperation(value = "重载配变列表", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
@ApiImplicitParam(name = "rows", value = "行数", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
})
@RequestMapping(value = "/hardTransformerList",method = RequestMethod.GET)
@UserLoginToken
public Object hardTransformerList(@RequestParam("page") int page,@RequestParam("rows") int rows) {
int total = capService.hardTransformerListCount();
List hardTransformerList = new ArrayList();
if(total>0){
hardTransformerList = capService.hardTransformerList(page,rows);
}
Map<String,Object> result = new HashMap<>();
result.put("total",total);
result.put("rows",hardTransformerList);
return result;
}
@ApiOperation(value = "超载线路列表", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
@ApiImplicitParam(name = "rows", value = "行数", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
})
@RequestMapping(value = "/overLineList",method = RequestMethod.GET)
@UserLoginToken
public Object overLineList(@RequestParam("page") int page,@RequestParam("rows") int rows) {
int total = capService.overLineListCount();
List overLineList = new ArrayList();
if(total>0){
overLineList = capService.overLineList(page,rows);
}
Map<String,Object> result = new HashMap<>();
result.put("total",total);
result.put("rows",overLineList);
return result;
}
@ApiOperation(value = "超载配变列表", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
@ApiImplicitParam(name = "rows", value = "行数", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
})
@RequestMapping(value = "/overTransformerList",method = RequestMethod.GET)
@UserLoginToken
public Object overTransformerList(@RequestParam("page") int page,@RequestParam("rows") int rows) {
int total = capService.overTransformerListCount();
List overTransformerList = new ArrayList();
if(total>0){
overTransformerList = capService.overTransformerList(page,rows);
}
Map<String,Object> result = new HashMap<>();
result.put("total",total);
result.put("rows",overTransformerList);
return result;
}
@ApiOperation(value = "配变三相不平衡度", notes = "")
@RequestMapping(value = "/transformerUnbalance",method = RequestMethod.GET)
@UserLoginToken
public Object transformerUnbalance() {
Map<String,Object> result = capService.transformerUnbalance();
return result;
}
@ApiOperation(value = "配变三相不平衡度列表", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
@ApiImplicitParam(name = "rows", value = "行数", dataType = "int", paramType = "query",example = "0",defaultValue = "0",required = true),
})
@RequestMapping(value = "/transformerUnbalanceList",method = RequestMethod.GET)
@UserLoginToken
public Object transformerUnbalanceList(@RequestParam("page") int page,@RequestParam("rows") int rows) {
Map<String,Object> result = capService.transformerUnbalanceList(page,rows);
return result;
}
@ApiOperation(value = "线路电流合格率", notes = "")
@RequestMapping(value = "/linePassRate",method = RequestMethod.GET)
@UserLoginToken
public Object linePassRate() {
List result = capService.linePassRate();
return result;
}
@ApiOperation(value = "配变负荷越限统计", notes = "")
@RequestMapping(value = "/transformerOverLoadRate",method = RequestMethod.GET)
@UserLoginToken
public Object transformerOverLoadRate() {
Object result = capService.transformerOverLoadRate();
return result;
}
@ApiOperation(value = "线路可开放容量大小", notes = "")
@RequestMapping(value = "/maxMinAvailCap",method = RequestMethod.GET)
@UserLoginToken
public Object maxMinAvailCap() {
Map<String, Object> result = capService.maxMinAvailCap();
return result;
}
}
package com.jinyun.web.dao;
import com.jinyun.web.entity.User;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface SysUserMapper {
public List<Map<String,Object>> selectAll();
User findByUsername(@Param("username") String username);
User findUserById(@Param("Id") String Id);
}
package com.jinyun.web.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ImportData {
String stationName;
String lineName;
String importTime;
}
package com.jinyun.web.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LinePassRateWeb {
String feederName;
String substation;
double springRate;
double summerRate;
double autumnRate;
double winterRate;
}
package com.jinyun.web.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TfOverLoadRateWeb {
String feederName;
String devName;
String mRID;
String lineName;
String lineMRID;
String substation;
double springRate;
double summerRate;
double autumnRate;
double winterRate;
}
package com.jinyun.web.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
String Id;
String username;
String password;
}
package com.jinyun.web.interceptor;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.jinyun.web.annotation.PassToken;
import com.jinyun.web.annotation.UserLoginToken;
import com.jinyun.web.entity.User;
import com.jinyun.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
/**
* @author jinbin
* @date 2018-07-08 20:41
*/
public class AuthenticationInterceptor implements HandlerInterceptor {
@Autowired
UserService userService;
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws Exception {
if(httpServletRequest.getMethod().equals(RequestMethod.OPTIONS.name())){
httpServletResponse.setStatus(HttpStatus.OK.value());
return true;
}
String token = httpServletRequest.getHeader("token");// 从 http 请求头中取出 token
// 如果不是映射到方法直接通过
if(!(object instanceof HandlerMethod)){
return true;
}
HandlerMethod handlerMethod=(HandlerMethod)object;
Method method=handlerMethod.getMethod();
//检查是否有passtoken注释,有则跳过认证
if (method.isAnnotationPresent(PassToken.class)) {
PassToken passToken = method.getAnnotation(PassToken.class);
if (passToken.required()) {
return true;
}
}
//检查有没有需要用户权限的注解
if (method.isAnnotationPresent(UserLoginToken.class)) {
UserLoginToken userLoginToken = method.getAnnotation(UserLoginToken.class);
if (userLoginToken.required()) {
// 执行认证
if (token == null) {
throw new RuntimeException("403");
}
// 获取 token 中的 user id
String userId;
try {
userId = JWT.decode(token).getAudience().get(0);
} catch (JWTDecodeException j) {
throw new RuntimeException("401");
}
User user = userService.findUserById(userId);
if (user == null) {
throw new RuntimeException("用户不存在,请重新登录");
}
// 验证 token
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(user.getPassword())).build();
try {
jwtVerifier.verify(token);
} catch (JWTVerificationException e) {
throw new RuntimeException("401");
}
return true;
}
}
return true;
}
@Override
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
}
}
package com.jinyun.web.interceptor;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice
public class GloablExceptionHandler {
@ResponseBody
@ExceptionHandler(Exception.class)
public Object handleException(Exception e) {
String msg = e.getMessage();
if (msg == null || msg.equals("")) {
msg = "服务器出错";
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", msg);
return jsonObject;
}
}
package com.jinyun.web.service;
import com.jinyun.cap.*;
import com.jinyun.web.entity.ImportData;
import com.jinyun.web.entity.LinePassRateWeb;
import com.jinyun.web.entity.TfOverLoadRateWeb;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;
@Service("CapService")
public class CapService {
static String allFeederNameTable = "所有馈线名称";
static String allPsWarnTable = "所有馈线预警设备";
static String allPsLineWarnTable = "所有馈线线路预警设备";
static String allPsTfWarnTable = "所有馈线公变预警设备";
static String maxMinAvailCapTable = "最大最小可开放容量线路";
static String lineITableName = "电流";
static String switchTableName = "开关";
static String lineParamTableName = "参数";
static String oneLineParamTableName = "单线参数";
static String transformerTableName = "公变";
static String tfParamTableName = "公变参数";
static String availCapTableName = "可接入容量";
static String swToLineTableName = "开关线路对应";
static String swToTfTableName = "开关公变对应";
static String tfToLineTableName = "公变线路对应";
static String lineWarnTableName = "线路预警";
static String tfWarnTableName = "公变预警";
static String substationTableName = "变电站";
static String tfMonthUbTableName = "公变月不平衡度";
static String linePassRateTableName = "线路合格率";
static String tfOverLoadRateTableName = "公变越限率";
static String feederTableName = "馈线名称";
static String loadPosTable = "负荷接入位置";
static String allPsDbFile = "D:\\others\\yunqi\\项目\\缙云项目\\test\\allPsDb\\allPs.db";
static String feederDbFile = "D:\\others\\yunqi\\项目\\缙云项目\\test\\feederDb";
public static void setFeederDbName(String feederDbName) {
CapService.feederDbName = feederDbName;
}
static String feederDbName = "溪南G134线";
static String cimFile = "D:\\others\\yunqi\\项目\\缙云项目\\test\\CIM";
public Map<String, Object> gridStatistics() {
Map<String,Object> result = new HashMap<>();
result.put("110StationCount",25);
result.put("35StationCount",36);
result.put("10kVBusCount",67);
result.put("busCount",156);
result.put("transformerCount",300);
return result;
}
public Map<String, Object> lowMarginWarnStatistics() {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
int hardLineNum = sqliteDb.queryWarnDevNum(allPsWarnTable, 1, 1);
int overLineNum = sqliteDb.queryWarnDevNum(allPsWarnTable, 2, 1);
int hardTfNum = sqliteDb.queryWarnDevNum(allPsWarnTable, 1, 2);
int overTfNum = sqliteDb.queryWarnDevNum(allPsWarnTable, 2, 2);
Map<String,Object> result = new HashMap<>();
result.put("hardLineNum",hardLineNum);
result.put("overLineNum",overLineNum);
result.put("hardTfNum",hardTfNum);
result.put("overTfNum",overTfNum);
return result;
}
public Map<String, Object> transformerUnbalance() {
SqliteDb allPsDb = new SqliteDb(allPsDbFile);
List<String> feeders = allPsDb.queryAllFeederName(allFeederNameTable); // 查询馈线名称
List<TfUb> tfUbs = new LinkedList<>();
for (String feeder : feeders) {
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feeder + ".db");
tfUbs.addAll(sqliteDb.queryTfMonthUb(feeder + tfMonthUbTableName));
}
Map<String,Object> result = new HashMap<>();
int count = 0;
for(TfUb tfUb:tfUbs){
if(count == 5) break;
if(result.containsKey(tfUb.getDevName()))
continue;
result.put(tfUb.getDevName(),tfUb.getUb());
count ++;
}
return result;
}
public Map<String,Object> transformerUnbalanceList(int page, int rows) {
SqliteDb allPsDb = new SqliteDb(allPsDbFile);
List<String> feeders = allPsDb.queryAllFeederName(allFeederNameTable); // 查询馈线名称
List<TfUb> tfUbs = new LinkedList<>();
int startRow = (page-1)*rows;
int endRow = startRow+rows;
for (String feeder : feeders) {
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feeder + ".db");
List<TfUb> c = sqliteDb.queryTfMonthUb(feeder + tfMonthUbTableName);
tfUbs.addAll(c);;
}
List<TfUb> result = new LinkedList<>();
for(int i=startRow;i<endRow;i++){
result.add(tfUbs.get(i));
}
Map<String,Object> result1 = new HashMap<>();
result1.put("total",tfUbs.size());
result1.put("rows",result);
return result1;
}
public int hardLineListCount() {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
int total = sqliteDb.queryWarnLineCount(allPsLineWarnTable, 1);
return total;
}
public List hardLineList(int page, int rows) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
List<WarnLine> hardLine = sqliteDb.queryWarnLine(allPsLineWarnTable, 1,page,rows);
return hardLine;
}
public int hardTransformerListCount() {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
int total = sqliteDb.queryWarnTfCount(allPsTfWarnTable, 1);
return total;
}
public List hardTransformerList(int page, int rows) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
List<WarnTf> hardTf = sqliteDb.queryWarnTf(allPsTfWarnTable, 1,page,rows);
return hardTf;
}
public int overLineListCount() {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
int count = sqliteDb.queryWarnLineCount(allPsLineWarnTable, 2);
return count;
}
public List overLineList(int page, int rows) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
List<WarnLine> overLine = sqliteDb.queryWarnLine(allPsLineWarnTable, 2,page,rows);
return overLine;
}
public int overTransformerListCount() {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
int count = sqliteDb.queryWarnTfCount(allPsTfWarnTable, 2);
return count;
}
public List overTransformerList(int page, int rows) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
List<WarnTf> overTf = sqliteDb.queryWarnTf(allPsTfWarnTable, 2,page,rows);
return overTf;
}
public List linePassRate() {
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
List<LinePassRate> linePassRates = sqliteDb.queryLinePassRate(feederDbName + linePassRateTableName);
List<LinePassRateWeb> linePassRateWebs = new ArrayList<>();
for(LinePassRate it:linePassRates){
LinePassRateWeb linePassRateWeb = new LinePassRateWeb(it.getFeederName(),
it.getSubstation(),it.getPassRate()[0],it.getPassRate()[1],it.getPassRate()[2],it.getPassRate()[3]);
linePassRateWebs.add(linePassRateWeb);
}
return linePassRateWebs;
}
public Object transformerOverLoadRate() {
SqliteDb allPsDb = new SqliteDb(allPsDbFile);
List<String> feeders = allPsDb.queryAllFeederName(allFeederNameTable); // 查询馈线名称
List<TfOverLoadRate> tfOverLoadRates = new LinkedList<>();
for (String feeder : feeders) {
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feeder + ".db");
tfOverLoadRates.addAll(sqliteDb.queryTfOverLoadRate(feeder + tfOverLoadRateTableName));
}
TfOverLoadRate it = tfOverLoadRates.get(0); //todo 先取第一个
TfOverLoadRateWeb tfOverLoadRateWeb = new TfOverLoadRateWeb(it.getFeederName(),it.getDevName(),it.getmRID(),it.getLineName(),it.getLineMRID(),
it.getSubstation(),it.getOverLoadRate()[0],it.getOverLoadRate()[1],it.getOverLoadRate()[2],it.getOverLoadRate()[3]);
return tfOverLoadRateWeb;
}
public Map<String, Object> maxMinAvailCap() {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
MaxMinAvailCap maxFeeder = sqliteDb.queryMaxMinAvailCap(maxMinAvailCapTable, 1);
MaxMinAvailCap minFeeder = sqliteDb.queryMaxMinAvailCap(maxMinAvailCapTable, 2);
Map<String,Object> result = new HashMap<>();
result.put("max",maxFeeder);
result.put("min",minFeeder);
return result;
}
public Map<String, Object> baseInfo(String mRID) {
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(feederDbName + oneLineParamTableName, mRID);
double lineMaxI = sqliteDb.queryMaxSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, -1);
double avgI = sqliteDb.queryMaxSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, -2);
Map<String,Object> result = new HashMap<>();
result.put("lineRatedI",lineRatedI);
result.put("lineMaxI",lineMaxI);
result.put("avgI",avgI);
return result;
}
public Map<String, Object> lineSummer(String mRID) {
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
// lineRatedICv为线路限额,seasonCluster2为负荷聚类曲线,seasonMax2为最大负荷曲线,cap2为可开放容量
double lineRatedI = sqliteDb.queryOneLineParam(feederDbName + oneLineParamTableName, mRID);
double[] lineRatedICv = new double[96];
for (int i = 0; i < 96; i++) {
lineRatedICv[i] = lineRatedI;
}
double[] seasonCluster2 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonClusterTable, mRID, 2, 96);
double[] seasonMax2 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, 2, 96);
double[] cap2 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 2, 96);
Map<String,Object> result = new HashMap<>();
result.put("lineRatedICv",lineRatedICv);
result.put("seasonCluster2",seasonCluster2);
result.put("seasonMax2",seasonMax2);
result.put("cap2",cap2);
return result;
}
public Map<String, Object> lineWinter(String mRID) {
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(feederDbName + oneLineParamTableName, mRID);
double[] lineRatedICv = new double[96];
for (int i = 0; i < 96; i++) {
lineRatedICv[i] = lineRatedI;
}
double[] seasonCluster4 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonClusterTable, mRID, 4, 96);
double[] seasonMax4 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, 4, 96);
double[] cap4 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 4, 96);
Map<String,Object> result = new HashMap<>();
result.put("lineRatedICv",lineRatedICv);
result.put("seasonCluster4",seasonCluster4);
result.put("seasonMax4",seasonMax4);
result.put("cap4",cap4);
return result;
}
public Map<String, Object> linePs(String mRID) {
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(feederDbName + oneLineParamTableName, mRID);
double[] lineRatedICv = new double[96];
for (int i = 0; i < 96; i++) {
lineRatedICv[i] = lineRatedI;
}
double[] psCluster2 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.psClusterTable, mRID, 2, 96);
double[] seasonMax2 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, 2, 96);
double[] cap2 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 2, 96);
Map<String,Object> result = new HashMap<>();
result.put("lineRatedICv",lineRatedICv);
result.put("psCluster2",psCluster2);
result.put("seasonMax2",seasonMax2);
result.put("cap2",cap2);
return result;
}
public int loadPosListCout() {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
int total = sqliteDb.queryLoadPosSeasonCount(loadPosTable, 1);
return total;
}
public List loadPosList(int page, int rows) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
List<LoadPosSeason> loadPosSeason = sqliteDb.queryLoadPosSeason(loadPosTable, 1,page,rows);
return loadPosSeason;
}
public Object loadPosSw(String mRID) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
LoadPosSw loadPosSw = sqliteDb.queryLoadPosSw(loadPosTable, Integer.parseInt(mRID), 1);
return loadPosSw;
}
public Object loadPosTf(String mRID) {
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
LoadPosTf loadPosTf = sqliteDb.queryLoadPosTf(loadPosTable, Integer.parseInt(mRID), 1);
return loadPosTf;
}
public Map<String, Object> lineInfo(String mRID) {
// mouseOverSw为鼠标放置在开关上,查询线路限额,最大电流,可开放容量。args[1]为馈线数据库文件夹的路径,feederDbName为馈线名称,mRID为线路mRID
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(feederDbName + oneLineParamTableName, mRID);
double lineMaxI = sqliteDb.queryMaxSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, -1);
double[] cap1 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 1, 96);
double[] cap2 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 2, 96);
double[] cap3 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 3, 96);
double[] cap4 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 4, 96);
Map<String,Object> result = new HashMap<>();
result.put("lineRatedI",lineRatedI);
result.put("lineMaxI",lineMaxI);
result.put("cap1",cap1);
result.put("cap2",cap2);
result.put("cap3",cap3);
result.put("cap4",cap4);
return result;
}
public Map<String, Object> transformerInfo(String mRID) {
// mouseOverTF为鼠标放置在公变上,查询公变容量,最大负荷,三相不平衡度。args[1]为馈线数据库文件夹的路径,feederDbName为馈线名称,cimFile为公变mRID
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
double tFRatedCap = sqliteDb.queryTFCap(feederDbName + tfParamTableName, mRID);
double tFMaxP = sqliteDb.queryMaxTFP(feederDbName + transformerTableName + HistoryData.seasonTable, mRID, -1);
double[] ub = sqliteDb.queryTFUb(feederDbName + transformerTableName + HistoryData.unbalanceTable, mRID, -1);
// 低压负荷接入相别
String phase = sqliteDb.queryMinIPhase(feederDbName + transformerTableName + HistoryData.minITable, mRID, -1);
Map<String,Object> result = new HashMap<>();
result.put("tFRatedCap",tFRatedCap);
result.put("tFMaxP",tFMaxP);
result.put("ub",ub);
result.put("phase",phase);
return result;
}
public Map<String, Object> lineInfoDetail(String mRID) {
// mouseClickSw为鼠标点击开关上,查询线路限额,最大电流,可开放容量。args[1]为馈线数据库文件夹的路径,feederDbName为馈线名称,mRID为开关mRID
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
double lineRatedI = sqliteDb.queryOneLineParam(feederDbName + oneLineParamTableName, mRID);
double lineMaxI = sqliteDb.queryMaxSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, -1);
double lineAvgI = sqliteDb.queryMaxSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, -2);
double[] cap1 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 1, 96);
double[] cap2 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 2, 96);
double[] cap3 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 3, 96);
double[] cap4 = sqliteDb.queryAvailCap(feederDbName + availCapTableName, mRID, 4, 96);
double[] seasonCluster1 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonClusterTable, mRID, 1, 96);
double[] seasonCluster2 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonClusterTable, mRID, 2, 96);
double[] seasonCluster3 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonClusterTable, mRID, 3, 96);
double[] seasonCluster4 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonClusterTable, mRID, 4, 96);
double[] psCluster1 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.psClusterTable, mRID, 1, 96);
double[] psCluster2 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.psClusterTable, mRID, 2, 96);
double[] psCluster3 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.psClusterTable, mRID, 3, 96);
double[] psCluster4 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.psClusterTable, mRID, 4, 96);
double[] seasonMax1 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, 1, 96);
double[] seasonMax2 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, 2, 96);
double[] seasonMax3 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, 3, 96);
double[] seasonMax4 = sqliteDb.querySeasonSwitchI(feederDbName + switchTableName + HistoryData.seasonTable, mRID, 4, 96);
for (int i = 0; i < 96; i++) {
System.out.println(lineRatedI + "," + seasonCluster1[i] + "," + seasonMax1[i] + "," + seasonCluster2[i] + "," + seasonMax2[i] + "," +
seasonCluster3[i] + "," + seasonMax3[i] + "," + seasonCluster4[i] + "," + seasonMax4[i]);
}
System.out.println();
for (int i = 0; i < 96; i++) {
System.out.println(lineRatedI + "," + psCluster1[i] + "," + seasonMax1[i] + "," + psCluster2[i] + "," + seasonMax2[i] + "," +
psCluster3[i] + "," + seasonMax3[i] + "," + psCluster4[i] + "," + seasonMax4[i]);
}
Map<String,Object> result = new HashMap<>();
result.put("lineRatedI",lineRatedI);
result.put("lineMaxI",lineMaxI);
result.put("lineAvgI",lineAvgI);
result.put("cap1",cap1);
result.put("cap2",cap2);
result.put("cap3",cap3);
result.put("cap4",cap4);
result.put("seasonCluster1",seasonCluster1);
result.put("seasonCluster2",seasonCluster2);
result.put("seasonCluster3",seasonCluster3);
result.put("seasonCluster4",seasonCluster4);
result.put("psCluster1",psCluster1);
result.put("psCluster2",psCluster2);
result.put("psCluster3",psCluster3);
result.put("psCluster4",psCluster4);
result.put("seasonMax1",seasonMax1);
result.put("seasonMax2",seasonMax2);
result.put("seasonMax3",seasonMax3);
result.put("seasonMax4",seasonMax4);
return result;
}
public Map<String, Object> transformerInfoDetail(String mRID) {
// mouseClickTF为鼠标点击公变上,查询公变容量,最大负荷,三相不平衡度。args[1]为馈线数据库文件夹的路径,feederDbName为馈线名称,mRID为公变mRID
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
double tFRatedCap = sqliteDb.queryTFCap(feederDbName + tfParamTableName, mRID);
double tFMaxI = sqliteDb.queryMaxTFP(feederDbName + transformerTableName + HistoryData.seasonTable, mRID, -2);
double[] ub = sqliteDb.queryTFUb(feederDbName + transformerTableName + HistoryData.unbalanceTable, mRID, -1);
// 负荷
double[] seasonMax1 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.seasonTable, mRID, 1, 96);
double[] seasonMax2 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.seasonTable, mRID, 2, 96);
double[] seasonMax3 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.seasonTable, mRID, 3, 96);
double[] seasonMax4 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.seasonTable, mRID, 4, 96);
double[] seasonCluster1 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.seasonClusterTable, mRID, 1, 96);
double[] seasonCluster2 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.seasonClusterTable, mRID, 2, 96);
double[] seasonCluster3 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.seasonClusterTable, mRID, 3, 96);
double[] seasonCluster4 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.seasonClusterTable, mRID, 4, 96);
double[] psCluster1 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.psClusterTable, mRID, 1, 96);
double[] psCluster2 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.psClusterTable, mRID, 2, 96);
double[] psCluster3 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.psClusterTable, mRID, 3, 96);
double[] psCluster4 = sqliteDb.querySeasonTFP(feederDbName + transformerTableName + HistoryData.psClusterTable, mRID, 4, 96);
// 三相不平衡度
double[] seasonMaxUb1 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.ubMaxTable, mRID, 1, 96);
double[] seasonMaxUb2 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.ubMaxTable, mRID, 2, 96);
double[] seasonMaxUb3 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.ubMaxTable, mRID, 3, 96);
double[] seasonMaxUb4 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.ubMaxTable, mRID, 4, 96);
double[] seasonClusterUb1 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.seasonClusterTable, mRID, 1, 96);
double[] seasonClusterUb2 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.seasonClusterTable, mRID, 2, 96);
double[] seasonClusterUb3 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.seasonClusterTable, mRID, 3, 96);
double[] seasonClusterUb4 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.seasonClusterTable, mRID, 4, 96);
double[] psClusterUb1 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.psClusterTable, mRID, 1, 96);
double[] psClusterUb2 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.psClusterTable, mRID, 2, 96);
double[] psClusterUb3 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.psClusterTable, mRID, 3, 96);
double[] psClusterUb4 = sqliteDb.querySeasonTFUb(feederDbName + transformerTableName + HistoryData.psClusterTable, mRID, 4, 96);
// 公变可开放容量
double[] cap1 = sqliteDb.queryAvailCap(feederDbName + transformerTableName + HistoryData.tfAvailCapTable, mRID, 1, 96);
double[] cap2 = sqliteDb.queryAvailCap(feederDbName + transformerTableName + HistoryData.tfAvailCapTable, mRID, 2, 96);
double[] cap3 = sqliteDb.queryAvailCap(feederDbName + transformerTableName + HistoryData.tfAvailCapTable, mRID, 3, 96);
double[] cap4 = sqliteDb.queryAvailCap(feederDbName + transformerTableName + HistoryData.tfAvailCapTable, mRID, 4, 96);
Map<String,Object> result = new HashMap<>();
result.put("tFRatedCap",tFRatedCap);
result.put("tFMaxI",tFMaxI);
result.put("ub",ub);
result.put("seasonMax1",seasonMax1);
result.put("seasonMax2",seasonMax2);
result.put("seasonMax3",seasonMax3);
result.put("seasonMax4",seasonMax4);
result.put("seasonCluster1",seasonCluster1);
result.put("seasonCluster2",seasonCluster2);
result.put("seasonCluster3",seasonCluster3);
result.put("seasonCluster4",seasonCluster4);
result.put("psCluster1",psCluster1);
result.put("psCluster2",psCluster2);
result.put("psCluster3",psCluster3);
result.put("psCluster4",psCluster4);
result.put("seasonMaxUb1",seasonMaxUb1);
result.put("seasonMaxUb2",seasonMaxUb2);
result.put("seasonMaxUb3",seasonMaxUb3);
result.put("seasonMaxUb4",seasonMaxUb4);
result.put("seasonClusterUb1",seasonClusterUb1);
result.put("seasonClusterUb2",seasonClusterUb2);
result.put("seasonClusterUb3",seasonClusterUb3);
result.put("seasonClusterUb4",seasonClusterUb4);
result.put("psClusterUb1",psClusterUb1);
result.put("psClusterUb2",psClusterUb2);
result.put("psClusterUb3",psClusterUb3);
result.put("psClusterUb4",psClusterUb4);
result.put("cap1",cap1);
result.put("cap2",cap2);
result.put("cap3",cap3);
result.put("cap4",cap4);
return result;
}
public List dataImportList() {
ImportData importData1 = new ImportData("新建变电站","溪南G134线","2021.11.11 15:11:23");
ImportData importData2 = new ImportData("新建变电站","溪南G134线","2021.11.12 13:32:32");
ImportData importData3 = new ImportData("新建变电站","溪南G134线","2021.11.14 09:34:43");
List<ImportData> result = new ArrayList<ImportData>();
result.add(importData1);
result.add(importData2);
result.add(importData3);
return result;
}
public List lineNameList() {
// allFeederName为查询所有馈线名称。args[1]为存储所有馈线数据的数据库文件的路径
// feederNames为馈线名称列表
SqliteDb sqliteDb = new SqliteDb(allPsDbFile);
List<String> feederNames = sqliteDb.queryAllFeederName(allFeederNameTable);
return feederNames;
}
public Object loadPosAnalysis(String lineName, int cap, int type) {
// loadPos为分析负荷接入位置,args[1]为馈线数据库文件夹的路径,feederDbName为馈线名称,cimFile为.xml文件夹的路径
// args[4]为负荷容量,args[5]为负荷特征(1为峰用电,2为谷用电,3为峰谷用电),args[6]为存储所有馈线数据的数据库文件的路径
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
String[] sourceStationNames = new String[]{sqliteDb.querySubstationName(feederDbName + substationTableName)};
JyPowerSystem ps = new JyPowerSystem(sourceStationNames);
try {
ps.loadFromCimXML(new FileInputStream(new File(cimFile + "\\" + feederDbName + "单线图.sln.xml")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ps.createActiveIslands();
AvailCapModel availCapModel = new AvailCapModel(ps);
availCapModel.buildPaths();
availCapModel.createLoadPosTable(allPsDbFile, loadPosTable);
double loadCap = cap;
int loadType = type;
// 生成负荷曲线
double[] load = new double[96];
double peakAvg = 0.75 * loadCap;
double valleyAvg = 0.4 * loadCap;
double pvAvg = 0.7 * loadCap;
double minLoad = 0.2 * loadCap;
if (loadType == 1) {
load[0] = valleyAvg;
for (int i = 1; i < 32; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[32] = peakAvg;
for (int i = 33; i < 88; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[88] = valleyAvg;
for (int i = 89; i < 96; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
} else if (loadType == 2) {
load[0] = peakAvg;
for (int i = 1; i < 32; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[32] = valleyAvg;
for (int i = 33; i < 88; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
load[88] = peakAvg;
for (int i = 89; i < 96; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
} else if (loadType == 3) {
load[0] = pvAvg;
for (int i = 1; i < 96; i++) {
double r = 0.1 * (Math.random() - 0.5) * loadCap;
load[i] = load[i - 1] + r;
load[i] = Math.min(load[i], loadCap);
load[i] = Math.max(load[i], minLoad);
}
}
for (int i = 0; i < 96; i++) {
System.out.println(load[i] + ",");
}
// 负荷接入分析
LoadPos loadPos = availCapModel.loadPosOpt(load, feederDbName + switchTableName,
feederDbName + availCapTableName, feederDbFile + "\\" + feederDbName + ".db",
feederDbName + substationTableName, feederDbName + feederTableName,
feederDbName + oneLineParamTableName, feederDbName + switchTableName + HistoryData.seasonClusterTable,
feederDbName + swToTfTableName, feederDbName + tfParamTableName,
feederDbName + transformerTableName + HistoryData.tfAvailCapTable,
feederDbName + transformerTableName + HistoryData.seasonClusterTable,
feederDbName + transformerTableName + HistoryData.minITable, allPsDbFile, loadPosTable);
return loadPos;
}
public Map<String,Object> lowMarginAnalysis() {
// feederWarnDev为查询预警元件颜色。args[1]为馈线数据库文件夹路径,feederDbName为查询的馈线名称
// yellowTfs为显示黄色的公变列表,redTfs为显示红色的公变列表,yellowLines为显示黄色的线路列表,redLines为显示红色的线路列表,
// 属性loadState为1表示黄色,为2表示红色,属性mRID为设备mRID
SqliteDb sqliteDb = new SqliteDb(feederDbFile + "\\" + feederDbName + ".db");
List<WarnTf> warnTfs = sqliteDb.queryWarnTf(feederDbName + tfWarnTableName);
List<WarnLine> warnLines = sqliteDb.queryWarnLine(feederDbName + lineWarnTableName);
List<WarnTf> yellowTfs = new LinkedList<>(); // 显示黄色的公变
List<WarnTf> redTfs = new LinkedList<>(); // 显示红色的公变
List<WarnLine> yellowLines = new LinkedList<>(); // 显示黄色的线路
List<WarnLine> redLines = new LinkedList<>(); // 显示红色的线路
for (WarnTf warnTf : warnTfs) {
if (warnTf.getLoadState() == 1)
yellowTfs.add(warnTf);
else
redTfs.add(warnTf);
}
for (WarnLine warnLine : warnLines) {
if (warnLine.getLoadState() == 1)
yellowLines.add(warnLine);
else
redLines.add(warnLine);
}
Map<String,Object> result = new HashMap<>();
result.put("yellowTfs",yellowTfs);
result.put("redTfs",redTfs);
result.put("yellowLines",yellowLines);
result.put("redLines",redLines);
return result;
}
}
package com.jinyun.web.service;
import java.util.List;
import java.util.Map;
public interface SysUserService {
List<Map<String,Object>> findAll();
}
\ No newline at end of file
package com.jinyun.web.service;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.jinyun.web.entity.User;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* @author jinbin
* @date 2018-07-08 21:04
*/
@Service("TokenService")
public class TokenService {
public String getToken(User user) {
String token="";
Date expires = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
token= JWT.create().withExpiresAt(expires)
.withAudience(user.getId())// 将 user id 保存到 token 里面
.sign(Algorithm.HMAC256(user.getPassword()));// 以 password 作为 token 的密钥
return token;
}
}
package com.jinyun.web.service;
import com.jinyun.web.dao.SysUserMapper;
import com.jinyun.web.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author jinbin
* @date 2018-07-08 20:52
*/
@Service("UserService")
public class UserService {
@Autowired
SysUserMapper userMapper;
public User findByUsername(User user){
return userMapper.findByUsername(user.getUsername());
}
public User findUserById(String userId) {
return userMapper.findUserById(userId);
}
}
package com.jinyun.web.service.impl;
import com.jinyun.web.dao.SysUserMapper;
import com.jinyun.web.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class SysUserServiceImpl implements SysUserService {
@Autowired
SysUserMapper sysUserMapper;
@Override
public List<Map<String,Object>> findAll() {
return sysUserMapper.selectAll();
}
}
package com.jinyin.web
import com.alibaba.fastjson.JSONObject
import com.jinyun.web.annotation.UserLoginToken
import com.jinyun.web.entity.User
import com.jinyun.web.service.TokenService
import com.jinyun.web.service.UserService
import io.swagger.annotations.Api
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@Api(value = "desc of class", tags = arrayOf("Login1"), description = "登录")
@RestController
@RequestMapping("login1")
class LoginController {
@Autowired
var userService: UserService? = null
@Autowired
var tokenService: TokenService? = null
//登录
@PostMapping("/login1")
fun login(user: User): Any {
val jsonObject = JSONObject()
val userForBase = userService!!.findByUsername(user)
return if (userForBase == null) {
jsonObject["message"] = "登录失败,用户不存在"
jsonObject
} else {
// if (userForBase.password != user.password) {
// jsonObject["message"] = "登录失败,密码错误"
// jsonObject
// } else {
// val token = tokenService!!.getToken(userForBase)
// jsonObject["token"] = token
// jsonObject["user"] = userForBase
// jsonObject
// }
}
}
@get:GetMapping("/getMessage1")
@get:UserLoginToken
val message: String
get() = "你已通过验证"
}
\ No newline at end of file
server:
port: 8080
spring:
datasource:
driverClassName: org.sqlite.JDBC
url: jdbc:sqlite:D:/test.db
username:
password:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jinyun.web.dao.SysUserMapper">
<select id="selectAll" resultType="map">
select * from test
</select>
<select id="findUserById" resultType="com.jinyun.web.entity.User">
select * from user where id=#{Id}
</select>
<select id="findByUsername" resultType="com.jinyun.web.entity.User">
select * from user where username=#{username}
</select>
</mapper>
\ No newline at end of file
include 'jinyun:availCap',
'jinyun:web'
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论