纯批处理版
以题干所列文件名为样本测试- 20190511152311.032357965-CP14.dat
- 20190511152313.030170535-CP14.dat
- 20190511152315.030184055-CP14.dat
- 20190511152317.030193560-CP14.dat
- 20190511152319.030201595-CP14.dat
- 20190511152321.030213575-CP14.dat
- 20190511152323.030224565-CP14.dat
- 20190511152325.030236580-CP14.dat
- 20190511152327.030251605-CP14.dat
- 20190511152329.030265035-CP14.dat
- 20190511152331.030282525-CP14.dat
- 20190511152333.030282450-CP14.dat
- 20190511152335.030294435-CP15.dat
- 20190511152335.030294475-CP14.dat
- 20190511152335.030294495-CP16.dat
- 20190511152337.030309415-CP14.dat
- 20190511152337.030309435-CP16.dat
- 20190511152337.030309455-CP15.dat
复制代码
- @echo off
- setlocal enabledelayedexpansion
-
- set "nFileCount=0"
-
- REM =====统计文件总数
- echo,Step 1 :
- for /f "tokens=*" %%i in ('dir /b *.dat') do (
- set /a "nFileCount+=1"
- )
- echo,统计文件总数为 : !nFileCount!
- echo,&echo,
-
- REM =====统计毫秒、微秒、纳秒数量级分布规律
- echo,Step 2 :
- call :_ShowTimeCount
- REM 显示统计结果
- echo,LEVEL ms次数 us次数 ns次数
- echo,------------------------------------
- for /l %%i in (0 1 9) do (
- echo,%%i00-%%i99 !nMS%%i00%%i99! !nUS%%i00%%i99! !nNS%%i00%%i99!
- )
- echo,&echo,
-
- REM =====显示同一时刻不同网站纳秒差
- echo,Step 3 :
- for /l %%i in (1 1 !nMainCount!) do (
- call :_ShowTimeDiff %%i
- )
-
- pause
- goto :EOF
-
- :_ShowTimeCount
- (
- REM 变量初始化
- for /l %%i in (0 1 9) do (
- set "nMS%%i00%%i99=0"
- set "nUS%%i00%%i99=0"
- set "nNS%%i00%%i99=0"
- )
-
- REM for /l %%i in (0 1 9) do (
- REM echo,nMS%%i00%%i99=!nMS%%i00%%i99!
- REM echo,nUS%%i00%%i99=!nUS%%i00%%i99!
- REM echo,nNS%%i00%%i99=!nNS%%i00%%i99!
- REM )
-
- REM 定义查询字典
- set "strDict="
- REM 统计总时刻数
- set "nMainCount=0"
- for /f "tokens=1,2,3 delims=.-" %%i in ('dir /b *.dat') do (
- REM echo,当前处理信息为 : %%i.%%j-%%k.dat
- set "strMain=%%i"
- set "strS=%%j"
-
- set "nMS=!strS:~0,3!"
- REM echo,当前毫秒值为 : !nMS!
- for /l %%a in (0 1 9) do (
- if "!nMS:~0,1!" EQU "%%a" (
- set /a "nMS%%a00%%a99+=1"
- )
- )
-
- set "nUS=!strS:~3,3!"
- REM echo,当前微秒值为 : !nUS!
- for /l %%a in (0 1 9) do (
- if "!nUS:~0,1!" EQU "%%a" (
- set /a "nUS%%a00%%a99+=1"
- )
- )
-
- set "nNS=!strS:~6!"
- REM echo,当前纳秒值为 : !nNS!
- for /l %%a in (0 1 9) do (
- if "!nNS:~0,1!" EQU "%%a" (
- set /a "nNS%%a00%%a99+=1"
- )
- )
-
- REM 对同一秒内不同站点的纳秒值差进行统计
- REM echo,当前字典 : !strDict!
- echo,!strDict! | findstr "!strMain!" >nul 2>nul && (
- REM 有此时刻统计信息,更新网站数
- set /a "n!strMain!Count+=1"
- ) || (
- REM 无此时刻统计信息
- REM 更新时刻总数
- set /a "nMainCount+=1"
- REM 当前新时刻计数初始化
- set "n!strMain!Count=1"
- REM 更新字典
- set "strDict=!strDict!(!strMain!)"
- )
- REM 更新MAP
- call set "str!strMain!.%%n!strMain!Count%%.Name=%%k"
- call set "str!strMain!.%%n!strMain!Count%%.NS=!nNS!"
- REM echo,当前总时刻数 : nMainCount = !nMainCount!
- REM call echo,当前时刻总数 : n!strMain!Count = %%n!strMain!Count%%
- REM call call echo,当前分析站点 : str!strMain!.%%n!strMain!Count%%.Name = %%%%str!strMain!.%%n!strMain!Count%%.Name%%%%
- REM call call echo,当前分析纳秒 : str!strMain!.%%n!strMain!Count%%.NS = %%%%str!strMain!.%%n!strMain!Count%%.NS%%%%
- )
- for /l %%i in (0 1 9) do (
- set "nMS%%i00%%i99=000000!nMS%%i00%%i99!"
- set "nMS%%i00%%i99=!nMS%%i00%%i99:~-6!"
- set "nUS%%i00%%i99=000000!nUS%%i00%%i99!"
- set "nUS%%i00%%i99=!nUS%%i00%%i99:~-6!"
- set "nNS%%i00%%i99=000000!nNS%%i00%%i99!"
- set "nNS%%i00%%i99=!nNS%%i00%%i99:~-6!"
- )
- goto :EOF
- )
-
- :_ShowTimeDiff
- (
- for /f "tokens=%1 delims=()" %%a in ('echo,!strDict!') do (
- REM echo,当前处理时刻 %%a
- set "strTime=%%a"
- set "nTmpCount=0"
- call set "nTmpCount=%%n!strTime!Count%%"
- REM echo,共有网站记录数 : !nTmpCount!
- set /a "nMin=999"
- set /a "nMax=0"
- set /p=!strTime! <nul
- for /l %%i in (1 1 !nTmpCount!) do (
- REM echo,第 %%i 个网站 :
- call set "strTmpName=%%str!strTime!.%%i.Name%%"
- REM echo,Name : !strTmpName!
- call set "strTmpNS=%%str!strTime!.%%i.NS%%"
- REM call echo,NS : !strTmpNS!
- set /p=!strTmpName!:!strTmpNS! <nul
- if !nMin! GEQ !strTmpNS! set "nMin=!strTmpNS!"
- if !nMax! LEQ !strTmpNS! set "nMax=!strTmpNS!"
- )
- set /a "nDiff=!nMax!-!nMin!"
- echo,Diff:!nDiff!
- )
- goto :EOF
- )
复制代码
|