use GetExcelData;use ReaDWritefile;use Cwd;#获取本地路径模块#获得二维数组的一维全部元素,第三个变量是得到元素的数组引用。sub GetArrayValue{my($inputPoint,$iGetindex,$GetPoint) = @_;my $count = 0;#print "the array is @$inputPoint\n";foreach my $index (@$inputPoint){# print "\nEach Array value is @$index\n";if($iGetindex == $count){push @$GetPoint,@$index;return 1;}$count++;}0;}print "\n正在导入工参数据\n.......";#new一个对象的引用my $ExcelPoint = GetExcelData->new();#获取本地路径下所有EXCEL数据$ExcelPoint->GetAllExcelDate();#获得导入的所有的Excel的名字my @Excelname;@Excelname = $ExcelPoint->GetExcelname();#print "\nExcel name is @Excelname\n";print "\n数据导入完毕,按任意键继续......\n";my $input = <STDIN>;my $Excelname = "ex.xlsx";my $Sheetname = "Project Parameters";my @ProjectContent;my $iRowNum = $ExcelPoint->GetExcelSheetRowNum($Excelname,$Sheetname);foreach my $Iindex(3..$iRowNum){my @SheetRowDate = $ExcelPoint->GetExcelSheetRowDate($Excelname,$Sheetname,$Iindex);my $subnetID = $SheetRowDate[1];my $MEID = $SheetRowDate[2];my $eNodeB = $SheetRowDate[4];my $MCC = $SheetRowDate[9];my $MNC = $SheetRowDate[10];my $Lon = $SheetRowDate[6];my $Lat = $SheetRowDate[7];my $CellID = $SheetRowDate[12];#print "$subnetID is $subnetID\n";#print "$MEID is $MEID\n";#print "$eNodeB is $eNodeB\n";#print "$MCC is $MCC\n";#print "$MNC is $MNC\n";#print "$Lon is $Lon\n";#print "$Lat is $Lat\n";my @ProjectInfo;push @ProjectInfo,$subnetID;push @ProjectInfo,$MEID;push @ProjectInfo,$eNodeB;push @ProjectInfo,$MCC;push @ProjectInfo,$MNC;push @ProjectInfo,$Lon;push @ProjectInfo,$Lat;push @ProjectInfo,$CellID;my $Connet = join "&",@ProjectInfo;#存入工参所有相关小区信息push @ProjectContent,$Connet;}my $iProjectSize = @ProjectContent;print "\n工参的大小 $iProjectSize\n";#保存生成的SQL语句my @CellinsertValue;#获取本地路径my $dir = getcwd;#保存成功执行的sql$filePath = $dir."\生成语句\生成执行.sql";#获取对象引用my $filePoint = ReaDWritefile->new();my $sqlNumSize = 0;print "\n语句生成中,请耐心等待......\n";foreach my $Value (@ProjectContent){my $MaxsqlNum = 15;#每个小区最多生成的SQL语句数my $sqlNum = &GetRoundNum($MaxsqlNum);while($sqlNum == 0){$sqlNum = &GetRoundNum($MaxsqlNum);}@CellinsertValue = &GetCellinsersql($sqlNum,$Value,\@ProjectContent);my $Arraysize = @CellinsertValue;$sqlNumSize = $sqlNumSize + $Arraysize;#print "数组大小为 $Arraysize";#my $inputin = <STDIN>;$filePoint->WriteDatetofileAdd($filePath,@CellinsertValue);}print "\n共生成$sqlNumSize条测试语句\n";print "\n完成任务,按任意键退出....\n";my $inputTest = <STDIN>;sub GetRoundNum{my $MaxValue = shift;my $GetValue = int(rand($MaxValue));return $GetValue;}sub GetCellinsersql{my $sqlNum = shift;my $Value = shift;my $ProjectPoint = shift;my @ProjectContent = @$ProjectPoint;my @Generatesql;foreach my $Index (1..$sqlNum){# print "*" x 20,".\n";# print "\n第$Index条数据生成完毕\n";# print "*" x 20,".\n";my @sql = &GenerateEachsql($Value,\@ProjectContent);#print "\n最终生成的sql值@sql\n";# PrintOutsql(@sql);my $Insertsql = "insert into t054(D004,D005,D020,C001,C009,C010,C011,C012,C013,C015,C016,C017,C018,C019,C020)values";my $value ="($sql[0],$sql[1],'$sql[2]',$sql[3],$sql[4],$sql[5],$sql[6],'$sql[7]','$sql[8]','$sql[9]','$sql[10]',$sql[23],$sql[24],$sql[11],$sql[19])";# print "\nvalue is $value\n";my $resultsql = $Insertsql.$value."\n";# print "\n生成的sql是$resultsql\n";#my $test = <STDIN>;push @Generatesql,$resultsql;}return @Generatesql;}sub PrintOutsql{print "\n生成的数据为\n";@sql = @_;print "\nD004 is $sql[0]\n";print "\nD005 is $sql[1]\n";print "\nD020 is $sql[2]\n";print "\nC001 is $sql[3]\n";print "\nC009 is $sql[4]\n";print "\nC010 is $sql[5]\n";print "\nC011 is $sql[6]\n";print "\nC012 is $sql[7]\n";print "\nC013 is $sql[8]\n";print "\nC015 is $sql[9]\n";print "\nC016 is $sql[10]\n";print "\nC019 is $sql[11]\n";print "\nC020 is $sql[12]\n";print "\nC021 is $sql[13]\n";print "\nC022 is $sql[14]\n";print "\nC023 is $sql[15]\n";print "\nC024 is $sql[16]\n";print "\nC025 is $sql[17]\n";print "\nC026 is $sql[18]\n";print "\nC027 is $sql[19]\n";print "\nC029 is $sql[20]\n";print "\nC031 is $sql[21]\n";print "\nC032 is $sql[22]\n";}sub GenerateEachsql{my $Value = shift;my $ProjectPoint = shift;my @ProjectContent = @$ProjectPoint;my @SheetRowDate = split "&",$Value;my $subnetID = $SheetRowDate[0];my $MEID = $SheetRowDate[1];my $eNodeB = $SheetRowDate[2];my $MCC = $SheetRowDate[3];my $MNC = $SheetRowDate[4];my $Lon = $SheetRowDate[5];my $Lat = $SheetRowDate[6];my $CellID = $SheetRowDate[7];my $MaxRand = 10000;my $D004 = $eNodeB;my $D005 = $CellID;my $D020 = &GetRoundNum($MaxRand);my $C001 = &GetRoundNum($MaxRand);#RSRP与RSRQmy $MaxRsValue = 43;my $MaxRqValue = 17;my $C009 = &GetRoundNum($MaxRsValue);my $C010 = &GetRoundNum($MaxRqValue);$C009 = $C009 -140;$C010 = $C010 -20;#邻区数据邻区数目my $NeighSize = @ProjectContent;my $NeighMaxSize = 10;my $C011 = &GetRoundNum($NeighMaxSize);while($C011 == 0){$C011 = &GetRoundNum($NeighMaxSize);#test#print"\n邻区为0的循环执行了 $C011\n";#my $test = <STDIN>;}#控制最大邻区数目if($C011 > 30){$C011 = $C011 - 4;}my @EnodArray;my @CellArray;my @RsrpArray;my @RsrqArray;#获取邻区数据&GetNeighInfo($C011,\@EnodArray,\@CellArray,\@RsrpArray,\@RsrqArray,\@ProjectContent);#enodb序列my $C012 = join ",",@EnodArray;#cell序列my $C013 = join ",@CellArray;#邻区RSRP数据my $C015 = join ",@RsrpArray;#邻区RSRQ数据my $C016 = join ",@RsrqArray;#表示是MDT数据my $C019 = 3;my $C020 = 0;#是服务小区最近一次RSRP和RSRQ值my $C021 = &GetRoundNum($MaxRsValue);my $C022 = &GetRoundNum($MaxRqValue);$C021 = $C021 -140;$C022 = $C022 -20;my $C023 = $eNodeB;my $C024 = $CellID;#重新建立小区的信息my @RandCell = &GetRondCell(@ProjectContent);#重建立小区enodbIDmy $C025 = $RandCell[2];#重建立小区CellIDmy $C026 = $RandCell[7];#PHR默认值(这两个门限值,后续要根据算法重新设定)my $PHMax = 15;my $C027 = &GetRoundNum($PHMax);my $C029 = &GetRoundNum($PHMax);#RSRP经纬度my $MasValue = 100;my $tempvalue = &GetRoundNumSuborAdd($MasValue);my $C017 = $Lon + 0.001 * $tempvalue;$tempvalue = &GetRoundNumSuborAdd($MasValue);my $C018 = $Lat + 0.001 * $tempvalue;#小区经纬度$tempvalue = &GetRoundNumSuborAdd($MasValue);my $C031 = $Lat + 0.001 * $tempvalue;$tempvalue = &GetRoundNumSuborAdd($MasValue);my $C032 = $Lon + 0.001 * $tempvalue;my @sql = ($D004,$D005,$D020,$C001,$C009,$C010,$C011,$C012,$C013,$C015,$C016,$C019,$C020,$C021,$C022,$C023,$C024,$C025,$C026,$C027,$C029,$C031,$C032,$C017,$C018);return @sql;}sub GetRoundNumSuborAdd{my $MaxValue = shift;my $GetValue = int(rand($MaxValue));my $Point = int(rand(2));if($Point == 0){$GetValue = -$GetValue;}return $GetValue;}#获得邻区数据sub GetNeighInfo{#数组硬指针my $NeighNum = shift;my $Value = shift;my $EnodPoint = shift;my $CellPoint = shift;my $RsrpPoint = shift;my $RsrqPoint = shift;my $ProjectPoint = shift;my $CellValue = GetRondCellValue(@$ProjectPoint);my @NeighArray;push @NeighArray,$Value ;my $count = 1;if($NeighNum != 1){$NeighNum = $NeighNum - 1;}while($count <= $NeighNum){#包含邻区数据重新生成my $TestCount = 1;while(@NeighArray ~~ $CellValue){$CellValue = GetRondCellValue(@$ProjectPoint);if($TestCount > 25){#print "\n死循环内执行超过25次了\n";#print "\n邻区数目是$NeighNum\n";#print "\n生成的邻区数据是$count\n";#print "\n数据是@NeighArray\n";#print "\n生成的值是$CellValue\n";#my $test = <STDIN>;}$TestCount++;}push @NeighArray,$CellValue;$count++;}shift @NeighArray;foreach my $Value (@NeighArray){my @SplitResult = split "&",$Value;my $eNodeB = $SplitResult[2];my $CellID = $SplitResult[7];push @$EnodPoint,$eNodeB;push @$CellPoint,$CellID;#RSRP与RSRQmy $MaxRsValue = 43;my $Rsrp = &GetRoundNum($MaxRsValue);$Rsrp = $Rsrp - 140;push @$RsrpPoint,$Rsrp;my $MaxRqValue = 17;my $Rsrq = &GetRoundNum($MaxRqValue);$Rsrq = $Rsrq - 20;push @$RsrqPoint,$Rsrq;}}#获取一个随机的小区sub GetRondCell{my @ProjectContent = @_;my $CellSize = @ProjectContent;my $Index = &GetRoundNum($CellSize);my $CellValue = @ProjectContent[$Index];my @Cellinfo = split "&",$CellValue;return @Cellinfo;}#获取一个随机的小区sub GetRondCellValue{my @ProjectContent = @_;my $CellSize = @ProjectContent;my $Index = &GetRoundNum($CellSize);my $CellValue = @ProjectContent[$Index];return $CellValue;}sub GetfloatRandValue{my $max = shift;#生成整数部分my $IntValue = &GetRoundNum($max);my $Maxfloat = 100;#生成小数部分my $floatValue = &GetRoundNum($Maxfloat);#生成假浮点数my $floatValue = $IntValue + 0.01 * $floatValue;return $floatValue;}#print "Row Date is @SheetRowDate\n";总结
以上是内存溢出为你收集整理的PERL 生成数据全部内容,希望文章能够帮你解决PERL 生成数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)