Subversion Repositories DevTools

Rev

Rev 2195 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2195 brianf 1
@ECHO OFF
2
SETLOCAL ENABLEDELAYEDEXPANSION
3
REM ----------------------------------------------------------------------------------------------
4
REM Script: SOM_Dashboard_query.cmd
5
REM Created: 2011/11/01
6
REM Author: Brian Fergusson
7
REM Version: 1
8
REM Description:
9
REM This is the main script for extracting data for the Testing Statistics SOM Dashboard.
10
REM The result of each dashboard query is outputted to a csv file.
11
REM The queries are run for the previous month of data (Variable, date_code (set below), must be set to 1 for this mode).
12
REM ----------------------------------------------------------------------------------------------
13
 
14
SET DIR_INPUT=.\queries
15
SET DIR_OUTPUT=.\output
16
REM SET DIR_OUTPUT=\\auperanas01\Data\Transit\temp
17
 
18
 
19
REM Disable debug mode
20
SET DEBUG=N
21
SET SERVER_TD=AUPERAMTD01
22
SET SERVER_CQ=AUPERASQL05
23
SET SERVER_JR=AUPERASQL05
24
 
25
REM Versions of each query (for debugging)
26
SET VER_TD=5
27
SET VER_JR=3
28
SET VER_CQ=8
29
 
30
PUSHD .
31
 
32
ECHO.
33
ECHO Test Director Server: %SERVER_TD%
34
ECHO Clear Quest Server:   %SERVER_CQ%
35
ECHO Jira Server:          %SERVER_JR%
36
 
37
REM  get month.  This is for the csv filename
38
SET month_qry=SQLCMD -S%SERVER_TD% -E -Q "SET NOCOUNT ON; select rtrim(year(DATEADD(mm,-1,CURRENT_TIMESTAMP))) + '_' + right('0' + rtrim(month(DATEADD(mm,-1,CURRENT_TIMESTAMP))),2)" -h-1 -s"," -W
39
FOR /f "usebackq tokens=1,2 delims=_" %%A IN (`%month_qry%`) DO (
40
  SET year=%%A
41
  SET month=%%B
42
)
43
 
44
ECHO Query Month:          %year%/%month%
45
 
46
ECHO.
47
ECHO Running SOM Dashboard queries for Month: %year%/%month%
48
ECHO.
49
 
50
REM  query previous month
51
REM date_code is accessed in the sql script
52
SET date_code=1
2209 brianf 53
CALL :query_to_csv %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD.sql"    "%DIR_OUTPUT%\SOM_Dashboard_%year%%month%_TD.csv"    "Test Director"    "-E"
54
CALL :query_to_csv %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ_JR.sql" "%DIR_OUTPUT%\SOM_Dashboard_%year%%month%_CQ_JR.csv" "Clear Quest/Jira" "-E"
2195 brianf 55
 
56
IF %DEBUG% == Y (
57
  REM  This block of code is used for debugging purposes.
58
  REM  It is not required in a live system, ie SET DEBUG=N
59
 
60
  REM  Query data since 2009
61
  SET date_code=2
2209 brianf 62
  CALL :query_to_csv %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD.sql"    "%DIR_OUTPUT%\SOM_Dashboard_Test_TD_TEST_v%VER_TD%.csv"    "Test Director"    "-E"
63
  CALL :query_to_csv %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ_JR.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_CQ_DEVI_v%VER_CQ_JR%.csv" "Clear Quest/Jira" "-E"
2195 brianf 64
 
65
  REM  generate row data for issue investigation purposes
66
  REM  query data for a specific debug date range, See Dashboard_query_init.sql
67
  SET date_code=3
68
  CALL :query_to_csv  %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD_TEST_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_TD_TEST_rows_aug_to_oct_v%VER_TD%.csv" "Test Director" "-E"
69
  CALL :query_to_csv  %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ_DEVI_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_CQ_DEVI_rows_aug_to_oct_v%VER_CQ%.csv" "Clear Quest"   "-E"
70
  CALL :query_to_csv  %SERVER_JR% "%DIR_INPUT%\SOM_Dashboard_query_JR_DEVI_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_JR_DEVI_rows_aug_to_oct_v%VER_JR%.csv" "Jira"          "-E"
71
)
72
 
73
 
74
ECHO.
75
ECHO Completed SOM Dashboard queries for Month: %year%/%month%
76
ECHO.
77
goto end
78
 
79
REM ----------------------------------------------------------------------------------------------
80
: query_to_csv
81
REM  Runs SQLCMD to run the specified query and output the result to the specified output file.
82
REM 
83
REM 
84
 
85
REM Note: %~1: removes surrounding quotes on parameter %1
86
SET server=%1
87
SET inpfile=%~2
88
SET outfile=%~3
89
SET datatitle=%~4
90
SET login=%~5
91
 
92
ECHO   Querying %datatitle% databases...
93
ECHO   Running %inpfile%
94
ECHO   Outputting to:%outfile%
95
 
96
REM outsputs to csv using a comma separater (-s",") and includes a header and no trailing spaces (-W).  Note: to remove headers use (-h-1)
97
REM Run sqlcmd and remove dashed line after the column header
98
 
99
SQLCMD -S%server% %login% -i "%inpfile%" -o "%outfile%" -s"," -W
100
REM   SQLCMD -S%server% %login% -i "%inpfile%" -s"," -W | find /v "-----" > "%outfile%"
101
 
102
ECHO   Completed querying %datatitle% databases.
103
ECHO.
104
GOTO endp
105
REM ----------------------------------------------------------------------------------------------
106
 
107
 
108
:end
109
POPD
110
REM pause
111
:endp