#!/usr/bin/perl 
use strict;

my $in_net = $ARGV[0];
my @edge;
my @lane;
my @length;
my @tls;
my $avglane;
my $avglength;
my $sum;
my @distribution = (0)x6;

#開啟地圖檔
open FILE, $in_net or die "Loading error!";
#抓取資料
while (<FILE>) {
	if ($_ =~/edge id/) {
		#抓出edge部份
		push @edge, $_;
	}elsif ($_ =~/lane id="[\w\#\-]+"\sindex="[0-9]"\sspeed="[0-9\.]+"\slength="([0-9\.]+)"/) {
		#抓出junction部份
		push @lane, $_;
		push @length, $1;
	}elsif ($_ =~/tlLogic id/) {
		#抓出junction部份
		push @tls, $_;
	}
}
close FILE;

#計算edge平均lane數量
$avglane = @lane/@edge;
print "avglane:"+$avglane+"\n";

#計算lane平均長度
foreach my $val (@length){
	$sum += $val;
}
$avglength = $sum/@length;

#計算lane長度分佈
foreach my $val (@length){
	if ($val<=50) {
		$distribution[0]++;
	}elsif ($val<=75) {
		$distribution[1]++;
	}elsif ($val<=100) {
		$distribution[2]++;
	}elsif ($val<=125) {
		$distribution[3]++;
	}elsif ($val<=150) {
		$distribution[4]++;
	}else {
		$distribution[5]++;
	}
}

#結果輸出
print "<=50\t<=75\t<=100\t<=125\t<=150\t>150\t\n";
foreach my $val (@distribution){
    print $val . "\t";
}
#print "Edge num\t" . @edge . "\nlane num\t" . @lane . "\nlength num\t" . @length . 
"\nTls num\t" . @tls . "\navglane\t" . $avglane . "\navglength\t" . $avglength . 
"\nlength distribution\t\n<=50\t" . $distribution[0] . "\n<=75\t" . $distribution[1] . 
"\n<=100\t" . $distribution[2] . "\n<=125\t" . $distribution[3] . "\n<=150\t" . $distribution[4] . 
"\n>150\t" . $distribution[5] . "\n";
