-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIX_Log_Crawler.ps1
176 lines (131 loc) · 6.59 KB
/
FIX_Log_Crawler.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#The below script was developed to crawl through OMS FIX log and return a distribution of particular messages/tag values over given time period.
#Only works with the specific format of log files (not included, since that's confidential proprietary information).
#------------------------------------------------------------------------------
#
# PARAMETER SECTION
#
#------------------------------------------------------------------------------
$logfile = "D:\WorkFolder\Logcrawler\FIX_FileParserLogfile.log"
$FIXfile = "D:\WorkFolder\Logcrawler\FIX_logs\FIX_Log_filename.log"
$starthour = 9
$endhour = 17
$ChartOverhead = 20
#------------------------------------------------------------------------------
$msgType = "Incoming"
"Initialising hash-array" | Out-File $logfile -Append
$BookedTradesPerMin=@{}
for ($hours=0; $hours -lt 24; $hours++){
$BookedTradesPerMin[$hours]=@{}
for ($minutes=0; $minutes -lt 60; $minutes++){
$BookedTradesPerMin[$hours][$minutes]=0
}
}
$SkippedTradesPerMin=@{}
for ($hours=0; $hours -lt 24; $hours++){
$SkippedTradesPerMin[$hours]=@{}
for ($minutes=0; $minutes -lt 60; $minutes++){
$SkippedTradesPerMin[$hours][$minutes]=0
}
}
" " | Out-File $logfile -Append
"Initialising FIX file reader" | Out-File $logfile -Append
$newstreamreader = New-Object System.IO.StreamReader ($FIXfile)
" " | Out-File $logfile -Append
"Dumping all processed lines" | Out-File $logfile -Append
while (($readeachline = $newstreamreader.ReadLine()) -ne $null)
{
if (($readeachline.Contains($msgType)) -and (-not($readeachline.Contains("35=0"))) -and (($readeachline.Contains("150=2")) -or ($readeachline.Contains("150=1")))) {
"Message that WAS booked" | Out-File $logfile -Append
$readeachline | Out-File $logfile -Append
$hourstamp =[int]$readeachline.substring(0,2)
$minutestamp = [int]$readeachline.substring(3,2)
$BookedTradesPerMin[$hourstamp][$minutestamp]++
$hourstamp | Out-File $logfile -Append
$minutestamp | Out-File $logfile -Append
$BookedTradesPerMin[$hourstamp][$minutestamp] | Out-File $logfile -Append
}
if (($readeachline.Contains($msgType)) -and (-not($readeachline.Contains("35=0"))) -and (-not($readeachline.Contains("150=2"))) -and (-not($readeachline.Contains("150=1"))) -and (-not($readeachline.Contains("35=A"))) -and (-not($readeachline.Contains("35=1")))) {
"Message that was NOT booked" | Out-File $logfile -Append
$readeachline | Out-File $logfile -Append
$hourstamp =[int]$readeachline.substring(0,2)
$minutestamp = [int]$readeachline.substring(3,2)
$SkippedTradesPerMin[$hourstamp][$minutestamp]++
$hourstamp | Out-File $logfile -Append
$minutestamp | Out-File $logfile -Append
$SkippedTradesPerMin[$hourstamp][$minutestamp] | Out-File $logfile -Append
}
}
" " | Out-File $logfile -Append
"Consolidating results" | Out-File $logfile -Append
$ResultsConsolidated = [ordered]@{}
for ($hours=$starthour; $hours -lt $endhour; $hours++){
for ($minutes=0; $minutes -lt 60; $minutes++){
$ResultsConsolidated."$($hours):$($minutes)" = @()
$ResultsConsolidated."$($hours):$($minutes)" +="$($BookedTradesPerMin.$($hours).$($minutes))"
$ResultsConsolidated."$($hours):$($minutes)" +="$($SkippedTradesPerMin.$($hours).$($minutes))"
"Outputting both keys separatelly" | Out-File $logfile -Append
$ResultsConsolidated."$($hours):$($minutes)"[0] | Out-File $logfile -Append
$ResultsConsolidated."$($hours):$($minutes)"[1] | Out-File $logfile -Append
}
}
#-------------
#looking for maximum column height
$maxcolumn = 0
foreach ($datapoint in $ResultsConsolidated.GetEnumerator()){
$total = [int]$datapoint.value[0] + [int]$datapoint.value[1]
if ( $total -gt $maxcolumn) {
$maxcolumn =$total
}
}
"Maxcolumn is: $maxcolumn" | Out-File $logfile -Append
"Outputing to chart" | Out-File $logfile -Append
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms.DataVisualization
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$Chart.ChartAreas.Add($ChartArea)
$ChartTypes = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]
$legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
$legend.name = "MainLegend"
$Chart.Legends.Add($legend)
#$Series = New-Object -TypeName System.Windows.Forms.DataVisualization.Charting.Series
#$Series.ChartType = $ChartTypes::StackedColumn
[void]$Chart.Series.Add("Processed")
$Chart.Series["Processed"].ChartType = "StackedColumn"
$XValues = @(foreach($datapoint in $ResultsConsolidated.GetEnumerator()){$datapoint.key})
$YValues = @(foreach($datapoint in $ResultsConsolidated.GetEnumerator()){[int]$datapoint.value[0]})
$Chart.Series["Processed"].Points.DataBindXY($XValues, $YValues)
$Chart.Series["Processed"].IsXValueIndexed = $true
$Chart.Series["Processed"].Color =[System.Drawing.Color]::Magenta
$Chart.Series["Processed"].IsVisibleInLegend = $true
$Chart.Series["Processed"].Legend = "MainLegend"
#----
[void]$Chart.Series.Add("Skipped")
$Chart.Series["Skipped"].ChartType = "StackedColumn"
$XValues2 = @(foreach($datapoint in $ResultsConsolidated.GetEnumerator()){$datapoint.key})
$YValues2 = @(foreach($datapoint in $ResultsConsolidated.GetEnumerator()){[int]$datapoint.value[1]})
$Chart.Series["Skipped"].Points.DataBindXY($XValues2, $YValues2)
$Chart.Series["Skipped"].IsXValueIndexed = $true
$Chart.Series["Skipped"].Color =[System.Drawing.Color]::Blue
$Chart.Series["Skipped"].IsVisibleInLegend = $true
$Chart.Series["Skipped"].Legend = "MainLegend"
$Chart.Width = 1850
$Chart.Height = 1000
$Chart.Left = 0
$Chart.Top = 0
$ChartArea.AxisX.Interval = '20'
$ChartArea.AxisY.Interval = '10'
$ChartArea.AxisY.Maximum =[int]$maxcolumn + [int]$ChartOverhead
$ChartArea.AxisX.LabelStyle.Angle = -90
$ChartArea.AxisX.MajorGrid.LineColor = [System.Drawing.Color]::White
$ChartArea.BackColor = [System.Drawing.Color]::LightGray
$AnchorAll = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor
[System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left
$Form = New-Object Windows.Forms.Form
$Form.Width = 1850
$Form.Height = 1000
$Form.WindowState = System.Windows.Forms.FormWindowState.Maximized;
$Form.controls.add($Chart)
$Chart.Anchor = $AnchorAll
$Form.Add_Shown({$Form.Activate()})
[void]$Form.ShowDialog()